UNPKG

@craftercms/studio-ui

Version:

Services, components, models & utils to build CrafterCMS authoring extensions.

106 lines (104 loc) 4.18 kB
/* * Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License version 3 as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* * Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import * as React from 'react'; import PublishingStatusWidget from '../PublishingStatusWidget'; import Grid from '@mui/material/Grid'; import { PublishingQueueWidget } from '../PublishingQueue'; import PublishOnDemandWidget from '../PublishOnDemandWidget'; import GlobalAppToolbar from '../GlobalAppToolbar'; import { FormattedMessage } from 'react-intl'; import { useActiveSiteId } from '../../hooks/useActiveSiteId'; import Box from '@mui/material/Box'; import { useTheme } from '@mui/material/styles'; import useActiveUser from '../../hooks/useActiveUser'; export function PublishingDashboard(props) { var _a, _b; const { embedded, showAppsButton, onSubmittingAndOrPendingChange } = props; const user = useActiveUser(); const site = useActiveSiteId(); const userRoles = (_a = user === null || user === void 0 ? void 0 : user.rolesBySite[site]) !== null && _a !== void 0 ? _a : []; const userPermissions = (_b = user === null || user === void 0 ? void 0 : user.permissionsBySite[site]) !== null && _b !== void 0 ? _b : []; const allowedRole = userRoles.some((role) => role === 'developer' || role === 'admin'); const hasPublishPermission = userPermissions === null || userPermissions === void 0 ? void 0 : userPermissions.includes('publish'); const { spacing, palette: { mode } } = useTheme(); return React.createElement( Box, { component: 'section', sx: { bgcolor: `grey.${mode === 'light' ? 100 : 800}`, height: '100%' } }, !embedded && React.createElement(GlobalAppToolbar, { title: React.createElement(FormattedMessage, { id: 'publishingDashboard.title', defaultMessage: 'Publishing Dashboard' }), showAppsButton: showAppsButton }), React.createElement( Grid, { gap: 2, container: true, sx: Object.assign( { padding: spacing(2) }, embedded ? {} : { height: 'calc(100% - 65px)', overflowY: 'auto' } ) }, React.createElement(Grid, { item: true, xs: 12 }, React.createElement(PublishingStatusWidget, { siteId: site })), userPermissions.includes('get_publishing_queue') && React.createElement( Grid, { item: true, xs: 12 }, React.createElement(PublishingQueueWidget, { siteId: site, readOnly: !hasPublishPermission }) ), hasPublishPermission && React.createElement( Grid, { item: true, xs: 12 }, React.createElement(PublishOnDemandWidget, { siteId: site, mode: allowedRole ? null : 'everything', onSubmittingAndOrPendingChange: onSubmittingAndOrPendingChange }) ) ) ); } export default PublishingDashboard;