253 lines
12 KiB
TypeScript
253 lines
12 KiB
TypeScript
// AK-P21 Interim-UI (AD-28) — tenant deletion wizard as a REAL ~/ui Dialog
|
|
// (size M 720) with a StepperHorizontal. Copy and structure adapted from
|
|
// David's Subframe pages "S01 Settings Workspaces Loeschbereich" +
|
|
// "M01 Loeschung anfragen" (WF-P2 Konto loeschen) and the re-auth step from
|
|
// "M01 Identitaet bestaetigen" (WF-P2 Change Password). Steps:
|
|
// explain (30d grace, read-only, hard delete) → export offer → billing note
|
|
// (Lago/Mollie gateway wording, AD-27) → verify (password + optional TOTP) →
|
|
// slug confirm phrase. Submits go through the injected onSubmit callback —
|
|
// no fetching in here. Final Subframe optics = tracked design-nachzug.
|
|
//
|
|
// Interim simplification: the TOTP code uses a single TextInput instead of
|
|
// the InputOtp compound; David's final D-P21 screens may swap it back.
|
|
|
|
import { useEffect, useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { FeatherCheck, FeatherDownload, FeatherInfo, FeatherSend, FeatherShieldCheck, FeatherTrash2 } from "@subframe/core";
|
|
import { Alert } from "~/ui/components/Alert";
|
|
import { Button } from "~/ui/components/Button";
|
|
import { Dialog } from "~/ui/components/Dialog";
|
|
import { StepperHorizontal } from "~/ui/components/StepperHorizontal";
|
|
import { TextArea } from "~/ui/components/TextArea";
|
|
import { TextInput } from "~/ui/components/TextInput";
|
|
|
|
export type TenantDeletionSubmitFields = {
|
|
password: string;
|
|
otpCode: string;
|
|
slugConfirm: string;
|
|
reasonText: string;
|
|
};
|
|
|
|
export type TenantDeletionWizardDialogProps = {
|
|
open: boolean;
|
|
tenantSlug: string;
|
|
graceDays: number;
|
|
requiresOtp: boolean;
|
|
submitting: boolean;
|
|
errorKey?: string | null;
|
|
onSubmit: (fields: TenantDeletionSubmitFields) => void;
|
|
onOpenExport: () => void;
|
|
onClose: () => void;
|
|
};
|
|
|
|
const STEPS = ["explain", "export", "billing", "verify", "confirm"] as const;
|
|
|
|
const bodyText = "text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary";
|
|
|
|
export function TenantDeletionWizardDialog(props: TenantDeletionWizardDialogProps) {
|
|
const { open, tenantSlug, graceDays, requiresOtp, submitting, errorKey, onSubmit, onOpenExport, onClose } = props;
|
|
const { t } = useTranslation();
|
|
const [step, setStep] = useState(0);
|
|
const [password, setPassword] = useState("");
|
|
const [otpCode, setOtpCode] = useState("");
|
|
const [slugConfirm, setSlugConfirm] = useState("");
|
|
const [reasonText, setReasonText] = useState("");
|
|
|
|
useEffect(() => {
|
|
if (open) {
|
|
setStep(0);
|
|
setPassword("");
|
|
setOtpCode("");
|
|
setSlugConfirm("");
|
|
setReasonText("");
|
|
}
|
|
}, [open]);
|
|
|
|
const verifyIncomplete = password.trim().length === 0 || (requiresOtp && otpCode.trim().length < 6);
|
|
const slugMismatch = slugConfirm.length > 0 && slugConfirm !== tenantSlug;
|
|
const confirmIncomplete = slugConfirm !== tenantSlug;
|
|
|
|
function submit() {
|
|
onSubmit({ password: password.trim(), otpCode: otpCode.trim(), slugConfirm, reasonText: reasonText.trim() });
|
|
}
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={(nextOpen: boolean) => (nextOpen ? undefined : onClose())}>
|
|
<Dialog.Content className="w-[720px] max-w-[90vw] p-6" aria-label={t("settings.privacy.deletion.wizard.title")}>
|
|
<div className="flex w-full flex-col gap-6" data-ui-id="ui.settings.privacy.deletion.wizard">
|
|
<div className="flex flex-col gap-2">
|
|
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("settings.privacy.deletion.wizard.title")}</span>
|
|
{errorKey ? <Alert variant="error" title={t(errorKey)} /> : null}
|
|
</div>
|
|
|
|
<StepperHorizontal>
|
|
{STEPS.map((key, index) => (
|
|
<StepperHorizontal.Step
|
|
key={key}
|
|
firstStep={index === 0}
|
|
lastStep={index === STEPS.length - 1}
|
|
stepNumber={String(index + 1)}
|
|
label={t(`settings.privacy.deletion.wizard.step.${key}`)}
|
|
variant={index === step ? "active" : index < step ? "completed" : "default"}
|
|
/>
|
|
))}
|
|
</StepperHorizontal>
|
|
|
|
{step === 0 ? (
|
|
<div className="flex w-full flex-col gap-4" data-wizard-step="explain">
|
|
<span className={bodyText}>{t("settings.privacy.deletion.wizard.explain.body", { days: graceDays })}</span>
|
|
<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.wizard.explain.notImmediateTitle")}
|
|
</span>
|
|
</div>
|
|
{(["grace", "readOnly", "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.wizard.explain.point.${point}`, { days: graceDays })}
|
|
</span>
|
|
</div>
|
|
))}
|
|
</div>
|
|
<TextArea className="w-full max-w-none" label={t("settings.privacy.deletion.wizard.explain.reasonLabel")} showLabel>
|
|
<TextArea.Input value={reasonText} onChange={(event) => setReasonText(event.target.value)} data-wizard-field="reasonText" />
|
|
</TextArea>
|
|
</div>
|
|
) : null}
|
|
|
|
{step === 1 ? (
|
|
<div className="flex w-full flex-col gap-4" data-wizard-step="export">
|
|
<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.wizard.export.title")}
|
|
</span>
|
|
<span className={bodyText}>{t("settings.privacy.deletion.wizard.export.description")}</span>
|
|
</div>
|
|
<Button
|
|
className="mobile:w-full"
|
|
variant="tertiary"
|
|
size="small"
|
|
icon={<FeatherDownload />}
|
|
onClick={onOpenExport}
|
|
data-ui-id="ui.settings.privacy.deletion.wizard.openExport"
|
|
>
|
|
{t("settings.privacy.deletion.wizard.export.cta")}
|
|
</Button>
|
|
</div>
|
|
<span className={bodyText}>{t("settings.privacy.deletion.wizard.export.skipHint")}</span>
|
|
</div>
|
|
) : null}
|
|
|
|
{step === 2 ? (
|
|
<div className="flex w-full flex-col gap-4" data-wizard-step="billing">
|
|
<Alert
|
|
notDismissible
|
|
variant="information"
|
|
title={t("settings.privacy.deletion.wizard.billing.title")}
|
|
description={t("settings.privacy.deletion.wizard.billing.description")}
|
|
/>
|
|
<span className={bodyText}>{t("settings.privacy.deletion.wizard.billing.timing")}</span>
|
|
</div>
|
|
) : null}
|
|
|
|
{step === 3 ? (
|
|
<div className="flex w-full flex-col gap-4" data-wizard-step="verify">
|
|
<div className="flex w-full items-center gap-2">
|
|
<FeatherShieldCheck className="text-body-default-regular-0 font-body-default-regular-0 text-icon-feedback-information" />
|
|
<span className={bodyText}>{t("settings.privacy.deletion.wizard.verify.body")}</span>
|
|
</div>
|
|
<TextInput className="w-full" label={t("settings.privacy.deletion.wizard.verify.passwordLabel")} showLabel>
|
|
<TextInput.Input
|
|
type="password"
|
|
autoComplete="current-password"
|
|
value={password}
|
|
onChange={(event) => setPassword(event.target.value)}
|
|
required
|
|
data-wizard-field="password"
|
|
/>
|
|
</TextInput>
|
|
{requiresOtp ? (
|
|
<TextInput
|
|
className="w-full"
|
|
label={t("settings.privacy.deletion.wizard.verify.otpLabel")}
|
|
helpText={t("settings.privacy.deletion.wizard.verify.otpHelp")}
|
|
showLabel
|
|
>
|
|
<TextInput.Input
|
|
inputMode="numeric"
|
|
autoComplete="one-time-code"
|
|
maxLength={6}
|
|
value={otpCode}
|
|
onChange={(event) => setOtpCode(event.target.value.replace(/\D/g, ""))}
|
|
required
|
|
data-wizard-field="otpCode"
|
|
/>
|
|
</TextInput>
|
|
) : null}
|
|
</div>
|
|
) : null}
|
|
|
|
{step === 4 ? (
|
|
<div className="flex w-full flex-col gap-4" data-wizard-step="confirm">
|
|
<Alert notDismissible variant="error" title={t("settings.privacy.deletion.wizard.confirm.warningTitle")} description={t("settings.privacy.deletion.wizard.confirm.warningDescription", { days: graceDays })} />
|
|
<TextInput
|
|
className="w-full"
|
|
label={t("settings.privacy.deletion.wizard.confirm.slugLabel", { slug: tenantSlug })}
|
|
showLabel
|
|
error={slugMismatch}
|
|
message={slugMismatch ? t("settings.privacy.deletion.wizard.confirm.slugMismatch") : undefined}
|
|
>
|
|
<TextInput.Input
|
|
autoComplete="off"
|
|
value={slugConfirm}
|
|
onChange={(event) => setSlugConfirm(event.target.value)}
|
|
placeholder={tenantSlug}
|
|
required
|
|
data-wizard-field="slugConfirm"
|
|
/>
|
|
</TextInput>
|
|
</div>
|
|
) : null}
|
|
|
|
<div className="flex w-full items-center justify-end gap-2">
|
|
<Button variant="tertiary" onClick={onClose}>
|
|
{t("shared.cancel")}
|
|
</Button>
|
|
{step > 0 ? (
|
|
<Button variant="secondary" onClick={() => setStep(step - 1)}>
|
|
{t("shared.back")}
|
|
</Button>
|
|
) : null}
|
|
{step < STEPS.length - 1 ? (
|
|
<Button
|
|
disabled={step === 3 && verifyIncomplete}
|
|
onClick={() => setStep(step + 1)}
|
|
data-ui-id="ui.settings.privacy.deletion.wizard.next"
|
|
>
|
|
{t("shared.next")}
|
|
</Button>
|
|
) : (
|
|
<Button
|
|
variant="destructive"
|
|
icon={<FeatherTrash2 />}
|
|
iconRight={<FeatherSend />}
|
|
disabled={confirmIncomplete || verifyIncomplete}
|
|
loading={submitting}
|
|
onClick={submit}
|
|
data-ui-id="ui.settings.privacy.deletion.wizard.submit"
|
|
>
|
|
{t("settings.privacy.deletion.wizard.confirm.submit")}
|
|
</Button>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</Dialog.Content>
|
|
</Dialog>
|
|
);
|
|
}
|