diff --git a/src/pages/master/aldeias/blocks/DeleteDialog.tsx b/src/pages/master/aldeias/blocks/DeleteDialog.tsx index 44fc4c1..17c4954 100644 --- a/src/pages/master/aldeias/blocks/DeleteDialog.tsx +++ b/src/pages/master/aldeias/blocks/DeleteDialog.tsx @@ -2,38 +2,42 @@ import { apiConfig } from '@/config/api.config'; import { useManageAldeiasContext } from '../hooks/useManageAldeiasContext'; import { Alert, useDataGrid } from '@/components'; import { useCallApi } from '@/hooks'; -import { ChangeEvent, useCallback, useState } from 'react'; +import { useCallback, useState } from 'react'; import { toast } from 'sonner'; import { Dialog, DialogContent, DialogFooter, DialogHeader } from '@/components/ui/dialog'; -import { EnforceSwitch } from '@/components/switch'; import { Button } from '@/components/ui/button'; const API_URL = apiConfig.service_master_data; + const DeleteDialog = () => { const { showDeleteDialog, handleDeleteDialog, selectedAldeias } = useManageAldeiasContext(); const { reload } = useDataGrid(); const { DeleteData } = useCallApi(); - const [enforce, setEnforce] = useState(false); const [alert, setAlert] = useState({ show: false, message: '' - }) + }); const doDeleteAldeias = useCallback(async () => { - const response = await DeleteData(`${API_URL}/aldeias/delete/${selectedAldeias}/${enforce}`, { + if (!selectedAldeias) { + toast.error('No Aldeias selected'); + return; + } + + const response = await DeleteData(`${API_URL}/aldeias/delete/${selectedAldeias}/false`, { id: selectedAldeias }); if (response?.status) { - setAlert((prev) => ({ ...prev, show: false, message: '' })); + setAlert({ show: false, message: '' }); handleDeleteDialog(false, null); toast.success('Success Delete Aldeias'); reload(); } else { + setAlert({ show: true, message: response?.message }); toast.error('Failed Delete Aldeias'); - setAlert((prev) => ({ ...prev, show: true, message: response?.message })); } - }, [selectedAldeias, enforce]); + }, [selectedAldeias, DeleteData, handleDeleteDialog, reload]); return ( handleDeleteDialog(open, null)}> @@ -41,16 +45,7 @@ const DeleteDialog = () => {

Are you sure?

- you will delete this data! -
- - ) => { - setEnforce(e.target.checked); - }} - /> -
+ You will delete this data!
{alert.show && ( diff --git a/src/pages/master/municipios/blocks/DeleteDialog.tsx b/src/pages/master/municipios/blocks/DeleteDialog.tsx index 0605ab5..f7e6f5d 100644 --- a/src/pages/master/municipios/blocks/DeleteDialog.tsx +++ b/src/pages/master/municipios/blocks/DeleteDialog.tsx @@ -1,69 +1,56 @@ import { Alert, useDataGrid } from '@/components'; import { useManageMunicipiosContext } from '../hooks/useManageMunicipiosContext'; -import { ChangeEvent, useCallback, useState } from 'react'; -import axios from 'axios'; +import { useCallback, useState } from 'react'; 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 { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; -import { doSaveLogActivity } from '@/actions/GlobalActions'; +import { DialogDescription } from '@radix-ui/react-dialog'; const API_URL = apiConfig.service_master_data; const DeleteDialog = () => { - const { showDeleteDialog, handleDeleteDialog, selectedMunicipios, municipios } = - useManageMunicipiosContext(); + const { showDeleteDialog, handleDeleteDialog, selectedMunicipios } = useManageMunicipiosContext(); const { reload } = useDataGrid(); const { DeleteData } = useCallApi(); - const [enforce, setEnforce] = useState(false); const [alert, setAlert] = useState({ show: false, message: '' }); const doDeleteMunicipio = useCallback(async () => { + if (!selectedMunicipios) { + toast.error('No Municipio selected'); + return; + } + const response = await DeleteData( - `${API_URL}/municipios/delete/${selectedMunicipios}/${enforce}`, - { - id: selectedMunicipios - } + `${API_URL}/municipios/delete/${selectedMunicipios}/false`, + { id: selectedMunicipios } ); if (response?.status) { - setAlert((prev) => ({ ...prev, show: false, message: '' })); + setAlert({ 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 })); + setAlert({ show: true, message: response?.message }); + toast.error('Failed Delete Municipio'); } - }, [selectedMunicipios, enforce]); + }, [selectedMunicipios, DeleteData, handleDeleteDialog, reload]); return ( handleDeleteDialog(open, null)}> + + +

Are you sure?

- you will delete this data! -
- - ) => { - setEnforce(e.target.checked); - }} - /> -
+ You will delete this data!
{alert.show && ( @@ -72,10 +59,10 @@ const DeleteDialog = () => { )}
- - diff --git a/src/pages/master/postoadms/blocks/DeleteDialog.tsx b/src/pages/master/postoadms/blocks/DeleteDialog.tsx index bc597ae..fca5448 100644 --- a/src/pages/master/postoadms/blocks/DeleteDialog.tsx +++ b/src/pages/master/postoadms/blocks/DeleteDialog.tsx @@ -1,11 +1,10 @@ import { Alert, useDataGrid } from '@/components'; import { useManagePostoAdmsContext } from '../hooks/useManagePostoAdmsContext'; import { useCallApi } from '@/hooks'; -import { ChangeEvent, useCallback, useState } from 'react'; +import { useCallback, useState } from 'react'; import { apiConfig } from '@/config/api.config'; import { toast } from 'sonner'; -import { Dialog, DialogContent, DialogFooter, DialogHeader } from '@/components/ui/dialog'; -import { EnforceSwitch } from '@/components/switch'; +import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; const API_URL = apiConfig.service_master_data; @@ -14,46 +13,42 @@ const DeleteDialog = () => { const { showDeleteDialog, handleDeleteDialog, selectedPostoAdms } = useManagePostoAdmsContext(); const { reload } = useDataGrid(); const { DeleteData } = useCallApi(); - const [enforce, setEnforce] = useState(false); const [alert, setAlert] = useState({ show: false, message: '' }); const doDeletePostoAdm = useCallback(async () => { + if (!selectedPostoAdms) { + toast.error('No Posto Adm selected'); + return; + } + const response = await DeleteData( - `${API_URL}/postoadms/delete/${selectedPostoAdms}/${enforce}`, - { - id: selectedPostoAdms - } + `${API_URL}/postoadms/delete/${selectedPostoAdms}/false`, + { id: selectedPostoAdms } ); if (response?.status) { - setAlert((prev) => ({ ...prev, show: false, message: '' })); + setAlert({ show: false, message: '' }); handleDeleteDialog(false, null); toast.success('Success Delete Posto Adm'); reload(); } else { - setAlert((prev) => ({ ...prev, show: true, message: response?.message })); + setAlert({ show: true, message: response?.message }); + toast.error('Failed Delete Posto Adm'); } - }, [selectedPostoAdms, enforce]); + }, [selectedPostoAdms, DeleteData, handleDeleteDialog, reload]); return ( handleDeleteDialog(open, null)}> + +

