2022-08-05 18:15:17 +02:00
|
|
|
import { FieldError } from "react-hook-form";
|
|
|
|
|
import I18n from 'i18n-js';
|
|
|
|
|
|
|
|
|
|
export const getLabel = (
|
|
|
|
|
entity: string,
|
2023-02-05 11:55:38 +01:00
|
|
|
attribute: string = undefined,
|
2022-08-05 18:15:17 +02:00
|
|
|
) => (
|
2023-02-05 11:55:38 +01:00
|
|
|
attribute ?
|
|
|
|
|
I18n.t(`activerecord.attributes.${entity}.${attribute}`)
|
|
|
|
|
:
|
2024-02-14 11:07:23 +01:00
|
|
|
I18n.t(`activerecord.models.${entity}`, { count: 1 })
|
2022-08-05 18:15:17 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const getValidationMessage = (
|
|
|
|
|
validationType: FieldError['type'],
|
|
|
|
|
entity: string,
|
|
|
|
|
attribute: string,
|
|
|
|
|
) => (
|
|
|
|
|
I18n.t(
|
|
|
|
|
`common.validations.${validationType}`,
|
|
|
|
|
{ attribute: getLabel(entity, attribute) }
|
|
|
|
|
)
|
|
|
|
|
);
|