diff --git a/src/Components/Common/OnlineUsersSelect.tsx b/src/Components/Common/OnlineUsersSelect.tsx index c7cdf28ffe3..ca977adf0f4 100644 --- a/src/Components/Common/OnlineUsersSelect.tsx +++ b/src/Components/Common/OnlineUsersSelect.tsx @@ -200,9 +200,11 @@ export const OnlineUsersSelect = (props: Props) => { > {user.first_name} {user.last_name}{" "} - {user.home_facility_object?.name && - {user.home_facility_object?.name} - } + {user.home_facility_object?.name && ( + + {user.home_facility_object?.name} + + )} {user.id?.toString() == userId && ( diff --git a/src/Components/Users/UserAdd.tsx b/src/Components/Users/UserAdd.tsx index 664412ca907..c76685c0aec 100644 --- a/src/Components/Users/UserAdd.tsx +++ b/src/Components/Users/UserAdd.tsx @@ -132,6 +132,9 @@ export const UserAdd = (props: UserProps) => { >([]); const [phoneIsWhatsApp, setPhoneIsWhatsApp] = useState(true); const [usernameInputInFocus, setUsernameInputInFocus] = useState(false); + const [passwordInputInFocus, setPasswordInputInFocus] = useState(false); + const [confirmPasswordInputInFocus, setConfirmPasswordInputInFocus] = + useState(false); const [usernameInput, setUsernameInput] = useState(""); const userExistsEnums = { @@ -422,7 +425,7 @@ export const UserAdd = (props: UserProps) => { return; case "c_password": if (!state.form.password) { - errors.password = "Confirm password is required"; + errors.c_password = "Confirm password is required"; invalidForm = true; } else if (state.form.password !== state.form.c_password) { errors.c_password = "Passwords not matching"; @@ -507,6 +510,21 @@ export const UserAdd = (props: UserProps) => { return true; }; + const validateRule = (valid: boolean, content: JSX.Element | string) => { + return ( +
+ {valid ? ( + + ) : ( + + )}{" "} + + {content} + +
+ ); + }; + const handleSubmit = async (e: any) => { e.preventDefault(); const validated = validateForm(); @@ -691,57 +709,28 @@ export const UserAdd = (props: UserProps) => { checking... - ) : usernameExists === userExistsEnums.exists ? ( - - {" "} - User already exists - ) : ( - usernameExists === userExistsEnums.avaliable && ( - - {" "} - Available! - + validateRule( + usernameExists === userExistsEnums.exists, + "Username should not be taken" ) )} )}
- {state.form.username?.length < 2 ? ( - - ) : ( - - )}{" "} - - Username should be atleast 2 characters long - + {validateRule( + state.form.username?.length < 2, + "Username should be atleast 2 characters long" + )}
- {!/[^.@+_-]/.test( - state.form.username[state.form.username?.length - 1] - ) ? ( - - ) : ( - - )}{" "} - - Username can't end with ^ . @ + _ - - + {validateRule( + !/[^.@+_-]/.test( + state.form.username[state.form.username?.length - 1] + ), + "Username can't end with ^ . @ + _ -" + )}
)} @@ -774,9 +763,30 @@ export const UserAdd = (props: UserProps) => { value={state.form.password} onChange={handleChange} errors={state.errors.password} + onFocus={() => setPasswordInputInFocus(true)} + onBlur={() => setPasswordInputInFocus(false)} /> + {passwordInputInFocus && ( +
+ {validateRule( + state.form.password?.length < 8, + "Password should be atleast 8 characters long" + )} + {validateRule( + state.form.password === state.form.password.toUpperCase(), + "Password should contain at least 1 lowercase letter" + )} + {validateRule( + state.form.password === state.form.password.toLowerCase(), + "Password should contain at least 1 uppercase letter" + )} + {validateRule( + !/\d/.test(state.form.password), + "Password should contain at least 1 number" + )} +
+ )} -
Confirm Password* { value={state.form.c_password} onChange={handleChange} errors={state.errors.c_password} + onFocus={() => setConfirmPasswordInputInFocus(true)} + onBlur={() => setConfirmPasswordInputInFocus(false)} /> + {confirmPasswordInputInFocus && + state.form.c_password.length > 0 && + validateRule( + state.form.c_password !== state.form.password, + "Confirm password should match the entered password" + )}
-
First name*