// R-P6 (P6 CRM core) Interim-UI (AD-28) — create-contact screen (D-CRM // "Kontakt anlegen", archetype A4), composed from ~/ui. Pure/presentational: it // holds the form draft and calls actions.onCheckDuplicates (live hard/soft hits, // DoD 4) + actions.onCreate; the route runs the fetcher/submit. No useLoaderData/ // useFetcher. Final Subframe optics = tracked design-nachzug. import { useState } from "react"; import { useTranslation } from "react-i18next"; import { BadgeFeedback } from "~/ui/components/BadgeFeedback"; import { Button } from "~/ui/components/Button"; import { Card } from "~/ui/components/Card"; import { Select } from "~/ui/components/Select"; import { TextInput } from "~/ui/components/TextInput"; import { AppLink } from "~/components/app/AppLink"; export type KontaktNewDuplicateCard = { id: string; displayName: string; primaerEmail: string | null; primaerTelefon: string | null; detailHref: string }; export type KontaktNewDuplicates = { hard: readonly KontaktNewDuplicateCard[]; soft: readonly KontaktNewDuplicateCard[] }; export type KontaktNewFields = { kontaktTyp: string; kontaktStatus: string; vorname: string; nachname: string; orgName: string; orgMerkmal: string; email: string; telefon: string; zustaendigerUserId: string; }; export type KontaktNewPageActions = { onCheckDuplicates: (fields: KontaktNewFields) => void; onCreate: (fields: KontaktNewFields) => void; }; export type KontaktNewPageProps = { moduleActive: boolean; ownerOptions: readonly { id: string; label: string }[]; defaultOwnerId: string; backHref: string; listLabelKey: string; duplicates: KontaktNewDuplicates | null; submitting: boolean; errorKey?: string | null; actions: KontaktNewPageActions; }; export function KontaktNewPage(props: KontaktNewPageProps) { const { t } = useTranslation(); const [fields, setFields] = useState({ kontaktTyp: "privatperson", kontaktStatus: "kontakt", vorname: "", nachname: "", orgName: "", orgMerkmal: "", email: "", telefon: "", zustaendigerUserId: props.defaultOwnerId, }); const set = (patch: Partial) => setFields((s) => ({ ...s, ...patch })); const isOrg = fields.kontaktTyp === "organisation"; const dup = props.duplicates; if (!props.moduleActive) { return (
{t("crm.locked.headline")}
); } return (
{t("crm.new.title")} {props.errorKey ? (
{t(props.errorKey)}
) : null} {dup && (dup.hard.length > 0 || dup.soft.length > 0) ? ( 0 ? "negative" : "warning"} data-ui-id="ui.crm.new.duplicates"> {dup.hard.length > 0 ? (
{t("crm.new.duplicates.hard")} {dup.hard.map((card) => ( {card.displayName} {card.primaerEmail ? ` · ${card.primaerEmail}` : ""} {card.primaerTelefon ? ` · ${card.primaerTelefon}` : ""} ))}
) : null} {dup.soft.length > 0 ? (
{t("crm.new.duplicates.soft")} {dup.soft.map((card) => ( {card.displayName} {card.primaerEmail ? ` · ${card.primaerEmail}` : ""} ))}
) : null}
) : null}
{isOrg ? ( <> set({ orgName: e.target.value })} onBlur={() => props.actions.onCheckDuplicates(fields)} data-ui-id="ui.crm.new.orgName" /> ) : ( <> set({ vorname: e.target.value })} onBlur={() => props.actions.onCheckDuplicates(fields)} data-ui-id="ui.crm.new.vorname" /> set({ nachname: e.target.value })} onBlur={() => props.actions.onCheckDuplicates(fields)} data-ui-id="ui.crm.new.nachname" /> )} set({ email: e.target.value })} onBlur={() => props.actions.onCheckDuplicates(fields)} data-ui-id="ui.crm.new.email" /> set({ telefon: e.target.value })} onBlur={() => props.actions.onCheckDuplicates(fields)} data-ui-id="ui.crm.new.telefon" />
); } export default KontaktNewPage;