'use client'; import { TrashIcon } from '@heroicons/react/24/outline'; import { useRouter } from 'next/navigation'; import { ReactNode, useState } from 'react'; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, DialogTrigger, } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; import { Label } from '@/components/ui/label'; import { AlertOctagon } from 'lucide-react'; import { useTranslations } from 'next-intl'; type ConfirmDeleteModalProps = { namespace: string; entityTitle: string; onDelete: () => Promise; onSuccess?: () => void; triggerClassName?: string; triggerIconClassName?: string; trigger?: ReactNode; }; export default function ConfirmDeleteModal({ namespace, entityTitle, onDelete, onSuccess, triggerClassName = 'h-8 w-8', triggerIconClassName = 'h-4 w-4', trigger, }: ConfirmDeleteModalProps) { const t = useTranslations(namespace); const router = useRouter(); const [deleting, setDeleting] = useState(false); const [open, setOpen] = useState(false); const handleDeleteClick = async () => { setDeleting(true); let deleted: unknown; try { deleted = await onDelete(); } catch (error) { console.error('Delete failed:', error); return; } finally { setDeleting(false); } // Delete actions return null when the user may not delete the entity. if (deleted === null) return; setOpen(false); if (onSuccess) onSuccess(); else router.refresh(); }; return ( {trigger || ( )} {t('title')}

{t('description', { title: entityTitle })}

{t('warning')}

); }