"use client"; import { useState, useTransition } from "react"; import { useRouter } from "next/navigation"; import { AdminDialog } from "@/components/ui/admin-dialog"; type ActionResult = { ok: true } | { error: string }; interface Props { open: boolean; onOpenChange: (v: boolean) => void; label: string; onConfirm: () => Promise; } export function DeleteConfirmDialog({ open, onOpenChange, label, onConfirm }: Props) { const router = useRouter(); const [error, setError] = useState(""); const [isPending, startTransition] = useTransition(); function handleClose() { if (isPending) return; setError(""); onOpenChange(false); } function handleConfirm() { setError(""); startTransition(async () => { const result = await onConfirm(); if ("error" in result) { setError(result.error); } else { onOpenChange(false); router.refresh(); } }); } return (

This action cannot be undone. Are you sure you want to permanently delete{" "} {label}?

{error && (

{error}

)}
); }