diff --git a/src/modules/registratura/components/quick-contact-dialog.tsx b/src/modules/registratura/components/quick-contact-dialog.tsx index c26b3cd..411c6e7 100644 --- a/src/modules/registratura/components/quick-contact-dialog.tsx +++ b/src/modules/registratura/components/quick-contact-dialog.tsx @@ -13,17 +13,24 @@ import { DialogFooter, } from "@/shared/components/ui/dialog"; +export interface QuickContactData { + name: string; + company: string; + phone: string; + email: string; +} + interface QuickContactDialogProps { open: boolean; onOpenChange: (open: boolean) => void; /** Pre-filled name from the text the user typed */ initialName: string; - onConfirm: (data: { name: string; phone: string; email: string }) => void; + onConfirm: (data: QuickContactData) => void; } /** * Rapid popup for creating a new Address Book contact from Registratura. - * Only requires Name; Phone and Email are optional. + * Requires either Name or Company; Phone and Email are optional. */ export function QuickContactDialog({ open, @@ -32,27 +39,34 @@ export function QuickContactDialog({ onConfirm, }: QuickContactDialogProps) { const [name, setName] = useState(initialName); + const [company, setCompany] = useState(""); const [phone, setPhone] = useState(""); const [email, setEmail] = useState(""); // Sync name with initialName whenever the dialog opens - // (useState(initialName) only works on first mount; controlled open - // bypasses onOpenChange so we need useEffect) useEffect(() => { if (open) { setName(initialName); + setCompany(""); setPhone(""); setEmail(""); } }, [open, initialName]); + const hasIdentifier = name.trim() || company.trim(); + const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); // Stop propagation so the submit doesn't bubble through the React portal // to the outer registry-entry-form, which would close the whole form. e.stopPropagation(); - if (!name.trim()) return; - onConfirm({ name: name.trim(), phone: phone.trim(), email: email.trim() }); + if (!hasIdentifier) return; + onConfirm({ + name: name.trim(), + company: company.trim(), + phone: phone.trim(), + email: email.trim(), + }); }; return ( @@ -65,15 +79,31 @@ export function QuickContactDialog({