Skip to content

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

Add error handling

dominik-zeglenacf291c17524
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeCreatePage/ProductTypeCreatePage.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeCreatePage/ProductTypeCreatePage.tsx
index a202af5e03..10ce39d201 100644
--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeCreatePage/ProductTypeCreatePage.tsx
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeCreatePage/ProductTypeCreatePage.tsx
@@ -10,10 +10,10 @@ import PageHeader from "@saleor/components/PageHeader";
import SaveButtonBar from "@saleor/components/SaveButtonBar";
import { ChangeEvent, FormChange } from "@saleor/hooks/useForm";
import useStateFromProps from "@saleor/hooks/useStateFromProps";
+import i18n from "@saleor/i18n";
import { ProductTypeDetails_taxTypes } from "@saleor/productTypes/types/ProductTypeDetails";
import { UserError } from "@saleor/types";
-import i18n from "../../../i18n";
-import { WeightUnitsEnum } from "../../../types/globalTypes";
+import { WeightUnitsEnum } from "@saleor/types/globalTypes";
import ProductTypeDetails from "../ProductTypeDetails/ProductTypeDetails";
import ProductTypeShipping from "../ProductTypeShipping/ProductTypeShipping";
import ProductTypeTaxes from "../ProductTypeTaxes/ProductTypeTaxes";
@@ -76,7 +76,7 @@ const ProductTypeCreatePage: React.StatelessComponent<
onSubmit={onSubmit}
confirmLeave
>
- {({ change, data, hasChanged, submit }) => (
+ {({ change, data, errors: formErrors, hasChanged, submit }) => (
<Container>
<AppHeader onBack={onBack}>{i18n.t("Product Types")}</AppHeader>
<PageHeader title={pageTitle} />
@@ -85,6 +85,7 @@ const ProductTypeCreatePage: React.StatelessComponent<
<ProductTypeDetails
data={data}
disabled={disabled}
+ errors={formErrors}
onChange={change}
/>
<CardSpacer />
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetails/ProductTypeDetails.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetails/ProductTypeDetails.tsx
index e25977bd08..dfe12c9370 100644
--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetails/ProductTypeDetails.tsx
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetails/ProductTypeDetails.tsx
@@ -5,7 +5,8 @@ import TextField from "@material-ui/core/TextField";
import React from "react";
import CardTitle from "@saleor/components/CardTitle";
-import i18n from "../../../i18n";
+import i18n from "@saleor/i18n";
+import { FormErrors } from "@saleor/types";
const styles = createStyles({
root: {
@@ -18,17 +19,20 @@ interface ProductTypeDetailsProps extends WithStyles<typeof styles> {
name: string;
};
disabled: boolean;
+ errors: FormErrors<"name">;
onChange: (event: React.ChangeEvent<any>) => void;
}
const ProductTypeDetails = withStyles(styles, { name: "ProductTypeDetails" })(
- ({ classes, data, disabled, onChange }: ProductTypeDetailsProps) => (
+ ({ classes, data, disabled, errors, onChange }: ProductTypeDetailsProps) => (
<Card className={classes.root}>
<CardTitle title={i18n.t("Information")} />
<CardContent>
<TextField
disabled={disabled}
+ error={!!errors.name}
fullWidth
+ helperText={errors.name}
label={i18n.t("Product Type Name")}
name="name"
onChange={onChange}
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
index aab5f7e470..e0193475f9 100644
--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
@@ -127,7 +127,7 @@ const ProductTypeDetailsPage: React.StatelessComponent<
onSubmit={onSubmit}
confirmLeave
>
- {({ change, data, hasChanged, submit }) => (
+ {({ change, data, errors: formErrors, hasChanged, submit }) => (
<Container>
<AppHeader onBack={onBack}>{i18n.t("Product Types")}</AppHeader>
<PageHeader title={pageTitle} />
@@ -136,6 +136,7 @@ const ProductTypeDetailsPage: React.StatelessComponent<
<ProductTypeDetails
data={data}
disabled={disabled}
+ errors={formErrors}
onChange={change}
/>
<CardSpacer />
diff --git a/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeCreatePage.tsx b/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeCreatePage.tsx
index 6112379ffb..e4e2b6ac00 100644
--- a/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeCreatePage.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeCreatePage.tsx
@@ -2,8 +2,10 @@ import { Omit } from "@material-ui/core";
import { storiesOf } from "@storybook/react";
import React from "react";
+import { formError } from "@saleor/storybook/misc";
import ProductTypeCreatePage, {
- ProductTypeCreatePageProps
+ ProductTypeCreatePageProps,
+ ProductTypeForm
} from "../../../productTypes/components/ProductTypeCreatePage";
import { WeightUnitsEnum } from "../../../types/globalTypes";
import Decorator from "../../Decorator";
@@ -24,4 +26,10 @@ storiesOf("Views / Product types / Create product type", module)
.add("default", () => <ProductTypeCreatePage {...props} />)
.add("loading", () => (
<ProductTypeCreatePage {...props} disabled={true} pageTitle={undefined} />
+ ))
+ .add("form errors", () => (
+ <ProductTypeCreatePage
+ {...props}
+ errors={(["name"] as Array<keyof ProductTypeForm>).map(formError)}
+ />
));
diff --git a/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeDetailsPage.tsx b/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeDetailsPage.tsx
index bad72c5e96..a95a7a11bf 100644
--- a/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeDetailsPage.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeDetailsPage.tsx
@@ -3,8 +3,10 @@ import { storiesOf } from "@storybook/react";
import React from "react";
import { listActionsProps } from "@saleor/fixtures";
+import { formError } from "@saleor/storybook/misc";
import ProductTypeDetailsPage, {
- ProductTypeDetailsPageProps
+ ProductTypeDetailsPageProps,
+ ProductTypeForm
} from "../../../productTypes/components/ProductTypeDetailsPage";
import { productType } from "../../../productTypes/fixtures";
import { WeightUnitsEnum } from "../../../types/globalTypes";
@@ -16,6 +18,7 @@ const props: Omit<ProductTypeDetailsPageProps, "classes"> = {
errors: [],
onAttributeAdd: () => undefined,
onAttributeClick: () => undefined,
+ onAttributeReorder: () => undefined,
onAttributeUnassign: () => undefined,
onBack: () => undefined,
onDelete: () => undefined,
@@ -38,4 +41,10 @@ storiesOf("Views / Product types / Product type details", module)
pageTitle={undefined}
productType={undefined}
/>
+ ))
+ .add("form errors", () => (
+ <ProductTypeDetailsPage
+ {...props}
+ errors={(["name"] as Array<keyof ProductTypeForm>).map(formError)}
+ />
));