Skip to content

Commit

Permalink
checks for username and username in card overflow fix (#8940)
Browse files Browse the repository at this point in the history
  • Loading branch information
SwanandBhuskute authored Nov 6, 2024
1 parent 4f775ad commit 1e45600
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 22 deletions.
6 changes: 5 additions & 1 deletion src/components/ABDM/LinkAbhaNumber/CreateWithAadhaar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)}
</div>

Expand Down
6 changes: 6 additions & 0 deletions src/components/Auth/ResetPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)}
</div>
)}
Expand All @@ -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,
)}
</div>
<div className="grid p-4 sm:flex sm:justify-between">
Expand Down
4 changes: 3 additions & 1 deletion src/components/Users/ManageUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
<div className="max-w-full break-words">
{formatName(user)}
</div>

{user.last_login && cur_online ? (
<div
Expand Down
22 changes: 20 additions & 2 deletions src/components/Users/UserAdd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,25 @@ const getDate = (value: any) =>
export const validateRule = (
condition: boolean,
content: JSX.Element | string,
isInitialState: boolean,
) => {
return (
<div>
{condition ? (
{isInitialState ? (
<CareIcon icon="l-circle" className="text-xl text-gray-500" />
) : condition ? (
<CareIcon icon="l-check-circle" className="text-xl text-green-500" />
) : (
<CareIcon icon="l-times-circle" className="text-xl text-red-500" />
)}{" "}
<span
className={classNames(condition ? "text-primary-500" : "text-red-500")}
className={classNames(
isInitialState
? "text-black"
: condition
? "text-primary-500"
: "text-red-500",
)}
>
{content}
</span>
Expand Down Expand Up @@ -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,
)}
</div>
<div>
{validateRule(
/^[a-z0-9._-]*$/.test(usernameInput),
"Username can only contain lowercase letters, numbers, and . _ -",
!state.form.username,
)}
</div>
<div>
{validateRule(
/^[a-z0-9].*[a-z0-9]$/i.test(usernameInput),
"Username must start and end with a letter or number",
!state.form.username,
)}
</div>
<div>
{validateRule(
!/(?:[._-]{2,})/.test(usernameInput),
"Username can't contain consecutive special characters . _ -",
!state.form.username,
)}
</div>
</div>
Expand Down Expand Up @@ -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,
)}
</div>
)}
Expand All @@ -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,
)}
</div>
<TextFormField
Expand Down
44 changes: 26 additions & 18 deletions src/components/Users/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,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 @@ -913,24 +937,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",
)}
{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)}
</div>
</div>
<div className="col-span-6 sm:col-span-3">
Expand All @@ -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,
)}
</div>
)}
Expand Down

0 comments on commit 1e45600

Please sign in to comment.