mirror of
https://github.com/strapi/strapi.git
synced 2025-12-12 15:32:42 +00:00
Merge pull request #14346 from strapi/feature/relations-main-view-invalidate-post
FormWrapper: Invalidate relation-queries after submit
This commit is contained in:
commit
a3f298d558
@ -1,4 +1,5 @@
|
||||
import { memo, useCallback, useEffect, useMemo, useRef } from 'react';
|
||||
import { useQueryClient } from 'react-query';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import axios from 'axios';
|
||||
import get from 'lodash/get';
|
||||
@ -34,6 +35,7 @@ import selectCrudReducer from '../../sharedReducers/crudReducer/selectors';
|
||||
|
||||
// This container is used to handle the CRUD
|
||||
const CollectionTypeFormWrapper = ({ allLayoutData, children, slug, id, origin }) => {
|
||||
const queryClient = useQueryClient();
|
||||
const toggleNotification = useNotification();
|
||||
const { setCurrentStep } = useGuidedTour();
|
||||
const { trackUsage } = useTracking();
|
||||
@ -260,7 +262,11 @@ const CollectionTypeFormWrapper = ({ allLayoutData, children, slug, id, origin }
|
||||
|
||||
setCurrentStep('contentManager.success');
|
||||
|
||||
// TODO: need to find a better place, or a better abstraction
|
||||
queryClient.invalidateQueries(['relation']);
|
||||
|
||||
dispatch(submitSucceeded(cleanReceivedData(data)));
|
||||
|
||||
// Enable navigation and remove loaders
|
||||
dispatch(setStatus('resolved'));
|
||||
|
||||
@ -284,6 +290,7 @@ const CollectionTypeFormWrapper = ({ allLayoutData, children, slug, id, origin }
|
||||
rawQuery,
|
||||
toggleNotification,
|
||||
setCurrentStep,
|
||||
queryClient,
|
||||
]
|
||||
);
|
||||
|
||||
@ -332,6 +339,9 @@ const CollectionTypeFormWrapper = ({ allLayoutData, children, slug, id, origin }
|
||||
message: { id: getTrad('success.record.save') },
|
||||
});
|
||||
|
||||
// TODO: need to find a better place, or a better abstraction
|
||||
queryClient.invalidateQueries(['relation']);
|
||||
|
||||
dispatch(submitSucceeded(cleanReceivedData(data)));
|
||||
|
||||
dispatch(setStatus('resolved'));
|
||||
@ -346,7 +356,7 @@ const CollectionTypeFormWrapper = ({ allLayoutData, children, slug, id, origin }
|
||||
return Promise.reject(err);
|
||||
}
|
||||
},
|
||||
[cleanReceivedData, displayErrors, slug, id, dispatch, toggleNotification]
|
||||
[cleanReceivedData, displayErrors, slug, id, dispatch, toggleNotification, queryClient]
|
||||
);
|
||||
|
||||
const onUnpublish = useCallback(async () => {
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { memo, useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { useQueryClient } from 'react-query';
|
||||
import get from 'lodash/get';
|
||||
import {
|
||||
useTracking,
|
||||
@ -28,6 +29,7 @@ import buildQueryString from '../../pages/ListView/utils/buildQueryString';
|
||||
|
||||
// This container is used to handle the CRUD
|
||||
const SingleTypeFormWrapper = ({ allLayoutData, children, slug }) => {
|
||||
const queryClient = useQueryClient();
|
||||
const { trackUsage } = useTracking();
|
||||
const { push } = useHistory();
|
||||
const { setCurrentStep } = useGuidedTour();
|
||||
@ -202,6 +204,9 @@ const SingleTypeFormWrapper = ({ allLayoutData, children, slug }) => {
|
||||
|
||||
setCurrentStep('contentManager.success');
|
||||
|
||||
// TODO: need to find a better place, or a better abstraction
|
||||
queryClient.invalidateQueries(['relation']);
|
||||
|
||||
dispatch(submitSucceeded(cleanReceivedData(data)));
|
||||
setIsCreatingEntry(false);
|
||||
|
||||
@ -218,7 +223,16 @@ const SingleTypeFormWrapper = ({ allLayoutData, children, slug }) => {
|
||||
return Promise.reject(err);
|
||||
}
|
||||
},
|
||||
[cleanReceivedData, displayErrors, slug, dispatch, rawQuery, toggleNotification, setCurrentStep]
|
||||
[
|
||||
cleanReceivedData,
|
||||
displayErrors,
|
||||
slug,
|
||||
dispatch,
|
||||
rawQuery,
|
||||
toggleNotification,
|
||||
setCurrentStep,
|
||||
queryClient,
|
||||
]
|
||||
);
|
||||
const onPublish = useCallback(async () => {
|
||||
try {
|
||||
@ -267,6 +281,9 @@ const SingleTypeFormWrapper = ({ allLayoutData, children, slug }) => {
|
||||
|
||||
trackUsageRef.current('didEditEntry', { trackerProperty });
|
||||
|
||||
// TODO: need to find a better place, or a better abstraction
|
||||
queryClient.invalidateQueries(['relation']);
|
||||
|
||||
dispatch(submitSucceeded(cleanReceivedData(data)));
|
||||
|
||||
dispatch(setStatus('resolved'));
|
||||
@ -282,7 +299,7 @@ const SingleTypeFormWrapper = ({ allLayoutData, children, slug }) => {
|
||||
return Promise.reject(err);
|
||||
}
|
||||
},
|
||||
[cleanReceivedData, displayErrors, slug, dispatch, rawQuery, toggleNotification]
|
||||
[cleanReceivedData, displayErrors, slug, dispatch, rawQuery, toggleNotification, queryClient]
|
||||
);
|
||||
|
||||
// The publish and unpublish method could be refactored but let's leave the duplication for now
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user