applying soft delete on masterdata, except walletrule and conversion

This commit is contained in:
bagusajisaputroo
2025-03-25 23:10:41 +07:00
parent 8a956ea950
commit 89dc164891
7 changed files with 123 additions and 202 deletions

View File

@ -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 (
<Dialog open={showDeleteDialog} onOpenChange={(open) => handleDeleteDialog(open, null)}>
@ -41,16 +45,7 @@ const DeleteDialog = () => {
<DialogHeader className="p-0 border-0 block">
<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">