Skip to content

Commit

Permalink
some coderabbitai suggestions applied
Browse files Browse the repository at this point in the history
  • Loading branch information
SwanandBhuskute committed Nov 5, 2024
1 parent 967ecff commit c101bea
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/components/ABDM/LinkAbhaNumber/CreateWithAadhaar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)}
Expand Down
3 changes: 2 additions & 1 deletion src/components/Auth/ResetPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)}
</div>
<div className="grid p-4 sm:flex sm:justify-between">
Expand Down
50 changes: 27 additions & 23 deletions src/components/Users/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down Expand Up @@ -904,28 +928,7 @@ export default function UserProfile() {
required
/>
<div className="text-small mb-2 hidden pl-2 text-secondary-500 peer-focus-within:block">
{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)}
</div>
</div>
<div className="col-span-6 sm:col-span-3">
Expand All @@ -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,
)}
</div>
)}
Expand Down

0 comments on commit c101bea

Please sign in to comment.