Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Display mutation errors
dominik-zeglen68e2cd9290f6
diff --git a/saleor/static/dashboard-next/components/AssignAttributeDialog/AssignAttributeDialog.tsx b/saleor/static/dashboard-next/components/AssignAttributeDialog/AssignAttributeDialog.tsxindex 6b75117024..b77adbf52f 100644--- a/saleor/static/dashboard-next/components/AssignAttributeDialog/AssignAttributeDialog.tsx+++ b/saleor/static/dashboard-next/components/AssignAttributeDialog/AssignAttributeDialog.tsx@@ -3,6 +3,7 @@ import CircularProgress from "@material-ui/core/CircularProgress";import Dialog from "@material-ui/core/Dialog";import DialogActions from "@material-ui/core/DialogActions";import DialogContent from "@material-ui/core/DialogContent";+import DialogContentText from "@material-ui/core/DialogContentText";import DialogTitle from "@material-ui/core/DialogTitle";import { createStyles, withStyles, WithStyles } from "@material-ui/core/styles";import Table from "@material-ui/core/Table";@@ -40,6 +41,7 @@ const styles = createStyles({export interface AssignAttributeDialogProps {confirmButtonState: ConfirmButtonTransitionState;+ errors: string[];open: boolean;attributes: SearchAttributes_attributes_edges_node[];loading: boolean;@@ -60,6 +62,7 @@ const AssignAttributeDialog = withStyles(styles, {attributes,classes,confirmButtonState,+ errors,loading,open,selected,@@ -138,6 +141,13 @@ const AssignAttributeDialog = withStyles(styles, {</TableBody></Table></DialogContent>+ {errors.length > 0 && (+ <DialogContent>+ {errors.map(error => (+ <DialogContentText color="error">{error}</DialogContentText>+ ))}+ </DialogContent>+ )}<DialogActions><Button onClick={onClose}>{i18n.t("Cancel", { context: "button" })}diff --git a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsxindex a317391264..8bc0c994e7 100644--- a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx+++ b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx@@ -31,6 +31,7 @@ import {ProductTypeUrlQueryParams} from "../../urls";import { ProductTypeUpdateErrors } from "./errors";+import { ReorderEvent } from "@saleor/types";interface ProductTypeUpdateProps {id: string;@@ -210,6 +211,25 @@ export const ProductTypeUpdate: React.FC<ProductTypeUpdateProps> = ({));+ const handleAttributeReorder = (+ event: ReorderEvent,+ type: AttributeTypeEnum+ ) => {+ const attributes =+ type === AttributeTypeEnum.PRODUCT+ ? data.productType.productAttributes+ : data.productType.variantAttributes;++ reorderAttribute.mutate({+ move: {+ id: attributes[event.oldIndex].id,+ sortOrder: event.newIndex - event.oldIndex+ },+ productTypeId: id,+ type+ });+ };+return (<><WindowTitle title={maybe(() => data.productType.name)} />@@ -234,19 +254,7 @@ export const ProductTypeUpdate: React.FC<ProductTypeUpdateProps> = ({onAttributeClick={attributeId =>navigate(attributeUrl(attributeId))}- onAttributeReorder={(event, type) =>- reorderAttribute.mutate({- move: {- id:- data.productType.productAttributes[- event.oldIndex- ].id,- sortOrder: event.newIndex - event.oldIndex- },- productTypeId: id,- type- })- }+ onAttributeReorder={handleAttributeReorder}onAttributeUnassign={attributeId =>navigate(productTypeUrl(id, {@@ -329,6 +337,13 @@ export const ProductTypeUpdate: React.FC<ProductTypeUpdateProps> = ({))}confirmButtonState={assignTransactionState}+ errors={maybe(+ () =>+ assignAttribute.opts.data.attributeAssign.errors.map(+ err => err.message+ ),+ []+ )}loading={result.loading}onClose={closeModal}onSubmit={handleAssignAttribute}@@ -343,7 +358,7 @@ export const ProductTypeUpdate: React.FC<ProductTypeUpdateProps> = ({navigate(productTypeUrl(id, {...params,- ids: ids.includes(id)+ ids: ids.includes(attributeId)? params.ids.filter(selectedId =>selectedId !== attributeIddiff --git a/saleor/static/dashboard-next/storybook/stories/components/AssignAttributeDialog.tsx b/saleor/static/dashboard-next/storybook/stories/components/AssignAttributeDialog.tsxindex b52f8177fe..8f0e5fb78c 100644--- a/saleor/static/dashboard-next/storybook/stories/components/AssignAttributeDialog.tsx+++ b/saleor/static/dashboard-next/storybook/stories/components/AssignAttributeDialog.tsx@@ -2,6 +2,7 @@ import { storiesOf } from "@storybook/react";import * as React from "react";import { attributes } from "@saleor/attributes/fixtures";+import { formError } from "@saleor/storybook/misc";import AssignAttributeDialog, {AssignAttributeDialogProps} from "../../../components/AssignAttributeDialog";@@ -10,6 +11,7 @@ import Decorator from "../../Decorator";const props: AssignAttributeDialogProps = {attributes: attributes.slice(0, 5),confirmButtonState: "default",+ errors: [],loading: false,onClose: () => undefined,onFetch: () => undefined,@@ -24,4 +26,7 @@ storiesOf("Generics / Assign attributes dialog", module).add("default", () => <AssignAttributeDialog {...props} />).add("loading", () => (<AssignAttributeDialog {...props} attributes={undefined} loading={true} />+ ))+ .add("errors", () => (+ <AssignAttributeDialog {...props} errors={[formError("").message]} />));