Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add form errors
dominik-zeglen8f649e5b0aca
diff --git a/saleor/static/dashboard-next/attributes/components/AttributeDetails/AttributeDetails.tsx b/saleor/static/dashboard-next/attributes/components/AttributeDetails/AttributeDetails.tsxindex 006c8dce70..adc1c525ae 100644--- a/saleor/static/dashboard-next/attributes/components/AttributeDetails/AttributeDetails.tsx+++ b/saleor/static/dashboard-next/attributes/components/AttributeDetails/AttributeDetails.tsx@@ -3,20 +3,23 @@ import CardContent from "@material-ui/core/CardContent";import TextField from "@material-ui/core/TextField";import * as React from "react";-import CardTitle from "../../../components/CardTitle";-import FormSpacer from "../../../components/FormSpacer";-import i18n from "../../../i18n";+import CardTitle from "@saleor/components/CardTitle";+import FormSpacer from "@saleor/components/FormSpacer";+import i18n from "@saleor/i18n";+import { FormErrors } from "@saleor/types";import { AttributePageFormData } from "../AttributePage";export interface AttributeDetailsProps {data: AttributePageFormData;disabled: boolean;+ errors: FormErrors<"name" | "slug">;onChange: (event: React.ChangeEvent<any>) => void;}const AttributeDetails: React.FC<AttributeDetailsProps> = ({data,disabled,+ errors,onChange}) => (<Card>@@ -24,18 +27,22 @@ const AttributeDetails: React.FC<AttributeDetailsProps> = ({<CardContent><TextFielddisabled={disabled}+ error={!!errors.name}label={i18n.t("Default Label")}name={"name" as keyof AttributePageFormData}fullWidth+ helperText={errors.name}value={data.name}onChange={onChange}/><FormSpacer /><TextFielddisabled={disabled}+ error={!!errors.slug}label={i18n.t("Attribute Code")}name={"slug" as keyof AttributePageFormData}fullWidth+ helperText={errors.slug}value={data.slug}onChange={onChange}/>diff --git a/saleor/static/dashboard-next/attributes/components/AttributePage/AttributePage.tsx b/saleor/static/dashboard-next/attributes/components/AttributePage/AttributePage.tsxindex e239f54cc2..f1bbc75e49 100644--- a/saleor/static/dashboard-next/attributes/components/AttributePage/AttributePage.tsx+++ b/saleor/static/dashboard-next/attributes/components/AttributePage/AttributePage.tsx@@ -1,15 +1,16 @@import * as React from "react";-import AppHeader from "../../../components/AppHeader";-import CardSpacer from "../../../components/CardSpacer";-import { ConfirmButtonTransitionState } from "../../../components/ConfirmButton";-import Container from "../../../components/Container";-import Form from "../../../components/Form";-import Grid from "../../../components/Grid";-import PageHeader from "../../../components/PageHeader";-import SaveButtonBar from "../../../components/SaveButtonBar";-import i18n from "../../../i18n";-import { maybe } from "../../../misc";+import AppHeader from "@saleor/components/AppHeader";+import CardSpacer from "@saleor/components/CardSpacer";+import { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton";+import Container from "@saleor/components/Container";+import Form from "@saleor/components/Form";+import Grid from "@saleor/components/Grid";+import PageHeader from "@saleor/components/PageHeader";+import SaveButtonBar from "@saleor/components/SaveButtonBar";+import i18n from "@saleor/i18n";+import { maybe } from "@saleor/misc";+import { UserError } from "@saleor/types";import {AttributeDetailsFragment,AttributeDetailsFragment_values@@ -20,6 +21,7 @@ import AttributeValues from "../AttributeValues";export interface AttributePageProps {attribute: AttributeDetailsFragment | null;disabled: boolean;+ errors: UserError[];saveButtonBarState: ConfirmButtonTransitionState;values: AttributeDetailsFragment_values[];onBack: () => void;@@ -38,6 +40,7 @@ export interface AttributePageFormData {const AttributePage: React.FC<AttributePageProps> = ({attribute,disabled,+ errors,saveButtonBarState,values,onBack,@@ -59,8 +62,8 @@ const AttributePage: React.FC<AttributePageProps> = ({};return (- <Form initial={initialForm} onSubmit={onSubmit}>- {({ change, data, submit }) => (+ <Form errors={errors} initial={initialForm} onSubmit={onSubmit}>+ {({ change, errors: formErrors, data, submit }) => (<Container><AppHeader onBack={onBack}>{i18n.t("Attributes")}</AppHeader><PageHeader@@ -77,6 +80,7 @@ const AttributePage: React.FC<AttributePageProps> = ({<AttributeDetailsdata={data}disabled={disabled}+ errors={formErrors}onChange={change}/><CardSpacer />diff --git a/saleor/static/dashboard-next/attributes/components/AttributeValueEditDialog/AttributeValueEditDialog.tsx b/saleor/static/dashboard-next/attributes/components/AttributeValueEditDialog/AttributeValueEditDialog.tsxindex 1555b725d4..755aa17bae 100644--- a/saleor/static/dashboard-next/attributes/components/AttributeValueEditDialog/AttributeValueEditDialog.tsx+++ b/saleor/static/dashboard-next/attributes/components/AttributeValueEditDialog/AttributeValueEditDialog.tsx@@ -13,6 +13,7 @@ import Form from "@saleor/components/Form";import FormSpacer from "@saleor/components/FormSpacer";import i18n from "@saleor/i18n";import { maybe } from "@saleor/misc";+import { UserError } from "@saleor/types";import { AttributeDetails_attribute_values } from "../../types/AttributeDetails";export interface AttributeValueEditDialogFormData {@@ -23,6 +24,7 @@ export interface AttributeValueEditDialogProps {attributeValue: AttributeDetails_attribute_values | null;confirmButtonState: ConfirmButtonTransitionState;disabled: boolean;+ errors: UserError[];open: boolean;onSubmit: (data: AttributeValueEditDialogFormData) => void;onClose: () => void;@@ -34,6 +36,7 @@ const AttributeValueEditDialog: React.StatelessComponent<attributeValue,confirmButtonState,disabled,+ errors,onClose,onSubmit,open@@ -54,12 +57,13 @@ const AttributeValueEditDialog: React.StatelessComponent<context: "edit attribute value"})}</DialogTitle>- <Form initial={initialForm} onSubmit={onSubmit}>- {({ change, data, submit }) => (+ <Form errors={errors} initial={initialForm} onSubmit={onSubmit}>+ {({ change, data, errors: formErrors, submit }) => (<><DialogContent><TextFielddisabled={disabled}+ error={!!formErrors.slug}fullWidthname={"slug" as keyof AttributeValueEditDialogFormData}label={i18n.t("Admin name", {@@ -71,6 +75,7 @@ const AttributeValueEditDialog: React.StatelessComponent<<FormSpacer /><TextFielddisabled={disabled}+ error={!!formErrors.name}fullWidthname={"name" as keyof AttributeValueEditDialogFormData}label={i18n.t("Default Storefront Name", {diff --git a/saleor/static/dashboard-next/attributes/views/AttributeCreate/AttributeCreate.tsx b/saleor/static/dashboard-next/attributes/views/AttributeCreate/AttributeCreate.tsxindex e049da3644..808b96c107 100644--- a/saleor/static/dashboard-next/attributes/views/AttributeCreate/AttributeCreate.tsx+++ b/saleor/static/dashboard-next/attributes/views/AttributeCreate/AttributeCreate.tsx@@ -88,6 +88,10 @@ const AttributeDetails: React.FC<AttributeDetailsProps> = ({ params }) => {<AttributePageattribute={null}disabled={false}+ errors={maybe(+ () => attributeCreateOpts.data.attributeCreate.errors,+ []+ )}onBack={() => navigate(attributeListUrl())}onDelete={undefined}onSubmit={input =>@@ -120,6 +124,7 @@ const AttributeDetails: React.FC<AttributeDetailsProps> = ({ params }) => {attributeValue={null}confirmButtonState="default"disabled={false}+ errors={[]}open={params.action === "add-value"}onClose={closeModal}onSubmit={handleValueCreate}@@ -137,6 +142,7 @@ const AttributeDetails: React.FC<AttributeDetailsProps> = ({ params }) => {attributeValue={maybe(() => values[params.id])}confirmButtonState="default"disabled={false}+ errors={[]}open={params.action === "edit-value"}onClose={closeModal}onSubmit={handleValueUpdate}diff --git a/saleor/static/dashboard-next/attributes/views/AttributeDetails/AttributeDetails.tsx b/saleor/static/dashboard-next/attributes/views/AttributeDetails/AttributeDetails.tsxindex bd2729955c..a54bfbbcdc 100644--- a/saleor/static/dashboard-next/attributes/views/AttributeDetails/AttributeDetails.tsx+++ b/saleor/static/dashboard-next/attributes/views/AttributeDetails/AttributeDetails.tsx@@ -155,6 +155,12 @@ const AttributeDetails: React.FC<AttributeDetailsProps> = ({ id, params }) => {<AttributePageattribute={maybe(() => data.attribute)}disabled={loading}+ errors={maybe(+ () =>+ attributeUpdateOpts.data.attributeUpdate+ .errors,+ []+ )}onBack={() => navigate(attributeListUrl())}onDelete={() => openModal("remove")}onSubmit={input =>@@ -215,6 +221,12 @@ const AttributeDetails: React.FC<AttributeDetailsProps> = ({ id, params }) => {createValueTransitionState}disabled={loading}+ errors={maybe(+ () =>+ attributeValueCreateOpts.data+ .attributeValueCreate.errors,+ []+ )}open={params.action === "add-value"}onClose={closeModal}onSubmit={input =>@@ -239,6 +251,12 @@ const AttributeDetails: React.FC<AttributeDetailsProps> = ({ id, params }) => {updateValueTransitionState}disabled={loading}+ errors={maybe(+ () =>+ attributeValueUpdateOpts.data+ .attributeValueUpdate.errors,+ []+ )}open={params.action === "edit-value"}onClose={closeModal}onSubmit={input =>diff --git a/saleor/static/dashboard-next/storybook/stories/attributes/AttributePage.tsx b/saleor/static/dashboard-next/storybook/stories/attributes/AttributePage.tsxindex 12841b3468..581c4e813e 100644--- a/saleor/static/dashboard-next/storybook/stories/attributes/AttributePage.tsx+++ b/saleor/static/dashboard-next/storybook/stories/attributes/AttributePage.tsx@@ -2,6 +2,7 @@ import { storiesOf } from "@storybook/react";import * as React from "react";import { attribute } from "@saleor/attributes/fixtures";+import { formError } from "@saleor/storybook/misc";import AttributePage, {AttributePageProps} from "../../../attributes/components/AttributePage";@@ -10,6 +11,7 @@ import Decorator from "../../Decorator";const props: AttributePageProps = {attribute,disabled: false,+ errors: [],onBack: () => undefined,onDelete: () => undefined,onSubmit: () => undefined,@@ -32,4 +34,7 @@ storiesOf("Views / Attributes / Attribute details", module)/>)).add("no values", () => <AttributePage {...props} values={undefined} />)+ .add("form errors", () => (+ <AttributePage {...props} errors={["name", "slug"].map(formError)} />+ )).add("create", () => <AttributePage {...props} attribute={null} />);