Fix single types edition

Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
soupette 2020-11-06 15:59:03 +01:00
parent 5d14e41b1f
commit 5dcad4d1da
4 changed files with 18 additions and 28 deletions

View File

@ -83,12 +83,6 @@ const CollectionTypeWrapper = ({ allLayoutData, children, from, slug }) => {
const shouldFetch = useRef(true);
// useEffect(() => {
// return () => {
// };
// }, [slug]);
useEffect(() => {
const abortController = new AbortController();
const { signal } = abortController;

View File

@ -1,17 +1,23 @@
import React, { Suspense, lazy } from 'react';
import React from 'react';
import { Switch, Route, useRouteMatch, useParams } from 'react-router-dom';
import { LoadingIndicatorPage, CheckPagePermissions } from 'strapi-helper-plugin';
import pluginPermissions from '../../permissions';
const EditView = lazy(() => import('../EditView'));
const EditSettingsView = lazy(() => import('../EditSettingsView'));
import { ContentTypeLayoutContext } from '../../contexts';
import { useFetchContentTypeLayout } from '../../hooks';
import EditView from '../EditView';
import EditSettingsView from '../EditSettingsView';
const SingleTypeRecursivePath = props => {
const { url } = useRouteMatch();
const { slug } = useParams();
const { isLoading, layout } = useFetchContentTypeLayout(slug);
if (isLoading) {
return <LoadingIndicatorPage />;
}
return (
<Suspense fallback={<LoadingIndicatorPage />}>
<ContentTypeLayoutContext.Provider value={layout}>
<Switch>
<Route
path={`${url}/ctm-configurations/edit-settings/:type`}
@ -23,10 +29,10 @@ const SingleTypeRecursivePath = props => {
/>
<Route
path={`${url}`}
render={routeProps => <EditView {...props} {...routeProps} slug={slug} isSingleType />}
render={() => <EditView layout={layout} slug={slug} isSingleType />}
/>
</Switch>
</Suspense>
</ContentTypeLayoutContext.Provider>
);
};

View File

@ -157,18 +157,13 @@ const SingleTypeWrapper = ({ allLayoutData, children, from, slug }) => {
}, []);
const onPost = useCallback(
async (formData, trackerProperty) => {
async (body, trackerProperty) => {
const endPoint = getRequestUrl(slug);
try {
dispatch({ type: 'SET_STATUS', status: 'submit-pending' });
const response = await request(
endPoint,
{ method: 'POST', headers: {}, body: formData },
false,
false
);
const response = await request(endPoint, { method: 'PUT', body });
emitEventRef.current('didCreateEntry', trackerProperty);
strapi.notification.success(getTrad('success.record.save'));
@ -206,7 +201,7 @@ const SingleTypeWrapper = ({ allLayoutData, children, from, slug }) => {
}, [cleanReceivedData, displayErrors, id, slug]);
const onPut = useCallback(
async (formData, trackerProperty) => {
async (body, trackerProperty) => {
const endPoint = getRequestUrl(`${slug}/${id}`);
try {
@ -214,12 +209,7 @@ const SingleTypeWrapper = ({ allLayoutData, children, from, slug }) => {
dispatch({ type: 'SET_STATUS', status: 'submit-pending' });
const response = await request(
endPoint,
{ method: 'PUT', headers: {}, body: formData },
false,
false
);
const response = await request(endPoint, { method: 'PUT', body });
emitEventRef.current('didEditEntry', { trackerProperty });

View File

@ -1,5 +1,5 @@
import pluginId from '../../../pluginId';
const getRequestUrl = path => `/${pluginId}/explorer/${path}`;
const getRequestUrl = path => `/${pluginId}/single-types/${path}`;
export default getRequestUrl;