diff --git a/app/(app)/create/CreateFlowLayoutClient.tsx b/app/(app)/create/CreateFlowLayoutClient.tsx index 5b73d0f..2310da6 100644 --- a/app/(app)/create/CreateFlowLayoutClient.tsx +++ b/app/(app)/create/CreateFlowLayoutClient.tsx @@ -866,24 +866,18 @@ function CreateFlowLayoutContent({ valuesCount={customizeDialog?.valuesCount ?? 0} cardsCount={customizeDialog?.cardsCount ?? 0} initialTitle={ - fromCreateWizard && state.templateReviewEntryFromCreateFlow === true - ? typeof state.title === "string" - ? state.title - : "" + fromCreateWizard && typeof state.title === "string" + ? state.title : "" } initialDescription={ - fromCreateWizard && state.templateReviewEntryFromCreateFlow === true - ? typeof state.communityContext === "string" - ? state.communityContext - : "" + fromCreateWizard && typeof state.communityContext === "string" + ? state.communityContext : "" } initialLocation={ - fromCreateWizard && state.templateReviewEntryFromCreateFlow === true - ? typeof state.communityLocation === "string" - ? state.communityLocation - : "" + fromCreateWizard && typeof state.communityLocation === "string" + ? state.communityLocation : "" } onClose={closeCustomizeDialog} diff --git a/app/(app)/create/hooks/useTemplateReviewActions.ts b/app/(app)/create/hooks/useTemplateReviewActions.ts index 887752a..0eba944 100644 --- a/app/(app)/create/hooks/useTemplateReviewActions.ts +++ b/app/(app)/create/hooks/useTemplateReviewActions.ts @@ -145,8 +145,7 @@ export function useTemplateReviewActions({ pathname?.includes("/create/review-template/"), ); - const keepInFlowIdentity = - fromCreateWizard && state.templateReviewEntryFromCreateFlow === true; + const keepInFlowIdentity = fromCreateWizard; const confirmReplaceDraft = useCallback(async (): Promise => { if (!requestConfirm) return true; @@ -253,6 +252,7 @@ export function useTemplateReviewActions({ title: state.title, communityContext: state.communityContext, communityLocation: state.communityLocation, + communityAvatarUrl: state.communityAvatarUrl, } : undefined, }), @@ -264,6 +264,7 @@ export function useTemplateReviewActions({ markCreateFlowInteraction, replaceState, router, + state.communityAvatarUrl, state.communityContext, state.communityLocation, signedIn, diff --git a/docs/create-flow.md b/docs/create-flow.md index c4cf1a5..f09bcab 100644 --- a/docs/create-flow.md +++ b/docs/create-flow.md @@ -91,7 +91,7 @@ From that page, **Customize** opens a dialog for name, optional logo, descriptio - **Use without changes (direct)** — home Popular templates, `/templates` without `fromFlow`, or a pasted review-template URL. Identity is collected on the name, description, and photo screens. Back from name returns to template review. - **Use without changes (in-flow)** — `/create/review` → `/create/templates` → template. Community identity is already collected and pre-fills those three screens. Back from name still returns to template review. -**Direct entry vs in-flow template pick.** The same `/create/review-template/[slug]` URL is reached from two different origins. **Direct** picks (home Popular templates, `/templates`) do not wipe a draft on click. **Use without changes** and **Customize** ask before replacing a draft, then seed from the template with no leftover logo or setup answers. **In-flow** picks (`/create/templates?fromFlow=1`) keep the community name, description, and place already given. A hydration latch stops a saved server draft from overwriting the template after apply. +**Direct entry vs in-flow template pick.** The same `/create/review-template/[slug]` URL is reached from two different origins. **Direct** picks (home Popular templates, `/templates`) do not wipe a draft on click. **Use without changes** and **Customize** ask before replacing a draft, then seed from the template. Direct entry drops a leftover logo and setup answers. **In-flow** picks (`/create/templates?fromFlow=1`) keep the community name, description, place, and photo already given. A hydration latch stops a saved server draft from overwriting the template after apply. | Origin | Click-site behavior | URL the user lands on | | --- | --- | --- | diff --git a/lib/create/applyTemplatePrefill.ts b/lib/create/applyTemplatePrefill.ts index 16318f4..b6f9f74 100644 --- a/lib/create/applyTemplatePrefill.ts +++ b/lib/create/applyTemplatePrefill.ts @@ -238,6 +238,7 @@ export type TemplateApplyIdentity = { title?: string; communityContext?: string; communityLocation?: string; + communityAvatarUrl?: string; }; /** @@ -256,6 +257,7 @@ export function buildAppliedTemplateCreateFlowState(args: { const title = args.identity?.title?.trim(); const communityContext = args.identity?.communityContext?.trim(); const communityLocation = args.identity?.communityLocation?.trim(); + const communityAvatarUrl = args.identity?.communityAvatarUrl?.trim(); const seeded: CreateFlowState = { ...prefill, @@ -274,6 +276,7 @@ export function buildAppliedTemplateCreateFlowState(args: { seeded.summary = communityContext; } if (communityLocation) seeded.communityLocation = communityLocation; + if (communityAvatarUrl) seeded.communityAvatarUrl = communityAvatarUrl; if (args.identity) seeded.templateReviewEntryFromCreateFlow = true; if (args.mode === "useWithoutChanges") { diff --git a/tests/unit/applyTemplatePrefill.test.ts b/tests/unit/applyTemplatePrefill.test.ts index cc335a0..52cd818 100644 --- a/tests/unit/applyTemplatePrefill.test.ts +++ b/tests/unit/applyTemplatePrefill.test.ts @@ -248,6 +248,28 @@ describe("buildAppliedTemplateCreateFlowState", () => { mode: "useWithoutChanges", }); }); + + it("keeps an in-flow photo when identity includes it", () => { + const seeded = buildAppliedTemplateCreateFlowState({ + slug: "mutual-aid-mondays", + body: { + sections: [ + { + categoryName: "Communication", + entries: [{ title: "Signal" }], + }, + ], + }, + mode: "useWithoutChanges", + identity: { + title: "Neighborhood", + communityAvatarUrl: " /api/uploads/logo ", + }, + }); + expect(seeded.title).toBe("Neighborhood"); + expect(seeded.communityAvatarUrl).toBe("/api/uploads/logo"); + expect(seeded.templateReviewEntryFromCreateFlow).toBe(true); + }); }); describe("templatePresetDetailsFromPrefill", () => { diff --git a/tests/unit/hooks/useTemplateReviewActions.test.tsx b/tests/unit/hooks/useTemplateReviewActions.test.tsx index ccd60f5..fc6e8b8 100644 --- a/tests/unit/hooks/useTemplateReviewActions.test.tsx +++ b/tests/unit/hooks/useTemplateReviewActions.test.tsx @@ -145,12 +145,13 @@ describe("useTemplateReviewActions", () => { }); }); - it("in-flow Use without changes keeps the community name and pins the template path", async () => { + it("in-flow Use without changes keeps the community name, photo, and pins the template path", async () => { const { result } = renderActions( { title: "Neighborhood", communityContext: "We meet weekly", - templateReviewEntryFromCreateFlow: true, + communityLocation: "Oakland", + communityAvatarUrl: "/api/uploads/logo", }, true, ); @@ -162,6 +163,8 @@ describe("useTemplateReviewActions", () => { expect(router.push).toHaveBeenCalledWith("/create/community-name"); expect(applied?.title).toBe("Neighborhood"); expect(applied?.communityContext).toBe("We meet weekly"); + expect(applied?.communityLocation).toBe("Oakland"); + expect(applied?.communityAvatarUrl).toBe("/api/uploads/logo"); expect(applied?.setupTraits).toBeUndefined(); expect(applied?.pendingTemplateAction).toEqual({ slug: "mutual-aid-mondays", @@ -170,6 +173,24 @@ describe("useTemplateReviewActions", () => { expect(applied?.templateReviewBackSlug).toBe("mutual-aid-mondays"); }); + it("a persisted in-flow flag without ?fromFlow=1 clears leftover identity", async () => { + const { result } = renderActions( + { + title: "Neighborhood", + communityAvatarUrl: "/api/uploads/logo", + templateReviewEntryFromCreateFlow: true, + }, + false, + ); + + await act(async () => { + await result.current.handleUseWithoutChanges(); + }); + + expect(applied?.title).toBeUndefined(); + expect(applied?.communityAvatarUrl).toBeUndefined(); + }); + it("asks before replacing a draft in progress", async () => { requestConfirm.mockResolvedValueOnce(false); const { result } = renderActions({ title: "Juniper Street Tenants" });