From cec83eb27f37ff9634f738d89fb69326742d2468 Mon Sep 17 00:00:00 2001 From: adilallo <39313955+adilallo@users.noreply.github.com> Date: Thu, 5 Nov 2026 21:02:04 -0700 Subject: [PATCH] Clear leftover setup answers on template paths that skip those questions, and treat Continue as an edit so restored ticks are not overwritten. --- app/(app)/create/CreateFlowLayoutClient.tsx | 1 + .../create/hooks/useTemplateReviewActions.ts | 12 ++++--- .../hooks/useTemplateReviewActions.test.tsx | 34 +++++++++++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/app/(app)/create/CreateFlowLayoutClient.tsx b/app/(app)/create/CreateFlowLayoutClient.tsx index 770eead..6a968a6 100644 --- a/app/(app)/create/CreateFlowLayoutClient.tsx +++ b/app/(app)/create/CreateFlowLayoutClient.tsx @@ -999,6 +999,7 @@ function CreateFlowLayoutContent({ } className={CREATE_FLOW_FOOTER_BUTTON_CLASS} onClick={() => { + markCreateFlowInteraction(); goToNextStep(); }} > diff --git a/app/(app)/create/hooks/useTemplateReviewActions.ts b/app/(app)/create/hooks/useTemplateReviewActions.ts index 808715e..e44321b 100644 --- a/app/(app)/create/hooks/useTemplateReviewActions.ts +++ b/app/(app)/create/hooks/useTemplateReviewActions.ts @@ -30,7 +30,9 @@ export type UseTemplateReviewActionsResult = { * Customize: apply the template's selections onto state and route to * `/create/core-values` (if community name is set) or `/create/informational` * with a `pendingTemplateAction` pin so `/create/review` can later replace - * itself with `/create/core-values`. + * itself with `/create/core-values`. A named community skips setup + * questions, so leftover setup answers are dropped and cannot change + * suggested cards. */ handleCustomize: () => Promise; /** @@ -39,8 +41,9 @@ export type UseTemplateReviewActionsResult = { * Customize) so drilling from final-review via + shows selected cards, drop * the Values row from `state.sections`. Direct template entry routes to * `/create/community-name` with a pin so Next/Back collect only name → - * description → photo. In-flow (`?fromFlow=1`, community steps already done) - * routes to `/create/confirm-stakeholders`. + * description → photo, and drops leftover setup answers along with the + * other identity fields. In-flow (`?fromFlow=1`, community steps already + * done) routes to `/create/confirm-stakeholders` and keeps those answers. */ handleUseWithoutChanges: () => Promise; }; @@ -128,7 +131,7 @@ export function useTemplateReviewActions({ }, templateReviewBackSlug: undefined, ...(hasCommunityName - ? { pendingTemplateAction: undefined } + ? { pendingTemplateAction: undefined, setupTraits: undefined } : { pendingTemplateAction: { slug: templateReviewSlug, @@ -256,6 +259,7 @@ export function useTemplateReviewActions({ communityAvatarUrl: undefined, currentStep: undefined, templateReviewEntryFromCreateFlow: undefined, + setupTraits: undefined, pendingTemplateAction: { slug: templateReviewSlug, mode: "useWithoutChanges", diff --git a/tests/unit/hooks/useTemplateReviewActions.test.tsx b/tests/unit/hooks/useTemplateReviewActions.test.tsx index b183fbb..458f276 100644 --- a/tests/unit/hooks/useTemplateReviewActions.test.tsx +++ b/tests/unit/hooks/useTemplateReviewActions.test.tsx @@ -91,6 +91,7 @@ describe("useTemplateReviewActions", () => { title: "Neighborhood", communityContext: "Stale description", currentStep: "confirm-stakeholders", + setupTraits: { employer: true, network: false }, }); }, ); @@ -104,6 +105,7 @@ describe("useTemplateReviewActions", () => { expect(applied?.title).toBeUndefined(); expect(applied?.communityContext).toBeUndefined(); expect(applied?.currentStep).toBeUndefined(); + expect(applied?.setupTraits).toBeUndefined(); expect(applied?.pendingTemplateAction?.mode).toBe("useWithoutChanges"); }); @@ -114,6 +116,7 @@ describe("useTemplateReviewActions", () => { title: "Neighborhood", communityContext: "We meet weekly", templateReviewEntryFromCreateFlow: true, + setupTraits: { employer: true }, }); }, ); @@ -129,7 +132,38 @@ describe("useTemplateReviewActions", () => { expect(router.push).toHaveBeenCalledWith("/create/confirm-stakeholders"); expect(applied?.title).toBe("Neighborhood"); expect(applied?.communityContext).toBe("We meet weekly"); + expect(applied?.setupTraits).toEqual({ employer: true }); expect(applied?.pendingTemplateAction).toBeUndefined(); expect(applied?.templateReviewBackSlug).toBe("mutual-aid-mondays"); }); + + it("customize with a community name drops leftover setup answers", async () => { + const { result } = renderActions({ + title: "Neighborhood", + setupTraits: { employer: true }, + }); + + await act(async () => { + await result.current.handleCustomize(); + }); + + expect(router.push).toHaveBeenCalledWith("/create/core-values"); + expect(updateState).toHaveBeenCalledWith( + expect.objectContaining({ setupTraits: undefined }), + ); + }); + + it("customize without a community name leaves setup answers for the questionnaire", async () => { + const { result } = renderActions({ + setupTraits: { employer: true }, + }); + + await act(async () => { + await result.current.handleCustomize(); + }); + + expect(router.push).toHaveBeenCalledWith("/create/informational"); + const patch = updateState.mock.calls[0]?.[0] as CreateFlowState; + expect(patch).not.toHaveProperty("setupTraits"); + }); });