feat: Check for confirm password if password changes and confirm is filled, and they do not match anymore

This commit is contained in:
Caio Cabral
2024-10-26 19:20:53 -04:00
parent 3a19920298
commit ea4284a363
2 changed files with 24 additions and 2 deletions
+2
View File
@@ -11,3 +11,5 @@
- [x] Must contain at least one lower character
- [x] Pass mismatching password user feedback as the other messages, for consistency
- [ ] Get rid of toast message
- [x] Check for confirm password if password changes and confirm is filled, and they do not match anymore
- [ ] Check for confirm password if password changes, and they now match
+22 -2
View File
@@ -79,15 +79,35 @@ const SetNewPassword = () => {
};
const handleChange = (event) => {
//update form state
const { value, name } = event.target;
setForm((prev) => ({ ...prev, [name]: value }));
//validate
const validateValue = { [name]: value };
const validateOptions = { abortEarly: false, context: { password: form.password } };
if (name === "password" && form.confirm.length > 0) {
validateValue.confirm = form.confirm;
validateOptions.context = value;
}
const { error } = credentials.validate(validateValue, validateOptions);
const errors = error?.details.map((error) => error.message);
setErrors((prev) => ({ ...prev, [name]: errors }));
//update errors
//fazer o map com path e message
const errors = error?.details.map((error) => ({
message: error.message,
path: error.path[0],
}));
const errorsByPath = errors
? errors.reduce((acc, { path, message }) => {
if (!acc[path]) {
acc[path] = [];
}
acc[path].push(message);
return acc;
}, {})
: { [name]: [] };
setErrors((prev) => ({ ...prev, ...errorsByPath }));
};
const getFeedbackStatus = (field, criteria) => {