diff --git a/app/(app)/create/CreateFlowLayoutClient.tsx b/app/(app)/create/CreateFlowLayoutClient.tsx index 33ce2ab..85496b7 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"; @@ -323,6 +324,9 @@ function CreateFlowLayoutContent({ setTemplateReviewApplyError, handleCustomize: handleCustomizeTemplate, handleUseWithoutChanges: handleUseTemplateWithoutChanges, + customizeDialog, + closeCustomizeDialog, + confirmCustomizeDialog, } = useTemplateReviewActions({ pathname, state, @@ -876,6 +880,25 @@ function CreateFlowLayoutContent({ backdropVariant="blurredYellow" ariaLabel={messages.create.topNav.leaveConfirmTitle} /> + , +): 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)} +

+
+
+