import { apiConfig } from '@/config/api.config'; import { useManageSucosContext } from '../hooks/useManageSucosContext'; import { useCallback, useState } from 'react'; import { useCallApi } from '@/hooks'; import { Alert, useDataGrid } from '@/components'; import { toast } from 'sonner'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; import { doSaveLogActivity } from '@/actions/GlobalActions'; const API_URL = apiConfig.service_master_data; const DeleteDialog = () => { const { showDeleteDialog, handleDeleteDialog, selectedSucos } = useManageSucosContext(); const { reload } = useDataGrid(); const { DeleteData } = useCallApi(); const [alert, setAlert] = useState({ show: false, message: '' }); const doDeleteSucos = useCallback(async () => { if (!selectedSucos) { toast.error('No sucos selected'); return; } // Hanya soft delete (tanpa enforce) const response = await DeleteData(`${API_URL}/sucos/delete/${selectedSucos}/false`, { id: selectedSucos }); if (response?.status) { setAlert({ show: false, message: '' }); handleDeleteDialog(false, null); toast.success('Success Delete Sucos'); reload(); const createActivity = { module: 'Manage Sucos', description: `Delete Suco => ${selectedSucos}`, action: 'D' }; doSaveLogActivity(createActivity); } else { setAlert({ show: true, message: response?.message }); toast.error('Failed Delete Sucos'); } }, [selectedSucos, DeleteData, handleDeleteDialog, reload]); return ( handleDeleteDialog(open, null)}>

Are you sure?

You will delete this data!
{alert.show && (

{alert.message}

)}
); }; export default DeleteDialog;