import { useState } from "react"; import { type Client } from "../types/client"; import { deleteClient } from "../api/clients"; import { useTranslation } from "../hooks/useTranslation"; import { Button } from "./ui/button"; import { Modal } from "./Modal"; interface DeleteClientModalProps { isOpen: boolean; onClose: () => void; onSuccess: () => void; client: Client | null; } export default function DeleteClientModal({ isOpen, onClose, onSuccess, client }: DeleteClientModalProps) { const { t } = useTranslation(); const [isLoading, setIsLoading] = useState(false); const handleDelete = async () => { if (!client) return; setIsLoading(true); try { await deleteClient(client.id); onSuccess(); onClose(); } catch (error) { console.error(t.clients.errors.deleteFailed, error); } finally { setIsLoading(false); } }; const footer = ( <> {t.actions?.cancel} {isLoading ? "..." : t.clients.delete} > ); return ( {client ? t.clients.deleteConfirmMessage(client.name) : ""} ); }
{client ? t.clients.deleteConfirmMessage(client.name) : ""}