Changing hard delete to soft delete on transactiontype and transactionfee
This commit is contained in:
@ -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 (
|
||||
<Dialog open={showDeleteFeeDialog} onOpenChange={(open) => handleDeleteFeeDialog(open, null)}>
|
||||
<DialogContent className="container-fixed max-w-md flex flex-col p-5 overflow-hidden [&>button]:hidden">
|
||||
<DialogHeader className="p-0 border-0 block">
|
||||
<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">
|
||||
<h3 className="text-lg">Are you sure?</h3>
|
||||
<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>
|
||||
<span className="text-sm">You will delete this data!</span>
|
||||
</Alert>
|
||||
{alert.show && (
|
||||
<Alert variant="danger">
|
||||
@ -80,6 +65,5 @@ const DeleteDialog = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default DeleteDialog;
|
||||
|
||||
export default DeleteDialog;
|
||||
export { DeleteDialog };
|
||||
|
||||
@ -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 (
|
||||
<Dialog open={showDeleteDialog} onOpenChange={(open) => handleDeleteDialog(open, null)}>
|
||||
<DialogContent className="container-fixed max-w-md flex flex-col p-5 overflow-hidden [&>button]:hidden">
|
||||
<DialogHeader className="p-0 border-0 block">
|
||||
<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">
|
||||
<h3 className="text-lg">Are you sure?</h3>
|
||||
<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>
|
||||
<span className="text-sm">You will delete this data!</span>
|
||||
</Alert>
|
||||
{alert.show && (
|
||||
<Alert variant="danger">
|
||||
@ -86,6 +70,5 @@ const DeleteDialog = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default DeleteDialog;
|
||||
|
||||
export default DeleteDialog;
|
||||
export { DeleteDialog };
|
||||
|
||||
Reference in New Issue
Block a user