// R-P6 (P6 CRM core) Interim-UI (AD-28) — contact/organisation detail screen // (D-CRM "Kontakt-Detail"/"Organisation-Detail", archetype A3, master template), // composed from ~/ui. Pure/presentational: it renders the server-built // KontaktDetailVM data + ActivityStreamVM and turns every inline-edit into a // single typed onSubmit(intent, fields) callback the route POSTs. No // useLoaderData/useFetcher, no server imports. Final Subframe optics = tracked // design-nachzug. import { useState } from "react"; import { useTranslation } from "react-i18next"; import { AppLink } from "~/components/app/AppLink"; import { FeatherBuilding2, FeatherUser } from "@subframe/core"; import type { ActivityStreamVM, KontaktDetailData } from "@hivegrid/view-models"; import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageShell } from "../shared/PageShell"; import { Alert } from "~/ui/components/Alert"; import { BadgeFeedback } from "~/ui/components/BadgeFeedback"; import { Button } from "~/ui/components/Button"; import { Card } from "~/ui/components/Card"; import { Checkbox } from "~/ui/components/Checkbox"; import { EmptyState } from "~/ui/components/EmptyState"; import { Select } from "~/ui/components/Select"; import { TextArea } from "~/ui/components/TextArea"; import { TextInput } from "~/ui/components/TextInput"; import { APP_TIME_ZONE } from "~/locale/format"; import { ClickToCallEntryPoint, type ClickToCallEntryPointProps } from "../telephony/ClickToCallDialog"; /** POST a detail-edit intent with its string fields. The route builds the * FormData + submits; unknown fields are ignored server-side. */ export type KontaktDetailSubmit = (intent: string, fields?: Record) => void; export type KontaktDetailPageActions = { onSubmit: KontaktDetailSubmit }; export type KontaktDetailTagOption = { id: string; name: string; farbe: string }; export type KontaktDetailCustomFieldDef = { id: string; key: string; label: string; datentyp: string; datentypLabelKey: string }; export type KontaktDetailOwnerOption = { id: string; label: string }; export type KontaktDetailPageProps = { data: KontaktDetailData; activity: ActivityStreamVM; allTags: readonly KontaktDetailTagOption[]; customFieldDefs: readonly KontaktDetailCustomFieldDef[]; ownerOptions: readonly KontaktDetailOwnerOption[]; listLabelKey: string; backHref: string; /** Tag-Verwaltung link, shown as next action when the tenant has no tags yet. */ tagsAdminHref?: string; submitting: boolean; errorKey?: string | null; messageKey?: string | null; language?: string; /** Optional telephony affordance; omitted when the feature or permission gate is closed. */ clickToCall?: ClickToCallEntryPointProps; actions: KontaktDetailPageActions; }; const sectionHeading = "text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary"; const subHeading = "text-body-small-semibold-150 font-body-small-semibold-150 text-text-neutral-primary"; const mutedText = "text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary"; export function KontaktDetailPage(props: KontaktDetailPageProps) { const { t, i18n } = useTranslation(); const { data } = props; const isOrg = data.kontaktTyp === "organisation"; const submit = props.actions.onSubmit; const dateTime = new Intl.DateTimeFormat(props.language ?? i18n.language, { timeZone: APP_TIME_ZONE, dateStyle: "medium", timeStyle: "short" }); // Inline-edit basics draft. const [basics, setBasics] = useState({ vorname: data.vorname ?? "", nachname: data.nachname ?? "", orgName: data.orgName ?? "", orgMerkmal: data.orgMerkmal ?? "", kontaktStatus: data.kontaktStatus as string, }); // Add-form drafts. const [newEmail, setNewEmail] = useState({ email: "", primaer: false }); const [newTelefon, setNewTelefon] = useState({ telefon: "", primaer: false }); const [newRelation, setNewRelation] = useState({ zuKontaktId: "", rolle: "hauptkontakt", kontext: "" }); const [tagToAdd, setTagToAdd] = useState(props.allTags[0]?.id ?? ""); const [cf, setCf] = useState({ definitionId: props.customFieldDefs[0]?.id ?? "", wert: "" }); const [reassignTo, setReassignTo] = useState(data.zustaendigerUserId ?? ""); const [note, setNote] = useState(""); // Single top-right "Speichern": persists the basics form and, when the owner // actually changed, the reassignment too — server folds both into one // updateBasics intent (no separate "Zuweisen" button anymore). function saveAll() { const ownerChanged = reassignTo !== (data.zustaendigerUserId ?? ""); submit("updateBasics", { ...(isOrg ? { orgName: basics.orgName, orgMerkmal: basics.orgMerkmal, kontaktStatus: basics.kontaktStatus } : { vorname: basics.vorname, nachname: basics.nachname, kontaktStatus: basics.kontaktStatus }), ...(ownerChanged && reassignTo ? { zustaendigerUserId: reassignTo } : {}), }); } return ( : } title={ {data.displayName} {data.isArchived ? ( {t("crm.detail.archivedBadge")} ) : null} } subtitle={`${t(data.typLabelKey)} · ${t(data.statusLabelKey)}`} actions={ props.clickToCall || data.canInviteToPortal || data.canWrite ? ( <> {props.clickToCall ? : null} {data.canInviteToPortal ? ( ) : null} {data.canWrite ? ( ) : null} ) : undefined } />
{props.errorKey ? (
{t(props.errorKey)}
) : null} {props.messageKey ? ( ) : null} {/* --- Basics (inline edit) --- */} {t("crm.detail.section.basics")} {data.canWrite ? (
{isOrg ? ( <> setBasics((s) => ({ ...s, orgName: e.target.value }))} /> ) : ( <> setBasics((s) => ({ ...s, vorname: e.target.value }))} /> setBasics((s) => ({ ...s, nachname: e.target.value }))} /> )}
) : (
{t("crm.fields.status")}: {t(data.statusLabelKey)} {data.orgMerkmalLabelKey ? ( {t("crm.fields.orgMerkmal")}: {t(data.orgMerkmalLabelKey)} ) : null}
)}
{/* --- Contact data: emails / phones / address / relations / tags / custom fields combined into one wide card with a 2-column grid so each section uses the horizontal space instead of leaving the right half empty. --- */}
{/* Left column: communication channels (emails, phones, address). Two independent flex columns keep each section's height self-contained, so no empty gaps appear from grid row-height coupling. */}
{/* --- Emails --- */}
{t("crm.detail.section.emails")}
{data.emails.map((email) => (
{email.email} {email.primaer ? ( {t("crm.detail.primary")} ) : null} {data.canWrite && !email.primaer ? ( ) : null} {data.canWrite ? ( ) : null}
))}
{data.canWrite ? (
setNewEmail((s) => ({ ...s, email: e.target.value }))} data-ui-id="ui.crm.detail.emails.new" />
setNewEmail((s) => ({ ...s, primaer: c }))} label={t("crm.detail.primary")} />
) : null}
{/* --- Phones --- */}
{t("crm.detail.section.telefone")}
{data.telefone.map((tel) => (
{tel.telefon} {tel.primaer ? ( {t("crm.detail.primary")} ) : null} {data.canWrite && !tel.primaer ? ( ) : null} {data.canWrite ? ( ) : null}
))}
{data.canWrite ? (
setNewTelefon((s) => ({ ...s, telefon: e.target.value }))} data-ui-id="ui.crm.detail.telefone.new" />
setNewTelefon((s) => ({ ...s, primaer: c }))} label={t("crm.detail.primary")} />
) : null}
{/* --- Address (read-only) --- */} {data.adresse ? (
{t("crm.detail.section.adresse")} {[data.adresse.strasse, data.adresse.hausnummer].filter(Boolean).join(" ")} {data.adresse.plz || data.adresse.ort ? `, ${[data.adresse.plz, data.adresse.ort].filter(Boolean).join(" ")}` : ""} {`, ${data.adresse.land}`}
) : null}
{/* Right column: relations, tags and custom fields. */}
{/* --- Relations --- */}
{t("crm.detail.section.relations")}
{data.relationen.map((rel) => (
{rel.otherKontaktId} {t(rel.rolleLabelKey)} {rel.kontext ? {rel.kontext} : null} {data.canWrite ? ( ) : null}
))}
{data.canWrite ? (
setNewRelation((s) => ({ ...s, zuKontaktId: e.target.value }))} /> setNewRelation((s) => ({ ...s, kontext: e.target.value }))} />
) : null}
{/* --- Tags --- */}
{t("crm.detail.section.tags")}
{data.tags.map((tag) => ( {tag.name} {data.canWrite ? ( ) : null} ))}
{data.canWrite && props.allTags.length === 0 ? ( {t("crm.detail.tags.emptyHint")}{" "} {props.tagsAdminHref ? ( {t("crm.admin.tags.title")} ) : null} ) : null} {data.canWrite && props.allTags.length > 0 ? (
) : null}
{/* --- Custom fields --- */}
{t("crm.detail.section.customFields")}
{data.customFields.map((field) => (
{field.label}: {field.wert == null ? "—" : String(field.wert)}
))}
{data.canWrite && props.customFieldDefs.length > 0 ? (
setCf((s) => ({ ...s, wert: e.target.value }))} />
) : null}
{/* --- Quick actions --- */} {data.canWrite || data.canDelete ? ( {t("crm.detail.section.actions")} {data.canWrite ? (
) : null} {data.canWrite ? (
) : null}
{data.canWrite ? ( ) : null} {data.canDelete ? ( ) : null}
) : null} {/* --- Activity stream --- */} {t("crm.detail.section.activity")} {props.activity.status === "ready" && props.activity.data && props.activity.data.entries.length > 0 ? (
{props.activity.data.entries.map((entry) => (
{entry.summaryKey ? t(entry.summaryKey) : entry.summaryText} {t(entry.activityLabelKey)} {entry.actorLabel ? ` · ${entry.actorLabel}` : ""} · {dateTime.format(new Date(entry.createdAtIso))}
))}
) : (
)}
); } export default KontaktDetailPage;