import type { Asset } from "@cloudhal/core-contracts"; import { Banner, Checkbox, InputArea, InsetPanel, LayerDialog, Text } from "@cloudhal/ui"; import { ProhibitInset, WarningCircle } from "@phosphor-icons/react"; import { useEffect, useState } from "react"; import { useT } from "../i18n/index.tsx"; import { apiErrorText } from "../lib/api-errors.ts"; /** * Take down a file (RFC-0004 ยง4.6, Owner only): the bytes are deleted from storage and from every * snapshot, its URL answers 410 Gone (451 for a legal reason), the file is retired and the same * bytes cannot come back until an Owner allows it. A reason is required and audited; browsers that * cached the file may keep their copy, and the dialog says so. */ export function TakedownDialog({ asset, name, open, onOpenChange, busy, error, onConfirm, }: { asset: Asset | undefined; name: string; open: boolean; onOpenChange: (open: boolean) => void; busy: boolean; /** The failed takedown, worded by `apiErrorText`. */ error: unknown; onConfirm: (input: { reason: string; legal: boolean }) => void; }) { const t = useT("media"); const [reason, setReason] = useState(""); const [legal, setLegal] = useState(false); const [tried, setTried] = useState(false); useEffect(() => { if (!open) return; setReason(""); setLegal(false); setTried(false); }, [open]); const missing = reason.trim() === ""; return ( {t("media.takedown.title", { name })} {t("media.takedown.description")}
} title={t("media.takedown.warningTitle")} description={t("media.takedown.warning")} /> {t("media.takedown.consequences")}
{(["bytes", "status", "retired", "reupload", "caches"] as const).map((k) => ( {t(`media.takedown.points.${k}`)} ))}
setLegal(v)} /> {Boolean(error) && ( } title={t("errors.title")} description={apiErrorText(t, error)} /> )}
{ setTried(true); if (missing) return; onConfirm({ reason: reason.trim(), legal }); }} data-testid="takedown-confirm" > {t("media.takedown.confirm")}
); }