mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-01-20 00:29:45 -06:00
- update validation for advanced settings page black list some unused fields which causing errors
37 lines
848 B
JavaScript
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 }; |