Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Fix types

dominik-zeglen01a932742003
diff --git a/saleor/static/dashboard-next/categories/components/CategoryCreatePage/CategoryCreatePage.tsx b/saleor/static/dashboard-next/categories/components/CategoryCreatePage/CategoryCreatePage.tsx
index d5c3befecf..ee50650a04 100644
--- a/saleor/static/dashboard-next/categories/components/CategoryCreatePage/CategoryCreatePage.tsx
+++ b/saleor/static/dashboard-next/categories/components/CategoryCreatePage/CategoryCreatePage.tsx
@@ -1,26 +1,26 @@
+import { RawDraftContentState } from "draft-js";
import * as React from "react";
import { CardSpacer } from "../../../components/CardSpacer";
+import { ConfirmButtonTransitionState } from "../../../components/ConfirmButton/ConfirmButton";
import Container from "../../../components/Container";
import Form from "../../../components/Form";
import PageHeader from "../../../components/PageHeader";
+import SaveButtonBar from "../../../components/SaveButtonBar/SaveButtonBar";
import SeoForm from "../../../components/SeoForm";
import i18n from "../../../i18n";
import { UserError } from "../../../types";
import CategoryDetailsForm from "../../components/CategoryDetailsForm";
-import { ConfirmButtonTransitionState } from "../../../components/ConfirmButton/ConfirmButton";
-import SaveButtonBar from "../../../components/SaveButtonBar/SaveButtonBar";
-
interface FormData {
- description: string;
+ description: RawDraftContentState;
name: string;
seoTitle: string;
seoDescription: string;
}
const initialData: FormData = {
- description: "",
+ description: {} as any,
name: "",
seoDescription: "",
seoTitle: ""
@@ -67,7 +67,7 @@ export const CategoryCreatePage: React.StatelessComponent<
title={data.seoTitle}
titlePlaceholder={data.name}
description={data.seoDescription}
- descriptionPlaceholder={data.description}
+ descriptionPlaceholder={data.name}
loading={disabled}
onChange={change}
disabled={disabled}
diff --git a/saleor/static/dashboard-next/categories/components/CategoryDetailsForm/CategoryDetailsForm.tsx b/saleor/static/dashboard-next/categories/components/CategoryDetailsForm/CategoryDetailsForm.tsx
index 1f68db5904..04ed2c967c 100644
--- a/saleor/static/dashboard-next/categories/components/CategoryDetailsForm/CategoryDetailsForm.tsx
+++ b/saleor/static/dashboard-next/categories/components/CategoryDetailsForm/CategoryDetailsForm.tsx
@@ -2,11 +2,12 @@ import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
import { createStyles, withStyles, WithStyles } from "@material-ui/core/styles";
import TextField from "@material-ui/core/TextField";
+import { RawDraftContentState } from "draft-js";
import * as React from "react";
import CardTitle from "../../../components/CardTitle";
import FormSpacer from "../../../components/FormSpacer";
-import { RichTextEditor } from "../../../components/RichTextEditor";
+import RichTextEditor from "../../../components/RichTextEditor";
import i18n from "../../../i18n";
const styles = createStyles({
@@ -18,7 +19,7 @@ const styles = createStyles({
interface CategoryDetailsFormProps extends WithStyles<typeof styles> {
data: {
name: string;
- description: string;
+ description: RawDraftContentState;
};
disabled: boolean;
errors: { [key: string]: string };
@@ -50,16 +51,9 @@ export const CategoryDetailsForm = withStyles(styles, {
<RichTextEditor
disabled={disabled}
label={i18n.t("Description")}
- fullWidth
- helperText={
- errors.description
- ? errors.description
- : i18n.t("Select text to enable text-formatting tools.")
- }
+ initial={data.description}
name="description"
- value={data.description}
onChange={onChange}
- error={!!errors.description}
/>
</>
</CardContent>
diff --git a/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx b/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx
index 845dd879f3..34a62cd8c0 100644
--- a/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx
+++ b/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx
@@ -1,3 +1,4 @@
+import { RawDraftContentState } from "draft-js";
import * as React from "react";
import { CardSpacer } from "../../../components/CardSpacer";
@@ -24,7 +25,7 @@ import CategoryProductsCard from "../CategoryProductsCard";
export interface FormData {
backgroundImageAlt: string;
- description: string;
+ description: RawDraftContentState;
name: string;
seoTitle: string;
seoDescription: string;
@@ -91,7 +92,7 @@ export const CategoryUpdatePage: React.StatelessComponent<
const initialData: FormData = category
? {
backgroundImageAlt: maybe(() => category.backgroundImage.alt, ""),
- description: category.description || "",
+ description: maybe(() => JSON.parse(category.description)),
name: category.name || "",
seoDescription: category.seoDescription || "",
seoTitle: category.seoTitle || ""
@@ -138,7 +139,7 @@ export const CategoryUpdatePage: React.StatelessComponent<
title={data.seoTitle}
titlePlaceholder={data.name}
description={data.seoDescription}
- descriptionPlaceholder={data.description}
+ descriptionPlaceholder={data.name}
loading={!category}
onChange={change}
disabled={disabled}
diff --git a/saleor/static/dashboard-next/categories/views/CategoryCreate.tsx b/saleor/static/dashboard-next/categories/views/CategoryCreate.tsx
index 0e7b0f09c0..6c9292efa6 100644
--- a/saleor/static/dashboard-next/categories/views/CategoryCreate.tsx
+++ b/saleor/static/dashboard-next/categories/views/CategoryCreate.tsx
@@ -55,7 +55,7 @@ export const CategoryCreateView: React.StatelessComponent<
createCategory({
variables: {
input: {
- description: formData.description,
+ description: JSON.stringify(formData.description),
name: formData.name,
seo: {
description: formData.seoDescription,
diff --git a/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx b/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx
index 530820afc7..b4eb3697d5 100644
--- a/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx
+++ b/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx
@@ -187,7 +187,9 @@ export const CategoryDetails: React.StatelessComponent<
input: {
backgroundImageAlt:
formData.backgroundImageAlt,
- description: formData.description,
+ description: JSON.stringify(
+ formData.description
+ ),
name: formData.name,
seo: {
description:
diff --git a/saleor/static/dashboard-next/collections/components/CollectionCreatePage/CollectionCreatePage.tsx b/saleor/static/dashboard-next/collections/components/CollectionCreatePage/CollectionCreatePage.tsx
index cee6217e57..6ae031219f 100644
--- a/saleor/static/dashboard-next/collections/components/CollectionCreatePage/CollectionCreatePage.tsx
+++ b/saleor/static/dashboard-next/collections/components/CollectionCreatePage/CollectionCreatePage.tsx
@@ -1,5 +1,6 @@
import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
+import { RawDraftContentState } from "draft-js";
import * as React from "react";
import { CardSpacer } from "../../../components/CardSpacer";
@@ -23,7 +24,7 @@ export interface CollectionCreatePageFormData {
value: string;
};
backgroundImageAlt: string;
- description: string;
+ description: RawDraftContentState;
name: string;
isPublished: boolean;
seoDescription: string;
@@ -44,7 +45,7 @@ const initialForm: CollectionCreatePageFormData = {
value: null
},
backgroundImageAlt: "",
- description: "",
+ description: {} as any,
isPublished: false,
name: "",
seoDescription: "",
diff --git a/saleor/static/dashboard-next/collections/components/CollectionDetails/CollectionDetails.tsx b/saleor/static/dashboard-next/collections/components/CollectionDetails/CollectionDetails.tsx
index a478c7d5cb..49eee46f52 100644
--- a/saleor/static/dashboard-next/collections/components/CollectionDetails/CollectionDetails.tsx
+++ b/saleor/static/dashboard-next/collections/components/CollectionDetails/CollectionDetails.tsx
@@ -2,6 +2,7 @@ import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
import { createStyles, withStyles, WithStyles } from "@material-ui/core/styles";
import TextField from "@material-ui/core/TextField";
+import { RawDraftContentState } from "draft-js";
import * as React from "react";
import CardTitle from "../../../components/CardTitle";
@@ -17,12 +18,11 @@ const styles = createStyles({
export interface CollectionDetailsProps extends WithStyles<typeof styles> {
data: {
- description: string;
+ description: RawDraftContentState;
name: string;
};
disabled: boolean;
errors: {
- description?: string;
name?: string;
};
onChange: (event: React.ChangeEvent<any>) => void;
@@ -47,16 +47,9 @@ const CollectionDetails = withStyles(styles, { name: "CollectionDetails" })(
<RichTextEditor
label={i18n.t("Description")}
name="description"
+ initial={data.description}
disabled={disabled}
- value={data.description}
onChange={onChange}
- error={!!errors.name}
- helperText={
- !!errors.name
- ? errors.name
- : i18n.t("Select text to enable text-formatting tools.")
- }
- fullWidth
/>
</CardContent>
</Card>
diff --git a/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx b/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx
index f8d71b8a77..60bbab622d 100644
--- a/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx
+++ b/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx
@@ -1,3 +1,4 @@
+import { RawDraftContentState } from "draft-js";
import * as React from "react";
import { CardSpacer } from "../../../components/CardSpacer";
@@ -19,7 +20,7 @@ import CollectionStatus from "../CollectionStatus/CollectionStatus";
export interface CollectionDetailsPageFormData {
backgroundImageAlt: string;
- description: string;
+ description: RawDraftContentState;
name: string;
seoDescription: string;
seoTitle: string;
@@ -56,7 +57,7 @@ const CollectionDetailsPage: React.StatelessComponent<
<Form
initial={{
backgroundImageAlt: maybe(() => collection.backgroundImage.alt, ""),
- description: maybe(() => collection.description, ""),
+ description: maybe(() => JSON.parse(collection.description), {}),
isFeatured,
isPublished: maybe(() => collection.isPublished, false),
name: maybe(() => collection.name, ""),
diff --git a/saleor/static/dashboard-next/collections/views/CollectionCreate.tsx b/saleor/static/dashboard-next/collections/views/CollectionCreate.tsx
index 4f1cd0b20d..5b916f545f 100644
--- a/saleor/static/dashboard-next/collections/views/CollectionCreate.tsx
+++ b/saleor/static/dashboard-next/collections/views/CollectionCreate.tsx
@@ -60,7 +60,7 @@ export const CollectionCreate: React.StatelessComponent<{}> = () => (
input: {
backgroundImage: formData.backgroundImage.value,
backgroundImageAlt: formData.backgroundImageAlt,
- description: formData.description,
+ description: JSON.stringify(formData.description),
isPublished: formData.isPublished,
name: formData.name,
seo: {
diff --git a/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx b/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx
index 7efa8c099c..9b91ed108c 100644
--- a/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx
+++ b/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx
@@ -152,12 +152,18 @@ export const CollectionDetails: React.StatelessComponent<
updateCollectionWithHomepage.mutate({
homepageId: formData.isFeatured ? id : null,
id,
- input
+ input: {
+ ...input,
+ description: JSON.stringify(input.description)
+ }
});
} else {
updateCollection.mutate({
id,
- input
+ input: {
+ ...input,
+ description: JSON.stringify(input.description)
+ }
});
}
};
diff --git a/saleor/static/dashboard-next/pages/components/PageDetailsPage/PageDetailsPage.tsx b/saleor/static/dashboard-next/pages/components/PageDetailsPage/PageDetailsPage.tsx
index 16f360e0a7..4dcda7c66d 100644
--- a/saleor/static/dashboard-next/pages/components/PageDetailsPage/PageDetailsPage.tsx
+++ b/saleor/static/dashboard-next/pages/components/PageDetailsPage/PageDetailsPage.tsx
@@ -1,3 +1,4 @@
+import { RawDraftContentState } from "draft-js";
import * as React from "react";
import CardSpacer from "../../../components/CardSpacer";
@@ -16,7 +17,7 @@ import PageSlug from "../PageSlug";
export interface FormData {
availableOn: string;
- content: string;
+ content: RawDraftContentState;
isVisible: boolean;
seoDescription: string;
seoTitle: string;
@@ -43,7 +44,7 @@ const PageDetailsPage: React.StatelessComponent<PageDetailsPageProps> = ({
}) => {
const initialForm: FormData = {
availableOn: maybe(() => page.availableOn, ""),
- content: maybe(() => page.content, ""),
+ content: maybe(() => JSON.parse(page.content)),
isVisible: maybe(() => page.isVisible, false),
seoDescription: maybe(() => page.seoDescription, ""),
seoTitle: maybe(() => page.seoTitle, ""),
diff --git a/saleor/static/dashboard-next/pages/components/PageInfo/PageInfo.tsx b/saleor/static/dashboard-next/pages/components/PageInfo/PageInfo.tsx
index 44b6bce1bf..d4571ce591 100644
--- a/saleor/static/dashboard-next/pages/components/PageInfo/PageInfo.tsx
+++ b/saleor/static/dashboard-next/pages/components/PageInfo/PageInfo.tsx
@@ -12,7 +12,7 @@ import { FormData } from "../PageDetailsPage";
export interface PageInfoProps {
data: FormData;
disabled: boolean;
- errors: Partial<Record<"title" | "content", string>>;
+ errors: Partial<Record<"title", string>>;
onChange: (event: React.ChangeEvent<any>) => void;
}
@@ -38,7 +38,7 @@ const PageInfo: React.StatelessComponent<PageInfoProps> = ({
<FormSpacer />
<RichTextEditor
disabled={disabled}
- initial={JSON.parse(data.content)}
+ initial={data.content}
label={i18n.t("Content")}
name={"content" as keyof FormData}
onChange={onChange}
diff --git a/saleor/static/dashboard-next/pages/fixtures.ts b/saleor/static/dashboard-next/pages/fixtures.ts
index 92065ec4a2..ab4139b4c6 100644
--- a/saleor/static/dashboard-next/pages/fixtures.ts
+++ b/saleor/static/dashboard-next/pages/fixtures.ts
@@ -1,3 +1,4 @@
+import { content } from "../storybook/stories/components/RichTextEditor";
import { PageDetails_page } from "./types/PageDetails";
import { PageList_pages_edges_node } from "./types/PageList";
@@ -34,7 +35,7 @@ export const pageList: PageList_pages_edges_node[] = [
export const page: PageDetails_page = {
__typename: "Page",
availableOn: "",
- content: "",
+ content: JSON.stringify(content),
id: "Kzx152sEm==",
isVisible: false,
seoDescription: "About",
diff --git a/saleor/static/dashboard-next/products/components/ProductCreatePage/ProductCreatePage.tsx b/saleor/static/dashboard-next/products/components/ProductCreatePage/ProductCreatePage.tsx
index 8c30a77805..e2857a7952 100644
--- a/saleor/static/dashboard-next/products/components/ProductCreatePage/ProductCreatePage.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductCreatePage/ProductCreatePage.tsx
@@ -1,3 +1,4 @@
+import { RawDraftContentState } from "draft-js";
import * as React from "react";
import CardSpacer from "../../../components/CardSpacer";
@@ -30,7 +31,7 @@ export interface FormData {
category: ChoiceType;
chargeTaxes: boolean;
collections: ChoiceType[];
- description: string;
+ description: RawDraftContentState;
name: string;
price: number;
productType: {
@@ -100,7 +101,7 @@ export const ProductCreatePage: React.StatelessComponent<
},
chargeTaxes: false,
collections: [],
- description: "",
+ description: {} as any,
name: "",
price: 0,
productType: {
@@ -151,7 +152,7 @@ export const ProductCreatePage: React.StatelessComponent<
title={data.seoTitle}
titlePlaceholder={data.name}
description={data.seoDescription}
- descriptionPlaceholder={data.description}
+ descriptionPlaceholder={data.seoTitle}
loading={disabled}
onChange={change}
/>
diff --git a/saleor/static/dashboard-next/products/components/ProductDetailsForm/ProductDetailsForm.tsx b/saleor/static/dashboard-next/products/components/ProductDetailsForm/ProductDetailsForm.tsx
index 0abb1c503e..d35134b438 100644
--- a/saleor/static/dashboard-next/products/components/ProductDetailsForm/ProductDetailsForm.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductDetailsForm/ProductDetailsForm.tsx
@@ -7,11 +7,12 @@ import {
WithStyles
} from "@material-ui/core/styles";
import TextField from "@material-ui/core/TextField";
+import { RawDraftContentState } from "draft-js";
import * as React from "react";
import CardTitle from "../../../components/CardTitle";
import FormSpacer from "../../../components/FormSpacer";
-import { RichTextEditor } from "../../../components/RichTextEditor";
+import RichTextEditor from "../../../components/RichTextEditor";
import i18n from "../../../i18n";
const styles = (theme: Theme) =>
@@ -25,7 +26,7 @@ const styles = (theme: Theme) =>
interface ProductDetailsFormProps extends WithStyles<typeof styles> {
data: {
- description: string;
+ description: RawDraftContentState;
name: string;
};
disabled?: boolean;
@@ -45,7 +46,6 @@ export const ProductDetailsForm = withStyles(styles, {
helperText={errors.name}
disabled={disabled}
fullWidth
- key="nameInput"
label={i18n.t("Name")}
name="name"
rows={5}
@@ -55,18 +55,10 @@ export const ProductDetailsForm = withStyles(styles, {
</div>
<FormSpacer />
<RichTextEditor
- error={!!errors.description}
disabled={disabled}
- fullWidth
- helperText={
- errors.description
- ? errors.description
- : i18n.t("Select text to enable text-formatting tools.")
- }
- key="descriptionInput"
+ initial={data.description}
label={i18n.t("Description")}
name="description"
- value={data.description}
onChange={onChange}
/>
</CardContent>
diff --git a/saleor/static/dashboard-next/products/views/ProductCreate.tsx b/saleor/static/dashboard-next/products/views/ProductCreate.tsx
index 5bf1617991..936e68c0a8 100644
--- a/saleor/static/dashboard-next/products/views/ProductCreate.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductCreate.tsx
@@ -78,7 +78,9 @@ export const ProductUpdate: React.StatelessComponent<
collections: formData.collections.map(
collection => collection.value
),
- description: formData.description,
+ description: JSON.stringify(
+ formData.description
+ ),
isPublished: formData.available,
name: formData.name,
price: decimal(formData.price),
diff --git a/saleor/static/dashboard-next/storybook/stories/components/RichTextEditor.tsx b/saleor/static/dashboard-next/storybook/stories/components/RichTextEditor.tsx
index c02702f47a..3d30d96aa6 100644
--- a/saleor/static/dashboard-next/storybook/stories/components/RichTextEditor.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/components/RichTextEditor.tsx
@@ -1,93 +1,95 @@
import { storiesOf } from "@storybook/react";
+import { RawDraftContentState } from "draft-js";
import * as React from "react";
import RichTextEditor from "../../../components/RichTextEditor";
import Decorator from "../../Decorator";
+export const content: RawDraftContentState = {
+ blocks: [
+ {
+ data: {},
+ depth: 0,
+ entityRanges: [],
+ inlineStyleRanges: [{ offset: 0, length: 4, style: "BOLD" }],
+ key: "rosn",
+ text: "bold",
+ type: "unstyled"
+ },
+ {
+ data: {},
+ depth: 0,
+ entityRanges: [],
+ inlineStyleRanges: [{ offset: 0, length: 6, style: "ITALIC" }],
+ key: "6tbch",
+ text: "italic",
+ type: "unstyled"
+ },
+ {
+ data: {},
+ depth: 0,
+ entityRanges: [],
+ inlineStyleRanges: [],
+ key: "9rabl",
+ text: "h2",
+ type: "header-two"
+ },
+ {
+ data: {},
+ depth: 0,
+ entityRanges: [],
+ inlineStyleRanges: [],
+ key: "bv0ac",
+ text: "h3",
+ type: "header-three"
+ },
+ {
+ data: {},
+ depth: 0,
+ entityRanges: [],
+ inlineStyleRanges: [],
+ key: "2ip7q",
+ text: "blockquote",
+ type: "blockquote"
+ },
+ {
+ data: {},
+ depth: 0,
+ entityRanges: [],
+ inlineStyleRanges: [],
+ key: "8r8ss",
+ text: "ul",
+ type: "unordered-list-item"
+ },
+ {
+ data: {},
+ depth: 0,
+ entityRanges: [],
+ inlineStyleRanges: [],
+ key: "911hc",
+ text: "ol",
+ type: "ordered-list-item"
+ },
+ {
+ data: {},
+ depth: 0,
+ entityRanges: [{ offset: 0, length: 4, key: 0 }],
+ inlineStyleRanges: [],
+ key: "5aejo",
+ text: "link",
+ type: "unstyled"
+ }
+ ],
+ entityMap: {
+ "0": { type: "LINK", mutability: "MUTABLE", data: { href: "#" } }
+ }
+};
storiesOf("Generics / Rich text editor", module)
.addDecorator(Decorator)
.add("default", () => (
<RichTextEditor
disabled={false}
- initial={{
- blocks: [
- {
- data: {},
- depth: 0,
- entityRanges: [],
- inlineStyleRanges: [{ offset: 0, length: 4, style: "BOLD" }],
- key: "rosn",
- text: "bold",
- type: "unstyled"
- },
- {
- data: {},
- depth: 0,
- entityRanges: [],
- inlineStyleRanges: [{ offset: 0, length: 6, style: "ITALIC" }],
- key: "6tbch",
- text: "italic",
- type: "unstyled"
- },
- {
- data: {},
- depth: 0,
- entityRanges: [],
- inlineStyleRanges: [],
- key: "9rabl",
- text: "h2",
- type: "header-two"
- },
- {
- data: {},
- depth: 0,
- entityRanges: [],
- inlineStyleRanges: [],
- key: "bv0ac",
- text: "h3",
- type: "header-three"
- },
- {
- data: {},
- depth: 0,
- entityRanges: [],
- inlineStyleRanges: [],
- key: "2ip7q",
- text: "blockquote",
- type: "blockquote"
- },
- {
- data: {},
- depth: 0,
- entityRanges: [],
- inlineStyleRanges: [],
- key: "8r8ss",
- text: "ul",
- type: "unordered-list-item"
- },
- {
- data: {},
- depth: 0,
- entityRanges: [],
- inlineStyleRanges: [],
- key: "911hc",
- text: "ol",
- type: "ordered-list-item"
- },
- {
- data: {},
- depth: 0,
- entityRanges: [{ offset: 0, length: 4, key: 0 }],
- inlineStyleRanges: [],
- key: "5aejo",
- text: "link",
- type: "unstyled"
- }
- ],
- entityMap: {
- "0": { type: "LINK", mutability: "MUTABLE", data: { href: "#" } }
- }
- }}
+ initial={content}
label="Content"
name="content"
onChange={() => undefined}