Changing hard delete to soft delete on transactiontype and transactionfee

This commit is contained in:
bagusajisaputroo
2025-03-25 19:38:17 +07:00
parent 252e32f06b
commit 2600e3072f
2 changed files with 20 additions and 53 deletions

View File

@ -1,17 +1,12 @@
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';
import { Alert, useDataGrid } from '@/components'; import { Alert, useDataGrid } from '@/components';
import { ChangeEvent, useCallback, useState } from 'react'; import { useCallback, useState } from 'react';
import { apiConfig } from '@/config/api.config'; import { apiConfig } from '@/config/api.config';
import { toast } from 'sonner'; import { toast } from 'sonner';
import { useCallApi } from '@/hooks'; import { useCallApi } from '@/hooks';
import { doSaveLogActivity } from '@/actions/GlobalActions';
import { EnforceSwitch } from '@/components/switch';
import { useContext } from 'react';
import { useManageTransferFeeContext } from '../hooks/useManageTransferFeeContext'; import { useManageTransferFeeContext } from '../hooks/useManageTransferFeeContext';
import { ManageTransferFeeContext } from '../hooks/ManageTransferFeeContext';
import { DialogDescription } from '@radix-ui/react-dialog'; import { DialogDescription } from '@radix-ui/react-dialog';
import { useManageAccessTypeContext } from '@/pages/access/access-type/hooks/useManageAccessTypeContext';
const API_URL = apiConfig.service_transaction; const API_URL = apiConfig.service_transaction;
@ -19,47 +14,37 @@ const DeleteDialog = () => {
const { showDeleteFeeDialog, handleDeleteFeeDialog, selectedTransferFee } = useManageTransferFeeContext(); const { showDeleteFeeDialog, handleDeleteFeeDialog, selectedTransferFee } = useManageTransferFeeContext();
const { reload } = useDataGrid(); const { reload } = useDataGrid();
const { DeleteData } = useCallApi(); const { DeleteData } = useCallApi();
const [enforce, setEnforce] = useState(false);
const [alert, setAlert] = useState({ const [alert, setAlert] = useState({
show: false, show: false,
message: '' message: ''
}); });
const doDeleteTransferFee = useCallback(async () => { 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 id: selectedTransferFee
}); });
if (response?.status) { if (response?.status) {
setAlert((prev) => ({ ...prev, show: false, message: '' })); setAlert({ show: false, message: '' });
handleDeleteFeeDialog(false, null); handleDeleteFeeDialog(false, null);
toast.success('Success Delete Product'); toast.success('Success Delete Product');
reload(); reload();
} else { } else {
toast.error('Failed Delete Product'); toast.error('Failed Delete Product');
setAlert((prev) => ({ ...prev, show: true, message: response?.message })); setAlert({ show: true, message: response?.message });
} }
}, [selectedTransferFee, enforce]); }, [selectedTransferFee]);
return ( return (
<Dialog open={showDeleteFeeDialog} onOpenChange={(open) => handleDeleteFeeDialog(open, null)}> <Dialog open={showDeleteFeeDialog} onOpenChange={(open) => handleDeleteFeeDialog(open, null)}>
<DialogContent className="container-fixed max-w-md flex flex-col p-5 overflow-hidden [&>button]:hidden"> <DialogContent className="container-fixed max-w-md flex flex-col p-5 overflow-hidden [&>button]:hidden">
<DialogHeader className="p-0 border-0 block"> <DialogHeader className="p-0 border-0 block">
<DialogTitle className="text-lg">Delete Transfer Type</DialogTitle> <DialogTitle className="text-lg">Delete Transfer Type</DialogTitle>
<DialogDescription className="text-sm">Delete Transfer Type</DialogDescription> <DialogDescription className="text-sm">Are you sure you want to delete this data?</DialogDescription>
<Alert variant="warning"> <Alert variant="warning">
<h3 className="text-lg">Are you sure?</h3> <h3 className="text-lg">Are you sure?</h3>
<span className="text-sm">you will delete this data!</span> <span className="text-sm">You will delete this data!</span>
<div className="mt-2 flex items-center gap-x-2">
<label className="form-label max-w-56">Hard Delete</label>
<EnforceSwitch
enforce={enforce}
onChange={(e: ChangeEvent<HTMLInputElement>) => {
setEnforce(e.target.checked);
}}
/>
</div>
</Alert> </Alert>
{alert.show && ( {alert.show && (
<Alert variant="danger"> <Alert variant="danger">
@ -80,6 +65,5 @@ const DeleteDialog = () => {
); );
}; };
export default DeleteDialog; export default DeleteDialog;
export { DeleteDialog }; export { DeleteDialog };

View File

@ -1,18 +1,12 @@
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';
import { Alert, useDataGrid } from '@/components'; import { Alert, useDataGrid } from '@/components';
import { ChangeEvent, useCallback, useState } from 'react'; import { useCallback, useState } from 'react';
import { apiConfig } from '@/config/api.config'; import { apiConfig } from '@/config/api.config';
import { toast } from 'sonner'; import { toast } from 'sonner';
import { useCallApi } from '@/hooks'; import { useCallApi } from '@/hooks';
import { doSaveLogActivity } from '@/actions/GlobalActions';
import { EnforceSwitch } from '@/components/switch';
import { useContext } from 'react';
import { useManageTransferTypeContext } from '../hooks/useManageTransferTypeContext'; import { useManageTransferTypeContext } from '../hooks/useManageTransferTypeContext';
import { ManageTransferTypeContext } from '../hooks/ManageTransferTypeContext';
import TransferType from '../TransferType';
import { DialogDescription } from '@radix-ui/react-dialog'; import { DialogDescription } from '@radix-ui/react-dialog';
import { useManageAccessTypeContext } from '@/pages/access/access-type/hooks/useManageAccessTypeContext';
const API_URL = apiConfig.service_transaction; const API_URL = apiConfig.service_transaction;
@ -20,7 +14,6 @@ const DeleteDialog = () => {
const { showDeleteDialog, handleDeleteDialog, selectedTransferType } = useManageTransferTypeContext(); const { showDeleteDialog, handleDeleteDialog, selectedTransferType } = useManageTransferTypeContext();
const { reload } = useDataGrid(); const { reload } = useDataGrid();
const { DeleteData } = useCallApi(); const { DeleteData } = useCallApi();
const [enforce, setEnforce] = useState(false);
const [alert, setAlert] = useState({ const [alert, setAlert] = useState({
show: false, show: false,
message: '' message: ''
@ -32,40 +25,31 @@ const DeleteDialog = () => {
return; 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 id: selectedTransferType
}); });
if (response?.status) { if (response?.status) {
setAlert((prev) => ({ ...prev, show: false, message: '' })); setAlert({ show: false, message: '' });
handleDeleteDialog(false, null); handleDeleteDialog(false, null);
reload(); reload();
setTimeout(() => toast.success('Success Delete Product'), 0); setTimeout(() => toast.success('Success Delete Product'), 0);
} else { } else {
setAlert((prev) => ({ ...prev, show: true, message: response?.message })); setAlert({ show: true, message: response?.message });
setTimeout(() => toast.error('Failed Delete Product'), 0); setTimeout(() => toast.error('Failed Delete Product'), 0);
} }
}, [selectedTransferType, enforce, DeleteData, handleDeleteDialog, reload]); }, [selectedTransferType, DeleteData, handleDeleteDialog, reload]);
return ( return (
<Dialog open={showDeleteDialog} onOpenChange={(open) => handleDeleteDialog(open, null)}> <Dialog open={showDeleteDialog} onOpenChange={(open) => handleDeleteDialog(open, null)}>
<DialogContent className="container-fixed max-w-md flex flex-col p-5 overflow-hidden [&>button]:hidden"> <DialogContent className="container-fixed max-w-md flex flex-col p-5 overflow-hidden [&>button]:hidden">
<DialogHeader className="p-0 border-0 block"> <DialogHeader className="p-0 border-0 block">
<DialogTitle className="text-lg">Delete Transfer Type</DialogTitle> <DialogTitle className="text-lg">Delete Transfer Type</DialogTitle>
<DialogDescription className="text-sm">Delete Transfer Type</DialogDescription> <DialogDescription className="text-sm">Are you sure you want to delete this data?</DialogDescription>
<Alert variant="warning"> <Alert variant="warning">
<h3 className="text-lg">Are you sure?</h3> <h3 className="text-lg">Are you sure?</h3>
<span className="text-sm">you will delete this data!</span> <span className="text-sm">You will delete this data!</span>
<div className="mt-2 flex items-center gap-x-2">
<label className="form-label max-w-56">Hard Delete</label>
<EnforceSwitch
enforce={enforce}
onChange={(e: ChangeEvent<HTMLInputElement>) => {
setEnforce(e.target.checked);
}}
/>
</div>
</Alert> </Alert>
{alert.show && ( {alert.show && (
<Alert variant="danger"> <Alert variant="danger">
@ -86,6 +70,5 @@ const DeleteDialog = () => {
); );
}; };
export default DeleteDialog; export default DeleteDialog;
export { DeleteDialog }; export { DeleteDialog };