2019-06-19 14:40:52 +00:00
|
|
|
import Card from "@material-ui/core/Card";
|
|
|
|
import CardContent from "@material-ui/core/CardContent";
|
2019-10-30 14:34:24 +00:00
|
|
|
import { makeStyles } from "@material-ui/core/styles";
|
2019-06-19 14:40:52 +00:00
|
|
|
import TextField from "@material-ui/core/TextField";
|
|
|
|
import CardTitle from "@saleor/components/CardTitle";
|
|
|
|
import FormSpacer from "@saleor/components/FormSpacer";
|
|
|
|
import RichTextEditor from "@saleor/components/RichTextEditor";
|
2020-07-07 10:14:12 +00:00
|
|
|
import { PageErrorFragment } from "@saleor/fragments/types/PageErrorFragment";
|
2019-08-26 17:48:13 +00:00
|
|
|
import { commonMessages } from "@saleor/intl";
|
2020-05-14 09:30:32 +00:00
|
|
|
import { getFormErrors } from "@saleor/utils/errors";
|
2020-03-17 10:57:02 +00:00
|
|
|
import getPageErrorMessage from "@saleor/utils/errors/page";
|
2020-05-14 09:30:32 +00:00
|
|
|
import React from "react";
|
|
|
|
import { useIntl } from "react-intl";
|
|
|
|
|
2019-06-19 14:40:52 +00:00
|
|
|
import { maybe } from "../../../misc";
|
|
|
|
import { PageDetails_page } from "../../types/PageDetails";
|
|
|
|
import { FormData } from "../PageDetailsPage";
|
|
|
|
|
|
|
|
export interface PageInfoProps {
|
|
|
|
data: FormData;
|
|
|
|
disabled: boolean;
|
2020-03-17 10:57:02 +00:00
|
|
|
errors: PageErrorFragment[];
|
2019-06-19 14:40:52 +00:00
|
|
|
page: PageDetails_page;
|
|
|
|
onChange: (event: React.ChangeEvent<any>) => void;
|
|
|
|
}
|
|
|
|
|
2019-12-03 15:28:40 +00:00
|
|
|
const useStyles = makeStyles(
|
|
|
|
{
|
|
|
|
root: {
|
|
|
|
overflow: "visible"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ name: "PageInfo" }
|
|
|
|
);
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
const PageInfo: React.FC<PageInfoProps> = props => {
|
|
|
|
const { data, disabled, errors, page, onChange } = props;
|
2019-08-26 17:48:13 +00:00
|
|
|
|
2020-03-17 10:57:02 +00:00
|
|
|
const classes = useStyles(props);
|
2019-10-30 14:34:24 +00:00
|
|
|
const intl = useIntl();
|
|
|
|
|
2020-03-17 10:57:02 +00:00
|
|
|
const formErrors = getFormErrors(["title", "contentJson"], errors);
|
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
return (
|
|
|
|
<Card className={classes.root}>
|
|
|
|
<CardTitle
|
|
|
|
title={intl.formatMessage(commonMessages.generalInformations)}
|
|
|
|
/>
|
|
|
|
<CardContent>
|
|
|
|
<TextField
|
|
|
|
disabled={disabled}
|
2020-03-17 10:57:02 +00:00
|
|
|
error={!!formErrors.title}
|
2019-10-30 14:34:24 +00:00
|
|
|
fullWidth
|
2020-03-17 10:57:02 +00:00
|
|
|
helperText={getPageErrorMessage(formErrors.title, intl)}
|
2019-10-30 14:34:24 +00:00
|
|
|
label={intl.formatMessage({
|
|
|
|
defaultMessage: "Title",
|
|
|
|
description: "page title"
|
|
|
|
})}
|
|
|
|
name={"title" as keyof FormData}
|
|
|
|
value={data.title}
|
|
|
|
onChange={onChange}
|
2019-06-19 14:40:52 +00:00
|
|
|
/>
|
2019-10-30 14:34:24 +00:00
|
|
|
<FormSpacer />
|
|
|
|
<RichTextEditor
|
|
|
|
disabled={disabled}
|
2020-03-17 10:57:02 +00:00
|
|
|
error={!!formErrors.contentJson}
|
|
|
|
helperText={getPageErrorMessage(formErrors.contentJson, intl)}
|
2019-10-30 14:34:24 +00:00
|
|
|
initial={maybe(() => JSON.parse(page.contentJson))}
|
|
|
|
label={intl.formatMessage({
|
|
|
|
defaultMessage: "Content",
|
|
|
|
description: "page content"
|
|
|
|
})}
|
|
|
|
name={"content" as keyof FormData}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
</CardContent>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
PageInfo.displayName = "PageInfo";
|
|
|
|
export default PageInfo;
|