"use client"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@openstatus/ui/components/ui/alert-dialog"; import { Button } from "@openstatus/ui/components/ui/button"; import { Input } from "@openstatus/ui/components/ui/input"; import { useCopyToClipboard } from "@openstatus/ui/hooks/use-copy-to-clipboard"; import { isTRPCClientError } from "@trpc/client"; import { Check, Copy } from "lucide-react"; import { useState, useTransition } from "react"; import { toast } from "sonner"; interface FormAlertDialogProps { confirmationValue: string; submitAction: () => Promise; children?: React.ReactNode; } export function FormAlertDialog({ confirmationValue, submitAction, children, }: FormAlertDialogProps) { const [value, setValue] = useState(""); const [isPending, startTransition] = useTransition(); const { copy, isCopied } = useCopyToClipboard(); const [open, setOpen] = useState(false); const handleDelete = async () => { try { startTransition(async () => { const promise = submitAction(); toast.promise(promise, { loading: "Deleting...", success: "Deleted", error: (error) => { if (isTRPCClientError(error)) { return error.message; } return "Failed to delete"; }, }); await promise; setOpen(false); }); } catch (error) { console.error("Failed to revoke:", error); } }; return ( {children ?? ( )} Are you sure about delete `{confirmationValue}`? This action cannot be undone. This will permanently delete the item.

Type{" "} {" "} to confirm

setValue(e.target.value)} />
Cancel { e.preventDefault(); handleDelete(); }} > {isPending ? "Deleting..." : "Delete"}
); }