import { FormEvent, useEffect, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { PlusCircle } from "lucide-react"; import * as Dialog from "@/components/Dialog"; import { Input } from "@/components/Input"; import { Button } from "@/components/Button"; type Props = { open: boolean; onOpenChange: (open: boolean) => void; onCreate: (name: string) => void; }; export const NewProfileModal = ({ open, onOpenChange, onCreate }: Props) => { const { t } = useTranslation(); const [name, setName] = useState(""); const [error, setError] = useState(null); const inputRef = useRef(null); useEffect(() => { if (!open) { setName(""); setError(null); } }, [open]); const handleSubmit = (e: FormEvent) => { e.preventDefault(); const trimmed = name.trim(); if (trimmed.length === 0) { setError(t("profile.dialog.required")); inputRef.current?.focus(); return; } onCreate(trimmed); onOpenChange(false); }; const handleChange = (value: string) => { setName(value); if (error) setError(null); }; return ( e.preventDefault()}>
{t("profile.dialog.title")} {t("profile.dialog.description")}
handleChange(e.target.value)} error={error ?? undefined} />
); };