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:
commit
f8f302518d
2 changed files with 10 additions and 2 deletions
|
@ -2,7 +2,7 @@ import { z } from 'zod';
|
||||||
|
|
||||||
export const multiTextInputErrorGuard = z.object({
|
export const multiTextInputErrorGuard = z.object({
|
||||||
required: z.string().optional(),
|
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>;
|
export type MultiTextInputError = z.infer<typeof multiTextInputErrorGuard>;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import { t } from 'i18next';
|
import { t } from 'i18next';
|
||||||
|
|
||||||
|
import { safeParseJson } from '@/utilities/json';
|
||||||
|
|
||||||
import { MultiTextInputError, multiTextInputErrorGuard, MultiTextInputRule } from './types';
|
import { MultiTextInputError, multiTextInputErrorGuard, MultiTextInputRule } from './types';
|
||||||
|
|
||||||
export const validate = (
|
export const validate = (
|
||||||
|
@ -57,7 +59,13 @@ export const convertRhfErrorMessage = (errorMessage?: string): MultiTextInputErr
|
||||||
return;
|
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) {
|
if (!result.success) {
|
||||||
throw new Error(t('admin_console.errors.invalid_error_message_format'));
|
throw new Error(t('admin_console.errors.invalid_error_message_format'));
|
||||||
|
|
Loading…
Reference in a new issue