50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
"use client";
|
|
|
|
import { useState, useTransition } from "react";
|
|
|
|
import { archiveEditorialAction } from "@/app/admin/redaktionen/[id]/actions";
|
|
|
|
type DangerZoneProps = {
|
|
editorialId: string;
|
|
editorialName: string;
|
|
};
|
|
|
|
export function DangerZone({ editorialId, editorialName }: DangerZoneProps) {
|
|
const [confirmText, setConfirmText] = useState("");
|
|
const [isPending, startTransition] = useTransition();
|
|
const isConfirmed = confirmText === editorialName;
|
|
|
|
function handleArchive() {
|
|
if (!isConfirmed) return;
|
|
startTransition(async () => {
|
|
await archiveEditorialAction(editorialId);
|
|
});
|
|
}
|
|
|
|
return (
|
|
<section className="danger-zone" aria-labelledby="danger-title">
|
|
<h2 id="danger-title">Gefahrenzone</h2>
|
|
<p>Alle Albumrechte werden widerrufen und der Login wird deaktiviert. Abrechnungsdaten bleiben erhalten.</p>
|
|
<label>
|
|
<span>Redaktionsname zur Bestätigung eingeben:</span>
|
|
<input
|
|
type="text"
|
|
value={confirmText}
|
|
onChange={(e) => setConfirmText(e.target.value)}
|
|
placeholder={editorialName}
|
|
className="danger-zone-input"
|
|
disabled={isPending}
|
|
/>
|
|
</label>
|
|
<button
|
|
type="button"
|
|
className="action-button action-button--danger"
|
|
disabled={!isConfirmed || isPending}
|
|
onClick={handleArchive}
|
|
>
|
|
{isPending ? "Wird archiviert…" : "Redaktion archivieren"}
|
|
</button>
|
|
</section>
|
|
);
|
|
}
|