fixing add dialog manage user & manage position and edit dialog manage user
This commit is contained in:
@ -26,6 +26,15 @@ import { doSaveLogActivity } from '@/actions/GlobalActions';
|
||||
|
||||
const API_URL = apiConfig.service_dashboard;
|
||||
|
||||
const initialState = {
|
||||
name: '',
|
||||
username: '',
|
||||
email: '',
|
||||
id_role: '',
|
||||
id_role_old: '',
|
||||
status: ''
|
||||
};
|
||||
|
||||
const EditDialog = () => {
|
||||
const parentRef = useRef<any | null>(null);
|
||||
const { showEditDialog, selectedUser, handleEditDialog, roles } = useUserContext();
|
||||
@ -35,16 +44,14 @@ const EditDialog = () => {
|
||||
show: false,
|
||||
message: ''
|
||||
});
|
||||
const initialState = {
|
||||
name: '',
|
||||
username: '',
|
||||
email: '',
|
||||
id_role: '',
|
||||
id_role_old: '',
|
||||
status: ''
|
||||
};
|
||||
|
||||
const [formField, setFormField] = useState(initialState);
|
||||
|
||||
const resetForm = () => {
|
||||
setFormField(initialState);
|
||||
setAlert({ show: false, message: '' });
|
||||
};
|
||||
|
||||
/* actions */
|
||||
const doResetForm = () => {
|
||||
setAlert({ show: false, message: '' });
|
||||
@ -58,7 +65,14 @@ const EditDialog = () => {
|
||||
...formField,
|
||||
id_role_old: undefined
|
||||
});
|
||||
|
||||
if (formField.name.trim() === '') {
|
||||
setAlert({ show: true, message: 'Please fill all required field' });
|
||||
return;
|
||||
}
|
||||
|
||||
if (response?.status) {
|
||||
resetForm();
|
||||
handleEditDialog(false, null);
|
||||
toast.success('Success Update User');
|
||||
reload();
|
||||
@ -111,7 +125,7 @@ const EditDialog = () => {
|
||||
|
||||
useEffect(() => {
|
||||
if (showEditDialog === false) {
|
||||
doResetForm();
|
||||
resetForm();
|
||||
}
|
||||
}, [showEditDialog]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user