From 2600e3072f5594b980dbc9b53133e3922f61eaad Mon Sep 17 00:00:00 2001 From: bagusajisaputroo Date: Tue, 25 Mar 2025 19:38:17 +0700 Subject: [PATCH] Changing hard delete to soft delete on transactiontype and transactionfee --- .../transferfee/blocks/DeleteDialog.tsx | 34 +++++----------- .../transfertype/blocks/DeleteDialog.tsx | 39 ++++++------------- 2 files changed, 20 insertions(+), 53 deletions(-) diff --git a/src/pages/transfer/transferfee/blocks/DeleteDialog.tsx b/src/pages/transfer/transferfee/blocks/DeleteDialog.tsx index 02faee8..e3d2f88 100644 --- a/src/pages/transfer/transferfee/blocks/DeleteDialog.tsx +++ b/src/pages/transfer/transferfee/blocks/DeleteDialog.tsx @@ -1,17 +1,12 @@ import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; import { Alert, useDataGrid } from '@/components'; -import { ChangeEvent, useCallback, useState } from 'react'; +import { useCallback, useState } from 'react'; import { apiConfig } from '@/config/api.config'; import { toast } from 'sonner'; import { useCallApi } from '@/hooks'; -import { doSaveLogActivity } from '@/actions/GlobalActions'; -import { EnforceSwitch } from '@/components/switch'; -import { useContext } from 'react'; import { useManageTransferFeeContext } from '../hooks/useManageTransferFeeContext'; -import { ManageTransferFeeContext } from '../hooks/ManageTransferFeeContext'; import { DialogDescription } from '@radix-ui/react-dialog'; -import { useManageAccessTypeContext } from '@/pages/access/access-type/hooks/useManageAccessTypeContext'; const API_URL = apiConfig.service_transaction; @@ -19,47 +14,37 @@ const DeleteDialog = () => { const { showDeleteFeeDialog, handleDeleteFeeDialog, selectedTransferFee } = useManageTransferFeeContext(); const { reload } = useDataGrid(); const { DeleteData } = useCallApi(); - const [enforce, setEnforce] = useState(false); const [alert, setAlert] = useState({ show: false, message: '' }); const doDeleteTransferFee = useCallback(async () => { - const response = await DeleteData(`${API_URL}/transactionfees/delete/${selectedTransferFee}/${enforce}`, { + // Kirim enforce=false untuk memastikan soft delete + const response = await DeleteData(`${API_URL}/transactionfees/delete/${selectedTransferFee}/false`, { id: selectedTransferFee }); if (response?.status) { - setAlert((prev) => ({ ...prev, show: false, message: '' })); + setAlert({ show: false, message: '' }); handleDeleteFeeDialog(false, null); toast.success('Success Delete Product'); reload(); } else { toast.error('Failed Delete Product'); - setAlert((prev) => ({ ...prev, show: true, message: response?.message })); + setAlert({ show: true, message: response?.message }); } - }, [selectedTransferFee, enforce]); - + }, [selectedTransferFee]); return ( handleDeleteFeeDialog(open, null)}> Delete Transfer Type - Delete Transfer Type + Are you sure you want to delete this data?

Are you sure?

- you will delete this data! -
- - ) => { - setEnforce(e.target.checked); - }} - /> -
+ You will delete this data!
{alert.show && ( @@ -80,6 +65,5 @@ const DeleteDialog = () => { ); }; -export default DeleteDialog; - +export default DeleteDialog; export { DeleteDialog }; diff --git a/src/pages/transfer/transfertype/blocks/DeleteDialog.tsx b/src/pages/transfer/transfertype/blocks/DeleteDialog.tsx index 4adfdc8..0f610e3 100644 --- a/src/pages/transfer/transfertype/blocks/DeleteDialog.tsx +++ b/src/pages/transfer/transfertype/blocks/DeleteDialog.tsx @@ -1,18 +1,12 @@ import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; import { Alert, useDataGrid } from '@/components'; -import { ChangeEvent, useCallback, useState } from 'react'; +import { useCallback, useState } from 'react'; import { apiConfig } from '@/config/api.config'; import { toast } from 'sonner'; import { useCallApi } from '@/hooks'; -import { doSaveLogActivity } from '@/actions/GlobalActions'; -import { EnforceSwitch } from '@/components/switch'; -import { useContext } from 'react'; import { useManageTransferTypeContext } from '../hooks/useManageTransferTypeContext'; -import { ManageTransferTypeContext } from '../hooks/ManageTransferTypeContext'; -import TransferType from '../TransferType'; import { DialogDescription } from '@radix-ui/react-dialog'; -import { useManageAccessTypeContext } from '@/pages/access/access-type/hooks/useManageAccessTypeContext'; const API_URL = apiConfig.service_transaction; @@ -20,7 +14,6 @@ const DeleteDialog = () => { const { showDeleteDialog, handleDeleteDialog, selectedTransferType } = useManageTransferTypeContext(); const { reload } = useDataGrid(); const { DeleteData } = useCallApi(); - const [enforce, setEnforce] = useState(false); const [alert, setAlert] = useState({ show: false, message: '' @@ -31,41 +24,32 @@ const DeleteDialog = () => { toast.error('No Transfer Type selected'); return; } - - const response = await DeleteData(`${API_URL}/transactiontype/delete/${selectedTransferType}/${enforce}`, { + + // Kirim enforce=false untuk memastikan soft delete + const response = await DeleteData(`${API_URL}/transactiontype/delete/${selectedTransferType}/false`, { id: selectedTransferType }); - + if (response?.status) { - setAlert((prev) => ({ ...prev, show: false, message: '' })); + setAlert({ show: false, message: '' }); handleDeleteDialog(false, null); reload(); setTimeout(() => toast.success('Success Delete Product'), 0); } else { - setAlert((prev) => ({ ...prev, show: true, message: response?.message })); + setAlert({ show: true, message: response?.message }); setTimeout(() => toast.error('Failed Delete Product'), 0); } - }, [selectedTransferType, enforce, DeleteData, handleDeleteDialog, reload]); - + }, [selectedTransferType, DeleteData, handleDeleteDialog, reload]); return ( handleDeleteDialog(open, null)}> Delete Transfer Type - Delete Transfer Type + Are you sure you want to delete this data?

Are you sure?

- you will delete this data! -
- - ) => { - setEnforce(e.target.checked); - }} - /> -
+ You will delete this data!
{alert.show && ( @@ -86,6 +70,5 @@ const DeleteDialog = () => { ); }; -export default DeleteDialog; - +export default DeleteDialog; export { DeleteDialog };