diff --git a/src/pages/menu/manage-menu/blocks/EditDialog.tsx b/src/pages/menu/manage-menu/blocks/EditDialog.tsx index 92c2f61..44d9a19 100644 --- a/src/pages/menu/manage-menu/blocks/EditDialog.tsx +++ b/src/pages/menu/manage-menu/blocks/EditDialog.tsx @@ -259,8 +259,10 @@ const EditDialog = () => { */} -
- +
+
diff --git a/src/pages/settings/user/manage-position/blocks/EditDialog.tsx b/src/pages/settings/user/manage-position/blocks/EditDialog.tsx index 1c4d8b3..f0dc3db 100644 --- a/src/pages/settings/user/manage-position/blocks/EditDialog.tsx +++ b/src/pages/settings/user/manage-position/blocks/EditDialog.tsx @@ -71,6 +71,7 @@ const EditDialog = () => { const { showEditDialog, handleEditDialog, menus, selectedPosition } = useManagePositionContext(); const { reload } = useDataGrid(); const { PutData } = useCallApi(); + const [isSubmitting, setIsSubmitting] = useState(false); const [alert, setAlert] = useState({ show: false, message: '' @@ -91,6 +92,7 @@ const EditDialog = () => { const doEditPosition = useCallback( async (e: React.FormEvent) => { e.preventDefault(); + setIsSubmitting(true); if (formField.name.trim() === '') { setAlert((prev) => ({ ...prev, show: true, message: 'Please fill name field.' })); @@ -102,26 +104,32 @@ const EditDialog = () => { return; } - const response = await PutData(`${API_URL}/user_role/update/${selectedPosition.id}`, { - name: formField.name, - roles: selectMenus, - status: formField.status - }); + try { + const response = await PutData(`${API_URL}/user_role/update/${selectedPosition.id}`, { + name: formField.name, + roles: selectMenus, + status: formField.status + }); - if (response?.status) { - setAlert((prev) => ({ ...prev, show: false, message: '' })); - handleEditDialog(false, null); - toast.success('Success Update Position'); - reload(); - const createActivity = { - module: 'Manage Position', - description: `Edit Position => ${selectedPosition.name}`, - action: 'U' - }; + if (response?.status) { + setAlert((prev) => ({ ...prev, show: false, message: '' })); + handleEditDialog(false, null); + toast.success('Success Update Position'); + reload(); + const createActivity = { + module: 'Manage Position', + description: `Edit Position => ${selectedPosition.name}`, + action: 'U' + }; - doSaveLogActivity(createActivity); - } else { - setAlert((prev) => ({ ...prev, show: true, message: response?.message })); + doSaveLogActivity(createActivity); + } else { + setAlert((prev) => ({ ...prev, show: true, message: response?.message })); + } + } catch (error) { + toast.error('Something went wrong, please try again.'); + } finally { + setIsSubmitting(false); } }, [formField, selectMenus, selectedPosition] @@ -217,9 +225,9 @@ const EditDialog = () => { ))}
-
-
diff --git a/src/pages/settings/user/manage-user/blocks/EditDialog.tsx b/src/pages/settings/user/manage-user/blocks/EditDialog.tsx index f8b5ef8..2193020 100644 --- a/src/pages/settings/user/manage-user/blocks/EditDialog.tsx +++ b/src/pages/settings/user/manage-user/blocks/EditDialog.tsx @@ -60,6 +60,7 @@ const EditDialog = () => { const [open, setOpen] = useState(false); const [roles, setRoles] = useState([]); const [customers, setCustomers] = useState([]); + const [isSubmitting, setIsSubmitting] = useState(false); const [alert, setAlert] = useState({ show: false, message: '' @@ -76,29 +77,44 @@ const EditDialog = () => { const doUpdateUser = useCallback( async (e: React.FormEvent) => { e.preventDefault(); - const response = await PutData(`${API_URL}/user/update/${selectedUser}`, { - ...formField - }); + setIsSubmitting(true); - if (formField.name.trim() === '') { + if ( + !formField.name.trim() || + !formField.username.trim() || + !formField.email.trim() || + !formField.id_role || + !formField.status || + !formField.customerid + ) { setAlert({ show: true, message: 'Please fill all required field' }); return; } - if (response?.status) { - resetForm(); - handleEditDialog(false, null); - toast.success('Success Update User'); - reload(); - const createActivity = { - module: 'Manage User', - description: `Edit User => ${formField.username}`, - action: 'U' - }; + try { + const response = await PutData(`${API_URL}/user/update/${selectedUser}`, { + ...formField + }); - doSaveLogActivity(createActivity); - } else { - setAlert((prev) => ({ ...prev, show: true, message: response?.message })); + if (response?.status) { + resetForm(); + handleEditDialog(false, null); + toast.success('Success Update User'); + reload(); + const createActivity = { + module: 'Manage User', + description: `Edit User => ${formField.username}`, + action: 'U' + }; + + doSaveLogActivity(createActivity); + } else { + setAlert((prev) => ({ ...prev, show: true, message: response?.message })); + } + } catch (error) { + toast.error('Something went wrong, please try again.'); + } finally { + setIsSubmitting(false); } }, [selectedUser, formField] @@ -362,8 +378,10 @@ const EditDialog = () => { -
- +
+