From 37fe79f6669c70530dcd943b88b0035c74b2fbd6 Mon Sep 17 00:00:00 2001 From: mozzy11 Date: Mon, 20 Jan 2025 19:25:26 +0300 Subject: [PATCH] improve Form validation for add-user and some minor style fixes --- frontend/src/components/Style.css | 2 +- .../admin/userManagement/UserAddModify.js | 50 ++++++++++++++++++- .../notifications/PushNotificationPage.jsx | 11 +++- 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/Style.css b/frontend/src/components/Style.css index 35f75ebc78..2db9a8e960 100644 --- a/frontend/src/components/Style.css +++ b/frontend/src/components/Style.css @@ -40,7 +40,7 @@ li.clickableUserDetails:hover { } .adminPageContent { - margin-left: 21%; + margin-left: 18%; margin-right: 1%; } diff --git a/frontend/src/components/admin/userManagement/UserAddModify.js b/frontend/src/components/admin/userManagement/UserAddModify.js index 3535aef10b..e3e9ab0b17 100644 --- a/frontend/src/components/admin/userManagement/UserAddModify.js +++ b/frontend/src/components/admin/userManagement/UserAddModify.js @@ -56,6 +56,14 @@ function UserAddModify() { const intl = useIntl(); const [saveButton, setSaveButton] = useState(true); + const [validation, setValidation] = useState({ + validatepassword: false, + password: false, + password2: false, + loginName: false, + firstName: false, + secondName: false, + }); const [isLoading, setIsLoading] = useState(true); const [isLocked, setIsLocked] = useState("radio-2"); const [isDisabled, setIsDisabled] = useState("radio-4"); @@ -110,6 +118,14 @@ function UserAddModify() { setIsLoading(true); } else { setUserData(res); + setValidation({ + validatepassword: true, + password: true, + password2: true, + loginName: true, + firstName: true, + secondName: true, + }); var KeyList = []; Object.keys(res.selectedTestSectionLabUnits).map((key) => KeyList.push(key), @@ -277,6 +293,14 @@ function UserAddModify() { userDataShow.accountDisabled === "Y" ? "radio-3" : "radio-4", ); setIsActive(userDataShow.accountActive === "Y" ? "radio-5" : "radio-6"); + if ( + userDataShow.userPassword && + userDataShow.userPassword === userDataShow.confirmPassword + ) { + setValidation({ ...validation, validatepassword: true }); + } else { + setValidation({ ...validation, validatepassword: false }); + } } }, [userDataShow]); @@ -365,9 +389,11 @@ function UserAddModify() { }); } setSaveButton(true); + setValidation({ ...validation, loginName: false }); } else { setNotificationVisible(false); setSaveButton(false); + setValidation({ ...validation, loginName: true }); setUserDataPost((prevUserDataPost) => ({ ...prevUserDataPost, userLoginName: value, @@ -400,9 +426,11 @@ function UserAddModify() { }); } setSaveButton(true); + setValidation({ ...validation, password: false }); } else { setNotificationVisible(false); setSaveButton(false); + setValidation({ ...validation, password: true }); setUserDataPost((prevUserDataPost) => ({ ...prevUserDataPost, userPassword: value, @@ -435,9 +463,11 @@ function UserAddModify() { }); } setSaveButton(true); + setValidation({ ...validation, password2: false }); } else { setNotificationVisible(false); setSaveButton(false); + setValidation({ ...validation, password2: true }); setUserDataPost((prevUserDataPost) => ({ ...prevUserDataPost, confirmPassword: value, @@ -466,9 +496,11 @@ function UserAddModify() { }); } setSaveButton(true); + setValidation({ ...validation, firstName: false }); } else { setNotificationVisible(false); setSaveButton(false); + setValidation({ ...validation, firstName: true }); setUserDataPost((prevUserDataPost) => ({ ...prevUserDataPost, userFirstName: value, @@ -497,6 +529,7 @@ function UserAddModify() { }); } setSaveButton(true); + setValidation({ ...validation, secondName: false }); } else { setNotificationVisible(false); setUserDataPost((prevUserDataPost) => ({ @@ -504,6 +537,7 @@ function UserAddModify() { userLastName: value, })); setSaveButton(false); + setValidation({ ...validation, secondName: true }); } setUserDataShow((prevUserData) => ({ @@ -514,6 +548,7 @@ function UserAddModify() { function handleExpirationDateChange(e) { setSaveButton(false); + setValidation({ ...validation, expDate: true }); setUserDataPost((prevUserDataPost) => ({ ...prevUserDataPost, expirationDate: e.target.value, @@ -526,6 +561,7 @@ function UserAddModify() { function handleTimeoutChange(e) { setSaveButton(false); + setValidation({ ...validation, timeout: true }); setUserDataPost((prevUserDataPost) => ({ ...prevUserDataPost, timeout: e.target.value, @@ -538,6 +574,7 @@ function UserAddModify() { function handleAccountActiveChange(e) { setSaveButton(false); + setValidation({ ...validation, active: true }); setUserDataPost((prevUserDataPost) => ({ ...prevUserDataPost, accountActive: e.target.value, @@ -550,6 +587,7 @@ function UserAddModify() { function handleAccountDisabledChange(e) { setSaveButton(false); + setValidation({ ...validation, disabled: true }); setUserDataPost((prevUserDataPost) => ({ ...prevUserDataPost, accountDisabled: e.target.value, @@ -562,6 +600,7 @@ function UserAddModify() { function handleAccountLockedChange(e) { setSaveButton(false); + setValidation({ ...validation, locked: true }); setUserDataPost((prevUserDataPost) => ({ ...prevUserDataPost, accountLocked: e.target.value, @@ -575,12 +614,14 @@ function UserAddModify() { function handleCopyUserPermissionsChange() { if (copyUserPermission.length > 0) { setSaveButton(false); + setValidation({ ...validation, copy: true }); } } function handleAutoCompleteCopyUserPermissionsChange(selectedUserId) { setCopyUserPermission(selectedUserId); setSaveButton(false); + setValidation({ ...validation, autoCopy: true }); } function handleCopyUserPermissionsChangeClick() { @@ -625,6 +666,7 @@ function UserAddModify() { selectedRoles: updatedRoles, })); setSaveButton(false); + setValidation({ ...validation, checkBox: true }); } function handleTestSectionsSelectChange(e, key) { @@ -658,6 +700,7 @@ function UserAddModify() { setSelectedTestSectionLabUnits(updatedTestSectionLabUnits); setSaveButton(false); + setValidation({ ...validation, testSection: true }); } const addRoleToSelectedUnits = (key, roleIdToAdd) => { @@ -667,6 +710,7 @@ function UserAddModify() { if (!currentRoles.includes(roleIdToAdd)) { updatedUnits[key] = [...currentRoles, roleIdToAdd]; setSaveButton(false); + setValidation({ ...validation, role: true }); } return updatedUnits; }); @@ -680,6 +724,7 @@ function UserAddModify() { (roleId) => roleId !== roleIdToRemove, ); setSaveButton(false); + setValidation({ ...validation, removeSelected: true }); } return updatedUnits; }); @@ -1295,6 +1340,7 @@ function UserAddModify() { [key]: updatedRoles, })); setSaveButton(false); + setValidation({ ...validation, selectedLab: true }); }} />