'use client'; import { useTransition } from 'react'; import { useRouter } from 'next/navigation'; import { Trash2 } from 'lucide-react'; import { useTranslations } from 'next-intl'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from '@kit/ui/alert-dialog'; import { Button } from '@kit/ui/button'; interface DeleteDepartmentButtonProps { departmentId: string; departmentName: string; accountId: string; } export function DeleteDepartmentButton({ departmentId, departmentName, accountId, }: DeleteDepartmentButtonProps) { const t = useTranslations('members.departments'); const router = useRouter(); const [isPending, startTransition] = useTransition(); const handleDelete = () => { startTransition(async () => { try { const response = await fetch( `/api/members/departments/${departmentId}`, { method: 'DELETE', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ accountId }), }, ); if (response.ok) { router.refresh(); } } catch (error) { console.error('Failed to delete department:', error); } }); }; return ( ); }