Are you sure?

- you will delete this data! - {/*
- - ) => { - setEnforce(e.target.checked); - }} - /> -
*/} + You will delete this data!
{alert.show && ( @@ -62,10 +57,10 @@ const DeleteDialog = () => { )}
- - diff --git a/src/pages/master/products/blocks/DeleteDialog.tsx b/src/pages/master/products/blocks/DeleteDialog.tsx index 39c3cb1..652f56b 100644 --- a/src/pages/master/products/blocks/DeleteDialog.tsx +++ b/src/pages/master/products/blocks/DeleteDialog.tsx @@ -2,57 +2,49 @@ import { apiConfig } from '@/config/api.config'; import { useManageProductsContext } from '../hooks/useManageProductsContext'; import { Alert, useDataGrid } from '@/components'; import { useCallApi } from '@/hooks'; -import { ChangeEvent, useCallback, useState } from 'react'; +import { useCallback, useState } from 'react'; import { toast } from 'sonner'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'; -import { EnforceSwitch } from '@/components/switch'; import { Button } from '@/components/ui/button'; const API_URL = apiConfig.service_master_data; + const DeleteDialog = () => { const { showDeleteDialog, handleDeleteDialog, selectedProducts } = useManageProductsContext(); const { reload } = useDataGrid(); const { DeleteData } = useCallApi(); - const [enforce, setEnforce] = useState(false); - const [alert, setAlert] = useState({ - show: false, - message: '' - }); + const [alert, setAlert] = useState({ show: false, message: '' }); const doDeleteProduct = useCallback(async () => { - const response = await DeleteData(`${API_URL}/product/delete/${selectedProducts}/${enforce}`, { + if (!selectedProducts) { + toast.error('No product selected'); + return; + } + + const response = await DeleteData(`${API_URL}/product/delete/${selectedProducts}/false`, { id: selectedProducts }); if (response?.status) { - setAlert((prev) => ({ ...prev, show: false, message: '' })); + setAlert({ show: false, message: '' }); handleDeleteDialog(false, null); toast.success('Success Delete Product'); reload(); } else { + setAlert({ show: true, message: response?.message }); toast.error('Failed Delete Product'); - setAlert((prev) => ({ ...prev, show: true, message: response?.message })); } - }, [selectedProducts, enforce]); + }, [selectedProducts, DeleteData, handleDeleteDialog, reload]); return ( handleDeleteDialog(open, null)}> - + + + - -

Are you sure?

- you will delete this data! -
- - ) => { - setEnforce(e.target.checked); - }} - /> -
+ You will delete this data!
{alert.show && ( @@ -61,10 +53,10 @@ const DeleteDialog = () => { )}
- - diff --git a/src/pages/master/profession/blocks/DeleteDialog.tsx b/src/pages/master/profession/blocks/DeleteDialog.tsx index 0a74fc7..1f5f0f8 100644 --- a/src/pages/master/profession/blocks/DeleteDialog.tsx +++ b/src/pages/master/profession/blocks/DeleteDialog.tsx @@ -2,67 +2,48 @@ import { apiConfig } from '@/config/api.config'; import { useManageProfessionContext } from '../hooks/useManageProfessionContext'; import { Alert, useDataGrid } from '@/components'; import { useCallApi } from '@/hooks'; -import { ChangeEvent, useCallback, useState } from 'react'; +import { useCallback, useState } from 'react'; import { toast } from 'sonner'; -import { - Dialog, - DialogContent, - DialogDescription, - DialogFooter, - DialogHeader, - DialogTitle -} from '@/components/ui/dialog'; -import { EnforceSwitch } from '@/components/switch'; +import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; const API_URL = apiConfig.service_master_data; + const DeleteDialog = () => { const { showDeleteDialog, handleDeleteDialog, selectedProfession } = useManageProfessionContext(); const { reload } = useDataGrid(); const { DeleteData } = useCallApi(); - const [enforce, setEnforce] = useState(false); - const [alert, setAlert] = useState({ - show: false, - message: '' - }); + const [alert, setAlert] = useState({ show: false, message: '' }); const doDeleteProfession = useCallback(async () => { - const response = await DeleteData( - `${API_URL}/profession/delete/${selectedProfession}/${enforce}`, - { - id: selectedProfession - } - ); + if (!selectedProfession) { + toast.error('No profession selected'); + return; + } + const response = await DeleteData(`${API_URL}/profession/delete/${selectedProfession}/false`, { + id: selectedProfession + }); if (response?.status) { - setAlert((prev) => ({ ...prev, show: false, message: '' })); + setAlert({ show: false, message: '' }); handleDeleteDialog(false, null); toast.success('Success Delete Profession'); reload(); } else { + setAlert({ show: true, message: response?.message }); toast.error('Failed Delete Profession'); - setAlert((prev) => ({ ...prev, show: true, message: response?.message })); } - }, [selectedProfession, enforce]); + }, [selectedProfession, DeleteData, handleDeleteDialog, reload]); return ( handleDeleteDialog(open, null)}> - +

