mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 08:52:26 +00:00
Fix single types edition
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
5d14e41b1f
commit
5dcad4d1da
@ -83,12 +83,6 @@ const CollectionTypeWrapper = ({ allLayoutData, children, from, slug }) => {
|
|||||||
|
|
||||||
const shouldFetch = useRef(true);
|
const shouldFetch = useRef(true);
|
||||||
|
|
||||||
// useEffect(() => {
|
|
||||||
// return () => {
|
|
||||||
|
|
||||||
// };
|
|
||||||
// }, [slug]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const abortController = new AbortController();
|
const abortController = new AbortController();
|
||||||
const { signal } = abortController;
|
const { signal } = abortController;
|
||||||
|
@ -1,17 +1,23 @@
|
|||||||
import React, { Suspense, lazy } from 'react';
|
import React from 'react';
|
||||||
import { Switch, Route, useRouteMatch, useParams } from 'react-router-dom';
|
import { Switch, Route, useRouteMatch, useParams } from 'react-router-dom';
|
||||||
import { LoadingIndicatorPage, CheckPagePermissions } from 'strapi-helper-plugin';
|
import { LoadingIndicatorPage, CheckPagePermissions } from 'strapi-helper-plugin';
|
||||||
import pluginPermissions from '../../permissions';
|
import pluginPermissions from '../../permissions';
|
||||||
|
import { ContentTypeLayoutContext } from '../../contexts';
|
||||||
const EditView = lazy(() => import('../EditView'));
|
import { useFetchContentTypeLayout } from '../../hooks';
|
||||||
const EditSettingsView = lazy(() => import('../EditSettingsView'));
|
import EditView from '../EditView';
|
||||||
|
import EditSettingsView from '../EditSettingsView';
|
||||||
|
|
||||||
const SingleTypeRecursivePath = props => {
|
const SingleTypeRecursivePath = props => {
|
||||||
const { url } = useRouteMatch();
|
const { url } = useRouteMatch();
|
||||||
const { slug } = useParams();
|
const { slug } = useParams();
|
||||||
|
const { isLoading, layout } = useFetchContentTypeLayout(slug);
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return <LoadingIndicatorPage />;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Suspense fallback={<LoadingIndicatorPage />}>
|
<ContentTypeLayoutContext.Provider value={layout}>
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route
|
<Route
|
||||||
path={`${url}/ctm-configurations/edit-settings/:type`}
|
path={`${url}/ctm-configurations/edit-settings/:type`}
|
||||||
@ -23,10 +29,10 @@ const SingleTypeRecursivePath = props => {
|
|||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path={`${url}`}
|
path={`${url}`}
|
||||||
render={routeProps => <EditView {...props} {...routeProps} slug={slug} isSingleType />}
|
render={() => <EditView layout={layout} slug={slug} isSingleType />}
|
||||||
/>
|
/>
|
||||||
</Switch>
|
</Switch>
|
||||||
</Suspense>
|
</ContentTypeLayoutContext.Provider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -157,18 +157,13 @@ const SingleTypeWrapper = ({ allLayoutData, children, from, slug }) => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const onPost = useCallback(
|
const onPost = useCallback(
|
||||||
async (formData, trackerProperty) => {
|
async (body, trackerProperty) => {
|
||||||
const endPoint = getRequestUrl(slug);
|
const endPoint = getRequestUrl(slug);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dispatch({ type: 'SET_STATUS', status: 'submit-pending' });
|
dispatch({ type: 'SET_STATUS', status: 'submit-pending' });
|
||||||
|
|
||||||
const response = await request(
|
const response = await request(endPoint, { method: 'PUT', body });
|
||||||
endPoint,
|
|
||||||
{ method: 'POST', headers: {}, body: formData },
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
emitEventRef.current('didCreateEntry', trackerProperty);
|
emitEventRef.current('didCreateEntry', trackerProperty);
|
||||||
strapi.notification.success(getTrad('success.record.save'));
|
strapi.notification.success(getTrad('success.record.save'));
|
||||||
@ -206,7 +201,7 @@ const SingleTypeWrapper = ({ allLayoutData, children, from, slug }) => {
|
|||||||
}, [cleanReceivedData, displayErrors, id, slug]);
|
}, [cleanReceivedData, displayErrors, id, slug]);
|
||||||
|
|
||||||
const onPut = useCallback(
|
const onPut = useCallback(
|
||||||
async (formData, trackerProperty) => {
|
async (body, trackerProperty) => {
|
||||||
const endPoint = getRequestUrl(`${slug}/${id}`);
|
const endPoint = getRequestUrl(`${slug}/${id}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -214,12 +209,7 @@ const SingleTypeWrapper = ({ allLayoutData, children, from, slug }) => {
|
|||||||
|
|
||||||
dispatch({ type: 'SET_STATUS', status: 'submit-pending' });
|
dispatch({ type: 'SET_STATUS', status: 'submit-pending' });
|
||||||
|
|
||||||
const response = await request(
|
const response = await request(endPoint, { method: 'PUT', body });
|
||||||
endPoint,
|
|
||||||
{ method: 'PUT', headers: {}, body: formData },
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
emitEventRef.current('didEditEntry', { trackerProperty });
|
emitEventRef.current('didEditEntry', { trackerProperty });
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import pluginId from '../../../pluginId';
|
import pluginId from '../../../pluginId';
|
||||||
|
|
||||||
const getRequestUrl = path => `/${pluginId}/explorer/${path}`;
|
const getRequestUrl = path => `/${pluginId}/single-types/${path}`;
|
||||||
|
|
||||||
export default getRequestUrl;
|
export default getRequestUrl;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user