import React, { useState, useEffect } from 'react'; import { useIntl } from 'react-intl'; import { Box, Typography, Divider } from '@strapi/design-system'; import Action from '../Action'; import { getTrad } from '../../utils/getTrad'; import { useSettings } from '../../hooks/useSettings'; import { unstable_useDocument as useDocument, unstable_useContentManagerContext as useContentManagerContext, } from '@strapi/strapi/admin'; const actionModes = ['publish', 'unpublish']; const ActionManagerComponent = ({ document, entity }) => { const { formatMessage } = useIntl(); const [showActions, setShowActions] = useState(false); const { getSettings } = useSettings(); const { isLoading, data, isRefetching } = getSettings(); useEffect(() => { if (!isLoading && !isRefetching) { if (!data.contentTypes?.length || data.contentTypes?.find((uid) => uid === entity.slug)) { setShowActions(true); } } }, [isLoading, isRefetching]); if (!showActions) { return null; } return ( <> {formatMessage({ id: getTrad('plugin.name'), defaultMessage: 'Publisher', })} {actionModes.map((mode, index) => (
))} ); }; const ActionManager = () => { const entity = useContentManagerContext(); const { document } = useDocument({ documentId: entity?.id, model: entity?.model, collectionType: entity?.collectionType, }); if (! entity.hasDraftAndPublish || entity.isCreatingEntry) { return null; } if (! document || ! entity) { return null; } return ; }; export default ActionManager;