mirror of
https://github.com/strapi/strapi.git
synced 2025-09-22 06:50:51 +00:00
fix(ctb): refetch data after save or update (#19844)
This commit is contained in:
parent
426ddd2ec2
commit
67a503d9cc
@ -42,6 +42,7 @@ import {
|
|||||||
REMOVE_FIELD_FROM_DISPLAYED_COMPONENT,
|
REMOVE_FIELD_FROM_DISPLAYED_COMPONENT,
|
||||||
SET_MODIFIED_DATA,
|
SET_MODIFIED_DATA,
|
||||||
UPDATE_SCHEMA,
|
UPDATE_SCHEMA,
|
||||||
|
UPDATE_INITIAL_STATE,
|
||||||
} from './constants';
|
} from './constants';
|
||||||
import { makeSelectDataManagerProvider } from './selectors';
|
import { makeSelectDataManagerProvider } from './selectors';
|
||||||
import { formatMainDataType, getComponentsToPost, sortContentType } from './utils/cleanData';
|
import { formatMainDataType, getComponentsToPost, sortContentType } from './utils/cleanData';
|
||||||
@ -552,7 +553,7 @@ const DataManagerProvider = ({ children }: DataManagerProviderProps) => {
|
|||||||
await serverRestartWatcher(true);
|
await serverRestartWatcher(true);
|
||||||
|
|
||||||
// Unlock the app
|
// Unlock the app
|
||||||
await unlockAppWithAutoreload?.();
|
unlockAppWithAutoreload?.();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
isCreating &&
|
isCreating &&
|
||||||
@ -576,6 +577,10 @@ const DataManagerProvider = ({ children }: DataManagerProviderProps) => {
|
|||||||
trackUsage('didSaveComponent');
|
trackUsage('didSaveComponent');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// refetch and update initial state after the data has been saved
|
||||||
|
await getDataRef.current();
|
||||||
|
dispatch({ type: UPDATE_INITIAL_STATE });
|
||||||
|
|
||||||
// Update the app's permissions
|
// Update the app's permissions
|
||||||
await updatePermissions();
|
await updatePermissions();
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
|
@ -21,3 +21,4 @@ export const REMOVE_COMPONENT_FROM_DYNAMIC_ZONE =
|
|||||||
export const REMOVE_FIELD = 'ContentTypeBuilder/DataManagerProvider/REMOVE_FIELD';
|
export const REMOVE_FIELD = 'ContentTypeBuilder/DataManagerProvider/REMOVE_FIELD';
|
||||||
export const SET_MODIFIED_DATA = 'ContentTypeBuilder/DataManagerProvider/SET_MODIFIED_DATA';
|
export const SET_MODIFIED_DATA = 'ContentTypeBuilder/DataManagerProvider/SET_MODIFIED_DATA';
|
||||||
export const UPDATE_SCHEMA = 'ContentTypeBuilder/DataManagerProvider/UPDATE_SCHEMA';
|
export const UPDATE_SCHEMA = 'ContentTypeBuilder/DataManagerProvider/UPDATE_SCHEMA';
|
||||||
|
export const UPDATE_INITIAL_STATE = 'ContentTypeBuilder/DataManagerProvider/UPDATE_INITIAL_STATE';
|
||||||
|
@ -545,6 +545,11 @@ const reducer = (state = initialState, action: Action) =>
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case actions.UPDATE_INITIAL_STATE: {
|
||||||
|
draftState.initialData = draftState.modifiedData;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
case actions.DELETE_NOT_SAVED_TYPE: {
|
case actions.DELETE_NOT_SAVED_TYPE: {
|
||||||
// Doing so will also reset the modified and the initial data
|
// Doing so will also reset the modified and the initial data
|
||||||
draftState.contentTypes = state.initialContentTypes;
|
draftState.contentTypes = state.initialContentTypes;
|
||||||
|
@ -41,7 +41,7 @@ export interface DataManagerContextValue {
|
|||||||
removeComponentFromDynamicZone: (dzName: string, componentToRemoveIndex: number) => void;
|
removeComponentFromDynamicZone: (dzName: string, componentToRemoveIndex: number) => void;
|
||||||
setModifiedData: () => void;
|
setModifiedData: () => void;
|
||||||
sortedContentTypesList: any[]; // Define the actual type
|
sortedContentTypesList: any[]; // Define the actual type
|
||||||
submitData: (additionalContentTypeData?: Record<string, any>) => void;
|
submitData: (additionalContentTypeData?: Record<string, any>) => Promise<void>;
|
||||||
updateSchema: (data: Record<string, any>, schemaType: SchemaType, componentUID: UID.Any) => void;
|
updateSchema: (data: Record<string, any>, schemaType: SchemaType, componentUID: UID.Any) => void;
|
||||||
components: Record<UID.Component, Component>;
|
components: Record<UID.Component, Component>;
|
||||||
componentsGroupedByCategory: Record<string, Component[]>;
|
componentsGroupedByCategory: Record<string, Component[]>;
|
||||||
|
@ -139,7 +139,7 @@ const ListView = () => {
|
|||||||
)}
|
)}
|
||||||
<Button
|
<Button
|
||||||
startIcon={<Check />}
|
startIcon={<Check />}
|
||||||
onClick={() => submitData()}
|
onClick={async () => await submitData()}
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={isEqual(modifiedData, initialData)}
|
disabled={isEqual(modifiedData, initialData)}
|
||||||
>
|
>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user