@craftercms/studio-ui
Version:
Services, components, models & utils to build CrafterCMS authoring extensions.
206 lines (204 loc) • 7.6 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, useIntl } from 'react-intl';
import DialogBody from '../DialogBody/DialogBody';
import Grid from '@mui/material/Grid';
import TextField from '@mui/material/TextField';
import DialogFooter from '../DialogFooter/DialogFooter';
import SecondaryButton from '../SecondaryButton';
import PrimaryButton from '../PrimaryButton';
import React from 'react';
import { translations } from './translations';
import { useSiteDialogStyles } from './styles';
import Card from '@mui/material/Card';
import CardMedia from '@mui/material/CardMedia';
import CardActions from '@mui/material/CardActions';
import IconButton from '@mui/material/IconButton';
import EditRoundedIcon from '@mui/icons-material/EditRounded';
import Tooltip from '@mui/material/Tooltip';
export function EditSiteDialogUI(props) {
const {
siteId,
siteName,
siteDescription,
siteImage,
onSiteNameChange,
onSiteDescriptionChange,
submitting,
submitDisabled,
fallbackImageSrc,
onKeyPress,
onSubmit,
onCloseButtonClick,
onEditSiteImage
} = props;
const { formatMessage } = useIntl();
const { classes } = useSiteDialogStyles();
return React.createElement(
React.Fragment,
null,
React.createElement(
DialogBody,
null,
React.createElement(
Grid,
{ container: true, spacing: 2 },
React.createElement(
Grid,
{ item: true, sm: 7 },
React.createElement(
Grid,
{ container: true, spacing: 1, component: 'form' },
React.createElement(
Grid,
{ item: true, xs: 12 },
React.createElement(TextField, {
autoFocus: true,
fullWidth: true,
id: 'name',
name: 'name',
label: React.createElement(FormattedMessage, {
id: 'editSiteDialog.siteName',
defaultMessage: 'Project Name'
}),
onChange: (event) => onSiteNameChange(event),
onKeyPress: onKeyPress,
value: siteName,
inputProps: { maxLength: 255 },
error: submitDisabled,
helperText:
// prettier-ignore
!siteName.trim()
? formatMessage(translations.siteNameRequired)
: submitDisabled
? formatMessage(translations.siteNameExists)
: ''
})
),
React.createElement(
Grid,
{ item: true, xs: 12 },
React.createElement(TextField, {
id: 'siteId',
name: 'id',
label: React.createElement(FormattedMessage, {
id: 'editSiteDialog.siteId',
defaultMessage: 'Project ID'
}),
fullWidth: true,
value: siteId,
disabled: true,
helperText: React.createElement(FormattedMessage, {
id: 'editSiteDialog.notEditable',
defaultMessage: 'The project id is not editable'
})
})
),
React.createElement(
Grid,
{ item: true, xs: 12 },
React.createElement(TextField, {
id: 'description',
name: 'description',
label: React.createElement(FormattedMessage, {
id: 'editSiteDialog.siteDescription',
defaultMessage: 'Project Description'
}),
fullWidth: true,
multiline: true,
onChange: (event) => onSiteDescriptionChange(event.target.value),
onKeyPress: (e) => {
// This behaviour is kind of backwards from how it's usually seen in text editors.
// Perhaps we should flip it to shift/ctrl + enter creating new lines and only enter submitting?
if (e.key !== 'Enter' || e.ctrlKey || e.shiftKey) {
onKeyPress === null || onKeyPress === void 0 ? void 0 : onKeyPress(e);
}
},
value: siteDescription !== null && siteDescription !== void 0 ? siteDescription : '',
inputProps: { maxLength: 4000 }
})
)
)
),
React.createElement(
Grid,
{ item: true, sm: 5 },
React.createElement(
Card,
null,
React.createElement(CardMedia, {
component: 'img',
image: siteImage,
title: siteName,
className: classes.media,
onError: (event) => (event.target.src = fallbackImageSrc)
}),
React.createElement(
CardActions,
{ className: classes.cardActions, disableSpacing: true },
React.createElement(
Tooltip,
{ title: React.createElement(FormattedMessage, { id: 'words.edit', defaultMessage: 'Edit' }) },
React.createElement(
IconButton,
{ onClick: onEditSiteImage },
React.createElement(EditRoundedIcon, null)
)
)
)
)
)
)
),
React.createElement(
DialogFooter,
null,
onCloseButtonClick &&
React.createElement(
SecondaryButton,
{ onClick: onCloseButtonClick, variant: 'contained' },
React.createElement(FormattedMessage, { id: 'editSiteDialog.cancel', defaultMessage: 'Cancel' })
),
onSubmit &&
React.createElement(
PrimaryButton,
{
onClick: () => onSubmit(),
variant: 'contained',
color: 'primary',
loading: submitting,
disabled: submitting || submitDisabled
},
React.createElement(FormattedMessage, { id: 'words.submit', defaultMessage: 'Submit' })
)
)
);
}