From 640bf5f606abfced5b439b197ecc69e8e1bdc0cc Mon Sep 17 00:00:00 2001 From: root Date: Mon, 28 Oct 2024 06:01:48 +0000 Subject: [PATCH 1/5] checks for username and username in card overflow fix --- .../ABDM/LinkAbhaNumber/CreateWithAadhaar.tsx | 4 ++++ src/components/Auth/ResetPassword.tsx | 5 +++++ src/components/Users/ManageUsers.tsx | 4 +++- src/components/Users/UserAdd.tsx | 22 +++++++++++++++++-- src/components/Users/UserProfile.tsx | 7 ++++-- 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/components/ABDM/LinkAbhaNumber/CreateWithAadhaar.tsx b/src/components/ABDM/LinkAbhaNumber/CreateWithAadhaar.tsx index dc2b5ff7ef6..df8f6600aa3 100644 --- a/src/components/ABDM/LinkAbhaNumber/CreateWithAadhaar.tsx +++ b/src/components/ABDM/LinkAbhaNumber/CreateWithAadhaar.tsx @@ -682,18 +682,22 @@ function ChooseAbhaAddress({ {validateRule( healthId.length >= 4, t("abha_address_validation_length_error"), + false, )} {validateRule( 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 15fc6cbac69..58c00157ed2 100644 --- a/src/components/Auth/ResetPassword.tsx +++ b/src/components/Auth/ResetPassword.tsx @@ -128,18 +128,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,6 +161,7 @@ export const ResetPassword = (props: any) => { validateRule( form.confirm === form.password, "Confirm password should match the entered password", + !form.password, )}
diff --git a/src/components/Users/ManageUsers.tsx b/src/components/Users/ManageUsers.tsx index 7dc3eb8b5fe..a7dd90f2878 100644 --- a/src/components/Users/ManageUsers.tsx +++ b/src/components/Users/ManageUsers.tsx @@ -238,7 +238,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} @@ -786,24 +795,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, )}
@@ -836,18 +849,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, )}
)} @@ -868,6 +885,7 @@ export const UserAdd = (props: UserProps) => { validateRule( state.form.c_password === state.form.password, "Confirm password should match the entered password", + !state.form.password, )} = 8, "Password should be atleast 8 characters long", + !changePasswordForm.new_password_1, )} {validateRule( changePasswordForm.new_password_1 !== changePasswordForm.new_password_1.toUpperCase(), "Password should contain at least 1 lowercase letter", + !changePasswordForm.new_password_1, )} {validateRule( changePasswordForm.new_password_1 !== changePasswordForm.new_password_1.toLowerCase(), "Password should contain at least 1 uppercase letter", + !changePasswordForm.new_password_1, )} {validateRule( /\d/.test(changePasswordForm.new_password_1), "Password should contain at least 1 number", + !changePasswordForm.new_password_1, )} @@ -945,6 +947,7 @@ export default function UserProfile() { changePasswordForm.new_password_1 === changePasswordForm.new_password_2, "Confirm password should match the new password", + !changePasswordForm.new_password_1, )} )} From a0c274c904cdd1af95db4b1ba225c464e5c1188a Mon Sep 17 00:00:00 2001 From: root Date: Mon, 28 Oct 2024 06:01:48 +0000 Subject: [PATCH 2/5] checks for username and username in card overflow fix --- .../ABDM/LinkAbhaNumber/CreateWithAadhaar.tsx | 4 ++++ src/components/Auth/ResetPassword.tsx | 5 +++++ src/components/Users/ManageUsers.tsx | 4 +++- src/components/Users/UserAdd.tsx | 22 +++++++++++++++++-- src/components/Users/UserProfile.tsx | 7 ++++-- 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/components/ABDM/LinkAbhaNumber/CreateWithAadhaar.tsx b/src/components/ABDM/LinkAbhaNumber/CreateWithAadhaar.tsx index dc2b5ff7ef6..df8f6600aa3 100644 --- a/src/components/ABDM/LinkAbhaNumber/CreateWithAadhaar.tsx +++ b/src/components/ABDM/LinkAbhaNumber/CreateWithAadhaar.tsx @@ -682,18 +682,22 @@ function ChooseAbhaAddress({ {validateRule( healthId.length >= 4, t("abha_address_validation_length_error"), + false, )} {validateRule( 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 15fc6cbac69..58c00157ed2 100644 --- a/src/components/Auth/ResetPassword.tsx +++ b/src/components/Auth/ResetPassword.tsx @@ -128,18 +128,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,6 +161,7 @@ export const ResetPassword = (props: any) => { validateRule( form.confirm === form.password, "Confirm password should match the entered password", + !form.password, )}
diff --git a/src/components/Users/ManageUsers.tsx b/src/components/Users/ManageUsers.tsx index 6860a52f236..00ccafdd4fb 100644 --- a/src/components/Users/ManageUsers.tsx +++ b/src/components/Users/ManageUsers.tsx @@ -246,7 +246,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} @@ -786,24 +795,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, )}
@@ -835,18 +848,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, )}
)} @@ -867,6 +884,7 @@ export const UserAdd = (props: UserProps) => { validateRule( state.form.c_password === state.form.password, "Confirm password should match the entered password", + !state.form.password, )} = 8, "Password should be atleast 8 characters long", + !changePasswordForm.new_password_1, )} {validateRule( changePasswordForm.new_password_1 !== changePasswordForm.new_password_1.toUpperCase(), "Password should contain at least 1 lowercase letter", + !changePasswordForm.new_password_1, )} {validateRule( changePasswordForm.new_password_1 !== changePasswordForm.new_password_1.toLowerCase(), "Password should contain at least 1 uppercase letter", + !changePasswordForm.new_password_1, )} {validateRule( /\d/.test(changePasswordForm.new_password_1), "Password should contain at least 1 number", + !changePasswordForm.new_password_1, )} @@ -944,6 +946,7 @@ export default function UserProfile() { changePasswordForm.new_password_1 === changePasswordForm.new_password_2, "Confirm password should match the new password", + !changePasswordForm.new_password_1, )} )} From fef7d70a4619db3198040555b12be431937ee0d8 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 28 Oct 2024 19:54:08 +0000 Subject: [PATCH 3/5] commits error, changes not reflecting solved --- src/components/Users/UserProfile.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/Users/UserProfile.tsx b/src/components/Users/UserProfile.tsx index c7e58a07609..b6a583cb112 100644 --- a/src/components/Users/UserProfile.tsx +++ b/src/components/Users/UserProfile.tsx @@ -494,6 +494,8 @@ export default function UserProfile() { refetchUser(); Notification.Success({ msg: "Profile picture updated." }); setEditAvatar(false); + } else { + onError(); } }, null, From c101bea4434bcdf1560a29311c1adef710d3a884 Mon Sep 17 00:00:00 2001 From: SwanandBhuskute Date: Tue, 5 Nov 2024 18:27:33 +0000 Subject: [PATCH 4/5] some coderabbitai suggestions applied --- .../ABDM/LinkAbhaNumber/CreateWithAadhaar.tsx | 2 +- src/components/Auth/ResetPassword.tsx | 3 +- src/components/Users/UserProfile.tsx | 50 ++++++++++--------- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/components/ABDM/LinkAbhaNumber/CreateWithAadhaar.tsx b/src/components/ABDM/LinkAbhaNumber/CreateWithAadhaar.tsx index df8f6600aa3..7fdbcad76af 100644 --- a/src/components/ABDM/LinkAbhaNumber/CreateWithAadhaar.tsx +++ b/src/components/ABDM/LinkAbhaNumber/CreateWithAadhaar.tsx @@ -685,7 +685,7 @@ function ChooseAbhaAddress({ false, )} {validateRule( - isNaN(Number(healthId[0])) && healthId[0] !== ".", + Number.isNaN(Number(healthId[0])) && healthId[0] !== ".", t("abha_address_validation_start_error"), false, )} diff --git a/src/components/Auth/ResetPassword.tsx b/src/components/Auth/ResetPassword.tsx index 58c00157ed2..72642fbce38 100644 --- a/src/components/Auth/ResetPassword.tsx +++ b/src/components/Auth/ResetPassword.tsx @@ -158,10 +158,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 && form.password.length > 0, )}
diff --git a/src/components/Users/UserProfile.tsx b/src/components/Users/UserProfile.tsx index b6a583cb112..439aae81664 100644 --- a/src/components/Users/UserProfile.tsx +++ b/src/components/Users/UserProfile.tsx @@ -193,6 +193,30 @@ export default function UserProfile() { }, ); + const validatePassword = (password: string) => { + 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 || @@ -904,28 +928,7 @@ export default function UserProfile() { required />
- {validateRule( - changePasswordForm.new_password_1?.length >= 8, - "Password should be atleast 8 characters long", - !changePasswordForm.new_password_1, - )} - {validateRule( - changePasswordForm.new_password_1 !== - changePasswordForm.new_password_1.toUpperCase(), - "Password should contain at least 1 lowercase letter", - !changePasswordForm.new_password_1, - )} - {validateRule( - changePasswordForm.new_password_1 !== - changePasswordForm.new_password_1.toLowerCase(), - "Password should contain at least 1 uppercase letter", - !changePasswordForm.new_password_1, - )} - {validateRule( - /\d/.test(changePasswordForm.new_password_1), - "Password should contain at least 1 number", - !changePasswordForm.new_password_1, - )} + {validatePassword(changePasswordForm.new_password_1)}
@@ -948,7 +951,8 @@ export default function UserProfile() { changePasswordForm.new_password_1 === changePasswordForm.new_password_2, "Confirm password should match the new password", - !changePasswordForm.new_password_1, + !changePasswordForm.new_password_1 && + changePasswordForm.new_password_1.length > 0, )}
)} From 14d145c043d688b467ae4479241c7e463d88ecb4 Mon Sep 17 00:00:00 2001 From: SwanandBhuskute Date: Tue, 5 Nov 2024 18:48:28 +0000 Subject: [PATCH 5/5] changed new_password_1 to new_password_2 --- src/components/Users/UserProfile.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/Users/UserProfile.tsx b/src/components/Users/UserProfile.tsx index 439aae81664..18a06dbdc10 100644 --- a/src/components/Users/UserProfile.tsx +++ b/src/components/Users/UserProfile.tsx @@ -951,8 +951,7 @@ export default function UserProfile() { changePasswordForm.new_password_1 === changePasswordForm.new_password_2, "Confirm password should match the new password", - !changePasswordForm.new_password_1 && - changePasswordForm.new_password_1.length > 0, + !changePasswordForm.new_password_2, )} )}