import { Alert, useDataGrid } from '@/components'; import { useManageMunicipiosContext } from '../hooks/useManageMunicipiosContext'; import { ChangeEvent, useCallback, useState } from 'react'; import axios from 'axios'; import { apiConfig } from '@/config/api.config'; import { useCallApi } from '@/hooks'; import { toast } from 'sonner'; import { Dialog, DialogContent, DialogFooter, DialogHeader } from '@/components/ui/dialog'; import { EnforceSwitch } from '@/components/switch'; import { Button } from '@/components/ui/button'; import { doSaveLogActivity } from '@/actions/GlobalActions'; const API_URL = apiConfig.service_master_data; const DeleteDialog = () => { const { showDeleteDialog, handleDeleteDialog, selectedMunicipios, municipios } = useManageMunicipiosContext(); const { reload } = useDataGrid(); const { DeleteData } = useCallApi(); const [enforce, setEnforce] = useState(false); const [alert, setAlert] = useState({ show: false, message: '' }); const doDeleteMunicipio = useCallback(async () => { const response = await DeleteData( `${API_URL}/municipios/delete/${selectedMunicipios}/${enforce}`, { id: selectedMunicipios } ); if (response?.status) { setAlert((prev) => ({ ...prev, show: false, message: '' })); handleDeleteDialog(false, null); toast.success('Success Delete Municipio'); reload(); // const createActivity = { // module: 'Manage Municipio', // description: `Delete Municipio => ${selectedMunicipios}`, // action: 'D' // }; // doSaveLogActivity(createActivity); } else { setAlert((prev) => ({ ...prev, show: true, message: response?.message })); } }, [selectedMunicipios, enforce]); return ( handleDeleteDialog(open, null)}>

Are you sure?

you will delete this data!
) => { setEnforce(e.target.checked); }} />
{alert.show && (

{alert.message}

)}
); }; export default DeleteDialog;