fix loading page, add delete edit manage menu, search manage user
This commit is contained in:
@ -12,15 +12,25 @@ import {
|
||||
DialogHeader,
|
||||
DialogTitle
|
||||
} from '@/components/ui/dialog';
|
||||
import { FormControl,NativeSelect } from "@mui/material";
|
||||
import { FormControl, NativeSelect } from '@mui/material';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue
|
||||
} from '@/components/ui/select';
|
||||
|
||||
const API_URL = apiConfig.service_dashboard;
|
||||
|
||||
const EditDialog = () => {
|
||||
const { showEditDialog, handleEditDialog, selectedMenu, setSelectedMenu, parents }: any = useManageMenusContext();
|
||||
const { showEditDialog, handleEditDialog, selectedMenu, setSelectedMenu, parents }: any =
|
||||
useManageMenusContext();
|
||||
const { reload } = useDataGrid();
|
||||
const { PutData } = useCallApi();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [alert, setAlert] = useState({
|
||||
show: false,
|
||||
message: ''
|
||||
@ -38,11 +48,12 @@ const EditDialog = () => {
|
||||
|
||||
const handleUpdate = async (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
|
||||
|
||||
if (
|
||||
selectedMenu.module === '' ||
|
||||
selectedMenu.name === '' ||
|
||||
selectedMenu.link === '' ||
|
||||
selectedMenu.id_parent === '' ||
|
||||
selectedMenu.order_number === 0 ||
|
||||
selectedMenu.status === ''
|
||||
) {
|
||||
@ -51,8 +62,8 @@ const EditDialog = () => {
|
||||
}
|
||||
|
||||
const updateMenu = selectedMenu;
|
||||
if (updateMenu.id_parent === null) updateMenu.id_parent = "";
|
||||
delete updateMenu.parentName
|
||||
if (updateMenu.id_parent === null) updateMenu.id_parent = '';
|
||||
delete updateMenu.parentName;
|
||||
const response = await PutData(`${API_URL}/menus/update/${selectedMenu.id}`, selectedMenu);
|
||||
if (response?.status) {
|
||||
handleEditDialog(false, null);
|
||||
@ -67,7 +78,7 @@ const EditDialog = () => {
|
||||
};
|
||||
|
||||
const resetForm = () => {
|
||||
setSelectedMenu(initialState)
|
||||
setSelectedMenu(initialState);
|
||||
setAlert({ show: false, message: '' });
|
||||
};
|
||||
|
||||
@ -78,7 +89,7 @@ const EditDialog = () => {
|
||||
<DialogTitle>Menu - Update</DialogTitle>
|
||||
<DialogDescription></DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogBody>
|
||||
<DialogBody className="scrollable">
|
||||
<div className="flex flex-col">
|
||||
{alert.show && (
|
||||
<Alert variant="danger">
|
||||
@ -132,24 +143,27 @@ const EditDialog = () => {
|
||||
|
||||
<div className="w-full">
|
||||
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||
<label className="form-label flex items-center gap-1 max-w-56">ID Parent</label>
|
||||
<FormControl fullWidth margin="dense">
|
||||
<NativeSelect
|
||||
defaultValue={30}
|
||||
value={selectedMenu.id_parent}
|
||||
onChange={(e: any) => setSelectedMenu({ ...selectedMenu, id_parent: e.target.value })}
|
||||
inputProps={{
|
||||
name: 'id_parent',
|
||||
id: 'uncontrolled-native',
|
||||
}}
|
||||
>
|
||||
{
|
||||
parents ? parents.map((el: any) => (
|
||||
<option key={el.id} value={el.id}>{el.name}</option>
|
||||
)) : ''
|
||||
}
|
||||
</NativeSelect>
|
||||
</FormControl>
|
||||
<label className="form-label flex items-center gap-1 max-w-56">Parent</label>
|
||||
<Select
|
||||
value={selectedMenu.id_parent || ''}
|
||||
onValueChange={(value) => {
|
||||
setSelectedMenu({
|
||||
...selectedMenu,
|
||||
id_parent: value === '' ? null : value
|
||||
});
|
||||
}}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select As Parent" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{parents.map((parent: any) => (
|
||||
<SelectItem key={parent.id} value={parent.id}>
|
||||
{parent.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -165,7 +179,10 @@ const EditDialog = () => {
|
||||
value={selectedMenu.order_number === 0 ? '' : selectedMenu.order_number}
|
||||
onChange={(e) => {
|
||||
const value = parseInt(e.target.value, 10);
|
||||
setSelectedMenu({ ...selectedMenu, order_number: isNaN(value) ? 0 : value });
|
||||
setSelectedMenu({
|
||||
...selectedMenu,
|
||||
order_number: isNaN(value) ? 0 : value
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
@ -184,6 +201,26 @@ const EditDialog = () => {
|
||||
</div>
|
||||
|
||||
<div className="w-full">
|
||||
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||
<label className="form-label flex items-center gap-1 max-w-56">
|
||||
Status<span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Select
|
||||
value={selectedMenu.status}
|
||||
onValueChange={(value) => setSelectedMenu({ ...selectedMenu, status: value })}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Status" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="Y">Active</SelectItem>
|
||||
<SelectItem value="N">Inactive</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* <div className="w-full">
|
||||
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||
<label className="form-label flex items-center gap-1 max-w-56">
|
||||
Status<span className="text-red-500">*</span>
|
||||
@ -203,7 +240,7 @@ const EditDialog = () => {
|
||||
</NativeSelect>
|
||||
</FormControl>
|
||||
</div>
|
||||
</div>
|
||||
</div> */}
|
||||
|
||||
<div className="flex justify-end">
|
||||
<Button className="btn btn-primary">Save Changes</Button>
|
||||
|
||||
Reference in New Issue
Block a user