add crud provession

This commit is contained in:
Wikzyy
2025-03-06 15:14:05 +07:00
parent c0990e4b4d
commit 24daa38004
7 changed files with 616 additions and 0 deletions

View File

@ -0,0 +1,86 @@
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 { 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, selectedProfession } = useManageProfessionContext();
const { reload } = useDataGrid();
const { DeleteData } = useCallApi();
const [enforce, setEnforce] = useState(false);
const [alert, setAlert] = useState({
show: false,
message: ''
});
const doDeleteProfession = useCallback(async () => {
const response = await DeleteData(
`${API_URL}/profession/delete/${selectedProfession}/${enforce}`,
{
id: selectedProfession
}
);
if (response?.status) {
setAlert((prev) => ({ ...prev, show: false, message: '' }));
handleDeleteDialog(false, null);
toast.success('Success Delete Profession');
reload();
} else {
toast.error('Failed Delete Profession');
setAlert((prev) => ({ ...prev, show: true, message: response?.message }));
}
}, [selectedProfession, enforce]);
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>
</Alert>
{alert.show && (
<Alert variant="danger">
<h3>{alert.message}</h3>
</Alert>
)}
</DialogHeader>
<DialogFooter className="flex justify-end items-center gap-4 mt-3">
<Button variant={'outline'} onClick={() => handleDeleteDialog(false, null)}>
Cancel
</Button>
<Button variant={'destructive'} onClick={() => doDeleteProfession()}>
Delete
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
};
export default DeleteDialog;