263 lines
12 KiB
TypeScript
263 lines
12 KiB
TypeScript
// AK-P21 Interim-UI (AD-28) — AVV (data processing agreement) page (D-P21
|
|
// pending). Current version card + acceptance history table + re-acceptance
|
|
// dialog (S 560). The PDF download is interim-disabled because no AVV source
|
|
// PDF ships in the repo yet — the button stays visible with a plain-language
|
|
// interim hint so David's final D-P21 delta only swaps optics, not flow.
|
|
|
|
import { useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import { PrivacyBreadcrumbs } from "./PrivacyBreadcrumbs";
|
|
import { FeatherDownload, FeatherFileText } from "@subframe/core";
|
|
import type { AvvVM } from "@hivegrid/view-models";
|
|
import { useLocaleFormatters } from "~/locale/format";
|
|
import { Alert } from "~/ui/components/Alert";
|
|
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
|
import { Button } from "~/ui/components/Button";
|
|
import { Card } from "~/ui/components/Card";
|
|
import { PageIntro } from "../shared/PageShell";
|
|
import { Dialog } from "~/ui/components/Dialog";
|
|
import { EmptyState } from "~/ui/components/EmptyState";
|
|
import { Loader } from "~/ui/components/Loader";
|
|
import { Table } from "~/ui/components/Table";
|
|
import { TextInput } from "~/ui/components/TextInput";
|
|
|
|
export type AvvActions = {
|
|
readonly onAccept: (fields: { signerName: string; signerRole: string }) => void | Promise<void>;
|
|
readonly onRetry: () => void;
|
|
};
|
|
|
|
export function AvvPage({
|
|
vm,
|
|
actions,
|
|
hubHref,
|
|
embedded = false,
|
|
submitting = false,
|
|
errorKey = null,
|
|
}: {
|
|
vm: AvvVM;
|
|
actions: AvvActions;
|
|
hubHref: string;
|
|
/** Inside the Compliance hub (AK-SET-01) the hub owns breadcrumb and heading. */
|
|
embedded?: boolean;
|
|
submitting?: boolean;
|
|
errorKey?: string | null;
|
|
}): React.JSX.Element {
|
|
const { t } = useTranslation();
|
|
const formatters = useLocaleFormatters();
|
|
const [acceptOpen, setAcceptOpen] = useState(false);
|
|
const [signerName, setSignerName] = useState("");
|
|
const [signerRole, setSignerRole] = useState("");
|
|
const [accepting, setAccepting] = useState(false);
|
|
|
|
if (vm.status === "idle" || vm.status === "loading") {
|
|
return (
|
|
<div className="flex w-full flex-col items-start gap-6 px-6 py-6" data-ui-id="ui.settings.privacy.avv.loading">
|
|
<Card>
|
|
<div className="flex w-full items-center gap-3">
|
|
<Loader />
|
|
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
|
{t("settings.privacy.states.loadingDescription")}
|
|
</span>
|
|
</div>
|
|
</Card>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (vm.status === "error") {
|
|
return (
|
|
<div className="flex w-full flex-col items-start gap-6 px-6 py-6" data-ui-id="ui.settings.privacy.avv.error">
|
|
<EmptyState
|
|
outlined
|
|
variant="error"
|
|
title={t("settings.privacy.states.errorTitle")}
|
|
body={t(vm.error.messageKey)}
|
|
action={
|
|
<Button variant="tertiary" onClick={actions.onRetry} data-ui-id="ui.settings.privacy.avv.retry">
|
|
{t("settings.privacy.states.retry")}
|
|
</Button>
|
|
}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (vm.status === "empty") {
|
|
return (
|
|
<div className="flex w-full flex-col items-start gap-6 px-6 py-6" data-ui-id="ui.settings.privacy.avv.empty">
|
|
<EmptyState outlined title={t("settings.privacy.states.errorTitle")} body={t("settings.privacy.states.loadingDescription")} />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const { data } = vm;
|
|
|
|
async function confirmAccept(): Promise<void> {
|
|
setAccepting(true);
|
|
try {
|
|
await actions.onAccept({ signerName: signerName.trim(), signerRole: signerRole.trim() });
|
|
setAcceptOpen(false);
|
|
setSignerName("");
|
|
setSignerRole("");
|
|
} finally {
|
|
setAccepting(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="bg-surface-neutral-primary flex w-full flex-col items-start" data-ui-id="ui.settings.privacy.avv.page">
|
|
{embedded ? null : (
|
|
<div className="border-border-default bg-surface-neutral-secondary mobile:px-4 flex w-full flex-col items-start border-b border-solid px-6 py-6">
|
|
<PrivacyBreadcrumbs hubHref={hubHref} titleKey="settings.privacy.avv.title" />
|
|
<h1 className="text-heading- font-heading- text-text-neutral-primary">{t("settings.privacy.avv.title")}</h1>
|
|
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-tertiary">
|
|
{t("settings.privacy.avv.description")}
|
|
</span>
|
|
</div>
|
|
)}
|
|
|
|
{/* Full content width: the cards were capped at 720px, which left the
|
|
screen looking like a narrow column with two thirds of the page empty. */}
|
|
<div className="mobile:px-4 flex w-full flex-col items-start gap-6 px-6 py-6">
|
|
{embedded ? <PageIntro uiId="ui.settings.privacy.avv.intro">{t("settings.privacy.avv.description")}</PageIntro> : null}
|
|
{data.needsReacceptance ? (
|
|
<Alert
|
|
notDismissible
|
|
variant="warning"
|
|
title={t("settings.privacy.avv.reaccept.noticeTitle", { version: data.currentVersion })}
|
|
description={t("settings.privacy.avv.reaccept.noticeDescription")}
|
|
/>
|
|
) : null}
|
|
{errorKey ? <Alert variant="error" title={t(errorKey)} /> : null}
|
|
|
|
<Card data-ui-id="ui.settings.privacy.avv.current">
|
|
<div className="mobile:flex-col mobile:items-stretch flex w-full items-center gap-4">
|
|
<div className="border-border-default bg-surface-neutral-tertiary flex h-12 w-12 flex-none items-center justify-center rounded-md border border-solid">
|
|
<FeatherFileText className="text-heading- font-heading- text-icon-neutral-tertiary" />
|
|
</div>
|
|
<div className="flex grow shrink-0 basis-0 flex-col items-start gap-1">
|
|
<div className="flex items-center gap-2">
|
|
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
|
{t("settings.privacy.avv.current.title", { version: data.currentVersion })}
|
|
</span>
|
|
<BadgeFeedback farbe={data.currentAccepted ? "subtle-positive" : "subtle-warning"} size="small">
|
|
{data.currentAccepted ? t("settings.privacy.avv.current.acceptedBadge") : t("settings.privacy.avv.current.openBadge")}
|
|
</BadgeFeedback>
|
|
</div>
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
|
{data.pdfAvailable ? t("settings.privacy.avv.current.pdfHint") : t("settings.privacy.avv.current.pdfUnavailableHint")}
|
|
</span>
|
|
</div>
|
|
<div className="mobile:w-full mobile:flex-col flex items-center gap-2">
|
|
<Button
|
|
className="mobile:w-full"
|
|
variant="secondary"
|
|
icon={<FeatherDownload />}
|
|
disabled={!data.pdfAvailable}
|
|
data-ui-id="ui.settings.privacy.avv.pdfDownload"
|
|
>
|
|
{t("settings.privacy.avv.pdfDownload")}
|
|
</Button>
|
|
{!data.currentAccepted ? (
|
|
<Button className="mobile:w-full" onClick={() => setAcceptOpen(true)} data-ui-id="ui.settings.privacy.avv.accept">
|
|
{t("settings.privacy.avv.reaccept.cta")}
|
|
</Button>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
</Card>
|
|
|
|
<Card data-ui-id="ui.settings.privacy.avv.history">
|
|
<div className="flex w-full flex-col items-start">
|
|
<span className="text-body-large font-body-large text-text-neutral-primary">{t("settings.privacy.avv.history.title")}</span>
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
|
{t("settings.privacy.avv.history.description")}
|
|
</span>
|
|
</div>
|
|
{data.acceptances.length === 0 ? (
|
|
<EmptyState title={t("settings.privacy.avv.history.emptyTitle")} body={t("settings.privacy.avv.history.emptyDescription")} />
|
|
) : (
|
|
<div className="w-full overflow-x-auto">
|
|
<Table
|
|
header={
|
|
<Table.HeaderRow>
|
|
<Table.HeaderCell>{t("settings.privacy.avv.columns.version")}</Table.HeaderCell>
|
|
<Table.HeaderCell>{t("settings.privacy.avv.columns.date")}</Table.HeaderCell>
|
|
<Table.HeaderCell>{t("settings.privacy.avv.columns.signer")}</Table.HeaderCell>
|
|
<Table.HeaderCell>{t("settings.privacy.avv.columns.role")}</Table.HeaderCell>
|
|
</Table.HeaderRow>
|
|
}
|
|
>
|
|
{data.acceptances.map((acceptance) => (
|
|
<Table.Row key={acceptance.id}>
|
|
<Table.Cell>
|
|
<div className="flex items-center gap-2">
|
|
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-primary">{acceptance.avvVersion}</span>
|
|
{acceptance.isCurrentVersion ? (
|
|
<BadgeFeedback farbe="subtle-positive" size="small">
|
|
{t("settings.privacy.avv.currentBadge")}
|
|
</BadgeFeedback>
|
|
) : null}
|
|
</div>
|
|
</Table.Cell>
|
|
<Table.Cell>
|
|
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary">
|
|
{formatters.date(acceptance.createdAt, { dateStyle: "medium", timeStyle: "short" })}
|
|
</span>
|
|
</Table.Cell>
|
|
<Table.Cell>
|
|
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary">{acceptance.signerName}</span>
|
|
</Table.Cell>
|
|
<Table.Cell>
|
|
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">{acceptance.signerRole ?? "—"}</span>
|
|
</Table.Cell>
|
|
</Table.Row>
|
|
))}
|
|
</Table>
|
|
</div>
|
|
)}
|
|
</Card>
|
|
</div>
|
|
|
|
<Dialog open={acceptOpen} onOpenChange={(open: boolean) => (open ? undefined : setAcceptOpen(false))}>
|
|
<Dialog.Content
|
|
className="w-[560px] max-w-[90vw] p-4"
|
|
aria-label={t("settings.privacy.avv.reaccept.title")}
|
|
data-ui-id="ui.settings.privacy.avv.acceptDialog"
|
|
>
|
|
<div className="flex w-full flex-col items-start gap-2">
|
|
<span className="text-heading-0 font-heading-0 text-text-neutral-primary">
|
|
{t("settings.privacy.avv.reaccept.title", { version: data.currentVersion })}
|
|
</span>
|
|
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
|
{t("settings.privacy.avv.reaccept.description")}
|
|
</span>
|
|
</div>
|
|
<div className="flex w-full flex-col items-start gap-4 pt-4">
|
|
<TextInput className="w-full" label={t("settings.privacy.avv.reaccept.signerNameLabel")} showLabel>
|
|
<TextInput.Input value={signerName} onChange={(event) => setSignerName(event.target.value)} required />
|
|
</TextInput>
|
|
<TextInput className="w-full" label={t("settings.privacy.avv.reaccept.signerRoleLabel")} showLabel>
|
|
<TextInput.Input value={signerRole} onChange={(event) => setSignerRole(event.target.value)} />
|
|
</TextInput>
|
|
</div>
|
|
<div className="flex w-full items-center justify-end gap-2 pt-4">
|
|
<Button variant="tertiary" disabled={accepting || submitting} onClick={() => setAcceptOpen(false)}>
|
|
{t("shared.cancel")}
|
|
</Button>
|
|
<Button
|
|
loading={accepting || submitting}
|
|
disabled={signerName.trim().length === 0}
|
|
onClick={() => void confirmAccept()}
|
|
data-ui-id="ui.settings.privacy.avv.acceptConfirm"
|
|
>
|
|
{t("settings.privacy.avv.reaccept.confirm")}
|
|
</Button>
|
|
</div>
|
|
</Dialog.Content>
|
|
</Dialog>
|
|
</div>
|
|
);
|
|
}
|