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 committed 2024-10-26 19:20:53 -04:00
1 parent 3a19920298
commit ea4284a363
2 files changed
+24 -2

No files matched your search

+2
View File
@@ -11,3 +11,5 @@
- [x] Must contain at least one lower character - [x] Must contain at least one lower character
- [x] Pass mismatching password user feedback as the other messages, for consistency - [x] Pass mismatching password user feedback as the other messages, for consistency
- [ ] Get rid of toast message - [ ] 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) => { const handleChange = (event) => {
//update form state
const { value, name } = event.target; const { value, name } = event.target;
setForm((prev) => ({ ...prev, [name]: value })); setForm((prev) => ({ ...prev, [name]: value }));
//validate
const validateValue = { [name]: value }; const validateValue = { [name]: value };
const validateOptions = { abortEarly: false, context: { password: form.password } }; 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 { error } = credentials.validate(validateValue, validateOptions);
const errors = error?.details.map((error) => error.message); //update errors
setErrors((prev) => ({ ...prev, [name]: 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) => { const getFeedbackStatus = (field, criteria) => {