@craftercms/studio-ui
Version:
Services, components, models & utils to build CrafterCMS authoring extensions.
191 lines (189 loc) • 7.25 kB
JavaScript
/*
* 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 { FormattedMessage } from 'react-intl';
import DialogBody from '../DialogBody/DialogBody';
import Grid from '@mui/material/Grid';
import FormControl from '@mui/material/FormControl';
import InputLabel from '@mui/material/InputLabel';
import Select from '@mui/material/Select';
import MenuItem from '@mui/material/MenuItem';
import TextFieldWithMax from '../TextFieldWithMax/TextFieldWithMax';
import DialogFooter from '../DialogFooter/DialogFooter';
import SecondaryButton from '../SecondaryButton';
import PrimaryButton from '../PrimaryButton';
import React from 'react';
import { RejectDialogContentUI } from './RejectDialogContentUI';
import Typography from '@mui/material/Typography';
import Alert from '@mui/material/Alert';
import { nnou } from '../../utils/object';
import { LoadingState } from '../LoadingState';
import { ApiResponseErrorState } from '../ApiResponseErrorState';
import { EmptyState } from '../EmptyState';
import { useStyles } from './styles';
export function RejectDialogUI(props) {
const {
items,
cannedMessages,
published,
checkedItems,
rejectionReason,
rejectionComment,
error,
onRejectionReasonChange,
onCommentChange,
onUpdateChecked,
onCloseButtonClick,
onReject,
isSubmitting,
isSubmitDisabled
} = props;
const { classes } = useStyles();
return React.createElement(
React.Fragment,
null,
React.createElement(
DialogBody,
{ id: 'confirmDialogBody' },
React.createElement(
Grid,
{ container: true, spacing: 3 },
React.createElement(
Grid,
{ item: true, xs: 12, sm: 7, md: 7, lg: 7, xl: 7 },
error
? React.createElement(ApiResponseErrorState, { error: error })
: !Boolean(items && nnou(published) && cannedMessages)
? React.createElement(LoadingState, null)
: items.length > 0
? published
? React.createElement(RejectDialogContentUI, {
items: items,
checkedItems: checkedItems,
onUpdateChecked: onUpdateChecked,
classes: classes
})
: React.createElement(
Alert,
{ severity: 'warning' },
React.createElement(FormattedMessage, {
id: 'rejectDialog.firstPublish',
defaultMessage:
'The entire project publish will be rejected since this is the first publish request'
})
)
: React.createElement(EmptyState, {
title: React.createElement(FormattedMessage, {
id: 'rejectDialog.noItemsSelected',
defaultMessage: 'There are no files to reject'
})
})
),
React.createElement(
Grid,
{ item: true, xs: 12, sm: 5, md: 5, lg: 5, xl: 5 },
React.createElement(
'form',
null,
React.createElement(
FormControl,
{ fullWidth: true, variant: 'outlined' },
React.createElement(
InputLabel,
{ shrink: true },
React.createElement(FormattedMessage, {
id: 'rejectDialog.predefinedRejectionComments',
defaultMessage: 'Predefined Rejection Comments'
})
),
React.createElement(
Select,
{
fullWidth: true,
label: React.createElement(FormattedMessage, {
id: 'rejectDialog.predefinedRejectionComments',
defaultMessage: 'Predefined Rejection Comments'
}),
autoFocus: true,
value: rejectionReason,
onChange: (e) => onRejectionReasonChange(e.target.value)
},
React.createElement(
MenuItem,
{ value: 'typeCustomReason' },
React.createElement(FormattedMessage, {
id: 'rejectDialog.typeMyOwnComment',
defaultMessage: 'Type my own comment'
})
),
cannedMessages?.map((message) =>
React.createElement(
MenuItem,
{ value: message.key, key: message.key },
React.createElement(Typography, null, message.title)
)
)
)
),
React.createElement(TextFieldWithMax, {
required: true,
className: classes.submissionTextField,
label: React.createElement(FormattedMessage, {
id: 'rejectDialog.rejectCommentLabel',
defaultMessage: 'Rejection Comment'
}),
fullWidth: true,
multiline: true,
rows: 8,
value: rejectionComment,
onChange: (e) => onCommentChange(e.target.value)
})
)
)
)
),
React.createElement(
DialogFooter,
null,
onCloseButtonClick &&
React.createElement(
SecondaryButton,
{ onClick: onCloseButtonClick, disabled: isSubmitting },
React.createElement(FormattedMessage, { id: 'rejectDialog.cancel', defaultMessage: 'Cancel' })
),
onReject &&
React.createElement(
PrimaryButton,
{ onClick: onReject, loading: isSubmitting, disabled: isSubmitDisabled },
React.createElement(FormattedMessage, { id: 'rejectDialog.continue', defaultMessage: 'Reject' })
)
)
);
}