
* Bump Editor.js version * Refactor RichTextEditor to use react-editor-js wrapper * fixup! Bump Editor.js version * Rewrite RichTextEditor to use uncontrolled input * Fix RichTextEditorContent not rendering any content due to missing id * Fix RichTextEditorContent not working on initial render * Remove editorjs-undo * Refactor usage of RichTextEditor to get its data only during submit * Add useMultipleRichText hook for managing rich text attributes * fixup! Refactor usage of RichTextEditor to get its data only during submit * Rewrite Attributes usage to use EditorJS .save() on submit * Refactor RichTextContext into separate file * Rewrite tests for useRichText * Add PR changes to the changelog * Update snaphosts * Fix failing tests for components that use RichTextEditor * Remove duplicated getSubmitData function
88 lines
2.5 KiB
TypeScript
88 lines
2.5 KiB
TypeScript
import { Card, CardContent, TextField } from "@material-ui/core";
|
|
import CardTitle from "@saleor/components/CardTitle";
|
|
import FormSpacer from "@saleor/components/FormSpacer";
|
|
import RichTextEditor from "@saleor/components/RichTextEditor";
|
|
import { PageErrorFragment } from "@saleor/graphql";
|
|
import { commonMessages } from "@saleor/intl";
|
|
import { makeStyles } from "@saleor/macaw-ui";
|
|
import { getFormErrors } from "@saleor/utils/errors";
|
|
import getPageErrorMessage from "@saleor/utils/errors/page";
|
|
import { useRichTextContext } from "@saleor/utils/richText/context";
|
|
import React from "react";
|
|
import { useIntl } from "react-intl";
|
|
|
|
import { PageData } from "../PageDetailsPage/form";
|
|
|
|
export interface PageInfoProps {
|
|
data: PageData;
|
|
disabled: boolean;
|
|
errors: PageErrorFragment[];
|
|
onChange: (event: React.ChangeEvent<any>) => void;
|
|
}
|
|
|
|
const useStyles = makeStyles(
|
|
{
|
|
root: {
|
|
overflow: "visible"
|
|
}
|
|
},
|
|
{ name: "PageInfo" }
|
|
);
|
|
|
|
const PageInfo: React.FC<PageInfoProps> = props => {
|
|
const { data, disabled, errors, onChange } = props;
|
|
|
|
const classes = useStyles(props);
|
|
const intl = useIntl();
|
|
|
|
const {
|
|
defaultValue,
|
|
editorRef,
|
|
isReadyForMount,
|
|
handleChange
|
|
} = useRichTextContext();
|
|
const formErrors = getFormErrors(["title", "content"], errors);
|
|
|
|
return (
|
|
<Card className={classes.root}>
|
|
<CardTitle
|
|
title={intl.formatMessage(commonMessages.generalInformations)}
|
|
/>
|
|
<CardContent>
|
|
<TextField
|
|
disabled={disabled}
|
|
error={!!formErrors.title}
|
|
fullWidth
|
|
helperText={getPageErrorMessage(formErrors.title, intl)}
|
|
label={intl.formatMessage({
|
|
id: "gr+oXW",
|
|
defaultMessage: "Title",
|
|
description: "page title"
|
|
})}
|
|
name={"title" as keyof PageData}
|
|
value={data.title}
|
|
onChange={onChange}
|
|
/>
|
|
<FormSpacer />
|
|
{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}
|
|
/>
|
|
)}
|
|
</CardContent>
|
|
</Card>
|
|
);
|
|
};
|
|
PageInfo.displayName = "PageInfo";
|
|
export default PageInfo;
|