// R-P6 (P6 CRM core) Interim-UI (AD-28) — duplicate tool (D-CRM "Duplikat-Tool", // archetype A5), composed from ~/ui. Presentational: renders the server-built // DuplicateVM candidate pairs side-by-side (DoD 4 surface). Each contact carries a // destructive delete affordance (permission-gated) that opens an in-app confirm // dialog before the route hard-deletes it. The actual merge lands in a later phase // (VM exposes canMerge, kept false). Final Subframe optics = tracked design-nachzug. import { useState } from "react"; import { useTranslation } from "react-i18next"; import { FeatherCopy, FeatherTrash2 } from "@subframe/core"; import type { DuplicateVM } 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 { Dialog } from "~/ui/components/Dialog"; import { EmptyState } from "~/ui/components/EmptyState"; import { IconButton } from "~/ui/components/IconButton"; import { AppLink } from "~/components/app/AppLink"; export type DuplicateToolPageActions = { /** Hard-delete a single contact (route POSTs the intent, then revalidates). */ onDelete: (kontaktId: string) => void; }; export type DuplicateToolPageProps = { vm: DuplicateVM; moduleActive: boolean; detailHrefFor: (kontaktId: string) => string; /** Gate the destructive affordance on crm.delete (loader-provided). */ canDelete?: boolean; submitting?: boolean; actions?: DuplicateToolPageActions; }; const mutedSmall = "text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary"; export function DuplicateToolPage(props: DuplicateToolPageProps) { const { t } = useTranslation(); // The contact currently pending confirmation (null = dialog closed). const [pendingDelete, setPendingDelete] = useState<{ id: string; name: string } | null>(null); if (!props.moduleActive) { return ( } title={t("crm.admin.duplicates.title")} subtitle={t("crm.admin.duplicates.subtitle")} />
); } const pairs = props.vm.status === "ready" && props.vm.data ? props.vm.data.pairs : []; const canDelete = props.canDelete === true && Boolean(props.actions?.onDelete); const confirmDelete = () => { if (pendingDelete) props.actions?.onDelete(pendingDelete.id); setPendingDelete(null); }; return ( } title={t("crm.admin.duplicates.title")} subtitle={t("crm.admin.duplicates.subtitle")} /> {pairs.length === 0 ? (
) : (
{pairs.map((pair, index) => (
{t(`crm.duplicate.matchType.${pair.matchType}`)} {t(pair.matchReasonKey)}
{[pair.a, pair.b].map((card) => (
{card.displayName} {canDelete ? ( } loading={props.submitting} aria-label={t("crm.admin.duplicates.delete.action")} onClick={() => setPendingDelete({ id: card.id, name: card.displayName })} data-ui-id={`ui.crm.admin.duplicates.delete.${card.id}`} /> ) : null}
{t(card.statusLabelKey)} {card.primaerEmail ? {card.primaerEmail} : null} {card.primaerTelefon ? {card.primaerTelefon} : null} {card.zustaendigerLabel ? {card.zustaendigerLabel} : null}
))}
))}
)}
(open ? undefined : setPendingDelete(null))}>
{t("crm.admin.duplicates.delete.title")} {t("crm.admin.duplicates.delete.body", { name: pendingDelete?.name ?? "" })}
); } export default DuplicateToolPage;