2021-05-14 08:15:15 +00:00
|
|
|
import { Card, CardContent, TextField } from "@material-ui/core";
|
2019-06-19 14:40:52 +00:00
|
|
|
import CardTitle from "@saleor/components/CardTitle";
|
|
|
|
import FormSpacer from "@saleor/components/FormSpacer";
|
2022-05-26 08:06:46 +00:00
|
|
|
import RichTextEditor from "@saleor/components/RichTextEditor";
|
2022-03-09 08:56:55 +00:00
|
|
|
import { PageErrorFragment } from "@saleor/graphql";
|
2019-08-26 17:48:13 +00:00
|
|
|
import { commonMessages } from "@saleor/intl";
|
2021-07-21 08:59:52 +00:00
|
|
|
import { makeStyles } from "@saleor/macaw-ui";
|
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";
|
2022-05-26 08:06:46 +00:00
|
|
|
import { useRichTextContext } from "@saleor/utils/richText/context";
|
2020-05-14 09:30:32 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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 => {
|
2022-05-26 08:06:46 +00:00
|
|
|
const { data, disabled, errors, 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();
|
|
|
|
|
2022-05-26 08:06:46 +00:00
|
|
|
const {
|
|
|
|
defaultValue,
|
|
|
|
editorRef,
|
|
|
|
isReadyForMount,
|
|
|
|
handleChange
|
|
|
|
} = useRichTextContext();
|
2021-01-22 11:13:40 +00:00
|
|
|
const formErrors = getFormErrors(["title", "content"], errors);
|
2020-03-17 10:57:02 +00:00
|
|
|
|
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({
|
2022-05-05 07:54:28 +00:00
|
|
|
id: "gr+oXW",
|
2019-10-30 14:34:24 +00:00
|
|
|
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 />
|
2022-05-26 08:06:46 +00:00
|
|
|
{isReadyForMount && (
|
|
|
|
<RichTextEditor
|
|
|
|
defaultValue={defaultValue}
|
|
|
|
editorRef={editorRef}
|
|
|
|
onChange={handleChange}
|
|
|
|
disabled={disabled}
|
|
|
|
error={!!formErrors.content}
|
|
|
|
helperText={getPageErrorMessage(formErrors.content, intl)}
|
|
|
|
label={intl.formatMessage({
|
|
|
|
id: "gMwpNC",
|
|
|
|
defaultMessage: "Content",
|
|
|
|
description: "page content"
|
|
|
|
})}
|
|
|
|
name={"content" as keyof PageData}
|
|
|
|
/>
|
|
|
|
)}
|
2019-10-30 14:34:24 +00:00
|
|
|
</CardContent>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
PageInfo.displayName = "PageInfo";
|
|
|
|
export default PageInfo;
|