153 lines
7.3 KiB
TypeScript
153 lines
7.3 KiB
TypeScript
// 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 (
|
|
<PageShell uiId="ui.crm.admin.duplicates">
|
|
<PageHeader icon={<FeatherCopy className={PAGE_HEADER_ICON_CLASS} />} title={t("crm.admin.duplicates.title")} subtitle={t("crm.admin.duplicates.subtitle")} />
|
|
<PageBody>
|
|
<div data-ui-id="ui.crm.admin.duplicates.locked">
|
|
<EmptyState title={t("crm.locked.headline")} body={t("crm.locked.body")} />
|
|
</div>
|
|
</PageBody>
|
|
</PageShell>
|
|
);
|
|
}
|
|
|
|
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 (
|
|
<PageShell uiId="ui.crm.admin.duplicates">
|
|
<PageHeader icon={<FeatherCopy className={PAGE_HEADER_ICON_CLASS} />} title={t("crm.admin.duplicates.title")} subtitle={t("crm.admin.duplicates.subtitle")} />
|
|
<PageBody>
|
|
{pairs.length === 0 ? (
|
|
<div data-ui-id="ui.crm.admin.duplicates.empty">
|
|
<EmptyState title={t("crm.admin.duplicates.empty")} />
|
|
</div>
|
|
) : (
|
|
<div className="flex w-full flex-col gap-4" data-ui-id="ui.crm.admin.duplicates.list">
|
|
{pairs.map((pair, index) => (
|
|
<Card key={`${pair.a.id}-${pair.b.id}-${index}`} data-row-id={`${pair.a.id}-${pair.b.id}`}>
|
|
<div className="flex items-center gap-2">
|
|
<BadgeFeedback farbe={pair.matchType === "hard" ? "subtle-negative" : "subtle-warning"} size="small">
|
|
{t(`crm.duplicate.matchType.${pair.matchType}`)}
|
|
</BadgeFeedback>
|
|
<span className={mutedSmall}>{t(pair.matchReasonKey)}</span>
|
|
</div>
|
|
<div className="grid w-full gap-3 sm:grid-cols-2">
|
|
{[pair.a, pair.b].map((card) => (
|
|
<div key={card.id} className="flex flex-col gap-1 rounded-sm border border-solid border-border-default p-3">
|
|
<div className="flex w-full items-start justify-between gap-2">
|
|
<AppLink href={props.detailHrefFor(card.id)} className="text-body-default-medium-0 font-body-default-medium-0 text-text-feedback-link-default">
|
|
{card.displayName}
|
|
</AppLink>
|
|
{canDelete ? (
|
|
<IconButton
|
|
variant="destructive"
|
|
size="small"
|
|
icon={<FeatherTrash2 />}
|
|
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}
|
|
</div>
|
|
<span className={mutedSmall}>{t(card.statusLabelKey)}</span>
|
|
{card.primaerEmail ? <span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary">{card.primaerEmail}</span> : null}
|
|
{card.primaerTelefon ? <span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary">{card.primaerTelefon}</span> : null}
|
|
{card.zustaendigerLabel ? <span className={mutedSmall}>{card.zustaendigerLabel}</span> : null}
|
|
</div>
|
|
))}
|
|
</div>
|
|
</Card>
|
|
))}
|
|
</div>
|
|
)}
|
|
</PageBody>
|
|
|
|
<Dialog open={pendingDelete !== null} onOpenChange={(open) => (open ? undefined : setPendingDelete(null))}>
|
|
<Dialog.Content className="w-[420px] max-w-[92vw] p-6" data-ui-id="ui.crm.admin.duplicates.delete.dialog">
|
|
<div className="flex w-full flex-col gap-6">
|
|
<div className="flex w-full flex-col gap-2">
|
|
<span className="text-heading-0 font-heading-0 text-text-neutral-primary">{t("crm.admin.duplicates.delete.title")}</span>
|
|
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
|
{t("crm.admin.duplicates.delete.body", { name: pendingDelete?.name ?? "" })}
|
|
</span>
|
|
</div>
|
|
<div className="flex w-full items-center justify-end gap-2 mobile:flex-col-reverse mobile:items-stretch">
|
|
<Button
|
|
type="button"
|
|
variant="tertiary"
|
|
className="mobile:w-full"
|
|
onClick={() => setPendingDelete(null)}
|
|
data-ui-id="ui.crm.admin.duplicates.delete.cancel"
|
|
>
|
|
{t("shared.cancel")}
|
|
</Button>
|
|
<Button
|
|
type="button"
|
|
variant="destructive"
|
|
className="mobile:w-full"
|
|
icon={<FeatherTrash2 />}
|
|
loading={props.submitting}
|
|
onClick={confirmDelete}
|
|
data-ui-id="ui.crm.admin.duplicates.delete.confirm"
|
|
>
|
|
{t("crm.admin.duplicates.delete.action")}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</Dialog.Content>
|
|
</Dialog>
|
|
</PageShell>
|
|
);
|
|
}
|
|
|
|
export default DuplicateToolPage;
|