0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

Merge pull request #1895 from logto-io/charles-fix-app-crash-on-input-invalid-content-in-multilineinput-component

fix(console): input invalid format content in multitextinput will not crash the app
This commit is contained in:
Charles Zhao 2022-09-07 18:45:16 +08:00 committed by GitHub
commit f8f302518d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View file

@ -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<typeof multiTextInputErrorGuard>;

View file

@ -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'));