From 59e692bcbef5c26355798f70cd5badb0b2302bca Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Fri, 26 Jan 2024 16:50:03 -0500 Subject: [PATCH] fix(striker-ui): simplify field name in formik errors --- striker-ui/lib/getFormikErrorMessages.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/striker-ui/lib/getFormikErrorMessages.ts b/striker-ui/lib/getFormikErrorMessages.ts index 0707fb4e..18306ef8 100644 --- a/striker-ui/lib/getFormikErrorMessages.ts +++ b/striker-ui/lib/getFormikErrorMessages.ts @@ -1,7 +1,17 @@ +import { capitalize } from 'lodash'; + const getFormikErrorMessages = ( errors: object, { - build = (field, error) => ({ children: error, type: 'warning' }), + build = (field, error) => { + let children = error; + + if (typeof children === 'string') { + children = capitalize(children.replace(/^[^\s]+\.([^.]+)/, '$1')); + } + + return { children, type: 'warning' }; + }, chain = '', skip, }: {