Update hivegrid-cloud reference to latest main

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
davidandClaude Fable 5 committed 2026-07-08 16:15:37 +02:00
1 parent e98d38e716
commit 7b21524c86
3781 files changed
+373484 -225607

No files matched your search

@@ -0,0 +1,430 @@
// 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>
);
}
@@ -0,0 +1,256 @@
// R-P6 (P6 CRM core, Variante A) — presentational contact/organisation browser.
// Pure component: it renders the server-built KontaktListVM (filter / sort /
// paginate / bulk / CSV, DoD 2). The filter bar is a GET form (state lives in the
// URL); bulk actions are a POST form whose checkboxes carry the selected ids.
// No useLoaderData/useFetcher, no server imports.
import { useTranslation } from "react-i18next";
import type { KontaktListVM } from "@hivegrid/view-models";
import { kontaktListQueryToParams, type KontaktListQuery } from "~/utils/integrations/crm/kontaktListQuery";
export type KontaktListViewProps = {
moduleActive: boolean;
variant: "contacts" | "companies";
vm: KontaktListVM;
tagOptions: { id: string; name: string; farbe: string }[];
ownerOptions: { id: string; label: string }[];
query: KontaktListQuery;
baseHref: string;
newHref: string;
exportHref: string;
errorKey?: string | null;
};
function pageHref(baseHref: string, query: KontaktListQuery, page: number): string {
const params = kontaktListQueryToParams({ ...query, page });
const qs = params.toString();
return qs ? `${baseHref}?${qs}` : baseHref;
}
export default function KontaktListView(props: KontaktListViewProps) {
const { t } = useTranslation();
const titleKey = props.variant === "companies" ? "crm.companies.title" : "crm.contacts.title";
const emptyHeadlineKey = props.variant === "companies" ? "crm.empty.companies.headline" : "crm.empty.contacts.headline";
const emptyBodyKey = props.variant === "companies" ? "crm.empty.companies.body" : "crm.empty.contacts.body";
if (!props.moduleActive) {
return (
<main className="mx-auto max-w-5xl px-4 py-10" data-ui-id="ui.crm.list">
<div className="mt-10 text-center" data-ui-id="ui.crm.list.locked">
<p className="text-foreground font-medium">{t("crm.locked.headline")}</p>
<p className="text-muted-foreground mt-1 text-sm">{t("crm.locked.body")}</p>
</div>
</main>
);
}
const data = props.vm.status === "ready" ? props.vm.data : null;
const { filter, sort } = props.query;
return (
<main className="mx-auto max-w-6xl px-4 py-10" data-ui-id="ui.crm.list">
<header className="flex flex-wrap items-center justify-between gap-3">
<h1 className="text-foreground text-xl font-semibold">{t(titleKey)}</h1>
<div className="flex gap-3 text-sm">
<a href={props.exportHref} className="text-theme-600 font-medium" data-ui-id="ui.crm.list.export">
{t("crm.actions.exportCsv")}
</a>
<a href={props.newHref} className="text-theme-600 font-medium" data-ui-id="ui.crm.list.new">
{t("crm.actions.newContact")}
</a>
</div>
</header>
{/* --- Filter bar (GET, URL-driven, server-side) --- */}
<form method="get" action={props.baseHref} className="mt-6 flex flex-wrap items-end gap-2" data-ui-id="ui.crm.list.filter">
<label className="text-sm">
<span className="text-muted-foreground block text-xs">{t("crm.filter.search")}</span>
<input name="q" defaultValue={filter.search ?? ""} className="border-muted-foreground/40 rounded border px-2 py-1" />
</label>
{props.variant === "contacts" ? (
<label className="text-sm">
<span className="text-muted-foreground block text-xs">{t("crm.filter.type")}</span>
<select name="typ" defaultValue={filter.kontaktTyp ?? ""} className="border-muted-foreground/40 rounded border px-2 py-1">
<option value="">{t("crm.filter.any")}</option>
<option value="privatperson">{t("crm.kontaktTyp.privatperson")}</option>
<option value="organisation">{t("crm.kontaktTyp.organisation")}</option>
</select>
</label>
) : null}
<label className="text-sm">
<span className="text-muted-foreground block text-xs">{t("crm.filter.status")}</span>
<select name="status" defaultValue={filter.kontaktStatus ?? ""} className="border-muted-foreground/40 rounded border px-2 py-1">
<option value="">{t("crm.filter.any")}</option>
{(["kontakt", "kunde", "bestandskunde"] as const).map((status) => (
<option key={status} value={status}>
{t(`crm.kontaktStatus.${status}`)}
</option>
))}
</select>
</label>
<label className="text-sm">
<span className="text-muted-foreground block text-xs">{t("crm.filter.owner")}</span>
<select name="owner" defaultValue={filter.zustaendigerUserId ?? ""} className="border-muted-foreground/40 rounded border px-2 py-1">
<option value="">{t("crm.filter.any")}</option>
{props.ownerOptions.map((option) => (
<option key={option.id} value={option.id}>
{option.label}
</option>
))}
</select>
</label>
<label className="text-sm">
<span className="text-muted-foreground block text-xs">{t("crm.filter.tags")}</span>
<select name="tags" multiple defaultValue={filter.tagIds ?? []} className="border-muted-foreground/40 rounded border px-2 py-1">
{props.tagOptions.map((tag) => (
<option key={tag.id} value={tag.id}>
{tag.name}
</option>
))}
</select>
</label>
<label className="text-sm">
<span className="text-muted-foreground block text-xs">{t("crm.filter.tagMatch")}</span>
<select name="tagMatch" defaultValue={filter.tagMatch} className="border-muted-foreground/40 rounded border px-2 py-1">
<option value="or">{t("crm.filter.tagMatchOr")}</option>
<option value="and">{t("crm.filter.tagMatchAnd")}</option>
</select>
</label>
<label className="text-sm">
<span className="text-muted-foreground block text-xs">{t("crm.filter.sort")}</span>
<select name="sort" defaultValue={sort.field} className="border-muted-foreground/40 rounded border px-2 py-1">
<option value="createdAt">{t("crm.filter.sortCreated")}</option>
<option value="name">{t("crm.filter.sortName")}</option>
<option value="kontaktStatus">{t("crm.filter.sortStatus")}</option>
</select>
</label>
<label className="text-sm">
<span className="text-muted-foreground block text-xs">{t("crm.filter.direction")}</span>
<select name="dir" defaultValue={sort.dir} className="border-muted-foreground/40 rounded border px-2 py-1">
<option value="desc">{t("crm.filter.dirDesc")}</option>
<option value="asc">{t("crm.filter.dirAsc")}</option>
</select>
</label>
<label className="text-muted-foreground flex items-center gap-1 text-xs">
<input type="checkbox" name="archived" value="1" defaultChecked={filter.includeArchived} /> {t("crm.filter.includeArchived")}
</label>
<label className="text-muted-foreground flex items-center gap-1 text-xs">
<input type="checkbox" name="demo" value="show" defaultChecked={filter.includeDemoData} /> {t("onboarding.demoData.showInLists")}
</label>
<button type="submit" className="text-theme-600 text-sm font-medium">
{t("crm.actions.applyFilter")}
</button>
</form>
{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.list.error">
{t(props.errorKey)}
</p>
) : null}
{!data ? (
<div className="mt-10 text-center" data-ui-id="ui.crm.list.empty">
<p className="text-foreground font-medium">{t(emptyHeadlineKey)}</p>
<p className="text-muted-foreground mt-1 text-sm">{t(emptyBodyKey)}</p>
<a href={props.newHref} className="text-theme-600 mt-2 inline-block text-sm font-medium">
{t("crm.actions.newContact")}
</a>
</div>
) : (
<form method="post" className="mt-6" data-ui-id="ui.crm.list.bulkForm">
<div className="overflow-x-auto">
<table className="w-full text-left text-sm" data-ui-id="ui.crm.list.table">
<thead>
<tr className="text-muted-foreground border-b">
<th className="py-2" />
<th className="py-2">{t("crm.column.name")}</th>
<th className="py-2">{t("crm.column.type")}</th>
<th className="py-2">{t("crm.column.status")}</th>
<th className="py-2">{t("crm.column.email")}</th>
<th className="py-2">{t("crm.column.telefon")}</th>
<th className="py-2">{t("crm.column.owner")}</th>
<th className="py-2">{t("crm.column.tags")}</th>
</tr>
</thead>
<tbody>
{data.rows.map((row) => (
<tr key={row.id} className="border-b" data-row-id={row.id}>
<td className="py-2">
<input type="checkbox" name="kontaktId" value={row.id} aria-label={t("crm.actions.select")} />
</td>
<td className="py-2">
<a href={row.detailHref} className="text-theme-600">
{row.displayName}
</a>
{row.isArchived ? <span className="text-muted-foreground ml-1 text-xs">{t("crm.detail.archivedBadge")}</span> : null}
</td>
<td className="py-2">{t(row.typLabelKey)}</td>
<td className="py-2">{t(row.statusLabelKey)}</td>
<td className="py-2">{row.primaerEmail ?? ""}</td>
<td className="py-2">{row.primaerTelefon ?? ""}</td>
<td className="py-2">{row.zustaendigerLabel ?? ""}</td>
<td className="py-2">
{row.tagChips.map((tag) => (
<span key={tag.id} className="mr-1 inline-flex items-center gap-1">
<span aria-hidden className="inline-block h-2 w-2 rounded-full" style={{ backgroundColor: tag.farbe }} />
{tag.name}
</span>
))}
</td>
</tr>
))}
</tbody>
</table>
</div>
{/* --- Bulk actions (operate on the checked rows) --- */}
<div className="mt-4 flex flex-wrap items-end gap-3" data-ui-id="ui.crm.list.bulk">
<button type="submit" name="intent" value="bulkArchive" className="text-theme-600 text-sm font-medium">
{t("crm.actions.bulkArchive")}
</button>
<span className="flex items-end gap-1">
<select name="zustaendigerUserId" className="border-muted-foreground/40 rounded border px-2 py-1 text-sm" aria-label={t("crm.fields.owner")}>
{props.ownerOptions.map((option) => (
<option key={option.id} value={option.id}>
{option.label}
</option>
))}
</select>
<button type="submit" name="intent" value="bulkReassign" className="text-theme-600 text-sm font-medium">
{t("crm.actions.bulkReassign")}
</button>
</span>
<span className="flex items-end gap-1">
<select name="tagId" className="border-muted-foreground/40 rounded border px-2 py-1 text-sm" aria-label={t("crm.fields.tag")}>
{props.tagOptions.map((tag) => (
<option key={tag.id} value={tag.id}>
{tag.name}
</option>
))}
</select>
<button type="submit" name="intent" value="bulkTag" className="text-theme-600 text-sm font-medium">
{t("crm.actions.bulkTag")}
</button>
</span>
</div>
<nav className="mt-4 flex items-center gap-4 text-sm" data-ui-id="ui.crm.list.pagination">
{data.pagination.hasPrev ? (
<a href={pageHref(props.baseHref, props.query, data.pagination.page - 1)} className="text-theme-600">
{t("crm.pagination.prev")}
</a>
) : null}
<span className="text-muted-foreground">
{t("crm.pagination.page", { page: data.pagination.page, pageCount: Math.max(data.pagination.pageCount, 1), total: data.pagination.total })}
</span>
{data.pagination.hasNext ? (
<a href={pageHref(props.baseHref, props.query, data.pagination.page + 1)} className="text-theme-600">
{t("crm.pagination.next")}
</a>
) : null}
</nav>
</form>
)}
</main>
);
}