Are you sure?

- you will delete this data! -
- - ) => { - setEnforce(e.target.checked); - }} - /> -
+ You will delete this data!
{alert.show && ( @@ -71,10 +52,10 @@ const DeleteDialog = () => { )}
- - diff --git a/src/pages/master/provider/blocks/DeleteDialog.tsx b/src/pages/master/provider/blocks/DeleteDialog.tsx index 9be7895..41e0bef 100644 --- a/src/pages/master/provider/blocks/DeleteDialog.tsx +++ b/src/pages/master/provider/blocks/DeleteDialog.tsx @@ -2,64 +2,49 @@ import { apiConfig } from '@/config/api.config'; import { useManageProviderContext } from '../hooks/useManageProviderContext'; import { Alert, useDataGrid } from '@/components'; import { useCallApi } from '@/hooks'; -import { ChangeEvent, useCallback, useState } from 'react'; +import { useCallback, useState } from 'react'; import { toast } from 'sonner'; -import { - Dialog, - DialogContent, - DialogDescription, - DialogFooter, - DialogHeader, - DialogTitle -} from '@/components/ui/dialog'; -import { EnforceSwitch } from '@/components/switch'; +import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; const API_URL = apiConfig.service_master_data; + const DeleteDialog = () => { const { showDeleteDialog, handleDeleteDialog, selectedProvider } = useManageProviderContext(); const { reload } = useDataGrid(); const { DeleteData } = useCallApi(); - const [enforce, setEnforce] = useState(false); - const [alert, setAlert] = useState({ - show: false, - message: '' - }); + const [alert, setAlert] = useState({ show: false, message: '' }); const doDeleteProvider = useCallback(async () => { - const response = await DeleteData(`${API_URL}/provider/delete/${selectedProvider}/${enforce}`, { + if (!selectedProvider) { + toast.error('No provider selected'); + return; + } + + const response = await DeleteData(`${API_URL}/provider/delete/${selectedProvider}/false`, { id: selectedProvider }); if (response?.status) { - setAlert((prev) => ({ ...prev, show: false, message: '' })); + setAlert({ show: false, message: '' }); handleDeleteDialog(false, null); toast.success('Success Delete Provider'); reload(); } else { - setAlert((prev) => ({ ...prev, show: true, message: response?.message })); + setAlert({ show: true, message: response?.message }); toast.error('Failed Delete Provider'); } - }, [selectedProvider, enforce]); + }, [selectedProvider, DeleteData, handleDeleteDialog, reload]); return ( handleDeleteDialog(open, null)}> - +

Are you sure?

- you will delete this data! -
- - ) => { - setEnforce(e.target.checked); - }} - /> -
+ You will delete this data!
{alert.show && ( @@ -68,10 +53,10 @@ const DeleteDialog = () => { )}
- - diff --git a/src/pages/master/sucos/blocks/DeleteDialog.tsx b/src/pages/master/sucos/blocks/DeleteDialog.tsx index f1235f9..440ee6a 100644 --- a/src/pages/master/sucos/blocks/DeleteDialog.tsx +++ b/src/pages/master/sucos/blocks/DeleteDialog.tsx @@ -1,18 +1,10 @@ import { apiConfig } from '@/config/api.config'; import { useManageSucosContext } from '../hooks/useManageSucosContext'; -import { ChangeEvent, useCallback, useState } from 'react'; +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 { EnforceSwitch } from '@/components/switch'; +import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; const API_URL = apiConfig.service_master_data; @@ -21,45 +13,39 @@ const DeleteDialog = () => { const { showDeleteDialog, handleDeleteDialog, selectedSucos } = useManageSucosContext(); const { reload } = useDataGrid(); const { DeleteData } = useCallApi(); - const [enforce, setEnforce] = useState(false); - const [alert, setAlert] = useState({ - show: false, - message: '' - }); + const [alert, setAlert] = useState({ show: false, message: '' }); const doDeleteSucos = useCallback(async () => { - const response = await DeleteData(`${API_URL}/sucos/delete/${selectedSucos}/${enforce}`, { + 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((prev) => ({ ...prev, show: false, message: '' })); + setAlert({ show: false, message: '' }); handleDeleteDialog(false, null); toast.success('Success Delete Sucos'); reload(); } else { - setAlert((prev) => ({ ...prev, show: true, message: response?.message })); + setAlert({ show: true, message: response?.message }); + toast.error('Failed Delete Sucos'); } - }, [selectedSucos, enforce]); + }, [selectedSucos, DeleteData, handleDeleteDialog, reload]); return ( handleDeleteDialog(open, null)}> - +

Are you sure?

- you will delete this data! -
- - ) => { - setEnforce(e.target.checked); - }} - /> -
+ You will delete this data!
{alert.show && ( @@ -68,10 +54,10 @@ const DeleteDialog = () => { )}
- -