mirror of
https://github.com/strapi/strapi.git
synced 2025-11-05 20:36:08 +00:00
fix: issue 20747
This commit is contained in:
parent
860584b10c
commit
587fe5d570
@ -14,6 +14,7 @@ import {
|
|||||||
isFetchError,
|
isFetchError,
|
||||||
useStrapiApp,
|
useStrapiApp,
|
||||||
Layouts,
|
Layouts,
|
||||||
|
FormErrors,
|
||||||
} from '@strapi/admin/strapi-admin';
|
} from '@strapi/admin/strapi-admin';
|
||||||
import { unstable_useDocument } from '@strapi/content-manager/strapi-admin';
|
import { unstable_useDocument } from '@strapi/content-manager/strapi-admin';
|
||||||
import {
|
import {
|
||||||
@ -145,6 +146,42 @@ const EntryValidationText = ({ action, schema, entry, status }: EntryValidationT
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const errorsToString = (errors: FormErrors, prefix: string = ''): string => {
|
||||||
|
if (Object.keys(errors).length === 0) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return Object.entries(errors)
|
||||||
|
.map(([key, value]) => {
|
||||||
|
if (value === undefined || value === null) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof value === 'string') {
|
||||||
|
return formatMessage(
|
||||||
|
{ id: value, defaultMessage: value },
|
||||||
|
{ field: prefix ? `${prefix}.${key}` : key }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
typeof value === 'object' &&
|
||||||
|
value !== null &&
|
||||||
|
'id' in value &&
|
||||||
|
'defaultMessage' in value
|
||||||
|
) {
|
||||||
|
return formatMessage(
|
||||||
|
// @ts-expect-error – TODO: default message will be a string
|
||||||
|
{ id: `${value.id}.withField`, defaultMessage: value.defaultMessage },
|
||||||
|
{ field: prefix ? `${prefix}.${key}` : key }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return errorsToString(value as FormErrors, key);
|
||||||
|
})
|
||||||
|
.join(' ');
|
||||||
|
};
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -153,15 +190,7 @@ const EntryValidationText = ({ action, schema, entry, status }: EntryValidationT
|
|||||||
|
|
||||||
if (action === 'publish') {
|
if (action === 'publish') {
|
||||||
if (Object.keys(errors).length > 0) {
|
if (Object.keys(errors).length > 0) {
|
||||||
const validationErrorsMessages = Object.entries(errors)
|
const validationErrorsMessages = errorsToString(errors);
|
||||||
.map(([key, value]) =>
|
|
||||||
formatMessage(
|
|
||||||
// @ts-expect-error – TODO: fix this will better checks
|
|
||||||
{ id: `${value.id}.withField`, defaultMessage: value.defaultMessage },
|
|
||||||
{ field: key }
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.join(' ');
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex gap={2}>
|
<Flex gap={2}>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user