61 lines
1.9 KiB
TypeScript
61 lines
1.9 KiB
TypeScript
"use client";
|
|
|
|
import { useState, useTransition } from "react";
|
|
|
|
import { archiveEditorialAction } from "@/app/admin/redaktionen/[id]/actions";
|
|
import { Card, CardHeader, CardTitle, CardDescription, CardContent } from "@/components/ui/card";
|
|
import { Input } from "@/components/ui/input";
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
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 (
|
|
<Card className="border-destructive/50 bg-destructive/5 dark:bg-destructive/10">
|
|
<CardHeader>
|
|
<CardTitle className="text-destructive">Gefahrenzone</CardTitle>
|
|
<CardDescription>
|
|
Alle Albumrechte werden widerrufen und der Login wird deaktiviert. Abrechnungsdaten bleiben erhalten.
|
|
</CardDescription>
|
|
</CardHeader>
|
|
<CardContent className="space-y-4">
|
|
<div className="space-y-2">
|
|
<label className="text-sm font-medium">
|
|
Redaktionsname zur Bestätigung eingeben:
|
|
</label>
|
|
<Input
|
|
type="text"
|
|
value={confirmText}
|
|
onChange={(e) => setConfirmText(e.target.value)}
|
|
placeholder={editorialName}
|
|
disabled={isPending}
|
|
className="border-destructive/30 focus-visible:ring-destructive"
|
|
/>
|
|
</div>
|
|
<Button
|
|
type="button"
|
|
variant="destructive"
|
|
disabled={!isConfirmed || isPending}
|
|
onClick={handleArchive}
|
|
>
|
|
{isPending ? "Wird archiviert…" : "Redaktion archivieren"}
|
|
</Button>
|
|
</CardContent>
|
|
</Card>
|
|
);
|
|
}
|