// R-P6 Interim-UI (AD-28) — "Neuer Kontakt" as a modal on the contact/organisation // browser, mirroring the automation list pattern ("Neue Automation starten"). // Presentational only: it holds the form draft, reports blur events through // actions.onCheckDuplicates (live hard/soft hits, DoD 4) and posts to the create // route (`createHref`) with the same field contract as the standalone KontaktNewPage, // so the route action stays untouched. No useLoaderData / useFetcher (DoD A.5). import { useState } from "react"; import { useTranslation } from "react-i18next"; import { FeatherPlus, FeatherX } from "@subframe/core"; import { Button } from "~/ui/components/Button"; import { Dialog } from "~/ui/components/Dialog"; import { IconButton } from "~/ui/components/IconButton"; import { Select } from "~/ui/components/Select"; import { TextInput } from "~/ui/components/TextInput"; import type { KontaktNewDuplicates, KontaktNewFields } from "./KontaktNewPage"; import { AppLink } from "~/components/app/AppLink"; const ORG_MERKMAL_NONE = "__none__"; export type KontaktNewDialogProps = { open: boolean; onOpenChange: (open: boolean) => void; /** Route that owns the create action (the standalone /contacts/new route). */ createHref: string; ownerOptions: readonly { id: string; label: string }[]; defaultOwnerId: string; /** Organisation browser pre-selects the organisation type. */ defaultKontaktTyp?: string; duplicates?: KontaktNewDuplicates | null; onCheckDuplicates?: (fields: KontaktNewFields) => void; }; export function KontaktNewDialog({ open, onOpenChange, createHref, ownerOptions, defaultOwnerId, defaultKontaktTyp = "privatperson", duplicates = null, onCheckDuplicates, }: KontaktNewDialogProps) { const { t } = useTranslation(); const [fields, setFields] = useState({ kontaktTyp: defaultKontaktTyp, kontaktStatus: "kontakt", vorname: "", nachname: "", orgName: "", orgMerkmal: "", email: "", telefon: "", zustaendigerUserId: defaultOwnerId, }); const set = (patch: Partial) => setFields((state) => ({ ...state, ...patch })); const checkDuplicates = () => onCheckDuplicates?.(fields); const isOrg = fields.kontaktTyp === "organisation"; const hasIdentity = Boolean(isOrg ? fields.orgName.trim() : fields.vorname.trim() || fields.nachname.trim()); return (
{t("crm.new.title")} {t("crm.new.subtitle")}
} aria-label={t("shared.cancel")} onClick={() => onOpenChange(false)} />
{duplicates && (duplicates.hard.length > 0 || duplicates.soft.length > 0) ? (
{duplicates.hard.length > 0 ? (
{t("crm.new.duplicates.hard")} {duplicates.hard.map((card) => ( {card.displayName} {card.primaerEmail ? ` · ${card.primaerEmail}` : ""} ))}
) : null} {duplicates.soft.length > 0 ? (
{t("crm.new.duplicates.soft")} {duplicates.soft.map((card) => ( {card.displayName} {card.primaerEmail ? ` · ${card.primaerEmail}` : ""} ))}
) : null}
) : null}
{isOrg ? ( <> ) => set({ orgName: event.target.value })} onBlur={checkDuplicates} data-ui-id="ui.crm.new.dialog.orgName" /> ) : ( <> ) => set({ vorname: event.target.value })} onBlur={checkDuplicates} data-ui-id="ui.crm.new.dialog.vorname" /> ) => set({ nachname: event.target.value })} onBlur={checkDuplicates} data-ui-id="ui.crm.new.dialog.nachname" /> )} ) => set({ email: event.target.value })} onBlur={checkDuplicates} data-ui-id="ui.crm.new.dialog.email" /> ) => set({ telefon: event.target.value })} onBlur={checkDuplicates} data-ui-id="ui.crm.new.dialog.telefon" />
); }