Skip to content

Commit

Permalink
Merge pull request I-TECH-UW#1192 from adityadeshlahre/fix-user-manag…
Browse files Browse the repository at this point in the history
…ement-hot-fix

fix(userManagementValidation): minnor hot fix on userNanagment disable inital validation
  • Loading branch information
mozzy11 authored Jul 19, 2024
2 parents 296287d + 501b75d commit 2b80571
Showing 1 changed file with 45 additions and 26 deletions.
71 changes: 45 additions & 26 deletions frontend/src/components/admin/userManagement/UserAddModify.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ function UserAddModify() {
const [selectedTestSectionLabUnits, setSelectedTestSectionLabUnits] =
useState({});
const [selectedTestSectionList, setSelectedTestSectionList] = useState([]);
const [passwordTouched, setPasswordTouched] = useState({
userPassword: false,
confirmPassword: false,
});

const ID = (() => {
const hash = window.location.hash;
Expand Down Expand Up @@ -348,7 +352,6 @@ function UserAddModify() {
}

function handleUserLoginNameChange(e) {
setSaveButton(false);
const value = e.target.value.trim();
const isValid = loginNameRegex.test(value);

Expand All @@ -363,22 +366,27 @@ function UserAddModify() {
kind: NotificationKinds.info,
});
}
setSaveButton(true);
} else {
setNotificationVisible(false);
setSaveButton(false);
setUserDataPost((prevUserDataPost) => ({
...prevUserDataPost,
userLoginName: value,
}));
}

setUserDataPost((prevUserDataPost) => ({
...prevUserDataPost,
userLoginName: value,
}));
setUserDataShow((prevUserData) => ({
...prevUserData,
userLoginName: value,
}));
}

function handleUserPasswordChange(e) {
setSaveButton(false);
setPasswordTouched((prev) => ({
...prev,
userPassword: true,
}));
const value = e.target.value.trim();
const isValid = passwordPatternRegex.test(value);

Expand All @@ -393,24 +401,29 @@ function UserAddModify() {
kind: NotificationKinds.info,
});
}
setSaveButton(true);
} else {
setNotificationVisible(false);
setSaveButton(false);
setUserDataPost((prevUserDataPost) => ({
...prevUserDataPost,
userPassword: value,
}));
}

setUserDataPost((prevUserDataPost) => ({
...prevUserDataPost,
userPassword: value,
}));
setUserDataShow((prevUserData) => ({
...prevUserData,
userPassword: value,
}));
}

function handleConfirmPasswordChange(e) {
setPasswordTouched((prev) => ({
...prev,
confirmPassword: true,
}));
const value = e.target.value.trim();
const isValid = passwordPatternRegex.test(value);
setSaveButton(false);

if (value && !isValid) {
if (!notificationVisible) {
Expand All @@ -423,14 +436,16 @@ function UserAddModify() {
kind: NotificationKinds.info,
});
}
setSaveButton(true);
} else {
setNotificationVisible(false);
setSaveButton(false);
setUserDataPost((prevUserDataPost) => ({
...prevUserDataPost,
confirmPassword: value,
}));
}

setUserDataPost((prevUserDataPost) => ({
...prevUserDataPost,
confirmPassword: value,
}));
setUserDataShow((prevUserData) => ({
...prevUserData,
confirmPassword: value,
Expand All @@ -440,7 +455,6 @@ function UserAddModify() {
function handleUserFirstNameChange(e) {
const value = e.target.value;
const isValid = nameRegex.test(value);
setSaveButton(false);

if (value && !isValid) {
if (!notificationVisible) {
Expand All @@ -453,14 +467,16 @@ function UserAddModify() {
kind: NotificationKinds.info,
});
}
setSaveButton(true);
} else {
setNotificationVisible(false);
setSaveButton(false);
setUserDataPost((prevUserDataPost) => ({
...prevUserDataPost,
userFirstName: value,
}));
}

setUserDataPost((prevUserDataPost) => ({
...prevUserDataPost,
userFirstName: value,
}));
setUserDataShow((prevUserData) => ({
...prevUserData,
userFirstName: value,
Expand All @@ -470,7 +486,6 @@ function UserAddModify() {
function handleUserLastNameChange(e) {
const value = e.target.value;
const isValid = nameRegex.test(value);
setSaveButton(false);

if (value && !isValid) {
if (!notificationVisible) {
Expand All @@ -483,14 +498,16 @@ function UserAddModify() {
kind: NotificationKinds.info,
});
}
setSaveButton(true);
} else {
setNotificationVisible(false);
setUserDataPost((prevUserDataPost) => ({
...prevUserDataPost,
userLastName: value,
}));
setSaveButton(false);
}

setUserDataPost((prevUserDataPost) => ({
...prevUserDataPost,
userLastName: value,
}));
setUserDataShow((prevUserData) => ({
...prevUserData,
userLastName: value,
Expand Down Expand Up @@ -813,6 +830,7 @@ function UserAddModify() {
})}
required={true}
invalid={
passwordTouched.userPassword &&
userDataShow &&
userDataShow.userPassword &&
!passwordPatternRegex.test(userDataShow.userPassword)
Expand Down Expand Up @@ -845,7 +863,8 @@ function UserAddModify() {
})}
required={true}
invalid={
(userDataShow &&
(passwordTouched.confirmPassword &&
userDataShow &&
userDataShow.userPassword &&
userDataShow.confirmPassword &&
!passwordPatternRegex.test(
Expand Down

0 comments on commit 2b80571

Please sign in to comment.