/** * @file components/modals/DeleteServerModal.tsx * @description Confirmation modal for permanently deleting a server. */ "use client"; import { useState } from "react"; import { X, Loader2, AlertTriangle } from "lucide-react"; /** * Properties for the DeleteServerModal component. * * @interface DeleteServerModalProps * @property {boolean} isOpen - Indicates whether the modal dialog is currently visible. * @property {() => void} onClose - Callback function to handle closing the modal dialog. * @property {string} serverId - The unique identifier of the server to be deleted. * @property {string} serverName - The name of the server displayed in the confirmation message. */ interface DeleteServerModalProps { isOpen: boolean; onClose: () => void; serverId: string; serverName: string; } /** * Renders a confirmation modal allowing users to permanently delete a server. * * @param {DeleteServerModalProps} props - Component properties. * @returns {JSX.Element | null} The modal component or null if not open. */ export function DeleteServerModal({ isOpen, onClose, serverId, serverName, }: DeleteServerModalProps) { const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); if (!isOpen) return null; /** * Sends a DELETE request to remove the server and redirects to the home route upon success. */ const handleDelete = async () => { try { setIsLoading(true); setError(null); const response = await fetch(`/api/servers/${serverId}`, { method: "DELETE", }); if (!response.ok) { throw new Error("Failed to delete server."); } onClose(); window.location.href = "/"; } catch (err: unknown) { setError(err instanceof Error ? err.message : "Something went wrong."); } finally { setIsLoading(false); } }; return ( /* Outer Backdrop */
{/* Inner Modal Content */}
e.stopPropagation()} className="bg-surface border border-surface/50 rounded-2xl w-full max-w-md p-6 shadow-2xl relative animate-in fade-in zoom-in-95 duration-150" >

Delete Server

Are you sure you want to delete{" "} {serverName}? This action cannot be undone and will permanently remove all channels and messages.

{error &&

{error}

}
); }