// islands/DeleteApplicationButton.tsx import { useState } from "preact/hooks"; interface DeleteApplicationButtonProps { applicationId: string; applicantName: string; applicantEmail: string; } export default function DeleteApplicationButton({ applicationId, applicantName, applicantEmail }: DeleteApplicationButtonProps) { const [isDeleting, setIsDeleting] = useState(false); const handleDelete = async () => { const confirmed = confirm( `Are you sure you want to delete the application from ${applicantName} (${applicantEmail})? This action cannot be undone.` ); if (!confirmed) return; setIsDeleting(true); try { const formData = new FormData(); formData.append('id', applicationId); formData.append('sender', globalThis.location.pathname); const response = await fetch('/api/delete/tenant_application', { method: 'POST', body: formData }); if (response.redirected) { globalThis.location.href = response.url; } else if (response.ok) { globalThis.location.reload(); } else { alert('Failed to delete application. Please try again.'); } } catch (_error) { alert('Error deleting application'); } finally { setIsDeleting(false); } }; return ( ); }