mirror of
https://github.com/strapi/strapi.git
synced 2025-12-28 07:33:17 +00:00
EditViewDataManagerProvider: Reuse getYupInnerErrors from helper-plugin
This commit is contained in:
parent
538c1f1ac4
commit
3177ddda35
@ -14,11 +14,12 @@ import {
|
||||
useNotification,
|
||||
useOverlayBlocker,
|
||||
useTracking,
|
||||
getYupInnerErrors,
|
||||
} from '@strapi/helper-plugin';
|
||||
|
||||
import { getTrad, removeKeyInObject } from '../../utils';
|
||||
import reducer, { initialState } from './reducer';
|
||||
import { cleanData, createYupSchema, getYupInnerErrors } from './utils';
|
||||
import { cleanData, createYupSchema } from './utils';
|
||||
import { getAPIInnerError } from './utils/getAPIInnerError';
|
||||
|
||||
const EditViewDataManagerProvider = ({
|
||||
@ -268,7 +269,7 @@ const EditViewDataManagerProvider = ({
|
||||
);
|
||||
|
||||
const createFormData = useCallback(
|
||||
data => {
|
||||
(data) => {
|
||||
// First we need to remove the added keys needed for the dnd
|
||||
const preparedData = removeKeyInObject(cloneDeep(data), '__temp_key__');
|
||||
// Then we need to apply our helper
|
||||
@ -292,7 +293,7 @@ const EditViewDataManagerProvider = ({
|
||||
}, [hasDraftAndPublish, shouldNotRunValidations]);
|
||||
|
||||
const handleSubmit = useCallback(
|
||||
async e => {
|
||||
async (e) => {
|
||||
e.preventDefault();
|
||||
let errors = {};
|
||||
|
||||
@ -362,8 +363,8 @@ const EditViewDataManagerProvider = ({
|
||||
}, [allLayoutData, currentContentTypeLayout, isCreatingEntry, modifiedData, onPublish]);
|
||||
|
||||
const shouldCheckDZErrors = useCallback(
|
||||
dzName => {
|
||||
const doesDZHaveError = Object.keys(formErrors).some(key => key.split('.')[0] === dzName);
|
||||
(dzName) => {
|
||||
const doesDZHaveError = Object.keys(formErrors).some((key) => key.split('.')[0] === dzName);
|
||||
const shouldCheckErrors = !isEmpty(formErrors) && doesDZHaveError;
|
||||
|
||||
return shouldCheckErrors;
|
||||
@ -417,7 +418,7 @@ const EditViewDataManagerProvider = ({
|
||||
});
|
||||
}, []);
|
||||
|
||||
const onRemoveRelation = useCallback(keys => {
|
||||
const onRemoveRelation = useCallback((keys) => {
|
||||
dispatch({
|
||||
type: 'REMOVE_RELATION',
|
||||
keys,
|
||||
|
||||
@ -1,17 +0,0 @@
|
||||
import { get } from 'lodash';
|
||||
|
||||
const getYupInnerErrors = error => {
|
||||
return get(error, 'inner', []).reduce((acc, curr) => {
|
||||
acc[
|
||||
curr.path
|
||||
.split('[')
|
||||
.join('.')
|
||||
.split(']')
|
||||
.join('')
|
||||
] = { id: curr.message };
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
};
|
||||
|
||||
export default getYupInnerErrors;
|
||||
@ -1,4 +1,3 @@
|
||||
export { default as moveFields } from './moveFields';
|
||||
export { default as cleanData } from './cleanData';
|
||||
export { default as getYupInnerErrors } from './getYupInnerErrors';
|
||||
export { default as createYupSchema } from './schema';
|
||||
|
||||
@ -1,14 +1,11 @@
|
||||
import { get } from 'lodash';
|
||||
|
||||
const getYupInnerErrors = error => {
|
||||
const getYupInnerErrors = (error) => {
|
||||
return get(error, 'inner', []).reduce((acc, curr) => {
|
||||
acc[
|
||||
curr.path
|
||||
.split('[')
|
||||
.join('.')
|
||||
.split(']')
|
||||
.join('')
|
||||
] = { id: curr.message };
|
||||
acc[curr.path.split('[').join('.').split(']').join('')] = {
|
||||
id: curr.message,
|
||||
defaultMessage: curr.message,
|
||||
};
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user