diff --git a/app/(app)/create/CreateFlowLayoutClient.tsx b/app/(app)/create/CreateFlowLayoutClient.tsx index 33ce2ab..89e0d01 100644 --- a/app/(app)/create/CreateFlowLayoutClient.tsx +++ b/app/(app)/create/CreateFlowLayoutClient.tsx @@ -15,6 +15,7 @@ import { useCreateFlowExit } from "./hooks/useCreateFlowExit"; import { usePrefetchMethodFacetRecommendations } from "./hooks/usePrefetchMethodFacetRecommendations"; import { useCreateFlowFinalize } from "./hooks/useCreateFlowFinalize"; import { useTemplateReviewActions } from "./hooks/useTemplateReviewActions"; +import { TemplateCustomizeDialog } from "./components/TemplateCustomizeDialog"; import { useCompletedRuleShareExport } from "./hooks/useCompletedRuleShareExport"; import CreateFlowFooter from "../../components/navigation/CreateFlowFooter"; import CreateFlowTopNav from "../../components/navigation/CreateFlowTopNav"; @@ -24,6 +25,7 @@ import { CREATE_FLOW_REVIEW_RETURN_QUERY_KEY, getNextStep, parseReviewReturnSearchParam, + templatePathSkippedCommunityRedirect, shouldOfferCreateFlowSaveAndExit, isDirectTemplateReviewEntry, createFlowStepUsesSelectSplitScroll, @@ -100,6 +102,7 @@ import { EMPTY_SETUP_TRAITS, hasTickedSetupTrait, } from "../../../lib/create/setupTraits"; +import { templatePathFromState } from "../../../lib/create/templatePath"; import { useAuthModal } from "../../contexts/AuthModalContext"; import { useMessages, useTranslation } from "../../contexts/MessagesContext"; import { PostLoginDraftTransfer } from "./PostLoginDraftTransfer"; @@ -323,6 +326,9 @@ function CreateFlowLayoutContent({ setTemplateReviewApplyError, handleCustomize: handleCustomizeTemplate, handleUseWithoutChanges: handleUseTemplateWithoutChanges, + customizeDialog, + closeCustomizeDialog, + confirmCustomizeDialog, } = useTemplateReviewActions({ pathname, state, @@ -420,7 +426,18 @@ function CreateFlowLayoutContent({ await runAuthenticatedExit(opts); }; + const templatePathRedirect = templatePathSkippedCommunityRedirect( + currentStep, + templatePathFromState(state)?.mode, + ); + useEffect(() => { + if (!templatePathRedirect) return; + router.replace(createFlowStepPath(templatePathRedirect)); + }, [router, templatePathRedirect]); + + useEffect(() => { + if (templatePathRedirect) return; if ( sessionResolved && sessionUser && @@ -428,7 +445,7 @@ function CreateFlowLayoutContent({ ) { router.replace(CREATE_ROUTES.review); } - }, [sessionResolved, sessionUser, currentStep, router]); + }, [sessionResolved, sessionUser, currentStep, router, templatePathRedirect]); useEffect(() => { clearAttempted(); @@ -876,6 +893,25 @@ function CreateFlowLayoutContent({ backdropVariant="blurredYellow" ariaLabel={messages.create.topNav.leaveConfirmTitle} /> + - {children} + {templatePathRedirect ? null : children} - {!isCompletedStep && ( + {!isCompletedStep && !templatePathRedirect && ( , +): string { + const key = String(count); + if ((COUNT_WORD_KEYS as readonly string[]).includes(key)) { + const word = words[key]; + if (typeof word === "string" && word.length > 0) return word; + } + return key; +} + +function countPhrase( + count: number, + one: string, + many: string, + words: Record, +): string { + if (count === 1) return one; + return many.replace("{word}", countWord(count, words)); +} + +export function TemplateCustomizeDialog({ + isOpen, + templateTitle, + valuesCount, + cardsCount, + initialTitle, + initialDescription, + initialLocation, + onClose, + onContinue, +}: { + isOpen: boolean; + templateTitle: string; + valuesCount: number; + cardsCount: number; + initialTitle: string; + initialDescription: string; + initialLocation: string; + onClose: () => void; + onContinue: (_fields: TemplateCustomizeFields) => void; +}) { + const copy = useMessages().create.templateCustomize; + const tName = useTranslation("create.community.communityName"); + const tContext = useTranslation("create.community.communityContext"); + const avatar = useCommunityAvatarUpload(); + + const [title, setTitle] = useState(initialTitle); + const [description, setDescription] = useState(initialDescription); + const [location, setLocation] = useState(initialLocation); + const [attempted, setAttempted] = useState(false); + + useEffect(() => { + if (!isOpen) { + setAttempted(false); + return; + } + setTitle(initialTitle); + setDescription(initialDescription); + setLocation(initialLocation); + }, [isOpen, initialTitle, initialDescription, initialLocation]); + + const words = copy.countWords; + const valuesPhrase = countPhrase( + valuesCount, + copy.valuesOne, + copy.valuesMany, + words, + ); + const cardsPhrase = countPhrase( + cardsCount, + copy.cardsOne, + copy.cardsMany, + words, + ); + const heading = copy.title.replace("{template}", templateTitle); + const lockupDescription = copy.description + .replaceAll("{template}", templateTitle) + .replace("{valuesPhrase}", valuesPhrase) + .replace("{cardsPhrase}", cardsPhrase); + + const trimmedTitle = title.trim(); + const nameError = attempted && trimmedTitle.length === 0; + const canContinue = trimmedTitle.length > 0 && !avatar.busy; + + const nameHint = nameError ? copy.nameRequired : copy.nameHint; + + const handleContinue = () => { + setAttempted(true); + if (!canContinue) return; + onContinue({ + title: trimmedTitle, + communityContext: description.trim(), + communityLocation: location.trim(), + }); + }; + + return ( + + + + } + showBackButton={false} + showCancelButton + showNextButton + cancelButtonText={copy.cancel} + nextButtonText={copy.continue} + nextButtonDisabled={!canContinue} + onCancel={onClose} + onNext={handleContinue} + > +
+ setTitle(event.target.value)} + inputSize="medium" + formHeader + showHelpIcon={false} + textHint={nameHint} + error={nameError} + maxLength={COMMUNITY_TITLE_FIELD_MAX_LENGTH} + required + autoFocus + /> +
+ +
+ void avatar.handleFileChange(event)} + /> + +

+ {avatar.errorMessage ?? + (avatar.fileName && avatar.displaySrc + ? avatar.fileName + : copy.logoHint)} +

+
+
+