"use client"; /** * Figma: "Modal / Customize (template)" (24991:40503). * Name, optional logo, description, and optional location before the * template decks. */ import { useEffect, useState } from "react"; import Button from "../../../components/buttons/Button"; import Icon from "../../../components/asset/icon"; import TextInput from "../../../components/controls/TextInput"; import TextArea from "../../../components/controls/TextArea"; import Create from "../../../components/modals/Create"; import HeaderLockup from "../../../components/type/HeaderLockup"; import InputLabel from "../../../components/type/InputLabel"; import { useMessages, useTranslation } from "../../../contexts/MessagesContext"; import { COMMUNITY_TITLE_FIELD_MAX_LENGTH } from "./FinalReviewTitleEditModal"; import { COMMUNITY_CONTEXT_FIELD_MAX_LENGTH } from "./FinalReviewCommunityContextEditModal"; import { useCommunityAvatarUpload } from "../hooks/useCommunityAvatarUpload"; import type { TemplateCustomizeFields } from "../hooks/useTemplateReviewActions"; const COMMUNITY_LOCATION_MAX_LENGTH = 200; const COUNT_WORD_KEYS = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", ] as const; function countWord( count: number, words: Record, ): 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)}