feat(helper-plugin): getYupInnerErrors use yup params in error messaging

This commit is contained in:
Jamie Howard 2023-02-02 15:41:35 +00:00
parent 253ba050a7
commit e2d8282e81
2 changed files with 11 additions and 10 deletions

View File

@ -526,10 +526,10 @@
"components.Input.error.validation.email": "Value is an invalid email",
"components.Input.error.validation.json": "Value is invalid JSON",
"components.Input.error.validation.lowercase": "The value must be a lowercase string",
"components.Input.error.validation.max": "Value is larger than the maximum",
"components.Input.error.validation.maxLength": "Value is longer than the maximum",
"components.Input.error.validation.min": "Value is smaller than the minimum",
"components.Input.error.validation.minLength": "Value is shorter than the minimum",
"components.Input.error.validation.max": "Value is larger than the maximum {max}",
"components.Input.error.validation.maxLength": "Value is longer than the maximum length {max}",
"components.Input.error.validation.min": "Value is smaller than the minimum {min}",
"components.Input.error.validation.minLength": "Value is shorter than the minimum length {min}",
"components.Input.error.validation.minSupMax": "Value cannot be superior",
"components.Input.error.validation.regex": "Value does not match the required pattern",
"components.Input.error.validation.required": "Value is required",

View File

@ -1,10 +1,11 @@
import { get } from 'lodash';
const getYupInnerErrors = (error) => {
return get(error, 'inner', []).reduce((acc, curr) => {
acc[curr.path.split('[').join('.').split(']').join('')] = {
id: curr.message,
defaultMessage: curr.message,
return (error?.inner || []).reduce((acc, currentError) => {
acc[currentError.path.split('[').join('.').split(']').join('')] = {
id: currentError.message,
defaultMessage: currentError.message,
values: Object.keys(currentError?.params || {})
.filter((key) => !['label', 'originalValue', 'path', 'value'].includes(key))
.reduce((current, key) => Object.assign(current, { [key]: currentError.params[key] }), {}),
};
return acc;