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">

View File

@ -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 (
<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></DialogTitle>
<DialogDescription></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">
@ -72,10 +59,10 @@ const DeleteDialog = () => {
)}
</DialogHeader>
<DialogFooter className="flex justify-end items-center gap-4 mt-3">
<Button variant={'outline'} onClick={() => handleDeleteDialog(false, null)}>
<Button variant="outline" onClick={() => handleDeleteDialog(false, null)}>
Cancel
</Button>
<Button variant={'destructive'} onClick={() => doDeleteMunicipio()}>
<Button variant="destructive" onClick={doDeleteMunicipio}>
Delete
</Button>
</DialogFooter>

View File

@ -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 (
<Dialog open={showDeleteDialog} onOpenChange={(open) => handleDeleteDialog(open, null)}>
<DialogContent className="container-fixed max-w-md flex flex-col p-5 overflow-hidden [&>button]:hidden">
<DialogTitle></DialogTitle>
<DialogDescription></DialogDescription>
<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">
@ -62,10 +57,10 @@ const DeleteDialog = () => {
)}
</DialogHeader>
<DialogFooter className="flex justify-end items-center gap-4 mt-3">
<Button variant={'outline'} onClick={() => handleDeleteDialog(false, null)}>
<Button variant="outline" onClick={() => handleDeleteDialog(false, null)}>
Cancel
</Button>
<Button variant={'destructive'} onClick={() => doDeletePostoAdm()}>
<Button variant="destructive" onClick={doDeletePostoAdm}>
Delete
</Button>
</DialogFooter>

View File

@ -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 (
<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">
<DialogTitle></DialogTitle>
<DialogDescription></DialogDescription>
<DialogHeader className="p-0 border-0 block">
<DialogTitle></DialogTitle>
<DialogDescription></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">
@ -61,10 +53,10 @@ const DeleteDialog = () => {
)}
</DialogHeader>
<DialogFooter className="flex justify-end items-center gap-4 mt-3">
<Button variant={'outline'} onClick={() => handleDeleteDialog(false, null)}>
<Button variant="outline" onClick={() => handleDeleteDialog(false, null)}>
Cancel
</Button>
<Button variant={'destructive'} onClick={() => doDeleteProduct()}>
<Button variant="destructive" onClick={doDeleteProduct}>
Delete
</Button>
</DialogFooter>

View File

@ -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 (
<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">
<DialogHeader className="p-0 border-0 block">
<DialogTitle></DialogTitle>
<DialogDescription></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">
@ -71,10 +52,10 @@ const DeleteDialog = () => {
)}
</DialogHeader>
<DialogFooter className="flex justify-end items-center gap-4 mt-3">
<Button variant={'outline'} onClick={() => handleDeleteDialog(false, null)}>
<Button variant="outline" onClick={() => handleDeleteDialog(false, null)}>
Cancel
</Button>
<Button variant={'destructive'} onClick={() => doDeleteProfession()}>
<Button variant="destructive" onClick={doDeleteProfession}>
Delete
</Button>
</DialogFooter>

View File

@ -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 (
<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">
<DialogHeader className="p-0 border-0 block">
<DialogTitle></DialogTitle>
<DialogDescription></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">
@ -68,10 +53,10 @@ const DeleteDialog = () => {
)}
</DialogHeader>
<DialogFooter className="flex justify-end items-center gap-4 mt-3">
<Button variant={'outline'} onClick={() => handleDeleteDialog(false, null)}>
<Button variant="outline" onClick={() => handleDeleteDialog(false, null)}>
Cancel
</Button>
<Button variant={'destructive'} onClick={() => doDeleteProvider()}>
<Button variant="destructive" onClick={doDeleteProvider}>
Delete
</Button>
</DialogFooter>

View File

@ -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 (
<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">
<DialogHeader className="p-0 border-0 block">
<DialogTitle></DialogTitle>
<DialogDescription></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">
@ -68,10 +54,10 @@ const DeleteDialog = () => {
)}
</DialogHeader>
<DialogFooter className="flex justify-end items-center gap-4 mt-3">
<Button variant={'outline'} onClick={() => handleDeleteDialog(false, null)}>
<Button variant="outline" onClick={() => handleDeleteDialog(false, null)}>
Cancel
</Button>
<Button variant={'destructive'} onClick={() => doDeleteSucos()}>
<Button variant="destructive" onClick={doDeleteSucos}>
Delete
</Button>
</DialogFooter>