import React, { useState, useTransition } from "react"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog"; import { toast } from "react-hot-toast"; import { Loader2 } from "lucide-react"; const DeleteConfirmationDialog = ({ open, onClose, onConfirm, defaultToast = true, toastMessage = "Successfully deleted", }: { open: boolean; onClose: () => void; onConfirm?: () => Promise; defaultToast?: boolean; toastMessage?: string; }) => { const [isPending, startTransition] = useTransition(); const handleConfirm = () => { if (!onConfirm) { onClose(); return; } onConfirm(); onClose(); if (defaultToast) { toast.success(toastMessage, { position: "top-right", }); } }; return ( Are you absolutely sure? This action cannot be undone. This will permanently delete your account and remove your data from our servers. Cancel startTransition(handleConfirm)} > {isPending && } {isPending ? "Deleting.." : "Continue"} ); }; export default DeleteConfirmationDialog;