552 lines
25 KiB
TypeScript
552 lines
25 KiB
TypeScript
// 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<string, string>) => 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 (
|
|
<PageShell uiId="ui.crm.detail" className="bg-surface-neutral-primary">
|
|
<PageHeader
|
|
icon={isOrg ? <FeatherBuilding2 className={PAGE_HEADER_ICON_CLASS} /> : <FeatherUser className={PAGE_HEADER_ICON_CLASS} />}
|
|
title={
|
|
<span className="inline-flex flex-wrap items-center gap-2">
|
|
{data.displayName}
|
|
{data.isArchived ? (
|
|
<BadgeFeedback farbe="subtle-negative" size="small">
|
|
{t("crm.detail.archivedBadge")}
|
|
</BadgeFeedback>
|
|
) : null}
|
|
</span>
|
|
}
|
|
subtitle={`${t(data.typLabelKey)} · ${t(data.statusLabelKey)}`}
|
|
actions={
|
|
props.clickToCall || data.canInviteToPortal || data.canWrite ? (
|
|
<>
|
|
{props.clickToCall ? <ClickToCallEntryPoint {...props.clickToCall} /> : null}
|
|
{data.canInviteToPortal ? (
|
|
<Button
|
|
variant="neutral"
|
|
loading={props.submitting}
|
|
onClick={() => submit("invitePortalContact")}
|
|
data-ui-id="ui.crm.detail.portalInvite"
|
|
>
|
|
{t("customerPortal.admin.users.invite")}
|
|
</Button>
|
|
) : null}
|
|
{data.canWrite ? (
|
|
<Button loading={props.submitting} onClick={saveAll} data-ui-id="ui.crm.detail.basics.save">
|
|
{t("crm.actions.save")}
|
|
</Button>
|
|
) : null}
|
|
</>
|
|
) : undefined
|
|
}
|
|
/>
|
|
|
|
<PageBody>
|
|
<div className="mx-auto flex w-full max-w-7xl flex-col gap-6">
|
|
|
|
{props.errorKey ? (
|
|
<div data-ui-id="ui.crm.detail.error">
|
|
<BadgeFeedback farbe="subtle-negative">{t(props.errorKey)}</BadgeFeedback>
|
|
</div>
|
|
) : null}
|
|
{props.messageKey ? (
|
|
<Alert
|
|
variant="success"
|
|
title={t("customerPortal.invitation.successTitle")}
|
|
description={t(props.messageKey)}
|
|
data-ui-id="ui.crm.detail.portalInviteSuccess"
|
|
/>
|
|
) : null}
|
|
|
|
{/* --- Basics (inline edit) --- */}
|
|
<Card data-ui-id="ui.crm.detail.basics">
|
|
<span className={sectionHeading}>{t("crm.detail.section.basics")}</span>
|
|
{data.canWrite ? (
|
|
<div className="grid w-full gap-4 sm:grid-cols-2">
|
|
{isOrg ? (
|
|
<>
|
|
<TextInput label={t("crm.fields.orgName")} showLabel>
|
|
<TextInput.Input value={basics.orgName} onChange={(e) => setBasics((s) => ({ ...s, orgName: e.target.value }))} />
|
|
</TextInput>
|
|
<Select
|
|
label={t("crm.fields.orgMerkmal")}
|
|
showLabel
|
|
value={basics.orgMerkmal || "__none__"}
|
|
onValueChange={(v) => setBasics((s) => ({ ...s, orgMerkmal: v === "__none__" ? "" : v }))}
|
|
>
|
|
<Select.Item value="__none__">{t("crm.fields.none")}</Select.Item>
|
|
{(["gmbh", "kg", "oeffentliche_einrichtung", "sonstige"] as const).map((m) => (
|
|
<Select.Item key={m} value={m}>
|
|
{t(`crm.orgMerkmal.${m}`)}
|
|
</Select.Item>
|
|
))}
|
|
</Select>
|
|
</>
|
|
) : (
|
|
<>
|
|
<TextInput label={t("crm.fields.vorname")} showLabel>
|
|
<TextInput.Input value={basics.vorname} onChange={(e) => setBasics((s) => ({ ...s, vorname: e.target.value }))} />
|
|
</TextInput>
|
|
<TextInput label={t("crm.fields.nachname")} showLabel>
|
|
<TextInput.Input value={basics.nachname} onChange={(e) => setBasics((s) => ({ ...s, nachname: e.target.value }))} />
|
|
</TextInput>
|
|
</>
|
|
)}
|
|
<Select label={t("crm.fields.status")} showLabel value={basics.kontaktStatus} onValueChange={(v) => setBasics((s) => ({ ...s, kontaktStatus: v }))}>
|
|
{(["kontakt", "kunde", "bestandskunde"] as const).map((st) => (
|
|
<Select.Item key={st} value={st}>
|
|
{t(`crm.kontaktStatus.${st}`)}
|
|
</Select.Item>
|
|
))}
|
|
</Select>
|
|
</div>
|
|
) : (
|
|
<div className="flex flex-col gap-1">
|
|
<span className={mutedText}>
|
|
{t("crm.fields.status")}: {t(data.statusLabelKey)}
|
|
</span>
|
|
{data.orgMerkmalLabelKey ? (
|
|
<span className={mutedText}>
|
|
{t("crm.fields.orgMerkmal")}: {t(data.orgMerkmalLabelKey)}
|
|
</span>
|
|
) : null}
|
|
</div>
|
|
)}
|
|
</Card>
|
|
|
|
{/* --- 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. --- */}
|
|
<Card data-ui-id="ui.crm.detail.contactData">
|
|
<div className="grid w-full grid-cols-1 items-start gap-x-8 gap-y-6 lg:grid-cols-2">
|
|
|
|
{/* 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. */}
|
|
<div className="flex w-full flex-col gap-6">
|
|
|
|
{/* --- Emails --- */}
|
|
<section className="flex w-full flex-col gap-3" data-ui-id="ui.crm.detail.emails">
|
|
<span className={subHeading}>{t("crm.detail.section.emails")}</span>
|
|
<div className="flex w-full flex-col gap-2">
|
|
{data.emails.map((email) => (
|
|
<div key={email.id} className="flex items-center gap-2" data-row-id={email.id}>
|
|
<span className={mutedText}>{email.email}</span>
|
|
{email.primaer ? (
|
|
<BadgeFeedback farbe="subtle-brand-primary" size="small">
|
|
{t("crm.detail.primary")}
|
|
</BadgeFeedback>
|
|
) : null}
|
|
{data.canWrite && !email.primaer ? (
|
|
<Button variant="tertiary" size="small" onClick={() => submit("setPrimaryEmail", { emailId: email.id })}>
|
|
{t("crm.actions.makePrimary")}
|
|
</Button>
|
|
) : null}
|
|
{data.canWrite ? (
|
|
<Button variant="tertiary" size="small" onClick={() => submit("removeEmail", { emailId: email.id })}>
|
|
{t("crm.actions.remove")}
|
|
</Button>
|
|
) : null}
|
|
</div>
|
|
))}
|
|
</div>
|
|
{data.canWrite ? (
|
|
<div className="flex flex-wrap items-end gap-2">
|
|
<TextInput label={t("crm.fields.email")} showLabel>
|
|
<TextInput.Input
|
|
type="email"
|
|
value={newEmail.email}
|
|
onChange={(e) => setNewEmail((s) => ({ ...s, email: e.target.value }))}
|
|
data-ui-id="ui.crm.detail.emails.new"
|
|
/>
|
|
</TextInput>
|
|
<div className="flex h-9 items-center">
|
|
<Checkbox checked={newEmail.primaer} onCheckedChange={(c) => setNewEmail((s) => ({ ...s, primaer: c }))} label={t("crm.detail.primary")} />
|
|
</div>
|
|
<Button
|
|
variant="neutral"
|
|
disabled={!newEmail.email.trim()}
|
|
onClick={() => {
|
|
submit("addEmail", { email: newEmail.email.trim(), ...(newEmail.primaer ? { primaer: "1" } : {}) });
|
|
setNewEmail({ email: "", primaer: false });
|
|
}}
|
|
>
|
|
{t("crm.actions.add")}
|
|
</Button>
|
|
</div>
|
|
) : null}
|
|
</section>
|
|
|
|
{/* --- Phones --- */}
|
|
<section className="flex w-full flex-col gap-3" data-ui-id="ui.crm.detail.telefone">
|
|
<span className={subHeading}>{t("crm.detail.section.telefone")}</span>
|
|
<div className="flex w-full flex-col gap-2">
|
|
{data.telefone.map((tel) => (
|
|
<div key={tel.id} className="flex items-center gap-2" data-row-id={tel.id}>
|
|
<span className={mutedText}>{tel.telefon}</span>
|
|
{tel.primaer ? (
|
|
<BadgeFeedback farbe="subtle-brand-primary" size="small">
|
|
{t("crm.detail.primary")}
|
|
</BadgeFeedback>
|
|
) : null}
|
|
{data.canWrite && !tel.primaer ? (
|
|
<Button variant="tertiary" size="small" onClick={() => submit("setPrimaryTelefon", { telefonId: tel.id })}>
|
|
{t("crm.actions.makePrimary")}
|
|
</Button>
|
|
) : null}
|
|
{data.canWrite ? (
|
|
<Button variant="tertiary" size="small" onClick={() => submit("removeTelefon", { telefonId: tel.id })}>
|
|
{t("crm.actions.remove")}
|
|
</Button>
|
|
) : null}
|
|
</div>
|
|
))}
|
|
</div>
|
|
{data.canWrite ? (
|
|
<div className="flex flex-wrap items-end gap-2">
|
|
<TextInput label={t("crm.fields.telefon")} showLabel>
|
|
<TextInput.Input
|
|
value={newTelefon.telefon}
|
|
onChange={(e) => setNewTelefon((s) => ({ ...s, telefon: e.target.value }))}
|
|
data-ui-id="ui.crm.detail.telefone.new"
|
|
/>
|
|
</TextInput>
|
|
<div className="flex h-9 items-center">
|
|
<Checkbox checked={newTelefon.primaer} onCheckedChange={(c) => setNewTelefon((s) => ({ ...s, primaer: c }))} label={t("crm.detail.primary")} />
|
|
</div>
|
|
<Button
|
|
variant="neutral"
|
|
disabled={!newTelefon.telefon.trim()}
|
|
onClick={() => {
|
|
submit("addTelefon", { telefon: newTelefon.telefon.trim(), ...(newTelefon.primaer ? { primaer: "1" } : {}) });
|
|
setNewTelefon({ telefon: "", primaer: false });
|
|
}}
|
|
>
|
|
{t("crm.actions.add")}
|
|
</Button>
|
|
</div>
|
|
) : null}
|
|
</section>
|
|
|
|
{/* --- Address (read-only) --- */}
|
|
{data.adresse ? (
|
|
<section className="flex w-full flex-col gap-3" data-ui-id="ui.crm.detail.adresse">
|
|
<span className={subHeading}>{t("crm.detail.section.adresse")}</span>
|
|
<span className={mutedText}>
|
|
{[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}`}
|
|
</span>
|
|
</section>
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
{/* Right column: relations, tags and custom fields. */}
|
|
<div className="flex w-full flex-col gap-6">
|
|
|
|
{/* --- Relations --- */}
|
|
<section className="flex w-full flex-col gap-3" data-ui-id="ui.crm.detail.relations">
|
|
<span className={subHeading}>{t("crm.detail.section.relations")}</span>
|
|
<div className="flex w-full flex-col gap-2">
|
|
{data.relationen.map((rel) => (
|
|
<div key={rel.id} className="flex items-center gap-2" data-row-id={rel.id}>
|
|
<span className={mutedText}>{rel.otherKontaktId}</span>
|
|
<BadgeFeedback farbe="subtle-neutral" size="small">
|
|
{t(rel.rolleLabelKey)}
|
|
</BadgeFeedback>
|
|
{rel.kontext ? <span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">{rel.kontext}</span> : null}
|
|
{data.canWrite ? (
|
|
<Button variant="tertiary" size="small" onClick={() => submit("removeRelation", { relationId: rel.id })}>
|
|
{t("crm.actions.remove")}
|
|
</Button>
|
|
) : null}
|
|
</div>
|
|
))}
|
|
</div>
|
|
{data.canWrite ? (
|
|
<div className="flex flex-wrap items-end gap-2">
|
|
<TextInput label={t("crm.fields.relationTarget")} showLabel>
|
|
<TextInput.Input value={newRelation.zuKontaktId} onChange={(e) => setNewRelation((s) => ({ ...s, zuKontaktId: e.target.value }))} />
|
|
</TextInput>
|
|
<Select label={t("crm.fields.relationRole")} showLabel value={newRelation.rolle} onValueChange={(v) => setNewRelation((s) => ({ ...s, rolle: v }))}>
|
|
{(["hauptkontakt", "sekundaerkontakt", "mitarbeiter", "sonstige"] as const).map((r) => (
|
|
<Select.Item key={r} value={r}>
|
|
{t(`crm.kontaktArt.${r}`)}
|
|
</Select.Item>
|
|
))}
|
|
</Select>
|
|
<TextInput label={t("crm.fields.relationContext")} showLabel>
|
|
<TextInput.Input value={newRelation.kontext} onChange={(e) => setNewRelation((s) => ({ ...s, kontext: e.target.value }))} />
|
|
</TextInput>
|
|
<Button
|
|
variant="neutral"
|
|
disabled={!newRelation.zuKontaktId.trim()}
|
|
onClick={() => {
|
|
submit("addRelation", { zuKontaktId: newRelation.zuKontaktId.trim(), rolle: newRelation.rolle, kontext: newRelation.kontext });
|
|
setNewRelation({ zuKontaktId: "", rolle: "hauptkontakt", kontext: "" });
|
|
}}
|
|
>
|
|
{t("crm.actions.add")}
|
|
</Button>
|
|
</div>
|
|
) : null}
|
|
</section>
|
|
|
|
{/* --- Tags --- */}
|
|
<section className="flex w-full flex-col gap-3" data-ui-id="ui.crm.detail.tags">
|
|
<span className={subHeading}>{t("crm.detail.section.tags")}</span>
|
|
<div className="flex w-full flex-wrap gap-2">
|
|
{data.tags.map((tag) => (
|
|
<span key={tag.id} className="border-border-default inline-flex items-center gap-1 rounded-sm border border-solid px-2 py-1" data-row-id={tag.id}>
|
|
<span aria-hidden className="inline-block h-2 w-2 rounded-full" style={{ backgroundColor: tag.farbe }} />
|
|
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary">{tag.name}</span>
|
|
{data.canWrite ? (
|
|
<button
|
|
type="button"
|
|
className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary underline"
|
|
onClick={() => submit("removeTag", { tagId: tag.id })}
|
|
>
|
|
{t("crm.actions.remove")}
|
|
</button>
|
|
) : null}
|
|
</span>
|
|
))}
|
|
</div>
|
|
{data.canWrite && props.allTags.length === 0 ? (
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
|
{t("crm.detail.tags.emptyHint")}{" "}
|
|
{props.tagsAdminHref ? (
|
|
<AppLink href={props.tagsAdminHref} className="text-text-feedback-link-default underline">
|
|
{t("crm.admin.tags.title")}
|
|
</AppLink>
|
|
) : null}
|
|
</span>
|
|
) : null}
|
|
{data.canWrite && props.allTags.length > 0 ? (
|
|
<div className="flex items-end gap-2">
|
|
<Select label={t("crm.fields.tag")} showLabel value={tagToAdd} onValueChange={setTagToAdd}>
|
|
{props.allTags.map((tag) => (
|
|
<Select.Item key={tag.id} value={tag.id}>
|
|
{tag.name}
|
|
</Select.Item>
|
|
))}
|
|
</Select>
|
|
<Button variant="neutral" disabled={!tagToAdd} onClick={() => submit("addTag", { tagId: tagToAdd })}>
|
|
{t("crm.actions.add")}
|
|
</Button>
|
|
</div>
|
|
) : null}
|
|
</section>
|
|
|
|
{/* --- Custom fields --- */}
|
|
<section className="flex w-full flex-col gap-3" data-ui-id="ui.crm.detail.customFields">
|
|
<span className={subHeading}>{t("crm.detail.section.customFields")}</span>
|
|
<div className="flex w-full flex-col gap-1">
|
|
{data.customFields.map((field) => (
|
|
<div key={field.definitionId} className="flex items-center gap-2" data-row-id={field.definitionId}>
|
|
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">{field.label}:</span>
|
|
<span className={mutedText}>{field.wert == null ? "—" : String(field.wert)}</span>
|
|
</div>
|
|
))}
|
|
</div>
|
|
{data.canWrite && props.customFieldDefs.length > 0 ? (
|
|
<div className="flex flex-wrap items-end gap-2">
|
|
<Select label={t("crm.fields.customField")} showLabel value={cf.definitionId} onValueChange={(v) => setCf((s) => ({ ...s, definitionId: v }))}>
|
|
{props.customFieldDefs.map((def) => (
|
|
<Select.Item key={def.id} value={def.id}>
|
|
{def.label}
|
|
</Select.Item>
|
|
))}
|
|
</Select>
|
|
<TextInput label={t("crm.fields.value")} showLabel>
|
|
<TextInput.Input value={cf.wert} onChange={(e) => setCf((s) => ({ ...s, wert: e.target.value }))} />
|
|
</TextInput>
|
|
<Button variant="neutral" disabled={!cf.definitionId} onClick={() => submit("setCustomField", { definitionId: cf.definitionId, wert: cf.wert })}>
|
|
{t("crm.actions.save")}
|
|
</Button>
|
|
</div>
|
|
) : null}
|
|
</section>
|
|
|
|
</div>
|
|
</div>
|
|
</Card>
|
|
|
|
{/* --- Quick actions --- */}
|
|
{data.canWrite || data.canDelete ? (
|
|
<Card data-ui-id="ui.crm.detail.actions">
|
|
<span className={sectionHeading}>{t("crm.detail.section.actions")}</span>
|
|
{data.canWrite ? (
|
|
<div className="flex flex-wrap items-end gap-2">
|
|
<Select
|
|
label={t("crm.fields.owner")}
|
|
showLabel
|
|
value={reassignTo || "__none__"}
|
|
onValueChange={(v) => setReassignTo(v === "__none__" ? "" : v)}
|
|
>
|
|
<Select.Item value="__none__">{t("crm.fields.none")}</Select.Item>
|
|
{props.ownerOptions.map((option) => (
|
|
<Select.Item key={option.id} value={option.id}>
|
|
{option.label}
|
|
</Select.Item>
|
|
))}
|
|
</Select>
|
|
</div>
|
|
) : null}
|
|
{data.canWrite ? (
|
|
<div className="flex w-full flex-col gap-2">
|
|
<TextArea label={t("crm.fields.note")} showLabel>
|
|
<TextArea.Input value={note} onChange={(e) => setNote(e.target.value)} data-ui-id="ui.crm.detail.note" />
|
|
</TextArea>
|
|
<div className="flex">
|
|
<Button
|
|
variant="neutral"
|
|
disabled={!note.trim()}
|
|
onClick={() => {
|
|
submit("addNote", { note: note.trim() });
|
|
setNote("");
|
|
}}
|
|
data-ui-id="ui.crm.detail.addNote"
|
|
>
|
|
{t("crm.actions.addNote")}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
) : null}
|
|
<div className="flex flex-wrap gap-3">
|
|
{data.canWrite ? (
|
|
<Button variant="neutral" onClick={() => submit(data.isArchived ? "reactivate" : "archive")} data-ui-id="ui.crm.detail.archive">
|
|
{t(data.isArchived ? "crm.actions.reactivate" : "crm.actions.archive")}
|
|
</Button>
|
|
) : null}
|
|
{data.canDelete ? (
|
|
<Button variant="destructive" onClick={() => submit("delete")} data-ui-id="ui.crm.detail.delete">
|
|
{t("crm.actions.delete")}
|
|
</Button>
|
|
) : null}
|
|
</div>
|
|
</Card>
|
|
) : null}
|
|
|
|
{/* --- Activity stream --- */}
|
|
<Card data-ui-id="ui.crm.detail.activity">
|
|
<span className={sectionHeading}>{t("crm.detail.section.activity")}</span>
|
|
{props.activity.status === "ready" && props.activity.data && props.activity.data.entries.length > 0 ? (
|
|
<div className="flex w-full flex-col gap-3">
|
|
{props.activity.data.entries.map((entry) => (
|
|
<div key={entry.id} className="border-border-default flex flex-col gap-0.5 border-l-2 border-solid pl-3" data-row-id={entry.id}>
|
|
<span className={mutedText}>{entry.summaryKey ? t(entry.summaryKey) : entry.summaryText}</span>
|
|
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
|
|
{t(entry.activityLabelKey)}
|
|
{entry.actorLabel ? ` · ${entry.actorLabel}` : ""} · {dateTime.format(new Date(entry.createdAtIso))}
|
|
</span>
|
|
</div>
|
|
))}
|
|
</div>
|
|
) : (
|
|
<div className="w-full" data-ui-id="ui.crm.detail.activity.empty">
|
|
<EmptyState title={t("crm.detail.activityEmpty")} />
|
|
</div>
|
|
)}
|
|
</Card>
|
|
</div>
|
|
</PageBody>
|
|
</PageShell>
|
|
);
|
|
}
|
|
|
|
export default KontaktDetailPage;
|