287 lines
13 KiB
TypeScript
287 lines
13 KiB
TypeScript
// AK-P21 Interim-UI (AD-28) — tenant deletion area (D-P21 pending). Layout and
|
|
// copy adapted from David's Subframe page "S01 Settings Workspaces
|
|
// Loeschbereich" (WF-P2 Konto loeschen): explanation card with the
|
|
// "request, not immediate" info box, export hint, and the destructive request
|
|
// action. With a pending request the page shows the grace countdown banner
|
|
// with the cancel action instead. Final Subframe optics = design-nachzug.
|
|
|
|
import { useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import { PrivacyBreadcrumbs } from "./PrivacyBreadcrumbs";
|
|
import { FeatherCheck, FeatherDownload, FeatherInfo, FeatherShieldCheck, FeatherTrash2 } from "@subframe/core";
|
|
import type { TenantDeletionVM } from "@hivegrid/view-models";
|
|
import { useLocaleFormatters } from "~/locale/format";
|
|
import { Alert } from "~/ui/components/Alert";
|
|
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 { TenantDeletionWizardDialog, type TenantDeletionSubmitFields } from "./TenantDeletionWizardDialog";
|
|
|
|
export type TenantDeletionActions = {
|
|
readonly onRequest: (fields: TenantDeletionSubmitFields) => void;
|
|
readonly onCancelRequest: (requestId: string) => void | Promise<void>;
|
|
readonly onOpenExport: () => void;
|
|
readonly onRetry: () => void;
|
|
};
|
|
|
|
export function TenantDeletionPage({
|
|
vm,
|
|
actions,
|
|
hubHref,
|
|
embedded = false,
|
|
submitting = false,
|
|
errorKey = null,
|
|
}: {
|
|
vm: TenantDeletionVM;
|
|
actions: TenantDeletionActions;
|
|
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 [wizardOpen, setWizardOpen] = useState(false);
|
|
const [cancelOpen, setCancelOpen] = useState(false);
|
|
const [cancelling, setCancelling] = 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.deletion.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.deletion.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.deletion.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.deletion.empty">
|
|
<EmptyState outlined title={t("settings.privacy.states.errorTitle")} body={t("settings.privacy.states.loadingDescription")} />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const { data } = vm;
|
|
const request = data.request;
|
|
const pendingRequest = request && request.status === "pending" ? request : null;
|
|
const executingRequest = request && request.status === "executing" ? request : null;
|
|
|
|
async function confirmCancel(): Promise<void> {
|
|
if (!pendingRequest) return;
|
|
setCancelling(true);
|
|
try {
|
|
await actions.onCancelRequest(pendingRequest.id);
|
|
setCancelOpen(false);
|
|
} finally {
|
|
setCancelling(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="bg-surface-neutral-primary flex w-full flex-col items-start" data-ui-id="ui.settings.privacy.deletion.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.deletion.title" />
|
|
<h1 className="text-heading- font-heading- text-text-neutral-primary">{t("settings.privacy.deletion.title")}</h1>
|
|
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-tertiary">
|
|
{t("settings.privacy.deletion.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.deletion.intro">{t("settings.privacy.deletion.description")}</PageIntro> : null}
|
|
{pendingRequest ? (
|
|
<Card variant="warning" data-ui-id="ui.settings.privacy.deletion.grace">
|
|
<div className="flex w-full flex-col items-start gap-4">
|
|
<Alert
|
|
notDismissible
|
|
variant="warning"
|
|
title={t("settings.privacy.deletion.grace.title", { days: pendingRequest.graceDaysRemaining })}
|
|
description={t("settings.privacy.deletion.grace.description", {
|
|
date: formatters.date(pendingRequest.gracePeriodEndsAt, { dateStyle: "medium", timeStyle: "short" }),
|
|
})}
|
|
/>
|
|
<div className="flex w-full items-center justify-between gap-4 mobile:flex-col mobile:items-stretch">
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
|
{t("settings.privacy.deletion.grace.requestedAt", {
|
|
date: formatters.date(pendingRequest.createdAt, { dateStyle: "medium" }),
|
|
})}
|
|
</span>
|
|
<Button
|
|
className="mobile:w-full"
|
|
variant="secondary"
|
|
onClick={() => setCancelOpen(true)}
|
|
data-ui-id="ui.settings.privacy.deletion.cancel"
|
|
>
|
|
{t("settings.privacy.deletion.grace.cancelCta")}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</Card>
|
|
) : null}
|
|
|
|
{executingRequest ? (
|
|
<Alert
|
|
notDismissible
|
|
variant="error"
|
|
title={t("settings.privacy.deletion.executing.title")}
|
|
description={t("settings.privacy.deletion.executing.description")}
|
|
/>
|
|
) : null}
|
|
|
|
{!pendingRequest && !executingRequest ? (
|
|
<Card data-ui-id="ui.settings.privacy.deletion.request">
|
|
<div className="flex w-full flex-col items-start gap-5">
|
|
<div className="flex w-full items-start gap-3">
|
|
<div className="bg-surface-feedback-subtle-warning flex h-9 w-9 flex-none items-center justify-center rounded-md">
|
|
<FeatherTrash2 className="text-body-large font-body-large text-icon-feedback-warning" />
|
|
</div>
|
|
<div className="flex grow shrink-0 basis-0 flex-col items-start gap-1">
|
|
<span className="text-heading- font-heading- text-text-neutral-primary">
|
|
{t("settings.privacy.deletion.request.title")}
|
|
</span>
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
|
{t("settings.privacy.deletion.request.description", { days: data.graceDays })}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="border-border-information-subtle bg-surface-feedback-subtle-information flex w-full flex-col items-start gap-2 rounded-md border border-solid px-4 py-4">
|
|
<div className="flex w-full items-center gap-2">
|
|
<FeatherInfo className="text-body-default-regular-0 font-body-default-regular-0 text-icon-feedback-information" />
|
|
<span className="text-body-small-semibold-0 font-body-small-semibold-0 text-text-feedback-information">
|
|
{t("settings.privacy.deletion.request.notImmediateTitle")}
|
|
</span>
|
|
</div>
|
|
{(["grace", "cancel"] as const).map((point) => (
|
|
<div key={point} className="flex w-full items-start gap-2">
|
|
<FeatherCheck className="text-body-small-regular-0 font-body-small-regular-0 text-icon-feedback-information" />
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-feedback-information">
|
|
{t(`settings.privacy.deletion.request.point.${point}`, { days: data.graceDays })}
|
|
</span>
|
|
</div>
|
|
))}
|
|
</div>
|
|
|
|
<div className="border-border-default bg-surface-neutral-primary mobile:flex-col mobile:items-stretch flex w-full items-start gap-3 rounded-md border border-solid px-4 py-4">
|
|
<FeatherDownload className="text-body-large font-body-large text-icon-neutral-tertiary" />
|
|
<div className="flex grow shrink-0 basis-0 flex-col items-start gap-0.5">
|
|
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-primary">
|
|
{t("settings.privacy.deletion.request.exportTitle")}
|
|
</span>
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
|
{t("settings.privacy.deletion.request.exportDescription")}
|
|
</span>
|
|
</div>
|
|
<Button
|
|
className="mobile:w-full"
|
|
variant="tertiary"
|
|
size="small"
|
|
icon={<FeatherDownload />}
|
|
onClick={actions.onOpenExport}
|
|
data-ui-id="ui.settings.privacy.deletion.openExport"
|
|
>
|
|
{t("settings.privacy.deletion.request.exportCta")}
|
|
</Button>
|
|
</div>
|
|
|
|
<div className="bg-border-default flex h-px w-full flex-none flex-col items-start" />
|
|
|
|
<div className="mobile:flex-col mobile:items-stretch mobile:gap-4 flex w-full items-center justify-between gap-4">
|
|
<div className="flex items-center gap-2">
|
|
<FeatherShieldCheck className="text-body-default-regular-0 font-body-default-regular-0 text-icon-feedback-positive" />
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
|
{t("settings.privacy.deletion.request.permissionNote")}
|
|
</span>
|
|
</div>
|
|
<Button
|
|
className="mobile:w-full"
|
|
variant="destructive"
|
|
icon={<FeatherTrash2 />}
|
|
disabled={!data.canRequest}
|
|
onClick={() => setWizardOpen(true)}
|
|
data-ui-id="ui.settings.privacy.deletion.open"
|
|
>
|
|
{t("settings.privacy.deletion.request.cta")}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</Card>
|
|
) : null}
|
|
</div>
|
|
|
|
<TenantDeletionWizardDialog
|
|
open={wizardOpen}
|
|
tenantSlug={data.tenantSlug}
|
|
graceDays={data.graceDays}
|
|
requiresOtp={data.requiresOtp}
|
|
submitting={submitting}
|
|
errorKey={errorKey}
|
|
onSubmit={actions.onRequest}
|
|
onOpenExport={actions.onOpenExport}
|
|
onClose={() => setWizardOpen(false)}
|
|
/>
|
|
|
|
<Dialog open={cancelOpen} onOpenChange={(open: boolean) => (open ? undefined : setCancelOpen(false))}>
|
|
<Dialog.Content
|
|
className="w-[420px] max-w-[90vw] p-4"
|
|
aria-label={t("settings.privacy.deletion.cancelDialog.title")}
|
|
data-ui-id="ui.settings.privacy.deletion.cancelDialog"
|
|
>
|
|
<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.deletion.cancelDialog.title")}</span>
|
|
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
|
{t("settings.privacy.deletion.cancelDialog.description")}
|
|
</span>
|
|
</div>
|
|
<div className="flex w-full items-center justify-end gap-2 pt-4">
|
|
<Button variant="tertiary" disabled={cancelling} onClick={() => setCancelOpen(false)}>
|
|
{t("shared.cancel")}
|
|
</Button>
|
|
<Button
|
|
loading={cancelling}
|
|
onClick={() => void confirmCancel()}
|
|
data-ui-id="ui.settings.privacy.deletion.cancelConfirm"
|
|
>
|
|
{t("settings.privacy.deletion.cancelDialog.confirm")}
|
|
</Button>
|
|
</div>
|
|
</Dialog.Content>
|
|
</Dialog>
|
|
</div>
|
|
);
|
|
}
|