// R-P7 (P7 Lead-Inbox) Interim-UI (AD-28) — lead source admin (D-P7 // "Quellen-Verwaltung", archetype A2/A6), composed from ~/ui. Pure: renders the // server-built LeadSourceAdminVM and calls actions.onUpsert / onDelete; the route // POSTs the intents. The webhook token is stored hashed, so the table only shows // whether one exists. No useLoaderData. Final Subframe optics = tracked // design-nachzug. import { useState } from "react"; import { useTranslation } from "react-i18next"; import { FeatherDatabase } from "@subframe/core"; import type { LeadSourceAdminVM } from "@hivegrid/view-models"; 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"; import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageShell } from "../shared/PageShell"; export type LeadSourceUpsertInput = { key: string; name: string; defaultZustaendigerUserId: string }; export type LeadSourcesAdminActions = { onUpsert: (input: LeadSourceUpsertInput) => void; onDelete: (sourceId: string) => void; }; export type LeadSourcesAdminPageProps = { vm: LeadSourceAdminVM; submitting: boolean; errorKey?: string | null; actions: LeadSourcesAdminActions; }; const sectionHeading = "text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary"; const cellText = "text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary"; // Inputs share the card width evenly instead of sizing themselves by content. const fieldWidth = "w-full min-w-0 sm:w-auto sm:shrink sm:grow sm:basis-0"; const NO_OWNER = "__none__"; const EMPTY_DRAFT: LeadSourceUpsertInput = { key: "", name: "", defaultZustaendigerUserId: NO_OWNER }; export function LeadSourcesAdminPage(props: LeadSourcesAdminPageProps) { const { t } = useTranslation(); const [draft, setDraft] = useState(EMPTY_DRAFT); const set = (patch: Partial) => setDraft((s) => ({ ...s, ...patch })); const data = props.vm.status === "ready" ? props.vm.data : null; const rows = data?.rows ?? []; const assignableUsers = data?.assignableUsers ?? []; return ( } title={t("leads.sources.title")} subtitle={t("leads.sources.subtitle")} /> {props.errorKey ? {t(props.errorKey)} : null} {/* Create first, list below — same order as the custom-field admin. */} {data?.canWrite ? ( {t("leads.sources.createTitle")}
{/* The key's format hint rides in the placeholder — as a line of help text below the field it pushed this input off the shared baseline and made the row look misaligned. */} set({ key: e.target.value })} placeholder={t("leads.sources.keyPlaceholder")} data-ui-id="ui.leads.sources.create.key" /> {/* One name field only: the row's displayLabel is what every screen renders, and the service copies the name into it. A second "display label" input asked for the same thing twice. */} set({ name: e.target.value })} data-ui-id="ui.leads.sources.create.name" /> {/* The service already stores a default owner per source and the route already reads it — it just had no control until now. */}
) : null} {rows.length === 0 ? (
) : (
{t("leads.sources.field.name")}{t("leads.sources.field.key")}{t("leads.sources.field.type")}{t("leads.sources.field.defaultOwner")}{t("leads.sources.field.status")} {/* Action column: just wide enough for the button, centred. */} } > {rows.map((row) => ( {row.displayLabel} {row.key} {t(row.typeLabelKey)} {row.defaultZustaendigerLabel ?? "—"}
{row.isPaused ? ( {t("leads.sources.status.paused")} ) : null} {row.hasWebhookToken ? ( {t("leads.sources.status.webhook")} ) : null}
{/* Only custom sources can go: the system ones are wired to built-in capture paths and would break if removed. */} {data?.canWrite && row.type === "custom" ? (
) : null}
))}
)}
); } export default LeadSourcesAdminPage;