partial solution

This commit is contained in:
Simone Taeggi 2023-02-09 17:17:39 +01:00
parent c62c1400fb
commit a4cd6907a9

View File

@ -10,6 +10,7 @@ import {
useAppInfos, useAppInfos,
useRBACProvider, useRBACProvider,
useGuidedTour, useGuidedTour,
useFetchClient,
} from '@strapi/helper-plugin'; } from '@strapi/helper-plugin';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
import { useLocation, useRouteMatch, Redirect } from 'react-router-dom'; import { useLocation, useRouteMatch, Redirect } from 'react-router-dom';
@ -81,6 +82,8 @@ const DataManagerProvider = ({
const componentMatch = useRouteMatch( const componentMatch = useRouteMatch(
`/plugins/${pluginId}/component-categories/:categoryUid/:componentUid` `/plugins/${pluginId}/component-categories/:categoryUid/:componentUid`
); );
const fetchClient = useFetchClient();
const { post, del } = fetchClient;
const formatMessageRef = useRef(); const formatMessageRef = useRef();
formatMessageRef.current = formatMessage; formatMessageRef.current = formatMessage;
@ -107,8 +110,7 @@ const DataManagerProvider = ({
{ data: reservedNames }, { data: reservedNames },
] = await Promise.all( ] = await Promise.all(
['components', 'content-types', 'reserved-names'].map((endPoint) => { ['components', 'content-types', 'reserved-names'].map((endPoint) => {
// TODO: remember to pass also the pluginId when you use the new get, post, put, delete methods from getFetchClient return fetchClient.get(`/${pluginId}/${endPoint}`);
return axiosInstance.get(endPoint);
}) })
); );
@ -265,6 +267,8 @@ const DataManagerProvider = ({
if (userConfirm) { if (userConfirm) {
lockAppWithAutoreload(); lockAppWithAutoreload();
console.log('deleteCategory', requestURL);
// TODO: remember to pass also the pluginId when you use the new get, post, put, delete methods from getFetchClient // TODO: remember to pass also the pluginId when you use the new get, post, put, delete methods from getFetchClient
await axiosInstance.delete(requestURL); await axiosInstance.delete(requestURL);
@ -289,7 +293,7 @@ const DataManagerProvider = ({
const deleteData = async () => { const deleteData = async () => {
try { try {
const requestURL = `/${endPoint}/${currentUid}`; const requestURL = `/${pluginId}/${endPoint}/${currentUid}`;
const isTemporary = get(modifiedData, [firstKeyToMainSchema, 'isTemporary'], false); const isTemporary = get(modifiedData, [firstKeyToMainSchema, 'isTemporary'], false);
// eslint-disable-next-line no-alert // eslint-disable-next-line no-alert
const userConfirm = window.confirm( const userConfirm = window.confirm(
@ -315,8 +319,8 @@ const DataManagerProvider = ({
} }
lockAppWithAutoreload(); lockAppWithAutoreload();
// TODO: remember to pass also the pluginId when you use the new get, post, put, delete methods from getFetchClient
await axiosInstance.delete(requestURL); await del(requestURL);
// Make sure the server has restarted // Make sure the server has restarted
await serverRestartWatcher(true); await serverRestartWatcher(true);
@ -347,6 +351,7 @@ const DataManagerProvider = ({
// Lock the app // Lock the app
lockAppWithAutoreload(); lockAppWithAutoreload();
console.log('editCategory', requestURL);
// Update the category // Update the category
// TODO: remember to pass also the pluginId when you use the new get, post, put, delete methods from getFetchClient // TODO: remember to pass also the pluginId when you use the new get, post, put, delete methods from getFetchClient
@ -503,13 +508,14 @@ const DataManagerProvider = ({
// Lock the app // Lock the app
lockAppWithAutoreload(); lockAppWithAutoreload();
const baseURL = `/${endPoint}`; const baseURL = `/${pluginId}/${endPoint}`;
const requestURL = isCreating ? baseURL : `${baseURL}/${currentUid}`; const requestURL = isCreating ? baseURL : `${baseURL}/${currentUid}`;
// TODO: remember to pass also the pluginId when you use the new get, post, put, delete methods from getFetchClient // TODO: remember to pass also the pluginId when you use the new get, post, put, delete methods from getFetchClient
if (isCreating) { if (isCreating) {
await axiosInstance.post(requestURL, body); await post(requestURL, body);
} else { } else {
console.log('submitData Edit', requestURL);
await axiosInstance.put(requestURL, body); await axiosInstance.put(requestURL, body);
} }