Files
Checkmate/Client/src/Validation/error.js
Shemy Gan 57edff36c9 - handle form save for jwtTTL
- update validation for advanced settings page black list some unused fields which causing errors
2024-10-24 11:31:10 -04:00

37 lines
848 B
JavaScript

const buildErrors = (prev, id, error) => {
const updatedErrors = { ...prev };
if (error) {
updatedErrors[id] = error.details[0].message?? "Validation error";
} else {
delete updatedErrors[id];
}
return updatedErrors;
};
const hasValidationErrors = (form, validation, setErrors) => {
const { error } = validation.validate(form, {
abortEarly: false,
});
if (error) {
const newErrors = {};
error.details.forEach((err) => {
if (
![
"clientHost",
"refreshTokenSecret",
"dbConnectionString",
"refreshTokenTTL",
"jwtTTL",
].includes(err.path[0])
) {
newErrors[err.path[0]] = err.message ?? "Validation error";
}
});
if (Object.keys(newErrors).length > 0) {
setErrors(newErrors);
return true;
} else return false;
}
return false;
};
export { buildErrors, hasValidationErrors };