UNPKG

@craftercms/studio-ui

Version:

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

165 lines (163 loc) 6.3 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 React, { useEffect, useMemo } from 'react'; import { useSpreadStateWithSelected } from '../SiteDashboard/utils'; import DashletCard from '../DashletCard/DashletCard'; import { DashletEmptyMessage, DenseCheckbox, getItemSkeleton, List, ListItem, ListItemIcon } from '../DashletCard/dashletCommons'; import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; import palette from '../../styles/palette'; import Typography from '@mui/material/Typography'; import ListItemText from '@mui/material/ListItemText'; import Checkbox from '@mui/material/Checkbox'; import { fetchPendingApproval } from '../../services/dashboard'; import useActiveSiteId from '../../hooks/useActiveSiteId'; import { LIVE_COLOUR, STAGING_COLOUR } from '../ItemPublishingTargetIcon/styles'; import IconButton from '@mui/material/IconButton'; import { RefreshRounded } from '@mui/icons-material'; const messages = defineMessages({ staging: { id: 'words.staging', defaultMessage: 'Staging' }, live: { id: 'words.live', defaultMessage: 'Live' } }); export function PendingApprovalDashlet(props) { const { borderLeftColor = palette.purple.tint } = props; const [{ items, total, loading, isAllSelected }, setState, onSelectItem, onSelectAll, isSelected] = useSpreadStateWithSelected({ items: null, total: null, loading: false, selected: {}, isAllSelected: false, hasSelected: false }); const site = useActiveSiteId(); const { formatMessage } = useIntl(); const onRefresh = useMemo( () => () => { setState({ items: null, loading: true }); fetchPendingApproval(site, { limit: 10, offset: 0 }).subscribe((items) => { setState({ items: items, total: items.total, loading: false }); }); }, [setState, site] ); useEffect(() => { onRefresh(); }, [onRefresh]); return React.createElement( DashletCard, Object.assign({}, props, { borderLeftColor: borderLeftColor, title: React.createElement(FormattedMessage, { id: 'pendingApprovalDashlet.widgetTitle', defaultMessage: 'Pending Approval <render_total>{total}</render_total>', values: { total, render_total(total) { return total ? `(${total})` : ''; } } }), actionsBar: React.createElement( React.Fragment, null, React.createElement(DenseCheckbox, { checked: isAllSelected, onChange: onSelectAll }) ), headerAction: React.createElement(IconButton, { onClick: onRefresh }, React.createElement(RefreshRounded, null)) }), loading && getItemSkeleton({ numOfItems: 3, showAvatar: true, showCheckbox: true }), Boolean(items === null || items === void 0 ? void 0 : items.length) && React.createElement( List, null, items.map((item, index) => React.createElement( ListItem, { key: index }, React.createElement( ListItemIcon, null, React.createElement(Checkbox, { edge: 'start', checked: isSelected(item), onChange: (e) => onSelectItem(e, item) }) ), React.createElement(ListItemText, { primary: React.createElement(FormattedMessage, { id: 'pendingApprovalDashlet.entryPrimaryText', defaultMessage: '{name} submitted to <render_target>{publishingTarget}</render_target>', values: { name: item.sandbox.modifier, publishingTarget: item.stateMap.submittedToLive ? 'live' : 'staging', render_target(target) { return React.createElement( Typography, { component: 'span', fontWeight: 'bold', color: target[0] === 'live' ? LIVE_COLOUR : STAGING_COLOUR }, messages[target[0]] ? formatMessage(messages[target[0]]).toLowerCase() : target[0] ); } } }), secondary: React.createElement( Typography, { color: 'text.secondary', variant: 'body2' }, React.createElement(FormattedMessage, { id: 'pendingApprovalDashlet.noSubmissionCommentAvailable', defaultMessage: 'Submission comment not provided' }) ) }) ) ) ), total === 0 && React.createElement( DashletEmptyMessage, null, React.createElement(FormattedMessage, { id: 'pendingApprovalDashlet.noPendingItems', defaultMessage: 'There are no items pending approval' }) ) ); } export default PendingApprovalDashlet;