mirror of
https://github.com/strapi/strapi.git
synced 2025-11-11 07:39:16 +00:00
Fix multiple api calls
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
31ad694a7e
commit
307bcf9a08
@ -32,8 +32,9 @@ const Header = () => {
|
||||
onPublish,
|
||||
onUnpublish,
|
||||
} = useDataManager();
|
||||
const onPublishRef = useRef(onPublish);
|
||||
const {
|
||||
allowedActions: { canDelete, canUpdate, canCreate, canPublish },
|
||||
allowedActions: { canUpdate, canCreate, canPublish },
|
||||
} = useEditView();
|
||||
|
||||
const currentContentTypeMainField = useMemo(() => get(layout, ['settings', 'mainField'], 'id'), [
|
||||
@ -83,39 +84,30 @@ const Header = () => {
|
||||
];
|
||||
}
|
||||
|
||||
if (hasDraftAndPublish && canPublish && !initialData.published_at) {
|
||||
headerActions.unshift({
|
||||
...primaryButtonObject,
|
||||
disabled: didChangeData,
|
||||
label: formatMessage({
|
||||
id: 'app.utils.publish',
|
||||
}),
|
||||
onClick: onPublish,
|
||||
isLoading: status === 'publish-pending',
|
||||
});
|
||||
}
|
||||
if (hasDraftAndPublish && canPublish) {
|
||||
const isPublished = !isEmpty(initialData.published_at);
|
||||
const isLoading = isPublished ? status === 'unpublish-pending' : status === 'publish-pending';
|
||||
const labelID = isPublished ? 'app.utils.unpublish' : 'app.utils.publish';
|
||||
const onClick = isPublished ? () => setWarningUnpublish(true) : onPublishRef.current;
|
||||
|
||||
if (hasDraftAndPublish && canPublish && initialData.published_at) {
|
||||
headerActions.unshift({
|
||||
const action = {
|
||||
...primaryButtonObject,
|
||||
disabled: didChangeData,
|
||||
label: formatMessage({
|
||||
id: 'app.utils.unpublish',
|
||||
}),
|
||||
onClick: () => setWarningUnpublish(true),
|
||||
isLoading: status === 'unpublish-pending',
|
||||
});
|
||||
disabled: isCreatingEntry,
|
||||
isLoading,
|
||||
label: formatMessage({ id: labelID }),
|
||||
onClick,
|
||||
};
|
||||
|
||||
headerActions.unshift(action);
|
||||
}
|
||||
|
||||
return headerActions;
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [
|
||||
isCreatingEntry,
|
||||
canCreate,
|
||||
canUpdate,
|
||||
hasDraftAndPublish,
|
||||
canPublish,
|
||||
canDelete,
|
||||
didChangeData,
|
||||
formatMessage,
|
||||
status,
|
||||
|
||||
@ -244,7 +244,7 @@ const EditViewDataManagerProvider = ({
|
||||
abortController.abort();
|
||||
};
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [id, slug, isCreatingEntry, isLoadingForPermissions]);
|
||||
}, [id, slug, isLoadingForPermissions]);
|
||||
|
||||
const addComponentToDynamicZone = useCallback((keys, componentUid, shouldCheckErrors = false) => {
|
||||
emitEvent('didAddComponentToDynamicZone');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user