Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIXED] Improved the change password handling in profile edit page #7639

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f01f807
Improved the change password handling in profile edit page successfully
r-nikhilkumar Apr 16, 2024
6dd23bc
lint checks
r-nikhilkumar Apr 16, 2024
9dbbb91
lint checks
r-nikhilkumar Apr 16, 2024
e94ee50
done
r-nikhilkumar Apr 16, 2024
c5c7836
Merge branch 'coronasafe:develop' into Fixes#7605_Improve_change_pass…
r-nikhilkumar Apr 16, 2024
71a5f85
lint error solved
r-nikhilkumar Apr 16, 2024
fd5b5a0
change request done
r-nikhilkumar Apr 22, 2024
224ee4b
Merge branch 'coronasafe:develop' into Fixes#7605_Improve_change_pass…
r-nikhilkumar Apr 22, 2024
c8e8a1b
change req done
r-nikhilkumar Apr 24, 2024
caf3126
Merge branch 'Fixes#7605_Improve_change_password_handling' of https:/…
r-nikhilkumar Apr 24, 2024
018b56c
Update src/Components/Users/UserProfile.tsx
r-nikhilkumar Apr 24, 2024
05e9ec8
Merge branch 'develop' into Fixes#7605_Improve_change_password_handling
r-nikhilkumar Apr 24, 2024
6cac1fd
Merge branch 'develop' into Fixes#7605_Improve_change_password_handling
r-nikhilkumar Apr 26, 2024
e81920c
cypress test updated
r-nikhilkumar Apr 26, 2024
acd203d
removed precondition check to resolve spacing issue occured
r-nikhilkumar Apr 27, 2024
ddfd72b
change request | test failed done
r-nikhilkumar Apr 30, 2024
9635f85
done
r-nikhilkumar Apr 30, 2024
ae62231
Merge branch 'develop' into Fixes#7605_Improve_change_password_handling
r-nikhilkumar Apr 30, 2024
c540d1d
Merge branch 'coronasafe:develop' into Fixes#7605_Improve_change_pass…
r-nikhilkumar May 8, 2024
2afada7
onfocus onblur property controlled by css now, usestate removed for that
r-nikhilkumar May 8, 2024
0794468
Merge branch 'develop' into Fixes#7605_Improve_change_password_handling
r-nikhilkumar May 8, 2024
3c21073
Merge branch 'develop' into Fixes#7605_Improve_change_password_handling
r-nikhilkumar May 8, 2024
72fd3c2
minor type fix
khavinshankar May 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Components/Form/FormFields/FormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,19 @@ const FormField = ({
)}
</div>
<div className={field?.className}>{children}</div>
<FieldErrorText error={field?.error} className={field?.errorClassName} />
{field?.error && field?.error?.split("\n").length > 1 ? (
r-nikhilkumar marked this conversation as resolved.
Show resolved Hide resolved
field?.error?.split("\n").map((err) => (
<div key={err.length}>
<FieldErrorText error={err} className={field?.errorClassName} />
<br />
</div>
r-nikhilkumar marked this conversation as resolved.
Show resolved Hide resolved
))
) : (
<FieldErrorText
error={field?.error}
className={field?.errorClassName}
/>
)}
r-nikhilkumar marked this conversation as resolved.
Show resolved Hide resolved
</div>
);
};
Expand Down
80 changes: 68 additions & 12 deletions src/Components/Users/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,16 @@ export default function UserProfile() {
new_password_2: "",
});

const [changePasswordErrors] = useState<{
const [changePasswordErrors, setChangePasswordErrors] = useState<{
old_password: string;
password_confirmation: string;
}>({
old_password: "",
password_confirmation: "",
});

const [newPasswordError, setNewPasswordError] = useState<string>("");

const [showEdit, setShowEdit] = useState<boolean | false>(false);
khavinshankar marked this conversation as resolved.
Show resolved Hide resolved

const {
Expand Down Expand Up @@ -181,6 +183,45 @@ export default function UserProfile() {
},
);

const setNewPasswordErrorCallFun = (value: string) => {
if (value == "") {
setNewPasswordError("");
return;
}
setNewPasswordError(
[
value.length >= 8
? ""
: "Password should be at least 8 characters long",
value !== value.toUpperCase()
? ""
: "Password should contain at least 1 lowercase letter",
value !== value.toLowerCase()
? ""
: "Password should contain at least 1 uppercase letter",
/\d/.test(value) ? "" : "Password should contain at least 1 number",
]
.filter(Boolean)
.join("\n"), // Join only the non-empty error messages
);
};

const changePasswordErrorsCallFun = (value: string) => {
if (value === "" || value === changePasswordForm.new_password_1) {
setChangePasswordErrors((prev) => ({
...prev,
password_confirmation: "",
}));
return;
} else {
setChangePasswordErrors((prev) => ({
...prev,
password_confirmation:
"Confirm password should match the new password!",
}));
}
};

r-nikhilkumar marked this conversation as resolved.
Show resolved Hide resolved
const validateForm = () => {
const errors = { ...initError };
let invalidForm = false;
Expand Down Expand Up @@ -400,25 +441,38 @@ export default function UserProfile() {
e.preventDefault();
//validating form
if (
changePasswordForm.new_password_1 != changePasswordForm.new_password_2
changePasswordForm.new_password_1 !== changePasswordForm.new_password_2
) {
Notification.Error({
msg: "Passwords are different in new password and confirmation password column.",
});
} else if (
newPasswordError !== "" ||
changePasswordErrors.password_confirmation !== ""
) {
Notification.Error({
msg: "Passwords are different in the new and the confirmation column.",
msg: "Entered Password is not valid, please check!",
});
} else if (
changePasswordForm.new_password_1 === changePasswordForm.old_password
) {
Notification.Error({
msg: "New password is same as old password, Please enter a different new password.",
});
} else {
const form: UpdatePasswordForm = {
old_password: changePasswordForm.old_password,
username: authUser.username,
new_password: changePasswordForm.new_password_1,
};
const { res, data } = await request(routes.updatePassword, {
const { res, data, error } = await request(routes.updatePassword, {
body: form,
});
if (res?.ok && data?.message === "Password updated successfully") {
Notification.Success({
msg: "Password changed!",
});
r-nikhilkumar marked this conversation as resolved.
Show resolved Hide resolved
} else {
} else if (!error) {
Notification.Error({
msg: "There was some error. Please try again in some time.",
});
Expand Down Expand Up @@ -781,13 +835,14 @@ export default function UserProfile() {
type="password"
value={changePasswordForm.new_password_1}
className="col-span-6 sm:col-span-3"
onChange={(e) =>
onChange={(e) => {
setChangePasswordForm({
...changePasswordForm,
new_password_1: e.value,
})
}
error=""
});
setNewPasswordErrorCallFun(e.value);
}}
error={newPasswordError}
required
/>
<TextFormField
Expand All @@ -796,12 +851,13 @@ export default function UserProfile() {
className="col-span-6 sm:col-span-3"
type="password"
value={changePasswordForm.new_password_2}
onChange={(e) =>
onChange={(e) => {
setChangePasswordForm({
...changePasswordForm,
new_password_2: e.value,
})
}
});
changePasswordErrorsCallFun(e.value);
}}
error={changePasswordErrors.password_confirmation}
/>
</div>
Expand Down
Loading