saleor-dashboard/src/pages/components/PageInfo/PageInfo.tsx

82 lines
2.4 KiB
TypeScript
Raw Normal View History

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";
2020-11-04 10:48:49 +00:00
import RichTextEditor, {
RichTextEditorChange
} from "@saleor/components/RichTextEditor";
import { PageErrorFragment } from "@saleor/fragments/types/PageErrorFragment";
import { commonMessages } from "@saleor/intl";
import { getFormErrors } from "@saleor/utils/errors";
2020-03-17 10:57:02 +00:00
import getPageErrorMessage from "@saleor/utils/errors/page";
import React from "react";
import { useIntl } from "react-intl";
2020-11-04 10:48:49 +00:00
import { PageData } from "../PageDetailsPage/form";
2019-06-19 14:40:52 +00:00
export interface PageInfoProps {
2020-11-04 10:48:49 +00:00
data: PageData;
2019-06-19 14:40:52 +00:00
disabled: boolean;
2020-03-17 10:57:02 +00:00
errors: PageErrorFragment[];
2019-06-19 14:40:52 +00:00
onChange: (event: React.ChangeEvent<any>) => void;
2020-11-04 10:48:49 +00:00
onContentChange: RichTextEditorChange;
2019-06-19 14:40:52 +00:00
}
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 => {
2020-11-04 10:48:49 +00:00
const { data, disabled, errors, onChange, onContentChange } = props;
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"
})}
2020-11-04 10:48:49 +00:00
name={"title" as keyof PageData}
2019-10-30 14:34:24 +00:00
value={data.title}
onChange={onChange}
2019-06-19 14:40:52 +00:00
/>
2019-10-30 14:34:24 +00:00
<FormSpacer />
<RichTextEditor
2020-11-04 10:48:49 +00:00
data={data.content}
2019-10-30 14:34:24 +00:00
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
label={intl.formatMessage({
defaultMessage: "Content",
description: "page content"
})}
2020-11-04 10:48:49 +00:00
name={"content" as keyof PageData}
onChange={onContentChange}
2019-10-30 14:34:24 +00:00
/>
</CardContent>
</Card>
);
};
2019-06-19 14:40:52 +00:00
PageInfo.displayName = "PageInfo";
export default PageInfo;