diff --git a/packages/console/src/components/MultiTextInput/types.ts b/packages/console/src/components/MultiTextInput/types.ts index 2b6c97861..6712e4600 100644 --- a/packages/console/src/components/MultiTextInput/types.ts +++ b/packages/console/src/components/MultiTextInput/types.ts @@ -2,7 +2,7 @@ import { z } from 'zod'; export const multiTextInputErrorGuard = z.object({ required: z.string().optional(), - inputs: z.record(z.number(), z.string().optional()).optional(), + inputs: z.record(z.number().or(z.string()), z.string().optional()).optional(), }); export type MultiTextInputError = z.infer; diff --git a/packages/console/src/components/MultiTextInput/utils.ts b/packages/console/src/components/MultiTextInput/utils.ts index 398938da5..1bcb3078e 100644 --- a/packages/console/src/components/MultiTextInput/utils.ts +++ b/packages/console/src/components/MultiTextInput/utils.ts @@ -1,5 +1,7 @@ import { t } from 'i18next'; +import { safeParseJson } from '@/utilities/json'; + import { MultiTextInputError, multiTextInputErrorGuard, MultiTextInputRule } from './types'; export const validate = ( @@ -57,7 +59,13 @@ export const convertRhfErrorMessage = (errorMessage?: string): MultiTextInputErr return; } - const result = multiTextInputErrorGuard.safeParse(errorMessage); + const jsonParseResult = safeParseJson(errorMessage); + + if (!jsonParseResult.success) { + throw new Error(t('admin_console.errors.invalid_error_message_format')); + } + + const result = multiTextInputErrorGuard.safeParse(jsonParseResult.data); if (!result.success) { throw new Error(t('admin_console.errors.invalid_error_message_format'));