diff --git a/src/components/ABDM/LinkAbhaNumber/CreateWithAadhaar.tsx b/src/components/ABDM/LinkAbhaNumber/CreateWithAadhaar.tsx
index ce34b026fe..d2697633be 100644
--- a/src/components/ABDM/LinkAbhaNumber/CreateWithAadhaar.tsx
+++ b/src/components/ABDM/LinkAbhaNumber/CreateWithAadhaar.tsx
@@ -684,18 +684,22 @@ function ChooseAbhaAddress({
{validateRule(
healthId.length >= 4,
t("abha_address_validation_length_error"),
+ false,
)}
{validateRule(
- isNaN(Number(healthId[0])) && healthId[0] !== ".",
+ Number.isNaN(Number(healthId[0])) && healthId[0] !== ".",
t("abha_address_validation_start_error"),
+ false,
)}
{validateRule(
healthId[healthId.length - 1] !== ".",
t("abha_address_validation_end_error"),
+ false,
)}
{validateRule(
/^[0-9a-zA-Z._]+$/.test(healthId),
t("abha_address_validation_character_error"),
+ false,
)}
diff --git a/src/components/Auth/ResetPassword.tsx b/src/components/Auth/ResetPassword.tsx
index 3c24295295..793beb1699 100644
--- a/src/components/Auth/ResetPassword.tsx
+++ b/src/components/Auth/ResetPassword.tsx
@@ -131,18 +131,22 @@ export const ResetPassword = (props: any) => {
{validateRule(
form.password?.length >= 8,
"Password should be atleast 8 characters long",
+ !form.password,
)}
{validateRule(
form.password !== form.password.toUpperCase(),
"Password should contain at least 1 lowercase letter",
+ !form.password,
)}
{validateRule(
form.password !== form.password.toLowerCase(),
"Password should contain at least 1 uppercase letter",
+ !form.password,
)}
{validateRule(
/\d/.test(form.password),
"Password should contain at least 1 number",
+ !form.password,
)}
)}
@@ -157,9 +161,11 @@ export const ResetPassword = (props: any) => {
/>
{confirmPasswordInputInFocus &&
form.confirm.length > 0 &&
+ form.password.length > 0 &&
validateRule(
form.confirm === form.password,
"Confirm password should match the entered password",
+ !form.password && form.password.length > 0,
)}
diff --git a/src/components/Users/ManageUsers.tsx b/src/components/Users/ManageUsers.tsx
index 93eeda6be9..0b6a9149db 100644
--- a/src/components/Users/ManageUsers.tsx
+++ b/src/components/Users/ManageUsers.tsx
@@ -252,7 +252,9 @@ export default function ManageUsers() {
id="name"
className="mt-2 flex items-center gap-3 text-2xl font-bold capitalize"
>
- {formatName(user)}
+
+ {formatName(user)}
+
{user.last_login && cur_online ? (
export const validateRule = (
condition: boolean,
content: JSX.Element | string,
+ isInitialState: boolean,
) => {
return (
- {condition ? (
+ {isInitialState ? (
+
+ ) : condition ? (
) : (
)}{" "}
{content}
@@ -791,24 +800,28 @@ export const UserAdd = (props: UserProps) => {
{validateRule(
usernameInput.length >= 4 && usernameInput.length <= 16,
"Username should be 4-16 characters long",
+ !state.form.username,
)}
{validateRule(
/^[a-z0-9._-]*$/.test(usernameInput),
"Username can only contain lowercase letters, numbers, and . _ -",
+ !state.form.username,
)}
{validateRule(
/^[a-z0-9].*[a-z0-9]$/i.test(usernameInput),
"Username must start and end with a letter or number",
+ !state.form.username,
)}
{validateRule(
!/(?:[._-]{2,})/.test(usernameInput),
"Username can't contain consecutive special characters . _ -",
+ !state.form.username,
)}
@@ -840,18 +853,22 @@ export const UserAdd = (props: UserProps) => {
{validateRule(
state.form.password?.length >= 8,
"Password should be atleast 8 characters long",
+ !state.form.password,
)}
{validateRule(
state.form.password !== state.form.password.toUpperCase(),
"Password should contain at least 1 lowercase letter",
+ !state.form.password,
)}
{validateRule(
state.form.password !== state.form.password.toLowerCase(),
"Password should contain at least 1 uppercase letter",
+ !state.form.password,
)}
{validateRule(
/\d/.test(state.form.password),
"Password should contain at least 1 number",
+ !state.form.password,
)}
)}
@@ -872,6 +889,7 @@ export const UserAdd = (props: UserProps) => {
validateRule(
state.form.c_password === state.form.password,
"Confirm password should match the entered password",
+ !state.form.password,
)}
{
+ const rules = [
+ {
+ test: (p: string) => p.length >= 8,
+ message: "Password should be at least 8 characters long",
+ },
+ {
+ test: (p: string) => p !== p.toUpperCase(),
+ message: "Password should contain at least 1 lowercase letter",
+ },
+ {
+ test: (p: string) => p !== p.toLowerCase(),
+ message: "Password should contain at least 1 uppercase letter",
+ },
+ {
+ test: (p: string) => /\d/.test(p),
+ message: "Password should contain at least 1 number",
+ },
+ ];
+ return rules.map((rule) =>
+ validateRule(rule.test(password), rule.message, !password),
+ );
+ };
+
const validateNewPassword = (password: string) => {
if (
password.length < 8 ||
@@ -913,24 +937,7 @@ export default function UserProfile() {
required
/>
- {validateRule(
- changePasswordForm.new_password_1?.length >= 8,
- "Password should be atleast 8 characters long",
- )}
- {validateRule(
- changePasswordForm.new_password_1 !==
- changePasswordForm.new_password_1.toUpperCase(),
- "Password should contain at least 1 lowercase letter",
- )}
- {validateRule(
- changePasswordForm.new_password_1 !==
- changePasswordForm.new_password_1.toLowerCase(),
- "Password should contain at least 1 uppercase letter",
- )}
- {validateRule(
- /\d/.test(changePasswordForm.new_password_1),
- "Password should contain at least 1 number",
- )}
+ {validatePassword(changePasswordForm.new_password_1)}
@@ -953,6 +960,7 @@ export default function UserProfile() {
changePasswordForm.new_password_1 ===
changePasswordForm.new_password_2,
"Confirm password should match the new password",
+ !changePasswordForm.new_password_2,
)}
)}