// R-P6 (P6 CRM core) Interim-UI (AD-28) — contact custom-field admin (D-CRM // "Custom-Felder", archetype A2), composed from ~/ui. Pure/presentational: renders // the server-built CustomFieldAdminVM and calls actions.onArchive / onCreate; the // route POSTs the intents. Final Subframe optics = tracked design-nachzug. import { useState } from "react"; import { useTranslation } from "react-i18next"; import { FeatherSlidersHorizontal } from "@subframe/core"; import type { CustomFieldAdminVM, CustomFieldDatentyp } from "@hivegrid/view-models"; import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageShell } from "../shared/PageShell"; import { BadgeFeedback } from "~/ui/components/BadgeFeedback"; import { Button } from "~/ui/components/Button"; import { Card } from "~/ui/components/Card"; import { EmptyState } from "~/ui/components/EmptyState"; import { Select } from "~/ui/components/Select"; import { Table } from "~/ui/components/Table"; import { TextInput } from "~/ui/components/TextInput"; const DATENTYPEN: readonly CustomFieldDatentyp[] = [ "text", "textarea", "zahl", "waehrung", "datum", "datum_range", "select", "multiselect", "boolean", "email", "telefon", "datei", "prozent", "datum_zeit", "person_team", "adresse", "link", ]; export type CustomFieldCreateInput = { key: string; label: string; datentyp: string; optionen: string }; export type CustomFieldAdminPageActions = { onCreate: (input: CustomFieldCreateInput) => void; onArchive: (definitionId: string) => void; }; export type CustomFieldAdminPageProps = { vm: CustomFieldAdminVM; moduleActive: boolean; submitting: boolean; errorKey?: string | null; actions: CustomFieldAdminPageActions; }; const sectionHeading = "text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary"; export function CustomFieldAdminPage(props: CustomFieldAdminPageProps) { const { t } = useTranslation(); const [draft, setDraft] = useState({ key: "", label: "", datentyp: "text", optionen: "" }); const set = (patch: Partial) => setDraft((s) => ({ ...s, ...patch })); if (!props.moduleActive) { return ( } title={t("crm.admin.customFields.title")} subtitle={t("crm.admin.customFields.subtitle")} />
); } const rows = props.vm.status === "ready" && props.vm.data ? props.vm.data.rows : []; return ( } title={t("crm.admin.customFields.title")} subtitle={t("crm.admin.customFields.subtitle")} /> {props.errorKey ? {t(props.errorKey)} : null} {/* Create first, list below: this page exists to add fields, and the table grows over time — a form pushed below it drifts out of reach. */} {t("crm.admin.customFields.addHeading")} {/* The inputs share the card's full width evenly (basis-0 + grow), so they line up as one band instead of sizing themselves by content. */}
set({ key: e.target.value })} data-ui-id="ui.crm.admin.customFields.create.key" /> set({ label: e.target.value })} data-ui-id="ui.crm.admin.customFields.create.label" /> set({ optionen: e.target.value })} placeholder={t("crm.admin.customFields.optionsPlaceholder")} />
{rows.length > 0 ? (
{t("crm.admin.customFields.colKey")}{t("crm.admin.customFields.colLabel")}{t("crm.admin.customFields.colType")} {/* Action column: just wide enough for the button, centred. */} } > {rows.map((row) => ( {row.key}
{row.label} {row.isDemoData ? {t("crm.admin.demoBadge")} : null} {row.archiviert ? {t("crm.admin.archivedBadge")} : null}
{t(row.datentypLabelKey)} {!row.archiviert ? (
{/* Labelled "delete" but backed by the archive intent: the definition keeps existing so the values already stored on contacts are never dropped. */}
) : null}
))}
) : null}
); } export default CustomFieldAdminPage;