431 lines
21 KiB
TypeScript
431 lines
21 KiB
TypeScript
// R-P6 (P6 CRM core, Variante A) — presentational contact/organisation detail.
|
|
// Pure component: it receives the server-built KontaktDetailVM data + the
|
|
// Activity-Stream VM + option lists and renders the inline-edit forms (DoD 3).
|
|
// It NEVER calls useLoaderData/useFetcher (the route injects the data) and holds
|
|
// no server imports; every form posts back to the current route's action.
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
import type { ActivityStreamVM, KontaktDetailData } from "@hivegrid/view-models";
|
|
|
|
export type KontaktDetailViewProps = {
|
|
data: KontaktDetailData;
|
|
activity: ActivityStreamVM;
|
|
allTags: { id: string; name: string; farbe: string }[];
|
|
customFieldDefs: { id: string; key: string; label: string; datentyp: string; datentypLabelKey: string }[];
|
|
ownerOptions: { id: string; label: string }[];
|
|
backHref: string;
|
|
listLabelKey: string;
|
|
errorKey?: string | null;
|
|
};
|
|
|
|
const crmFieldLabelClass = "block text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary";
|
|
const crmFieldControlClass =
|
|
"mt-1 h-9 w-full rounded-sm border border-solid border-border-strong bg-surface-neutral-primary px-3 text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary outline-none placeholder:text-text-neutral-subtle focus:shadow-focus";
|
|
const crmTextareaClass =
|
|
"mt-1 w-full rounded-sm border border-solid border-border-strong bg-surface-neutral-primary px-3 py-2 text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary outline-none placeholder:text-text-neutral-subtle focus:shadow-focus";
|
|
|
|
export default function KontaktDetailView(props: KontaktDetailViewProps) {
|
|
const { t, i18n } = useTranslation();
|
|
const { data } = props;
|
|
const isOrg = data.kontaktTyp === "organisation";
|
|
const dateTime = new Intl.DateTimeFormat(i18n.language, { dateStyle: "medium", timeStyle: "short" });
|
|
|
|
return (
|
|
<main className="mx-auto max-w-4xl px-4 py-10" data-ui-id="ui.crm.detail">
|
|
<nav className="text-muted-foreground mb-4 text-sm" aria-label={t("crm.detail.breadcrumb")} data-ui-id="ui.crm.detail.breadcrumb">
|
|
<a href={props.backHref} className="hover:text-foreground" data-ui-id="ui.crm.detail.back">
|
|
{t(props.listLabelKey)}
|
|
</a>
|
|
<span className="px-2">{"/"}</span>
|
|
<span className="text-foreground">{data.displayName}</span>
|
|
</nav>
|
|
|
|
<header className="flex flex-wrap items-center gap-3">
|
|
<h1 className="text-foreground text-xl font-semibold">{data.displayName}</h1>
|
|
<span className="border-border rounded border px-2 py-0.5 text-xs">{t(data.typLabelKey)}</span>
|
|
<span className="border-border rounded border px-2 py-0.5 text-xs">{t(data.statusLabelKey)}</span>
|
|
{data.isArchived ? <span className="text-destructive text-xs">{t("crm.detail.archivedBadge")}</span> : null}
|
|
</header>
|
|
|
|
{props.errorKey ? (
|
|
<p className="border-destructive text-destructive mt-4 rounded border px-3 py-2 text-sm" role="alert" data-ui-id="ui.crm.detail.error">
|
|
{t(props.errorKey)}
|
|
</p>
|
|
) : null}
|
|
|
|
{/* --- Basics (inline edit) --- */}
|
|
<section className="mt-6" data-ui-id="ui.crm.detail.basics">
|
|
<h2 className="text-muted-foreground text-xs font-semibold uppercase">{t("crm.detail.section.basics")}</h2>
|
|
{data.canWrite ? (
|
|
<form method="post" className="mt-2 grid gap-2 sm:grid-cols-2">
|
|
<input type="hidden" name="intent" value="updateBasics" />
|
|
{isOrg ? (
|
|
<>
|
|
<label className="text-sm">
|
|
<span className={crmFieldLabelClass}>{t("crm.fields.orgName")}</span>
|
|
<input name="orgName" defaultValue={data.orgName ?? ""} className={crmFieldControlClass} />
|
|
</label>
|
|
<label className="text-sm">
|
|
<span className={crmFieldLabelClass}>{t("crm.fields.orgMerkmal")}</span>
|
|
<select name="orgMerkmal" defaultValue={data.orgMerkmal ?? ""} className={crmFieldControlClass}>
|
|
<option value="">{t("crm.fields.none")}</option>
|
|
{(["gmbh", "kg", "oeffentliche_einrichtung", "sonstige"] as const).map((merkmal) => (
|
|
<option key={merkmal} value={merkmal}>
|
|
{t(`crm.orgMerkmal.${merkmal}`)}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
</>
|
|
) : (
|
|
<>
|
|
<label className="text-sm">
|
|
<span className={crmFieldLabelClass}>{t("crm.fields.vorname")}</span>
|
|
<input name="vorname" defaultValue={data.vorname ?? ""} className={crmFieldControlClass} />
|
|
</label>
|
|
<label className="text-sm">
|
|
<span className={crmFieldLabelClass}>{t("crm.fields.nachname")}</span>
|
|
<input name="nachname" defaultValue={data.nachname ?? ""} className={crmFieldControlClass} />
|
|
</label>
|
|
</>
|
|
)}
|
|
<label className="text-sm">
|
|
<span className={crmFieldLabelClass}>{t("crm.fields.status")}</span>
|
|
<select name="kontaktStatus" defaultValue={data.kontaktStatus} className={crmFieldControlClass}>
|
|
{(["kontakt", "kunde", "bestandskunde"] as const).map((status) => (
|
|
<option key={status} value={status}>
|
|
{t(`crm.kontaktStatus.${status}`)}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<div className="sm:col-span-2">
|
|
<button type="submit" className="text-theme-600 text-sm font-medium" data-ui-id="ui.crm.detail.basics.save">
|
|
{t("crm.actions.save")}
|
|
</button>
|
|
</div>
|
|
</form>
|
|
) : (
|
|
<dl className="mt-2 grid grid-cols-[8rem_1fr] gap-y-1 text-sm">
|
|
<dt className="text-muted-foreground">{t("crm.fields.status")}</dt>
|
|
<dd>{t(data.statusLabelKey)}</dd>
|
|
{data.orgMerkmalLabelKey ? (
|
|
<>
|
|
<dt className="text-muted-foreground">{t("crm.fields.orgMerkmal")}</dt>
|
|
<dd>{t(data.orgMerkmalLabelKey)}</dd>
|
|
</>
|
|
) : null}
|
|
</dl>
|
|
)}
|
|
</section>
|
|
|
|
{/* --- Emails --- */}
|
|
<section className="mt-6" data-ui-id="ui.crm.detail.emails">
|
|
<h2 className="text-muted-foreground text-xs font-semibold uppercase">{t("crm.detail.section.emails")}</h2>
|
|
<ul className="mt-2 text-sm">
|
|
{data.emails.map((email) => (
|
|
<li key={email.id} className="flex items-center gap-2 py-0.5" data-row-id={email.id}>
|
|
<span>{email.email}</span>
|
|
{email.primaer ? <span className="text-theme-600 text-xs">{t("crm.detail.primary")}</span> : null}
|
|
{data.canWrite && !email.primaer ? (
|
|
<form method="post">
|
|
<input type="hidden" name="intent" value="setPrimaryEmail" />
|
|
<input type="hidden" name="emailId" value={email.id} />
|
|
<button type="submit" className="text-muted-foreground text-xs underline">
|
|
{t("crm.actions.makePrimary")}
|
|
</button>
|
|
</form>
|
|
) : null}
|
|
{data.canWrite ? (
|
|
<form method="post">
|
|
<input type="hidden" name="intent" value="removeEmail" />
|
|
<input type="hidden" name="emailId" value={email.id} />
|
|
<button type="submit" className="text-muted-foreground text-xs underline">
|
|
{t("crm.actions.remove")}
|
|
</button>
|
|
</form>
|
|
) : null}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
{data.canWrite ? (
|
|
<form method="post" className="mt-2 flex flex-wrap items-end gap-2">
|
|
<input type="hidden" name="intent" value="addEmail" />
|
|
<label className="text-sm">
|
|
<span className={crmFieldLabelClass}>{t("crm.fields.email")}</span>
|
|
<input name="email" type="email" required className={crmFieldControlClass} />
|
|
</label>
|
|
<label className="text-muted-foreground flex items-center gap-1 text-xs">
|
|
<input type="checkbox" name="primaer" value="1" /> {t("crm.detail.primary")}
|
|
</label>
|
|
<button type="submit" className="text-theme-600 text-sm font-medium">
|
|
{t("crm.actions.add")}
|
|
</button>
|
|
</form>
|
|
) : null}
|
|
</section>
|
|
|
|
{/* --- Phones --- */}
|
|
<section className="mt-6" data-ui-id="ui.crm.detail.telefone">
|
|
<h2 className="text-muted-foreground text-xs font-semibold uppercase">{t("crm.detail.section.telefone")}</h2>
|
|
<ul className="mt-2 text-sm">
|
|
{data.telefone.map((tel) => (
|
|
<li key={tel.id} className="flex items-center gap-2 py-0.5" data-row-id={tel.id}>
|
|
<span>{tel.telefon}</span>
|
|
{tel.primaer ? <span className="text-theme-600 text-xs">{t("crm.detail.primary")}</span> : null}
|
|
{data.canWrite && !tel.primaer ? (
|
|
<form method="post">
|
|
<input type="hidden" name="intent" value="setPrimaryTelefon" />
|
|
<input type="hidden" name="telefonId" value={tel.id} />
|
|
<button type="submit" className="text-muted-foreground text-xs underline">
|
|
{t("crm.actions.makePrimary")}
|
|
</button>
|
|
</form>
|
|
) : null}
|
|
{data.canWrite ? (
|
|
<form method="post">
|
|
<input type="hidden" name="intent" value="removeTelefon" />
|
|
<input type="hidden" name="telefonId" value={tel.id} />
|
|
<button type="submit" className="text-muted-foreground text-xs underline">
|
|
{t("crm.actions.remove")}
|
|
</button>
|
|
</form>
|
|
) : null}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
{data.canWrite ? (
|
|
<form method="post" className="mt-2 flex flex-wrap items-end gap-2">
|
|
<input type="hidden" name="intent" value="addTelefon" />
|
|
<label className="text-sm">
|
|
<span className={crmFieldLabelClass}>{t("crm.fields.telefon")}</span>
|
|
<input name="telefon" required className={crmFieldControlClass} />
|
|
</label>
|
|
<label className="text-muted-foreground flex items-center gap-1 text-xs">
|
|
<input type="checkbox" name="primaer" value="1" /> {t("crm.detail.primary")}
|
|
</label>
|
|
<button type="submit" className="text-theme-600 text-sm font-medium">
|
|
{t("crm.actions.add")}
|
|
</button>
|
|
</form>
|
|
) : null}
|
|
</section>
|
|
|
|
{/* --- Address (read-only) --- */}
|
|
{data.adresse ? (
|
|
<section className="mt-6" data-ui-id="ui.crm.detail.adresse">
|
|
<h2 className="text-muted-foreground text-xs font-semibold uppercase">{t("crm.detail.section.adresse")}</h2>
|
|
<p className="mt-1 text-sm">
|
|
{[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}`}
|
|
</p>
|
|
</section>
|
|
) : null}
|
|
|
|
{/* --- Relations --- */}
|
|
<section className="mt-6" data-ui-id="ui.crm.detail.relations">
|
|
<h2 className="text-muted-foreground text-xs font-semibold uppercase">{t("crm.detail.section.relations")}</h2>
|
|
<ul className="mt-2 text-sm">
|
|
{data.relationen.map((rel) => (
|
|
<li key={rel.id} className="flex items-center gap-2 py-0.5" data-row-id={rel.id}>
|
|
<span>{rel.otherKontaktId}</span>
|
|
<span className="text-muted-foreground text-xs">{t(rel.rolleLabelKey)}</span>
|
|
{rel.kontext ? <span className="text-muted-foreground text-xs">{rel.kontext}</span> : null}
|
|
{data.canWrite ? (
|
|
<form method="post">
|
|
<input type="hidden" name="intent" value="removeRelation" />
|
|
<input type="hidden" name="relationId" value={rel.id} />
|
|
<button type="submit" className="text-muted-foreground text-xs underline">
|
|
{t("crm.actions.remove")}
|
|
</button>
|
|
</form>
|
|
) : null}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
{data.canWrite ? (
|
|
<form method="post" className="mt-2 flex flex-wrap items-end gap-2">
|
|
<input type="hidden" name="intent" value="addRelation" />
|
|
<label className="text-sm">
|
|
<span className={crmFieldLabelClass}>{t("crm.fields.relationTarget")}</span>
|
|
<input name="zuKontaktId" required className={crmFieldControlClass} />
|
|
</label>
|
|
<label className="text-sm">
|
|
<span className={crmFieldLabelClass}>{t("crm.fields.relationRole")}</span>
|
|
<select name="rolle" className={crmFieldControlClass}>
|
|
{(["hauptkontakt", "sekundaerkontakt", "mitarbeiter", "sonstige"] as const).map((rolle) => (
|
|
<option key={rolle} value={rolle}>
|
|
{t(`crm.kontaktArt.${rolle}`)}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<label className="text-sm">
|
|
<span className={crmFieldLabelClass}>{t("crm.fields.relationContext")}</span>
|
|
<input name="kontext" className={crmFieldControlClass} />
|
|
</label>
|
|
<button type="submit" className="text-theme-600 text-sm font-medium">
|
|
{t("crm.actions.add")}
|
|
</button>
|
|
</form>
|
|
) : null}
|
|
</section>
|
|
|
|
{/* --- Tags --- */}
|
|
<section className="mt-6" data-ui-id="ui.crm.detail.tags">
|
|
<h2 className="text-muted-foreground text-xs font-semibold uppercase">{t("crm.detail.section.tags")}</h2>
|
|
<ul className="mt-2 flex flex-wrap gap-2 text-sm">
|
|
{data.tags.map((tag) => (
|
|
<li key={tag.id} className="border-border flex items-center gap-1 rounded border px-2 py-0.5" data-row-id={tag.id}>
|
|
<span aria-hidden className="inline-block h-2 w-2 rounded-full" style={{ backgroundColor: tag.farbe }} />
|
|
<span>{tag.name}</span>
|
|
{data.canWrite ? (
|
|
<form method="post">
|
|
<input type="hidden" name="intent" value="removeTag" />
|
|
<input type="hidden" name="tagId" value={tag.id} />
|
|
<button type="submit" className="text-muted-foreground text-xs underline">
|
|
{t("crm.actions.remove")}
|
|
</button>
|
|
</form>
|
|
) : null}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
{data.canWrite && props.allTags.length > 0 ? (
|
|
<form method="post" className="mt-2 flex items-end gap-2">
|
|
<input type="hidden" name="intent" value="addTag" />
|
|
<label className="text-sm">
|
|
<span className={crmFieldLabelClass}>{t("crm.fields.tag")}</span>
|
|
<select name="tagId" className={crmFieldControlClass}>
|
|
{props.allTags.map((tag) => (
|
|
<option key={tag.id} value={tag.id}>
|
|
{tag.name}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<button type="submit" className="text-theme-600 text-sm font-medium">
|
|
{t("crm.actions.add")}
|
|
</button>
|
|
</form>
|
|
) : null}
|
|
</section>
|
|
|
|
{/* --- Custom fields --- */}
|
|
<section className="mt-6" data-ui-id="ui.crm.detail.customFields">
|
|
<h2 className="text-muted-foreground text-xs font-semibold uppercase">{t("crm.detail.section.customFields")}</h2>
|
|
<dl className="mt-2 grid grid-cols-[10rem_1fr] gap-y-1 text-sm">
|
|
{data.customFields.map((cf) => (
|
|
<div key={cf.definitionId} className="contents" data-row-id={cf.definitionId}>
|
|
<dt className="text-muted-foreground">{cf.label}</dt>
|
|
<dd>{cf.wert == null ? "" : String(cf.wert)}</dd>
|
|
</div>
|
|
))}
|
|
</dl>
|
|
{data.canWrite && props.customFieldDefs.length > 0 ? (
|
|
<form method="post" className="mt-2 flex flex-wrap items-end gap-2">
|
|
<input type="hidden" name="intent" value="setCustomField" />
|
|
<label className="text-sm">
|
|
<span className={crmFieldLabelClass}>{t("crm.fields.customField")}</span>
|
|
<select name="definitionId" className={crmFieldControlClass}>
|
|
{props.customFieldDefs.map((def) => (
|
|
<option key={def.id} value={def.id}>
|
|
{def.label}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<label className="text-sm">
|
|
<span className={crmFieldLabelClass}>{t("crm.fields.value")}</span>
|
|
<input name="wert" className={crmFieldControlClass} />
|
|
</label>
|
|
<button type="submit" className="text-theme-600 text-sm font-medium">
|
|
{t("crm.actions.save")}
|
|
</button>
|
|
</form>
|
|
) : null}
|
|
</section>
|
|
|
|
{/* --- Quick actions --- */}
|
|
{data.canWrite || data.canDelete ? (
|
|
<section className="mt-8 border-t pt-4" data-ui-id="ui.crm.detail.actions">
|
|
<h2 className="text-muted-foreground text-xs font-semibold uppercase">{t("crm.detail.section.actions")}</h2>
|
|
<div className="mt-2 flex flex-wrap items-end gap-4">
|
|
{data.canWrite ? (
|
|
<form method="post" className="flex items-end gap-2">
|
|
<input type="hidden" name="intent" value="reassign" />
|
|
<label className="text-sm">
|
|
<span className={crmFieldLabelClass}>{t("crm.fields.owner")}</span>
|
|
<select name="zustaendigerUserId" defaultValue={data.zustaendigerUserId ?? ""} className={crmFieldControlClass}>
|
|
{props.ownerOptions.map((option) => (
|
|
<option key={option.id} value={option.id}>
|
|
{option.label}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<button type="submit" className="text-theme-600 text-sm font-medium">
|
|
{t("crm.actions.reassign")}
|
|
</button>
|
|
</form>
|
|
) : null}
|
|
{data.canWrite ? (
|
|
<form method="post" className="flex-1">
|
|
<input type="hidden" name="intent" value="addNote" />
|
|
<label className="text-sm">
|
|
<span className={crmFieldLabelClass}>{t("crm.fields.note")}</span>
|
|
<textarea name="note" required rows={2} className={crmTextareaClass} />
|
|
</label>
|
|
<button type="submit" className="text-theme-600 mt-1 text-sm font-medium" data-ui-id="ui.crm.detail.addNote">
|
|
{t("crm.actions.addNote")}
|
|
</button>
|
|
</form>
|
|
) : null}
|
|
</div>
|
|
<div className="mt-3 flex flex-wrap gap-3">
|
|
{data.canWrite ? (
|
|
<form method="post">
|
|
<input type="hidden" name="intent" value={data.isArchived ? "reactivate" : "archive"} />
|
|
<button type="submit" className="text-theme-600 text-sm font-medium" data-ui-id="ui.crm.detail.archive">
|
|
{t(data.isArchived ? "crm.actions.reactivate" : "crm.actions.archive")}
|
|
</button>
|
|
</form>
|
|
) : null}
|
|
{data.canDelete ? (
|
|
<form method="post">
|
|
<input type="hidden" name="intent" value="delete" />
|
|
<button type="submit" className="text-destructive text-sm font-medium" data-ui-id="ui.crm.detail.delete">
|
|
{t("crm.actions.delete")}
|
|
</button>
|
|
</form>
|
|
) : null}
|
|
</div>
|
|
</section>
|
|
) : null}
|
|
|
|
{/* --- Activity stream --- */}
|
|
<section className="mt-8 border-t pt-4" data-ui-id="ui.crm.detail.activity">
|
|
<h2 className="text-muted-foreground text-xs font-semibold uppercase">{t("crm.detail.section.activity")}</h2>
|
|
{props.activity.status === "ready" && props.activity.data ? (
|
|
<ul className="mt-2 space-y-2 text-sm">
|
|
{props.activity.data.entries.map((entry) => (
|
|
<li key={entry.id} className="border-border border-l-2 pl-3" data-row-id={entry.id}>
|
|
<p>{entry.summaryText}</p>
|
|
<p className="text-muted-foreground text-xs">
|
|
{t(entry.activityLabelKey)}
|
|
{entry.actorLabel ? ` · ${entry.actorLabel}` : ""} · <time dateTime={entry.createdAtIso}>{dateTime.format(new Date(entry.createdAtIso))}</time>
|
|
</p>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
) : (
|
|
<p className="text-muted-foreground mt-2 text-sm" data-ui-id="ui.crm.detail.activity.empty">
|
|
{t("crm.detail.activityEmpty")}
|
|
</p>
|
|
)}
|
|
</section>
|
|
</main>
|
|
);
|
|
}
|