applying soft delete on masterdata, except walletrule and conversion
This commit is contained in:
@ -2,38 +2,42 @@ import { apiConfig } from '@/config/api.config';
|
|||||||
import { useManageAldeiasContext } from '../hooks/useManageAldeiasContext';
|
import { useManageAldeiasContext } from '../hooks/useManageAldeiasContext';
|
||||||
import { Alert, useDataGrid } from '@/components';
|
import { Alert, useDataGrid } from '@/components';
|
||||||
import { useCallApi } from '@/hooks';
|
import { useCallApi } from '@/hooks';
|
||||||
import { ChangeEvent, useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import { Dialog, DialogContent, DialogFooter, DialogHeader } from '@/components/ui/dialog';
|
import { Dialog, DialogContent, DialogFooter, DialogHeader } from '@/components/ui/dialog';
|
||||||
import { EnforceSwitch } from '@/components/switch';
|
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
|
|
||||||
const API_URL = apiConfig.service_master_data;
|
const API_URL = apiConfig.service_master_data;
|
||||||
|
|
||||||
const DeleteDialog = () => {
|
const DeleteDialog = () => {
|
||||||
const { showDeleteDialog, handleDeleteDialog, selectedAldeias } = useManageAldeiasContext();
|
const { showDeleteDialog, handleDeleteDialog, selectedAldeias } = useManageAldeiasContext();
|
||||||
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 doDeleteAldeias = useCallback(async () => {
|
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
|
id: selectedAldeias
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response?.status) {
|
if (response?.status) {
|
||||||
setAlert((prev) => ({ ...prev, show: false, message: '' }));
|
setAlert({ show: false, message: '' });
|
||||||
handleDeleteDialog(false, null);
|
handleDeleteDialog(false, null);
|
||||||
toast.success('Success Delete Aldeias');
|
toast.success('Success Delete Aldeias');
|
||||||
reload();
|
reload();
|
||||||
} else {
|
} else {
|
||||||
|
setAlert({ show: true, message: response?.message });
|
||||||
toast.error('Failed Delete Aldeias');
|
toast.error('Failed Delete Aldeias');
|
||||||
setAlert((prev) => ({ ...prev, show: true, message: response?.message }));
|
|
||||||
}
|
}
|
||||||
}, [selectedAldeias, enforce]);
|
}, [selectedAldeias, DeleteData, handleDeleteDialog, reload]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={showDeleteDialog} onOpenChange={(open) => handleDeleteDialog(open, null)}>
|
<Dialog open={showDeleteDialog} onOpenChange={(open) => handleDeleteDialog(open, null)}>
|
||||||
@ -41,16 +45,7 @@ const DeleteDialog = () => {
|
|||||||
<DialogHeader className="p-0 border-0 block">
|
<DialogHeader className="p-0 border-0 block">
|
||||||
<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">
|
||||||
|
|||||||
@ -1,69 +1,56 @@
|
|||||||
import { Alert, useDataGrid } from '@/components';
|
import { Alert, useDataGrid } from '@/components';
|
||||||
import { useManageMunicipiosContext } from '../hooks/useManageMunicipiosContext';
|
import { useManageMunicipiosContext } from '../hooks/useManageMunicipiosContext';
|
||||||
import { ChangeEvent, useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
import axios from 'axios';
|
|
||||||
import { apiConfig } from '@/config/api.config';
|
import { apiConfig } from '@/config/api.config';
|
||||||
import { useCallApi } from '@/hooks';
|
import { useCallApi } from '@/hooks';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import { Dialog, DialogContent, DialogFooter, DialogHeader } from '@/components/ui/dialog';
|
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||||
import { EnforceSwitch } from '@/components/switch';
|
|
||||||
import { Button } from '@/components/ui/button';
|
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 API_URL = apiConfig.service_master_data;
|
||||||
|
|
||||||
const DeleteDialog = () => {
|
const DeleteDialog = () => {
|
||||||
const { showDeleteDialog, handleDeleteDialog, selectedMunicipios, municipios } =
|
const { showDeleteDialog, handleDeleteDialog, selectedMunicipios } = useManageMunicipiosContext();
|
||||||
useManageMunicipiosContext();
|
|
||||||
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 doDeleteMunicipio = useCallback(async () => {
|
const doDeleteMunicipio = useCallback(async () => {
|
||||||
|
if (!selectedMunicipios) {
|
||||||
|
toast.error('No Municipio selected');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const response = await DeleteData(
|
const response = await DeleteData(
|
||||||
`${API_URL}/municipios/delete/${selectedMunicipios}/${enforce}`,
|
`${API_URL}/municipios/delete/${selectedMunicipios}/false`,
|
||||||
{
|
{ id: selectedMunicipios }
|
||||||
id: selectedMunicipios
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response?.status) {
|
if (response?.status) {
|
||||||
setAlert((prev) => ({ ...prev, show: false, message: '' }));
|
setAlert({ show: false, message: '' });
|
||||||
handleDeleteDialog(false, null);
|
handleDeleteDialog(false, null);
|
||||||
toast.success('Success Delete Municipio');
|
toast.success('Success Delete Municipio');
|
||||||
reload();
|
reload();
|
||||||
// const createActivity = {
|
|
||||||
// module: 'Manage Municipio',
|
|
||||||
// description: `Delete Municipio => ${selectedMunicipios}`,
|
|
||||||
// action: 'D'
|
|
||||||
// };
|
|
||||||
|
|
||||||
// doSaveLogActivity(createActivity);
|
|
||||||
} else {
|
} 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 (
|
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></DialogTitle>
|
||||||
|
<DialogDescription></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">
|
||||||
@ -72,10 +59,10 @@ const DeleteDialog = () => {
|
|||||||
)}
|
)}
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<DialogFooter className="flex justify-end items-center gap-4 mt-3">
|
<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
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant={'destructive'} onClick={() => doDeleteMunicipio()}>
|
<Button variant="destructive" onClick={doDeleteMunicipio}>
|
||||||
Delete
|
Delete
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
|
|||||||
@ -1,11 +1,10 @@
|
|||||||
import { Alert, useDataGrid } from '@/components';
|
import { Alert, useDataGrid } from '@/components';
|
||||||
import { useManagePostoAdmsContext } from '../hooks/useManagePostoAdmsContext';
|
import { useManagePostoAdmsContext } from '../hooks/useManagePostoAdmsContext';
|
||||||
import { useCallApi } from '@/hooks';
|
import { useCallApi } from '@/hooks';
|
||||||
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 { Dialog, DialogContent, DialogFooter, DialogHeader } from '@/components/ui/dialog';
|
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||||
import { EnforceSwitch } from '@/components/switch';
|
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
|
|
||||||
const API_URL = apiConfig.service_master_data;
|
const API_URL = apiConfig.service_master_data;
|
||||||
@ -14,46 +13,42 @@ const DeleteDialog = () => {
|
|||||||
const { showDeleteDialog, handleDeleteDialog, selectedPostoAdms } = useManagePostoAdmsContext();
|
const { showDeleteDialog, handleDeleteDialog, selectedPostoAdms } = useManagePostoAdmsContext();
|
||||||
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 doDeletePostoAdm = useCallback(async () => {
|
const doDeletePostoAdm = useCallback(async () => {
|
||||||
|
if (!selectedPostoAdms) {
|
||||||
|
toast.error('No Posto Adm selected');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const response = await DeleteData(
|
const response = await DeleteData(
|
||||||
`${API_URL}/postoadms/delete/${selectedPostoAdms}/${enforce}`,
|
`${API_URL}/postoadms/delete/${selectedPostoAdms}/false`,
|
||||||
{
|
{ id: selectedPostoAdms }
|
||||||
id: selectedPostoAdms
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response?.status) {
|
if (response?.status) {
|
||||||
setAlert((prev) => ({ ...prev, show: false, message: '' }));
|
setAlert({ show: false, message: '' });
|
||||||
handleDeleteDialog(false, null);
|
handleDeleteDialog(false, null);
|
||||||
toast.success('Success Delete Posto Adm');
|
toast.success('Success Delete Posto Adm');
|
||||||
reload();
|
reload();
|
||||||
} else {
|
} 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 (
|
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">
|
||||||
|
<DialogTitle></DialogTitle>
|
||||||
|
<DialogDescription></DialogDescription>
|
||||||
<DialogHeader className="p-0 border-0 block">
|
<DialogHeader className="p-0 border-0 block">
|
||||||
<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">
|
||||||
@ -62,10 +57,10 @@ const DeleteDialog = () => {
|
|||||||
)}
|
)}
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<DialogFooter className="flex justify-end items-center gap-4 mt-3">
|
<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
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant={'destructive'} onClick={() => doDeletePostoAdm()}>
|
<Button variant="destructive" onClick={doDeletePostoAdm}>
|
||||||
Delete
|
Delete
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
|
|||||||
@ -2,57 +2,49 @@ import { apiConfig } from '@/config/api.config';
|
|||||||
import { useManageProductsContext } from '../hooks/useManageProductsContext';
|
import { useManageProductsContext } from '../hooks/useManageProductsContext';
|
||||||
import { Alert, useDataGrid } from '@/components';
|
import { Alert, useDataGrid } from '@/components';
|
||||||
import { useCallApi } from '@/hooks';
|
import { useCallApi } from '@/hooks';
|
||||||
import { ChangeEvent, useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||||
import { EnforceSwitch } from '@/components/switch';
|
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
|
|
||||||
const API_URL = apiConfig.service_master_data;
|
const API_URL = apiConfig.service_master_data;
|
||||||
|
|
||||||
const DeleteDialog = () => {
|
const DeleteDialog = () => {
|
||||||
const { showDeleteDialog, handleDeleteDialog, selectedProducts } = useManageProductsContext();
|
const { showDeleteDialog, handleDeleteDialog, selectedProducts } = useManageProductsContext();
|
||||||
const { reload } = useDataGrid();
|
const { reload } = useDataGrid();
|
||||||
const { DeleteData } = useCallApi();
|
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 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
|
id: selectedProducts
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response?.status) {
|
if (response?.status) {
|
||||||
setAlert((prev) => ({ ...prev, show: false, message: '' }));
|
setAlert({ show: false, message: '' });
|
||||||
handleDeleteDialog(false, null);
|
handleDeleteDialog(false, null);
|
||||||
toast.success('Success Delete Product');
|
toast.success('Success Delete Product');
|
||||||
reload();
|
reload();
|
||||||
} else {
|
} else {
|
||||||
|
setAlert({ show: true, message: response?.message });
|
||||||
toast.error('Failed Delete Product');
|
toast.error('Failed Delete Product');
|
||||||
setAlert((prev) => ({ ...prev, show: true, message: response?.message }));
|
|
||||||
}
|
}
|
||||||
}, [selectedProducts, enforce]);
|
}, [selectedProducts, 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">
|
||||||
|
<DialogTitle></DialogTitle>
|
||||||
|
<DialogDescription></DialogDescription>
|
||||||
<DialogHeader className="p-0 border-0 block">
|
<DialogHeader className="p-0 border-0 block">
|
||||||
<DialogTitle></DialogTitle>
|
|
||||||
<DialogDescription></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">
|
||||||
@ -61,10 +53,10 @@ const DeleteDialog = () => {
|
|||||||
)}
|
)}
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<DialogFooter className="flex justify-end items-center gap-4 mt-3">
|
<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
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant={'destructive'} onClick={() => doDeleteProduct()}>
|
<Button variant="destructive" onClick={doDeleteProduct}>
|
||||||
Delete
|
Delete
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
|
|||||||
@ -2,67 +2,48 @@ import { apiConfig } from '@/config/api.config';
|
|||||||
import { useManageProfessionContext } from '../hooks/useManageProfessionContext';
|
import { useManageProfessionContext } from '../hooks/useManageProfessionContext';
|
||||||
import { Alert, useDataGrid } from '@/components';
|
import { Alert, useDataGrid } from '@/components';
|
||||||
import { useCallApi } from '@/hooks';
|
import { useCallApi } from '@/hooks';
|
||||||
import { ChangeEvent, useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import {
|
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogDescription,
|
|
||||||
DialogFooter,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle
|
|
||||||
} from '@/components/ui/dialog';
|
|
||||||
import { EnforceSwitch } from '@/components/switch';
|
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
|
|
||||||
const API_URL = apiConfig.service_master_data;
|
const API_URL = apiConfig.service_master_data;
|
||||||
|
|
||||||
const DeleteDialog = () => {
|
const DeleteDialog = () => {
|
||||||
const { showDeleteDialog, handleDeleteDialog, selectedProfession } = useManageProfessionContext();
|
const { showDeleteDialog, handleDeleteDialog, selectedProfession } = useManageProfessionContext();
|
||||||
const { reload } = useDataGrid();
|
const { reload } = useDataGrid();
|
||||||
const { DeleteData } = useCallApi();
|
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 doDeleteProfession = useCallback(async () => {
|
||||||
const response = await DeleteData(
|
if (!selectedProfession) {
|
||||||
`${API_URL}/profession/delete/${selectedProfession}/${enforce}`,
|
toast.error('No profession selected');
|
||||||
{
|
return;
|
||||||
id: selectedProfession
|
}
|
||||||
}
|
const response = await DeleteData(`${API_URL}/profession/delete/${selectedProfession}/false`, {
|
||||||
);
|
id: selectedProfession
|
||||||
|
});
|
||||||
|
|
||||||
if (response?.status) {
|
if (response?.status) {
|
||||||
setAlert((prev) => ({ ...prev, show: false, message: '' }));
|
setAlert({ show: false, message: '' });
|
||||||
handleDeleteDialog(false, null);
|
handleDeleteDialog(false, null);
|
||||||
toast.success('Success Delete Profession');
|
toast.success('Success Delete Profession');
|
||||||
reload();
|
reload();
|
||||||
} else {
|
} else {
|
||||||
|
setAlert({ show: true, message: response?.message });
|
||||||
toast.error('Failed Delete Profession');
|
toast.error('Failed Delete Profession');
|
||||||
setAlert((prev) => ({ ...prev, show: true, message: response?.message }));
|
|
||||||
}
|
}
|
||||||
}, [selectedProfession, enforce]);
|
}, [selectedProfession, 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">
|
||||||
<DialogHeader className="p-0 border-0 block">
|
<DialogHeader className="p-0 border-0 block">
|
||||||
<DialogTitle></DialogTitle>
|
<DialogTitle></DialogTitle>
|
||||||
<DialogDescription></DialogDescription>
|
<DialogDescription></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">
|
||||||
@ -71,10 +52,10 @@ const DeleteDialog = () => {
|
|||||||
)}
|
)}
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<DialogFooter className="flex justify-end items-center gap-4 mt-3">
|
<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
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant={'destructive'} onClick={() => doDeleteProfession()}>
|
<Button variant="destructive" onClick={doDeleteProfession}>
|
||||||
Delete
|
Delete
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
|
|||||||
@ -2,64 +2,49 @@ import { apiConfig } from '@/config/api.config';
|
|||||||
import { useManageProviderContext } from '../hooks/useManageProviderContext';
|
import { useManageProviderContext } from '../hooks/useManageProviderContext';
|
||||||
import { Alert, useDataGrid } from '@/components';
|
import { Alert, useDataGrid } from '@/components';
|
||||||
import { useCallApi } from '@/hooks';
|
import { useCallApi } from '@/hooks';
|
||||||
import { ChangeEvent, useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import {
|
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogDescription,
|
|
||||||
DialogFooter,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle
|
|
||||||
} from '@/components/ui/dialog';
|
|
||||||
import { EnforceSwitch } from '@/components/switch';
|
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
|
|
||||||
const API_URL = apiConfig.service_master_data;
|
const API_URL = apiConfig.service_master_data;
|
||||||
|
|
||||||
const DeleteDialog = () => {
|
const DeleteDialog = () => {
|
||||||
const { showDeleteDialog, handleDeleteDialog, selectedProvider } = useManageProviderContext();
|
const { showDeleteDialog, handleDeleteDialog, selectedProvider } = useManageProviderContext();
|
||||||
const { reload } = useDataGrid();
|
const { reload } = useDataGrid();
|
||||||
const { DeleteData } = useCallApi();
|
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 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
|
id: selectedProvider
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response?.status) {
|
if (response?.status) {
|
||||||
setAlert((prev) => ({ ...prev, show: false, message: '' }));
|
setAlert({ show: false, message: '' });
|
||||||
handleDeleteDialog(false, null);
|
handleDeleteDialog(false, null);
|
||||||
toast.success('Success Delete Provider');
|
toast.success('Success Delete Provider');
|
||||||
reload();
|
reload();
|
||||||
} else {
|
} else {
|
||||||
setAlert((prev) => ({ ...prev, show: true, message: response?.message }));
|
setAlert({ show: true, message: response?.message });
|
||||||
toast.error('Failed Delete Provider');
|
toast.error('Failed Delete Provider');
|
||||||
}
|
}
|
||||||
}, [selectedProvider, enforce]);
|
}, [selectedProvider, 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">
|
||||||
<DialogHeader className="p-0 border-0 block">
|
<DialogHeader className="p-0 border-0 block">
|
||||||
<DialogTitle></DialogTitle>
|
<DialogTitle></DialogTitle>
|
||||||
<DialogDescription></DialogDescription>
|
<DialogDescription></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">
|
||||||
@ -68,10 +53,10 @@ const DeleteDialog = () => {
|
|||||||
)}
|
)}
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<DialogFooter className="flex justify-end items-center gap-4 mt-3">
|
<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
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant={'destructive'} onClick={() => doDeleteProvider()}>
|
<Button variant="destructive" onClick={doDeleteProvider}>
|
||||||
Delete
|
Delete
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
|
|||||||
@ -1,18 +1,10 @@
|
|||||||
import { apiConfig } from '@/config/api.config';
|
import { apiConfig } from '@/config/api.config';
|
||||||
import { useManageSucosContext } from '../hooks/useManageSucosContext';
|
import { useManageSucosContext } from '../hooks/useManageSucosContext';
|
||||||
import { ChangeEvent, useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
import { useCallApi } from '@/hooks';
|
import { useCallApi } from '@/hooks';
|
||||||
import { Alert, useDataGrid } from '@/components';
|
import { Alert, useDataGrid } from '@/components';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import {
|
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogDescription,
|
|
||||||
DialogFooter,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle
|
|
||||||
} from '@/components/ui/dialog';
|
|
||||||
import { EnforceSwitch } from '@/components/switch';
|
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
|
|
||||||
const API_URL = apiConfig.service_master_data;
|
const API_URL = apiConfig.service_master_data;
|
||||||
@ -21,45 +13,39 @@ const DeleteDialog = () => {
|
|||||||
const { showDeleteDialog, handleDeleteDialog, selectedSucos } = useManageSucosContext();
|
const { showDeleteDialog, handleDeleteDialog, selectedSucos } = useManageSucosContext();
|
||||||
const { reload } = useDataGrid();
|
const { reload } = useDataGrid();
|
||||||
const { DeleteData } = useCallApi();
|
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 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
|
id: selectedSucos
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response?.status) {
|
if (response?.status) {
|
||||||
setAlert((prev) => ({ ...prev, show: false, message: '' }));
|
setAlert({ show: false, message: '' });
|
||||||
handleDeleteDialog(false, null);
|
handleDeleteDialog(false, null);
|
||||||
toast.success('Success Delete Sucos');
|
toast.success('Success Delete Sucos');
|
||||||
reload();
|
reload();
|
||||||
} else {
|
} 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 (
|
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">
|
||||||
<DialogHeader className="p-0 border-0 block">
|
<DialogHeader className="p-0 border-0 block">
|
||||||
<DialogTitle></DialogTitle>
|
<DialogTitle></DialogTitle>
|
||||||
<DialogDescription></DialogDescription>
|
<DialogDescription></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">
|
||||||
@ -68,10 +54,10 @@ const DeleteDialog = () => {
|
|||||||
)}
|
)}
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<DialogFooter className="flex justify-end items-center gap-4 mt-3">
|
<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
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant={'destructive'} onClick={() => doDeleteSucos()}>
|
<Button variant="destructive" onClick={doDeleteSucos}>
|
||||||
Delete
|
Delete
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
|
|||||||
Reference in New Issue
Block a user