import { useState } from 'react'; import { useMutation } from '@tanstack/react-query'; import { removeTariffs } from '@/app/actions/tariffActions'; import { toast } from 'sonner'; interface TariffDeleteModalProps { tariffId: number; tariffName: string; onClose: () => void; onSuccess: () => void; } export function TariffDeleteModal({ tariffId, tariffName, onClose, onSuccess }: TariffDeleteModalProps) { const [isConfirmText, setIsConfirmText] = useState(''); const confirmText = 'УДАЛИТЬ'; const deleteTariffMutation = useMutation({ mutationFn: async () => { return await removeTariffs(tariffId); }, onSuccess: (data) => { if (data !== null && data !== undefined) { toast.success('Тариф успешно удален'); onSuccess(); } else { toast.error('Не удалось удалить тариф'); } }, onError: () => { toast.error('Произошла ошибка при удалении тарифа'); }, }); const handleDelete = () => { deleteTariffMutation.mutate(); }; const getDisplayName = (name: string) => { if (name) { return name.toUpperCase().replace(/_/g, ' '); } return `ID: ${tariffId}`; }; return (
Вы действительно хотите удалить тариф "{getDisplayName(tariffName)}"?
Это действие невозможно отменить.