fixing add dialog manage user & manage position and edit dialog manage user
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { useCallback, useRef, useState } from 'react';
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
|
||||
import {
|
||||
Dialog,
|
||||
@ -59,6 +59,10 @@ const MenuItemComponent: React.FC<{
|
||||
);
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
name: ''
|
||||
};
|
||||
|
||||
const AddDialog = () => {
|
||||
const parentRef = useRef<any | null>(null);
|
||||
const { showAddDialog, handleAddDialog, menus } = useManagePositionContext();
|
||||
@ -69,9 +73,7 @@ const AddDialog = () => {
|
||||
message: ''
|
||||
});
|
||||
const [selectMenus, setSelectMenus] = useState<string[]>([]);
|
||||
const [formField, setFormField] = useState({
|
||||
name: ''
|
||||
});
|
||||
const [formField, setFormField] = useState(initialState);
|
||||
|
||||
/* actions */
|
||||
const handleCheckboxChange = useCallback((key: string) => {
|
||||
@ -80,6 +82,12 @@ const AddDialog = () => {
|
||||
);
|
||||
}, []);
|
||||
|
||||
const resetForm = () => {
|
||||
setFormField(() => ({ name: '' }));
|
||||
setAlert({ show: false, message: '' });
|
||||
setSelectMenus([]);
|
||||
};
|
||||
|
||||
const doCreatePosition = useCallback(
|
||||
async (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
@ -96,7 +104,7 @@ const AddDialog = () => {
|
||||
});
|
||||
|
||||
if (response?.status) {
|
||||
setAlert((prev) => ({ ...prev, show: false, message: '' }));
|
||||
resetForm();
|
||||
handleAddDialog(false);
|
||||
toast.success('Success Create Position');
|
||||
reload();
|
||||
@ -114,6 +122,12 @@ const AddDialog = () => {
|
||||
[formField, selectMenus]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (showAddDialog === false) {
|
||||
resetForm();
|
||||
}
|
||||
}, [showAddDialog]);
|
||||
|
||||
return (
|
||||
<Dialog open={showAddDialog} onOpenChange={(open) => handleAddDialog(open)}>
|
||||
<DialogContent className="container-fixed max-w-screen-lg flex flex-col p-10 overflow-hidden [&>button]:hidden">
|
||||
|
||||
Reference in New Issue
Block a user