From 852bd71beb7a58f95096e6b78e1af3f290380003 Mon Sep 17 00:00:00 2001
From: dominik-zeglen
Date: Thu, 5 Mar 2020 15:59:25 +0100
Subject: [PATCH 01/35] Use translated errors in categories section
---
.../CategoryCreatePage/CategoryCreatePage.tsx | 4 +--
.../CategoryDetailsForm.tsx | 16 +++++-----
.../CategoryUpdatePage/CategoryUpdatePage.tsx | 5 ++--
src/categories/mutations.ts | 29 ++++++++++---------
src/categories/types/CategoryBulkDelete.ts | 6 ++--
src/categories/types/CategoryCreate.ts | 16 +++++-----
src/categories/types/CategoryDelete.ts | 6 ++--
src/categories/types/CategoryUpdate.ts | 16 +++++-----
src/categories/views/CategoryDetails.tsx | 2 +-
9 files changed, 54 insertions(+), 46 deletions(-)
diff --git a/src/categories/components/CategoryCreatePage/CategoryCreatePage.tsx b/src/categories/components/CategoryCreatePage/CategoryCreatePage.tsx
index 7f7036066..a47266f62 100644
--- a/src/categories/components/CategoryCreatePage/CategoryCreatePage.tsx
+++ b/src/categories/components/CategoryCreatePage/CategoryCreatePage.tsx
@@ -11,7 +11,7 @@ import PageHeader from "@saleor/components/PageHeader";
import SaveButtonBar from "@saleor/components/SaveButtonBar";
import SeoForm from "@saleor/components/SeoForm";
import { sectionNames } from "@saleor/intl";
-import { UserError } from "../../../types";
+import { ProductErrorFragment } from "@saleor/attributes/types/ProductErrorFragment";
import CategoryDetailsForm from "../../components/CategoryDetailsForm";
interface FormData {
@@ -29,7 +29,7 @@ const initialData: FormData = {
};
export interface CategoryCreatePageProps {
- errors: UserError[];
+ errors: ProductErrorFragment[];
disabled: boolean;
saveButtonBarState: ConfirmButtonTransitionState;
onSubmit(data: FormData);
diff --git a/src/categories/components/CategoryDetailsForm/CategoryDetailsForm.tsx b/src/categories/components/CategoryDetailsForm/CategoryDetailsForm.tsx
index 5ffcefab8..615667541 100644
--- a/src/categories/components/CategoryDetailsForm/CategoryDetailsForm.tsx
+++ b/src/categories/components/CategoryDetailsForm/CategoryDetailsForm.tsx
@@ -9,8 +9,8 @@ import CardTitle from "@saleor/components/CardTitle";
import FormSpacer from "@saleor/components/FormSpacer";
import RichTextEditor from "@saleor/components/RichTextEditor";
import { commonMessages } from "@saleor/intl";
-import { UserError } from "@saleor/types";
-import { getFieldError } from "@saleor/utils/errors";
+import { getFormErrors, getProductErrorMessage } from "@saleor/utils/errors";
+import { ProductErrorFragment } from "@saleor/attributes/types/ProductErrorFragment";
import { maybe } from "../../../misc";
import { CategoryDetails_category } from "../../types/CategoryDetails";
@@ -21,7 +21,7 @@ interface CategoryDetailsFormProps {
description: RawDraftContentState;
};
disabled: boolean;
- errors: UserError[];
+ errors: ProductErrorFragment[];
onChange: (event: React.ChangeEvent) => void;
}
@@ -34,6 +34,8 @@ export const CategoryDetailsForm: React.FC = ({
}) => {
const intl = useIntl();
+ const formErrors = getFormErrors(["name", "descriptionJson"], errors);
+
return (
= ({
disabled={disabled}
value={data && data.name}
onChange={onChange}
- error={!!getFieldError(errors, "name")}
- helperText={getFieldError(errors, "name")?.message}
+ error={!!formErrors.name}
+ helperText={getProductErrorMessage(formErrors.name, intl)}
fullWidth
/>
{
changeTab: (index: CategoryPageTab) => void;
currentTab: CategoryPageTab;
- errors: UserError[];
+ errors: ProductErrorFragment[];
disabled: boolean;
category: CategoryDetails_category;
products: CategoryDetails_category_products_edges_node[];
diff --git a/src/categories/mutations.ts b/src/categories/mutations.ts
index 7995b3c6f..a228faa8c 100644
--- a/src/categories/mutations.ts
+++ b/src/categories/mutations.ts
@@ -1,6 +1,7 @@
import gql from "graphql-tag";
import makeMutation from "@saleor/hooks/makeMutation";
+import { productErrorFragment } from "@saleor/attributes/mutations";
import { categoryDetailsFragment } from "./queries";
import {
CategoryBulkDelete,
@@ -20,11 +21,11 @@ import {
} from "./types/CategoryUpdate";
export const categoryDeleteMutation = gql`
+ ${productErrorFragment}
mutation CategoryDelete($id: ID!) {
categoryDelete(id: $id) {
- errors {
- field
- message
+ errors: productErrors {
+ ...ProductErrorFragment
}
}
}
@@ -36,15 +37,15 @@ export const useCategoryDeleteMutation = makeMutation<
export const categoryCreateMutation = gql`
${categoryDetailsFragment}
+ ${productErrorFragment}
mutation CategoryCreate($parent: ID, $input: CategoryInput!) {
categoryCreate(parent: $parent, input: $input) {
- errors {
- field
- message
- }
category {
...CategoryDetailsFragment
}
+ errors: productErrors {
+ ...ProductErrorFragment
+ }
}
}
`;
@@ -55,15 +56,15 @@ export const useCategoryCreateMutation = makeMutation<
export const categoryUpdateMutation = gql`
${categoryDetailsFragment}
+ ${productErrorFragment}
mutation CategoryUpdate($id: ID!, $input: CategoryInput!) {
categoryUpdate(id: $id, input: $input) {
- errors {
- field
- message
- }
category {
...CategoryDetailsFragment
}
+ errors: productErrors {
+ ...ProductErrorFragment
+ }
}
}
`;
@@ -73,11 +74,11 @@ export const useCategoryUpdateMutation = makeMutation<
>(categoryUpdateMutation);
export const categoryBulkDeleteMutation = gql`
+ ${productErrorFragment}
mutation CategoryBulkDelete($ids: [ID]!) {
categoryBulkDelete(ids: $ids) {
- errors {
- field
- message
+ errors: productErrors {
+ ...ProductErrorFragment
}
}
}
diff --git a/src/categories/types/CategoryBulkDelete.ts b/src/categories/types/CategoryBulkDelete.ts
index a5e6d54a9..9009acdcd 100644
--- a/src/categories/types/CategoryBulkDelete.ts
+++ b/src/categories/types/CategoryBulkDelete.ts
@@ -2,14 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { ProductErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: CategoryBulkDelete
// ====================================================
export interface CategoryBulkDelete_categoryBulkDelete_errors {
- __typename: "Error";
+ __typename: "ProductError";
+ code: ProductErrorCode;
field: string | null;
- message: string | null;
}
export interface CategoryBulkDelete_categoryBulkDelete {
diff --git a/src/categories/types/CategoryCreate.ts b/src/categories/types/CategoryCreate.ts
index 496872e41..0bcf34a74 100644
--- a/src/categories/types/CategoryCreate.ts
+++ b/src/categories/types/CategoryCreate.ts
@@ -2,18 +2,12 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { CategoryInput } from "./../../types/globalTypes";
+import { CategoryInput, ProductErrorCode } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: CategoryCreate
// ====================================================
-export interface CategoryCreate_categoryCreate_errors {
- __typename: "Error";
- field: string | null;
- message: string | null;
-}
-
export interface CategoryCreate_categoryCreate_category_backgroundImage {
__typename: "Image";
alt: string | null;
@@ -36,10 +30,16 @@ export interface CategoryCreate_categoryCreate_category {
parent: CategoryCreate_categoryCreate_category_parent | null;
}
+export interface CategoryCreate_categoryCreate_errors {
+ __typename: "ProductError";
+ code: ProductErrorCode;
+ field: string | null;
+}
+
export interface CategoryCreate_categoryCreate {
__typename: "CategoryCreate";
- errors: CategoryCreate_categoryCreate_errors[];
category: CategoryCreate_categoryCreate_category | null;
+ errors: CategoryCreate_categoryCreate_errors[];
}
export interface CategoryCreate {
diff --git a/src/categories/types/CategoryDelete.ts b/src/categories/types/CategoryDelete.ts
index 79634e78d..0b7fda57d 100644
--- a/src/categories/types/CategoryDelete.ts
+++ b/src/categories/types/CategoryDelete.ts
@@ -2,14 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { ProductErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: CategoryDelete
// ====================================================
export interface CategoryDelete_categoryDelete_errors {
- __typename: "Error";
+ __typename: "ProductError";
+ code: ProductErrorCode;
field: string | null;
- message: string | null;
}
export interface CategoryDelete_categoryDelete {
diff --git a/src/categories/types/CategoryUpdate.ts b/src/categories/types/CategoryUpdate.ts
index a4621ee45..8b04c1583 100644
--- a/src/categories/types/CategoryUpdate.ts
+++ b/src/categories/types/CategoryUpdate.ts
@@ -2,18 +2,12 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { CategoryInput } from "./../../types/globalTypes";
+import { CategoryInput, ProductErrorCode } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: CategoryUpdate
// ====================================================
-export interface CategoryUpdate_categoryUpdate_errors {
- __typename: "Error";
- field: string | null;
- message: string | null;
-}
-
export interface CategoryUpdate_categoryUpdate_category_backgroundImage {
__typename: "Image";
alt: string | null;
@@ -36,10 +30,16 @@ export interface CategoryUpdate_categoryUpdate_category {
parent: CategoryUpdate_categoryUpdate_category_parent | null;
}
+export interface CategoryUpdate_categoryUpdate_errors {
+ __typename: "ProductError";
+ code: ProductErrorCode;
+ field: string | null;
+}
+
export interface CategoryUpdate_categoryUpdate {
__typename: "CategoryUpdate";
- errors: CategoryUpdate_categoryUpdate_errors[];
category: CategoryUpdate_categoryUpdate_category | null;
+ errors: CategoryUpdate_categoryUpdate_errors[];
}
export interface CategoryUpdate {
diff --git a/src/categories/views/CategoryDetails.tsx b/src/categories/views/CategoryDetails.tsx
index 812b4dc7d..e33d91b96 100644
--- a/src/categories/views/CategoryDetails.tsx
+++ b/src/categories/views/CategoryDetails.tsx
@@ -99,7 +99,7 @@ export const CategoryDetails: React.FC = ({
);
if (backgroundImageError) {
notify({
- text: backgroundImageError.message
+ text: intl.formatMessage(commonMessages.somethingWentWrong)
});
}
}
From 2a1abe76b63c157597163e75af871a44b0238bda Mon Sep 17 00:00:00 2001
From: dominik-zeglen
Date: Thu, 5 Mar 2020 15:59:55 +0100
Subject: [PATCH 02/35] Use translated errors in collections
---
.../CollectionCreatePage.tsx | 4 +-
.../CollectionDetails/CollectionDetails.tsx | 16 +++--
.../CollectionDetailsPage.tsx | 5 +-
src/collections/mutations.ts | 72 ++++++++++---------
.../types/CollectionAssignProduct.ts | 16 +++--
src/collections/types/CollectionBulkDelete.ts | 6 +-
.../types/CollectionBulkPublish.ts | 6 +-
src/collections/types/CollectionUpdate.ts | 16 ++---
.../types/CollectionUpdateWithHomepage.ts | 20 +++---
src/collections/types/CreateCollection.ts | 16 ++---
src/collections/types/RemoveCollection.ts | 6 +-
src/collections/types/ShopErrorFragment.ts | 15 ++++
.../types/UnassignCollectionProduct.ts | 16 +++--
src/collections/views/CollectionCreate.tsx | 13 ++--
src/collections/views/CollectionDetails.tsx | 4 +-
src/types/globalTypes.ts | 10 +++
16 files changed, 141 insertions(+), 100 deletions(-)
create mode 100644 src/collections/types/ShopErrorFragment.ts
diff --git a/src/collections/components/CollectionCreatePage/CollectionCreatePage.tsx b/src/collections/components/CollectionCreatePage/CollectionCreatePage.tsx
index c7680bbcc..c6a3acabb 100644
--- a/src/collections/components/CollectionCreatePage/CollectionCreatePage.tsx
+++ b/src/collections/components/CollectionCreatePage/CollectionCreatePage.tsx
@@ -17,7 +17,7 @@ import SeoForm from "@saleor/components/SeoForm";
import VisibilityCard from "@saleor/components/VisibilityCard";
import useDateLocalize from "@saleor/hooks/useDateLocalize";
import { commonMessages, sectionNames } from "@saleor/intl";
-import { UserError } from "../../../types";
+import { ProductErrorFragment } from "@saleor/attributes/types/ProductErrorFragment";
import CollectionDetails from "../CollectionDetails/CollectionDetails";
import { CollectionImage } from "../CollectionImage/CollectionImage";
@@ -37,7 +37,7 @@ export interface CollectionCreatePageFormData {
export interface CollectionCreatePageProps {
disabled: boolean;
- errors: UserError[];
+ errors: ProductErrorFragment[];
saveButtonBarState: ConfirmButtonTransitionState;
onBack: () => void;
onSubmit: (data: CollectionCreatePageFormData) => void;
diff --git a/src/collections/components/CollectionDetails/CollectionDetails.tsx b/src/collections/components/CollectionDetails/CollectionDetails.tsx
index 5c219335c..c63bc1dea 100644
--- a/src/collections/components/CollectionDetails/CollectionDetails.tsx
+++ b/src/collections/components/CollectionDetails/CollectionDetails.tsx
@@ -10,8 +10,8 @@ import FormSpacer from "@saleor/components/FormSpacer";
import RichTextEditor from "@saleor/components/RichTextEditor";
import { commonMessages } from "@saleor/intl";
import { maybe } from "@saleor/misc";
-import { UserError } from "@saleor/types";
-import { getFieldError } from "@saleor/utils/errors";
+import { getProductErrorMessage, getFormErrors } from "@saleor/utils/errors";
+import { ProductErrorFragment } from "@saleor/attributes/types/ProductErrorFragment";
import { CollectionDetails_collection } from "../../types/CollectionDetails";
export interface CollectionDetailsProps {
@@ -21,7 +21,7 @@ export interface CollectionDetailsProps {
name: string;
};
disabled: boolean;
- errors: UserError[];
+ errors: ProductErrorFragment[];
onChange: (event: React.ChangeEvent) => void;
}
@@ -34,6 +34,8 @@ const CollectionDetails: React.FC = ({
}) => {
const intl = useIntl();
+ const formErrors = getFormErrors(["name", "descriptionJson"], errors);
+
return (
= ({
disabled={disabled}
value={data.name}
onChange={onChange}
- error={!!getFieldError(errors, "name")}
- helperText={getFieldError(errors, "name")?.message}
+ error={!!formErrors.name}
+ helperText={getProductErrorMessage(formErrors.name, intl)}
fullWidth
/>
JSON.parse(collection.descriptionJson))}
label={intl.formatMessage(commonMessages.description)}
name="description"
diff --git a/src/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx b/src/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx
index 3d81c31e4..106ba3463 100644
--- a/src/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx
+++ b/src/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx
@@ -17,8 +17,9 @@ import SeoForm from "@saleor/components/SeoForm";
import VisibilityCard from "@saleor/components/VisibilityCard";
import useDateLocalize from "@saleor/hooks/useDateLocalize";
import { sectionNames } from "@saleor/intl";
+import { ProductErrorFragment } from "@saleor/attributes/types/ProductErrorFragment";
import { maybe } from "../../../misc";
-import { ListActions, PageListProps, UserError } from "../../../types";
+import { ListActions, PageListProps } from "../../../types";
import { CollectionDetails_collection } from "../../types/CollectionDetails";
import CollectionDetails from "../CollectionDetails/CollectionDetails";
import { CollectionImage } from "../CollectionImage/CollectionImage";
@@ -37,7 +38,7 @@ export interface CollectionDetailsPageFormData {
export interface CollectionDetailsPageProps extends PageListProps, ListActions {
collection: CollectionDetails_collection;
- errors: UserError[];
+ errors: ProductErrorFragment[];
isFeatured: boolean;
saveButtonBarState: ConfirmButtonTransitionState;
onBack: () => void;
diff --git a/src/collections/mutations.ts b/src/collections/mutations.ts
index 94623492f..b339d1a04 100644
--- a/src/collections/mutations.ts
+++ b/src/collections/mutations.ts
@@ -1,5 +1,6 @@
import gql from "graphql-tag";
+import { productErrorFragment } from "@saleor/attributes/mutations";
import { TypedMutation } from "../mutations";
import {
collectionDetailsFragment,
@@ -38,17 +39,24 @@ import {
UnassignCollectionProductVariables
} from "./types/UnassignCollectionProduct";
+export const ShopErrorFragment = gql`
+ fragment ShopErrorFragment on ShopError {
+ code
+ field
+ }
+`;
+
const collectionUpdate = gql`
${collectionDetailsFragment}
+ ${productErrorFragment}
mutation CollectionUpdate($id: ID!, $input: CollectionInput!) {
collectionUpdate(id: $id, input: $input) {
- errors {
- field
- message
- }
collection {
...CollectionDetailsFragment
}
+ errors: productErrors {
+ ...ProductErrorFragment
+ }
}
}
`;
@@ -59,15 +67,16 @@ export const TypedCollectionUpdateMutation = TypedMutation<
const collectionUpdateWithHomepage = gql`
${collectionDetailsFragment}
+ ${productErrorFragment}
+ ${ShopErrorFragment}
mutation CollectionUpdateWithHomepage(
$id: ID!
$input: CollectionInput!
$homepageId: ID
) {
homepageCollectionUpdate(collection: $homepageId) {
- errors {
- field
- message
+ errors: shopErrors {
+ ...ShopErrorFragment
}
shop {
homepageCollection {
@@ -76,13 +85,12 @@ const collectionUpdateWithHomepage = gql`
}
}
collectionUpdate(id: $id, input: $input) {
- errors {
- field
- message
- }
collection {
...CollectionDetailsFragment
}
+ errors: productErrors {
+ ...ProductErrorFragment
+ }
}
}
`;
@@ -93,6 +101,7 @@ export const TypedCollectionUpdateWithHomepageMutation = TypedMutation<
const assignCollectionProduct = gql`
${collectionProductFragment}
+ ${productErrorFragment}
mutation CollectionAssignProduct(
$collectionId: ID!
$productIds: [ID!]!
@@ -102,10 +111,6 @@ const assignCollectionProduct = gql`
$before: String
) {
collectionAddProducts(collectionId: $collectionId, products: $productIds) {
- errors {
- field
- message
- }
collection {
id
products(first: $first, after: $after, before: $before, last: $last) {
@@ -122,6 +127,9 @@ const assignCollectionProduct = gql`
}
}
}
+ errors: productErrors {
+ ...ProductErrorFragment
+ }
}
}
`;
@@ -132,15 +140,15 @@ export const TypedCollectionAssignProductMutation = TypedMutation<
const createCollection = gql`
${collectionDetailsFragment}
+ ${productErrorFragment}
mutation CreateCollection($input: CollectionCreateInput!) {
collectionCreate(input: $input) {
- errors {
- field
- message
- }
collection {
...CollectionDetailsFragment
}
+ errors: productErrors {
+ ...ProductErrorFragment
+ }
}
}
`;
@@ -150,11 +158,11 @@ export const TypedCollectionCreateMutation = TypedMutation<
>(createCollection);
const removeCollection = gql`
+ ${productErrorFragment}
mutation RemoveCollection($id: ID!) {
collectionDelete(id: $id) {
- errors {
- field
- message
+ errors: productErrors {
+ ...ProductErrorFragment
}
}
}
@@ -165,6 +173,7 @@ export const TypedCollectionRemoveMutation = TypedMutation<
>(removeCollection);
const unassignCollectionProduct = gql`
+ ${productErrorFragment}
mutation UnassignCollectionProduct(
$collectionId: ID!
$productIds: [ID]!
@@ -177,10 +186,6 @@ const unassignCollectionProduct = gql`
collectionId: $collectionId
products: $productIds
) {
- errors {
- field
- message
- }
collection {
id
products(first: $first, after: $after, before: $before, last: $last) {
@@ -206,6 +211,9 @@ const unassignCollectionProduct = gql`
}
}
}
+ errors: productErrors {
+ ...ProductErrorFragment
+ }
}
}
`;
@@ -215,11 +223,11 @@ export const TypedUnassignCollectionProductMutation = TypedMutation<
>(unassignCollectionProduct);
const collectionBulkDelete = gql`
+ ${productErrorFragment}
mutation CollectionBulkDelete($ids: [ID]!) {
collectionBulkDelete(ids: $ids) {
- errors {
- field
- message
+ errors: productErrors {
+ ...ProductErrorFragment
}
}
}
@@ -230,11 +238,11 @@ export const TypedCollectionBulkDelete = TypedMutation<
>(collectionBulkDelete);
const collectionBulkPublish = gql`
+ ${productErrorFragment}
mutation CollectionBulkPublish($ids: [ID]!, $isPublished: Boolean!) {
collectionBulkPublish(ids: $ids, isPublished: $isPublished) {
- errors {
- field
- message
+ errors: productErrors {
+ ...ProductErrorFragment
}
}
}
diff --git a/src/collections/types/CollectionAssignProduct.ts b/src/collections/types/CollectionAssignProduct.ts
index 0fbfa3103..a2f5dce38 100644
--- a/src/collections/types/CollectionAssignProduct.ts
+++ b/src/collections/types/CollectionAssignProduct.ts
@@ -2,16 +2,12 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { ProductErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: CollectionAssignProduct
// ====================================================
-export interface CollectionAssignProduct_collectionAddProducts_errors {
- __typename: "Error";
- field: string | null;
- message: string | null;
-}
-
export interface CollectionAssignProduct_collectionAddProducts_collection_products_edges_node_productType {
__typename: "ProductType";
id: string;
@@ -57,10 +53,16 @@ export interface CollectionAssignProduct_collectionAddProducts_collection {
products: CollectionAssignProduct_collectionAddProducts_collection_products | null;
}
+export interface CollectionAssignProduct_collectionAddProducts_errors {
+ __typename: "ProductError";
+ code: ProductErrorCode;
+ field: string | null;
+}
+
export interface CollectionAssignProduct_collectionAddProducts {
__typename: "CollectionAddProducts";
- errors: CollectionAssignProduct_collectionAddProducts_errors[];
collection: CollectionAssignProduct_collectionAddProducts_collection | null;
+ errors: CollectionAssignProduct_collectionAddProducts_errors[];
}
export interface CollectionAssignProduct {
diff --git a/src/collections/types/CollectionBulkDelete.ts b/src/collections/types/CollectionBulkDelete.ts
index 84254bc4f..0214b943f 100644
--- a/src/collections/types/CollectionBulkDelete.ts
+++ b/src/collections/types/CollectionBulkDelete.ts
@@ -2,14 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { ProductErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: CollectionBulkDelete
// ====================================================
export interface CollectionBulkDelete_collectionBulkDelete_errors {
- __typename: "Error";
+ __typename: "ProductError";
+ code: ProductErrorCode;
field: string | null;
- message: string | null;
}
export interface CollectionBulkDelete_collectionBulkDelete {
diff --git a/src/collections/types/CollectionBulkPublish.ts b/src/collections/types/CollectionBulkPublish.ts
index 24739b592..542a2eaa5 100644
--- a/src/collections/types/CollectionBulkPublish.ts
+++ b/src/collections/types/CollectionBulkPublish.ts
@@ -2,14 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { ProductErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: CollectionBulkPublish
// ====================================================
export interface CollectionBulkPublish_collectionBulkPublish_errors {
- __typename: "Error";
+ __typename: "ProductError";
+ code: ProductErrorCode;
field: string | null;
- message: string | null;
}
export interface CollectionBulkPublish_collectionBulkPublish {
diff --git a/src/collections/types/CollectionUpdate.ts b/src/collections/types/CollectionUpdate.ts
index 95f216696..42f43cfd5 100644
--- a/src/collections/types/CollectionUpdate.ts
+++ b/src/collections/types/CollectionUpdate.ts
@@ -2,18 +2,12 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { CollectionInput } from "./../../types/globalTypes";
+import { CollectionInput, ProductErrorCode } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: CollectionUpdate
// ====================================================
-export interface CollectionUpdate_collectionUpdate_errors {
- __typename: "Error";
- field: string | null;
- message: string | null;
-}
-
export interface CollectionUpdate_collectionUpdate_collection_backgroundImage {
__typename: "Image";
alt: string | null;
@@ -32,10 +26,16 @@ export interface CollectionUpdate_collectionUpdate_collection {
seoTitle: string | null;
}
+export interface CollectionUpdate_collectionUpdate_errors {
+ __typename: "ProductError";
+ code: ProductErrorCode;
+ field: string | null;
+}
+
export interface CollectionUpdate_collectionUpdate {
__typename: "CollectionUpdate";
- errors: CollectionUpdate_collectionUpdate_errors[];
collection: CollectionUpdate_collectionUpdate_collection | null;
+ errors: CollectionUpdate_collectionUpdate_errors[];
}
export interface CollectionUpdate {
diff --git a/src/collections/types/CollectionUpdateWithHomepage.ts b/src/collections/types/CollectionUpdateWithHomepage.ts
index 71c2fd396..a51f43b1e 100644
--- a/src/collections/types/CollectionUpdateWithHomepage.ts
+++ b/src/collections/types/CollectionUpdateWithHomepage.ts
@@ -2,16 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { CollectionInput } from "./../../types/globalTypes";
+import { CollectionInput, ShopErrorCode, ProductErrorCode } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: CollectionUpdateWithHomepage
// ====================================================
export interface CollectionUpdateWithHomepage_homepageCollectionUpdate_errors {
- __typename: "Error";
+ __typename: "ShopError";
+ code: ShopErrorCode;
field: string | null;
- message: string | null;
}
export interface CollectionUpdateWithHomepage_homepageCollectionUpdate_shop_homepageCollection {
@@ -30,12 +30,6 @@ export interface CollectionUpdateWithHomepage_homepageCollectionUpdate {
shop: CollectionUpdateWithHomepage_homepageCollectionUpdate_shop | null;
}
-export interface CollectionUpdateWithHomepage_collectionUpdate_errors {
- __typename: "Error";
- field: string | null;
- message: string | null;
-}
-
export interface CollectionUpdateWithHomepage_collectionUpdate_collection_backgroundImage {
__typename: "Image";
alt: string | null;
@@ -54,10 +48,16 @@ export interface CollectionUpdateWithHomepage_collectionUpdate_collection {
seoTitle: string | null;
}
+export interface CollectionUpdateWithHomepage_collectionUpdate_errors {
+ __typename: "ProductError";
+ code: ProductErrorCode;
+ field: string | null;
+}
+
export interface CollectionUpdateWithHomepage_collectionUpdate {
__typename: "CollectionUpdate";
- errors: CollectionUpdateWithHomepage_collectionUpdate_errors[];
collection: CollectionUpdateWithHomepage_collectionUpdate_collection | null;
+ errors: CollectionUpdateWithHomepage_collectionUpdate_errors[];
}
export interface CollectionUpdateWithHomepage {
diff --git a/src/collections/types/CreateCollection.ts b/src/collections/types/CreateCollection.ts
index de5dc26e9..2a5ea5d9d 100644
--- a/src/collections/types/CreateCollection.ts
+++ b/src/collections/types/CreateCollection.ts
@@ -2,18 +2,12 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { CollectionCreateInput } from "./../../types/globalTypes";
+import { CollectionCreateInput, ProductErrorCode } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: CreateCollection
// ====================================================
-export interface CreateCollection_collectionCreate_errors {
- __typename: "Error";
- field: string | null;
- message: string | null;
-}
-
export interface CreateCollection_collectionCreate_collection_backgroundImage {
__typename: "Image";
alt: string | null;
@@ -32,10 +26,16 @@ export interface CreateCollection_collectionCreate_collection {
seoTitle: string | null;
}
+export interface CreateCollection_collectionCreate_errors {
+ __typename: "ProductError";
+ code: ProductErrorCode;
+ field: string | null;
+}
+
export interface CreateCollection_collectionCreate {
__typename: "CollectionCreate";
- errors: CreateCollection_collectionCreate_errors[];
collection: CreateCollection_collectionCreate_collection | null;
+ errors: CreateCollection_collectionCreate_errors[];
}
export interface CreateCollection {
diff --git a/src/collections/types/RemoveCollection.ts b/src/collections/types/RemoveCollection.ts
index 878406a25..588349acb 100644
--- a/src/collections/types/RemoveCollection.ts
+++ b/src/collections/types/RemoveCollection.ts
@@ -2,14 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { ProductErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: RemoveCollection
// ====================================================
export interface RemoveCollection_collectionDelete_errors {
- __typename: "Error";
+ __typename: "ProductError";
+ code: ProductErrorCode;
field: string | null;
- message: string | null;
}
export interface RemoveCollection_collectionDelete {
diff --git a/src/collections/types/ShopErrorFragment.ts b/src/collections/types/ShopErrorFragment.ts
new file mode 100644
index 000000000..ae705f05f
--- /dev/null
+++ b/src/collections/types/ShopErrorFragment.ts
@@ -0,0 +1,15 @@
+/* tslint:disable */
+/* eslint-disable */
+// This file was automatically generated and should not be edited.
+
+import { ShopErrorCode } from "./../../types/globalTypes";
+
+// ====================================================
+// GraphQL fragment: ShopErrorFragment
+// ====================================================
+
+export interface ShopErrorFragment {
+ __typename: "ShopError";
+ code: ShopErrorCode;
+ field: string | null;
+}
diff --git a/src/collections/types/UnassignCollectionProduct.ts b/src/collections/types/UnassignCollectionProduct.ts
index 054ca97f3..7104a9c85 100644
--- a/src/collections/types/UnassignCollectionProduct.ts
+++ b/src/collections/types/UnassignCollectionProduct.ts
@@ -2,16 +2,12 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { ProductErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: UnassignCollectionProduct
// ====================================================
-export interface UnassignCollectionProduct_collectionRemoveProducts_errors {
- __typename: "Error";
- field: string | null;
- message: string | null;
-}
-
export interface UnassignCollectionProduct_collectionRemoveProducts_collection_products_edges_node_productType {
__typename: "ProductType";
id: string;
@@ -57,10 +53,16 @@ export interface UnassignCollectionProduct_collectionRemoveProducts_collection {
products: UnassignCollectionProduct_collectionRemoveProducts_collection_products | null;
}
+export interface UnassignCollectionProduct_collectionRemoveProducts_errors {
+ __typename: "ProductError";
+ code: ProductErrorCode;
+ field: string | null;
+}
+
export interface UnassignCollectionProduct_collectionRemoveProducts {
__typename: "CollectionRemoveProducts";
- errors: UnassignCollectionProduct_collectionRemoveProducts_errors[];
collection: UnassignCollectionProduct_collectionRemoveProducts_collection | null;
+ errors: UnassignCollectionProduct_collectionRemoveProducts_errors[];
}
export interface UnassignCollectionProduct {
diff --git a/src/collections/views/CollectionCreate.tsx b/src/collections/views/CollectionCreate.tsx
index 8db1fcda5..345243306 100644
--- a/src/collections/views/CollectionCreate.tsx
+++ b/src/collections/views/CollectionCreate.tsx
@@ -4,7 +4,7 @@ import { useIntl } from "react-intl";
import { WindowTitle } from "@saleor/components/WindowTitle";
import useNavigator from "@saleor/hooks/useNavigator";
import useNotifier from "@saleor/hooks/useNotifier";
-import { maybe } from "../../misc";
+import { commonMessages } from "@saleor/intl";
import { CollectionCreateInput } from "../../types/globalTypes";
import CollectionCreatePage from "../components/CollectionCreatePage/CollectionCreatePage";
import { TypedCollectionCreateMutation } from "../mutations";
@@ -19,9 +19,7 @@ export const CollectionCreate: React.FC = () => {
const handleCollectionCreateSuccess = (data: CreateCollection) => {
if (data.collectionCreate.errors.length === 0) {
notify({
- text: intl.formatMessage({
- defaultMessage: "Created collection"
- })
+ text: intl.formatMessage(commonMessages.savedChanges)
});
navigate(collectionUrl(data.collectionCreate.collection.id));
} else {
@@ -31,7 +29,7 @@ export const CollectionCreate: React.FC = () => {
);
if (backgroundImageError) {
notify({
- text: backgroundImageError.message
+ text: intl.formatMessage(commonMessages.somethingWentWrong)
});
}
}
@@ -47,10 +45,7 @@ export const CollectionCreate: React.FC = () => {
})}
/>
createCollectionOpts.data.collectionCreate.errors,
- []
- )}
+ errors={createCollectionOpts.data?.collectionCreate.errors || []}
onBack={() => navigate(collectionListUrl())}
disabled={createCollectionOpts.loading}
onSubmit={formData =>
diff --git a/src/collections/views/CollectionDetails.tsx b/src/collections/views/CollectionDetails.tsx
index ed11232cb..74075e85e 100644
--- a/src/collections/views/CollectionDetails.tsx
+++ b/src/collections/views/CollectionDetails.tsx
@@ -88,7 +88,7 @@ export const CollectionDetails: React.FC = ({
);
if (backgroundImageError) {
notify({
- text: backgroundImageError.message
+ text: intl.formatMessage(commonMessages.somethingWentWrong)
});
}
}
@@ -204,7 +204,7 @@ export const CollectionDetails: React.FC = ({
onAdd={() => openModal("assign")}
onBack={handleBack}
disabled={loading}
- collection={maybe(() => data.collection)}
+ collection={data?.collection}
errors={
updateCollection.opts?.data?.collectionUpdate.errors || []
}
diff --git a/src/types/globalTypes.ts b/src/types/globalTypes.ts
index 2ad3dc59b..cdee80d75 100644
--- a/src/types/globalTypes.ts
+++ b/src/types/globalTypes.ts
@@ -563,6 +563,16 @@ export enum ShippingMethodTypeEnum {
WEIGHT = "WEIGHT",
}
+export enum ShopErrorCode {
+ ALREADY_EXISTS = "ALREADY_EXISTS",
+ CANNOT_FETCH_TAX_RATES = "CANNOT_FETCH_TAX_RATES",
+ GRAPHQL_ERROR = "GRAPHQL_ERROR",
+ INVALID = "INVALID",
+ NOT_FOUND = "NOT_FOUND",
+ REQUIRED = "REQUIRED",
+ UNIQUE = "UNIQUE",
+}
+
export enum StaffMemberStatus {
ACTIVE = "ACTIVE",
DEACTIVATED = "DEACTIVATED",
From a95054ecb3f283379628d23846b8fb4860bc3bbd Mon Sep 17 00:00:00 2001
From: dominik-zeglen
Date: Thu, 5 Mar 2020 16:03:10 +0100
Subject: [PATCH 03/35] Add form error stories
---
.../__snapshots__/Stories.test.ts.snap | 2247 ++++++++++++++++-
.../stories/categories/CategoryCreatePage.tsx | 19 +
.../stories/categories/CategoryUpdatePage.tsx | 19 +
.../collections/CollectionCreatePage.tsx | 29 +-
.../collections/CollectionDetailsPage.tsx | 26 +-
5 files changed, 2327 insertions(+), 13 deletions(-)
diff --git a/src/storybook/__snapshots__/Stories.test.ts.snap b/src/storybook/__snapshots__/Stories.test.ts.snap
index 5ced1da26..0ba09cbb4 100644
--- a/src/storybook/__snapshots__/Stories.test.ts.snap
+++ b/src/storybook/__snapshots__/Stories.test.ts.snap
@@ -10012,7 +10012,7 @@ exports[`Storyshots Views / Attributes / Attribute details form errors 1`] = `
- Generic form error
+ This field is required
- Generic form error
+ This field is required
- Generic form error
+ API error
`;
+exports[`Storyshots Views / Categories / Create category form errors 1`] = `
+
+`;
+
exports[`Storyshots Views / Categories / Update category default 1`] = `
`;
+exports[`Storyshots Views / Categories / Update category form errors 1`] = `
+
+`;
+
exports[`Storyshots Views / Categories / Update category loading 1`] = `
- Generic form error
+ This field is required
- Generic form error
+ This field is required
@@ -26436,9 +27911,7 @@ Ctrl + K"
/>
- Generic form error
-
+ />
@@ -30709,6 +32182,764 @@ Ctrl + K"
`;
+exports[`Storyshots Views / Collections / Create collection form errors 1`] = `
+
+
+
+`;
+
exports[`Storyshots Views / Collections / Create collection loading 1`] = `
)
.add("When loading", () => (
+ ))
+ .add("form errors", () => (
+
({
+ __typename: "ProductError",
+ ...err
+ }))}
+ />
));
diff --git a/src/storybook/stories/categories/CategoryUpdatePage.tsx b/src/storybook/stories/categories/CategoryUpdatePage.tsx
index 6bcd78919..f83b85ce2 100644
--- a/src/storybook/stories/categories/CategoryUpdatePage.tsx
+++ b/src/storybook/stories/categories/CategoryUpdatePage.tsx
@@ -3,6 +3,7 @@ import { Omit } from "@material-ui/core";
import { storiesOf } from "@storybook/react";
import React from "react";
+import { ProductErrorCode } from "@saleor/types/globalTypes";
import { category as categoryFixture } from "../../../categories/fixtures";
import CategoryUpdatePage, {
@@ -79,4 +80,22 @@ storiesOf("Views / Categories / Update category", module)
products={undefined}
category={undefined}
/>
+ ))
+ .add("form errors", () => (
+ ({
+ __typename: "ProductError",
+ ...err
+ }))}
+ />
));
diff --git a/src/storybook/stories/collections/CollectionCreatePage.tsx b/src/storybook/stories/collections/CollectionCreatePage.tsx
index 672dfe27f..9f174ad6e 100644
--- a/src/storybook/stories/collections/CollectionCreatePage.tsx
+++ b/src/storybook/stories/collections/CollectionCreatePage.tsx
@@ -2,6 +2,7 @@ import { Omit } from "@material-ui/core";
import { storiesOf } from "@storybook/react";
import React from "react";
+import { ProductErrorCode } from "@saleor/types/globalTypes";
import CollectionCreatePage, {
CollectionCreatePageProps
} from "../../../collections/components/CollectionCreatePage";
@@ -18,4 +19,30 @@ const props: Omit = {
storiesOf("Views / Collections / Create collection", module)
.addDecorator(Decorator)
.add("default", () => )
- .add("loading", () => );
+ .add("loading", () => )
+ .add("form errors", () => (
+ ({
+ __typename: "ProductError",
+ ...err
+ }))}
+ />
+ ));
diff --git a/src/storybook/stories/collections/CollectionDetailsPage.tsx b/src/storybook/stories/collections/CollectionDetailsPage.tsx
index ddf9dee05..91d976019 100644
--- a/src/storybook/stories/collections/CollectionDetailsPage.tsx
+++ b/src/storybook/stories/collections/CollectionDetailsPage.tsx
@@ -4,7 +4,7 @@ import React from "react";
import placeholderCollectionImage from "@assets/images/block1.jpg";
import placeholderProductImage from "@assets/images/placeholder60x60.png";
-import { formError } from "@saleor/storybook/misc";
+import { ProductErrorCode } from "@saleor/types/globalTypes";
import CollectionDetailsPage, {
CollectionDetailsPageProps
} from "../../../collections/components/CollectionDetailsPage";
@@ -42,9 +42,27 @@ storiesOf("Views / Collections / Collection details", module)
.add("form errors", () => (
({
+ __typename: "ProductError",
+ ...err
+ }))}
/>
))
.add("no products", () => (
From 490c4c302333148d63180557a457fe58e751e73f Mon Sep 17 00:00:00 2001
From: dominik-zeglen
Date: Thu, 5 Mar 2020 18:48:54 +0100
Subject: [PATCH 04/35] Check shop errors too
---
src/collections/containers/CollectionOperations.tsx | 6 +++++-
src/collections/views/CollectionDetails.tsx | 9 +++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/collections/containers/CollectionOperations.tsx b/src/collections/containers/CollectionOperations.tsx
index fd40ff642..9a65c37f1 100644
--- a/src/collections/containers/CollectionOperations.tsx
+++ b/src/collections/containers/CollectionOperations.tsx
@@ -54,6 +54,7 @@ interface CollectionUpdateOperationsProps {
>;
}) => React.ReactNode;
onUpdate: (data: CollectionUpdate) => void;
+ onUpdateWithCollection: (data: CollectionUpdateWithHomepage) => void;
onProductAssign: (data: CollectionAssignProduct) => void;
onProductUnassign: (data: UnassignCollectionProduct) => void;
onRemove: (data: RemoveCollection) => void;
@@ -62,6 +63,7 @@ interface CollectionUpdateOperationsProps {
const CollectionOperations: React.FC = ({
children,
onUpdate,
+ onUpdateWithCollection,
onProductAssign,
onProductUnassign,
onRemove
@@ -72,7 +74,9 @@ const CollectionOperations: React.FC = ({
{(...removeCollection) => (
{(...assignProduct) => (
-
+
{(...updateWithHomepage) => (
= ({
}
}
};
+ const handleCollectioUpdateWithHomepage = (
+ data: CollectionUpdateWithHomepage
+ ) => {
+ if (data.homepageCollectionUpdate.errors.length === 0) {
+ handleCollectionUpdate(data);
+ }
+ };
const handleProductAssign = (data: CollectionAssignProduct) => {
if (data.collectionAddProducts.errors.length === 0) {
@@ -130,6 +138,7 @@ export const CollectionDetails: React.FC = ({
return (
Date: Fri, 6 Mar 2020 12:09:55 +0100
Subject: [PATCH 05/35] Add error state
---
.../MultiAutocompleteSelectField.stories.tsx | 7 +++---
.../MultiAutocompleteSelectField.tsx | 23 ++++++++++---------
2 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/src/components/MultiAutocompleteSelectField/MultiAutocompleteSelectField.stories.tsx b/src/components/MultiAutocompleteSelectField/MultiAutocompleteSelectField.stories.tsx
index ff7e70fc0..7b6763e7e 100644
--- a/src/components/MultiAutocompleteSelectField/MultiAutocompleteSelectField.stories.tsx
+++ b/src/components/MultiAutocompleteSelectField/MultiAutocompleteSelectField.stories.tsx
@@ -30,7 +30,7 @@ const Story: React.FC> = ({ allowCustomValues, enableLoadMore }) => {
+>> = ({ enableLoadMore, ...rest }) => {
const { change, data: countries } = useMultiAutocomplete([suggestions[0]]);
return (
@@ -49,7 +49,7 @@ const Story: React.FC
)}
@@ -84,4 +84,5 @@ storiesOf("Generics / Multiple select with autocomplete", module)
.add("interactive with custom option", () => (
))
- .add("interactive with load more", () => );
+ .add("interactive with load more", () => )
+ .add("interactive with error", () => );
diff --git a/src/components/MultiAutocompleteSelectField/MultiAutocompleteSelectField.tsx b/src/components/MultiAutocompleteSelectField/MultiAutocompleteSelectField.tsx
index 61aabf8ba..fc1fcc625 100644
--- a/src/components/MultiAutocompleteSelectField/MultiAutocompleteSelectField.tsx
+++ b/src/components/MultiAutocompleteSelectField/MultiAutocompleteSelectField.tsx
@@ -59,6 +59,7 @@ export interface MultiAutocompleteSelectFieldProps
extends Partial {
allowCustomValues?: boolean;
displayValues: MultiAutocompleteChoiceType[];
+ error?: boolean;
name: string;
choices: MultiAutocompleteChoiceType[];
value: string[];
@@ -70,19 +71,16 @@ export interface MultiAutocompleteSelectFieldProps
onChange: (event: React.ChangeEvent) => void;
}
-const DebounceAutocomplete: React.ComponentType<
- DebounceProps
-> = Debounce;
+const DebounceAutocomplete: React.ComponentType> = Debounce;
-const MultiAutocompleteSelectFieldComponent: React.FC<
- MultiAutocompleteSelectFieldProps
-> = props => {
+const MultiAutocompleteSelectFieldComponent: React.FC = props => {
const {
allowCustomValues,
choices,
-
displayValues,
-
+ error,
hasMore,
helperText,
label,
@@ -147,6 +145,7 @@ const MultiAutocompleteSelectFieldComponent: React.FC<
id: undefined,
onClick: toggleMenu
}}
+ error={error}
helperText={helperText}
label={label}
fullWidth={true}
@@ -191,9 +190,11 @@ const MultiAutocompleteSelectFieldComponent: React.FC<
);
};
-const MultiAutocompleteSelectField: React.FC<
- MultiAutocompleteSelectFieldProps
-> = ({ choices, fetchChoices, ...props }) => {
+const MultiAutocompleteSelectField: React.FC = ({
+ choices,
+ fetchChoices,
+ ...props
+}) => {
const [query, setQuery] = React.useState("");
if (fetchChoices) {
From ff74c566ab567c436646e598b1f980bada4be824 Mon Sep 17 00:00:00 2001
From: dominik-zeglen
Date: Fri, 6 Mar 2020 15:25:23 +0100
Subject: [PATCH 06/35] Use error formatting in product section
---
.../ProductCreatePage/ProductCreatePage.tsx | 6 +-
.../ProductDetailsForm/ProductDetailsForm.tsx | 16 ++-
.../ProductOrganization.tsx | 34 +++--
.../ProductPricing/ProductPricing.tsx | 16 ++-
.../components/ProductStock/ProductStock.tsx | 38 +++---
.../ProductUpdatePage/ProductUpdatePage.tsx | 6 +-
.../ProductVariantCreateSummary.tsx | 51 ++++----
.../ProductVariantCreatePage.tsx | 4 +-
.../ProductVariantPrice.tsx | 18 +--
.../ProductVariantStock.tsx | 40 +++---
src/products/mutations.ts | 122 +++++++++---------
.../types/BulkProductErrorFragment.ts | 16 +++
src/products/types/ProductCreate.ts | 6 +-
src/products/types/ProductDelete.ts | 6 +-
src/products/types/ProductImageCreate.ts | 6 +-
src/products/types/ProductImageDelete.ts | 9 ++
src/products/types/ProductImageReorder.ts | 6 +-
src/products/types/ProductImageUpdate.ts | 6 +-
src/products/types/ProductUpdate.ts | 6 +-
.../types/ProductVariantBulkCreate.ts | 10 +-
.../types/ProductVariantBulkDelete.ts | 6 +-
src/products/types/SimpleProductUpdate.ts | 10 +-
src/products/types/VariantCreate.ts | 5 +-
src/products/types/VariantDelete.ts | 6 +-
src/products/types/VariantImageAssign.ts | 6 +-
src/products/types/VariantImageUnassign.ts | 6 +-
src/products/types/VariantUpdate.ts | 5 +-
src/products/types/productBulkDelete.ts | 6 +-
src/products/types/productBulkPublish.ts | 6 +-
src/products/views/ProductCreate.tsx | 12 +-
.../views/ProductUpdate/ProductUpdate.tsx | 20 +--
src/products/views/ProductVariantCreate.tsx | 17 +--
src/utils/errors/product.ts | 65 ++++++++++
33 files changed, 348 insertions(+), 244 deletions(-)
create mode 100644 src/products/types/BulkProductErrorFragment.ts
create mode 100644 src/utils/errors/product.ts
diff --git a/src/products/components/ProductCreatePage/ProductCreatePage.tsx b/src/products/components/ProductCreatePage/ProductCreatePage.tsx
index 10c543699..8386cfb8c 100644
--- a/src/products/components/ProductCreatePage/ProductCreatePage.tsx
+++ b/src/products/components/ProductCreatePage/ProductCreatePage.tsx
@@ -27,7 +27,8 @@ import { SearchCollections_search_edges_node } from "@saleor/searches/types/Sear
import { SearchProductTypes_search_edges_node_productAttributes } from "@saleor/searches/types/SearchProductTypes";
import createMultiAutocompleteSelectHandler from "@saleor/utils/handlers/multiAutocompleteSelectChangeHandler";
import createSingleAutocompleteSelectHandler from "@saleor/utils/handlers/singleAutocompleteSelectChangeHandler";
-import { FetchMoreProps, UserError } from "../../../types";
+import { ProductErrorFragment } from "@saleor/attributes/types/ProductErrorFragment";
+import { FetchMoreProps } from "../../../types";
import {
createAttributeChangeHandler,
createAttributeMultiChangeHandler,
@@ -62,7 +63,7 @@ export interface ProductCreatePageSubmitData extends FormData {
}
interface ProductCreatePageProps {
- errors: UserError[];
+ errors: ProductErrorFragment[];
collections: SearchCollections_search_edges_node[];
categories: SearchCategories_search_edges_node[];
currency: string;
@@ -227,6 +228,7 @@ export const ProductCreatePage: React.FC = ({
currency={currency}
data={data}
disabled={disabled}
+ errors={errors}
onChange={change}
/>
diff --git a/src/products/components/ProductDetailsForm/ProductDetailsForm.tsx b/src/products/components/ProductDetailsForm/ProductDetailsForm.tsx
index 3ade54592..04d3321f4 100644
--- a/src/products/components/ProductDetailsForm/ProductDetailsForm.tsx
+++ b/src/products/components/ProductDetailsForm/ProductDetailsForm.tsx
@@ -9,8 +9,8 @@ import CardTitle from "@saleor/components/CardTitle";
import FormSpacer from "@saleor/components/FormSpacer";
import RichTextEditor from "@saleor/components/RichTextEditor";
import { commonMessages } from "@saleor/intl";
-import { UserError } from "@saleor/types";
-import { getFieldError } from "@saleor/utils/errors";
+import { getFormErrors, getProductErrorMessage } from "@saleor/utils/errors";
+import { ProductErrorFragment } from "@saleor/attributes/types/ProductErrorFragment";
interface ProductDetailsFormProps {
data: {
@@ -18,7 +18,7 @@ interface ProductDetailsFormProps {
name: string;
};
disabled?: boolean;
- errors: UserError[];
+ errors: ProductErrorFragment[];
// Draftail isn't controlled - it needs only initial input
// because it's autosaving on its own.
// Ref https://github.com/mirumee/saleor/issues/4470
@@ -35,6 +35,8 @@ export const ProductDetailsForm: React.FC = ({
}) => {
const intl = useIntl();
+ const formErrors = getFormErrors(["name", "descriptionJson"], errors);
+
return (
= ({
/>
= ({
= props => {
const classes = useStyles(props);
const intl = useIntl();
+ const formErrors = getFormErrors(
+ ["productType", "category", "collections"],
+ errors
+ );
+
return (
= props => {
{canChangeType ? (
= props => {
= props => {
({
@@ -26,15 +28,18 @@ interface ProductPricingProps {
basePrice: number;
};
disabled: boolean;
+ errors: ProductErrorFragment[];
onChange: (event: React.ChangeEvent) => void;
}
const ProductPricing: React.FC = props => {
- const { currency, data, disabled, onChange } = props;
- const classes = useStyles(props);
+ const { currency, data, disabled, errors, onChange } = props;
+ const classes = useStyles(props);
const intl = useIntl();
+ const formErrors = getFormErrors(["basePrice"], errors);
+
return (
= props => {
defaultMessage: "Price",
description: "product price"
})}
+ error={!!formErrors.basePrice}
+ hint={getProductErrorMessage(formErrors.basePrice, intl)}
name="basePrice"
value={data.basePrice}
currencySymbol={currency}
onChange={onChange}
+ InputProps={{
+ inputProps: {
+ min: 0
+ }
+ }}
/>
diff --git a/src/products/components/ProductStock/ProductStock.tsx b/src/products/components/ProductStock/ProductStock.tsx
index 17a61cf59..c76609af4 100644
--- a/src/products/components/ProductStock/ProductStock.tsx
+++ b/src/products/components/ProductStock/ProductStock.tsx
@@ -6,8 +6,8 @@ import React from "react";
import { useIntl } from "react-intl";
import CardTitle from "@saleor/components/CardTitle";
-import { UserError } from "@saleor/types";
-import { getFieldError } from "@saleor/utils/errors";
+import { ProductErrorFragment } from "@saleor/attributes/types/ProductErrorFragment";
+import { getFormErrors, getProductErrorMessage } from "@saleor/utils/errors";
import { maybe } from "../../../misc";
import { ProductDetails_product } from "../../types/ProductDetails";
@@ -28,17 +28,19 @@ interface ProductStockProps {
stockQuantity: number;
};
disabled: boolean;
- errors: UserError[];
+ errors: ProductErrorFragment[];
product: ProductDetails_product;
onChange: (event: React.ChangeEvent) => void;
}
const ProductStock: React.FC = props => {
const { data, disabled, product, onChange, errors } = props;
- const classes = useStyles(props);
+ const classes = useStyles(props);
const intl = useIntl();
+ const formErrors = getFormErrors(["sku", "stockQuantity"], errors);
+
return (
= props => {
})}
value={data.sku}
onChange={onChange}
- error={!!getFieldError(errors, "sku")}
- helperText={getFieldError(errors, "sku")?.message}
+ error={!!formErrors.sku}
+ helperText={getProductErrorMessage(formErrors.sku, intl)}
/>
= props => {
type="number"
onChange={onChange}
helperText={
- product
- ? intl.formatMessage(
- {
- defaultMessage: "Allocated: {quantity}",
- description: "allocated product stock"
- },
- {
- quantity: maybe(
- () => product.variants[0].quantityAllocated
- )
- }
- )
- : undefined
+ getProductErrorMessage(formErrors.stockQuantity, intl) ||
+ (product &&
+ intl.formatMessage(
+ {
+ defaultMessage: "Allocated: {quantity}",
+ description: "allocated product stock"
+ },
+ {
+ quantity: product?.variants[0].quantityAllocated
+ }
+ ))
}
/>
diff --git a/src/products/components/ProductUpdatePage/ProductUpdatePage.tsx b/src/products/components/ProductUpdatePage/ProductUpdatePage.tsx
index 92adbea8e..0e7362403 100644
--- a/src/products/components/ProductUpdatePage/ProductUpdatePage.tsx
+++ b/src/products/components/ProductUpdatePage/ProductUpdatePage.tsx
@@ -19,9 +19,10 @@ import { sectionNames } from "@saleor/intl";
import { maybe } from "@saleor/misc";
import { SearchCategories_search_edges_node } from "@saleor/searches/types/SearchCategories";
import { SearchCollections_search_edges_node } from "@saleor/searches/types/SearchCollections";
-import { FetchMoreProps, ListActions, UserError } from "@saleor/types";
+import { FetchMoreProps, ListActions } from "@saleor/types";
import createMultiAutocompleteSelectHandler from "@saleor/utils/handlers/multiAutocompleteSelectChangeHandler";
import createSingleAutocompleteSelectHandler from "@saleor/utils/handlers/singleAutocompleteSelectChangeHandler";
+import { ProductErrorFragment } from "@saleor/attributes/types/ProductErrorFragment";
import {
ProductDetails_product,
ProductDetails_product_images,
@@ -48,7 +49,7 @@ import ProductStock from "../ProductStock";
import ProductVariants from "../ProductVariants";
export interface ProductUpdatePageProps extends ListActions {
- errors: UserError[];
+ errors: ProductErrorFragment[];
placeholderImage: string;
collections: SearchCollections_search_edges_node[];
categories: SearchCategories_search_edges_node[];
@@ -219,6 +220,7 @@ export const ProductUpdatePage: React.FC = ({
currency={currency}
data={data}
disabled={disabled}
+ errors={errors}
onChange={change}
/>
diff --git a/src/products/components/ProductVariantCreateDialog/ProductVariantCreateSummary.tsx b/src/products/components/ProductVariantCreateDialog/ProductVariantCreateSummary.tsx
index 86cf5cc90..01e370e9e 100644
--- a/src/products/components/ProductVariantCreateDialog/ProductVariantCreateSummary.tsx
+++ b/src/products/components/ProductVariantCreateDialog/ProductVariantCreateSummary.tsx
@@ -10,12 +10,13 @@ import Typography from "@material-ui/core/Typography";
import DeleteIcon from "@material-ui/icons/Delete";
import classNames from "classnames";
import React from "react";
-import { FormattedMessage } from "react-intl";
+import { FormattedMessage, useIntl } from "react-intl";
import Hr from "@saleor/components/Hr";
-import { maybe } from "@saleor/misc";
-import { ProductVariantBulkCreate_productVariantBulkCreate_bulkProductErrors } from "@saleor/products/types/ProductVariantBulkCreate";
+import { ProductVariantBulkCreate_productVariantBulkCreate_errors } from "@saleor/products/types/ProductVariantBulkCreate";
import { ProductVariantBulkCreateInput } from "@saleor/types/globalTypes";
+import { getFormErrors } from "@saleor/utils/errors";
+import { getBulkProductErrorMessage } from "@saleor/utils/errors/product";
import { ProductDetails_product_productType_variantAttributes } from "../../types/ProductDetails";
import { ProductVariantCreateFormData } from "./form";
import { VariantField } from "./reducer";
@@ -24,7 +25,7 @@ export interface ProductVariantCreateSummaryProps {
attributes: ProductDetails_product_productType_variantAttributes[];
currencySymbol: string;
data: ProductVariantCreateFormData;
- errors: ProductVariantBulkCreate_productVariantBulkCreate_bulkProductErrors[];
+ errors: ProductVariantBulkCreate_productVariantBulkCreate_errors[];
onVariantDataChange: (
variantIndex: number,
field: VariantField,
@@ -107,9 +108,7 @@ function getVariantName(
);
}
-const ProductVariantCreateSummary: React.FC<
- ProductVariantCreateSummaryProps
-> = props => {
+const ProductVariantCreateSummary: React.FC = props => {
const {
attributes,
currencySymbol,
@@ -119,6 +118,7 @@ const ProductVariantCreateSummary: React.FC<
onVariantDelete
} = props;
const classes = useStyles(props);
+ const intl = useIntl();
return (
<>
@@ -181,6 +181,10 @@ const ProductVariantCreateSummary: React.FC<
const variantErrors = errors.filter(
error => error.index === variantIndex
);
+ const variantFormErrors = getFormErrors(
+ ["priceOverride", "quantity", "sku"],
+ variantErrors
+ );
return (
error.field === "priceOverride"
- )
- }
- helperText={maybe(
- () =>
- variantErrors.find(
- error => error.field === "priceOverride"
- ).message
+ error={!!variantFormErrors.priceOverride}
+ helperText={getBulkProductErrorMessage(
+ variantFormErrors.priceOverride,
+ intl
)}
inputProps={{
min: 0,
@@ -241,13 +239,10 @@ const ProductVariantCreateSummary: React.FC<
error.field === "quantity")
- }
- helperText={maybe(
- () =>
- variantErrors.find(error => error.field === "quantity")
- .message
+ error={!!variantFormErrors.quantity}
+ helperText={getBulkProductErrorMessage(
+ variantFormErrors.quantity,
+ intl
)}
inputProps={{
min: 0,
@@ -267,10 +262,10 @@ const ProductVariantCreateSummary: React.FC<
error.field === "sku")}
- helperText={maybe(
- () =>
- variantErrors.find(error => error.field === "sku").message
+ error={!!variantFormErrors.sku}
+ helperText={getBulkProductErrorMessage(
+ variantFormErrors.sku,
+ intl
)}
fullWidth
value={variant.sku}
diff --git a/src/products/components/ProductVariantCreatePage/ProductVariantCreatePage.tsx b/src/products/components/ProductVariantCreatePage/ProductVariantCreatePage.tsx
index eb6449f09..47b3c4d13 100644
--- a/src/products/components/ProductVariantCreatePage/ProductVariantCreatePage.tsx
+++ b/src/products/components/ProductVariantCreatePage/ProductVariantCreatePage.tsx
@@ -13,8 +13,8 @@ import useFormset, {
FormsetChange,
FormsetData
} from "@saleor/hooks/useFormset";
-import { VariantCreate_productVariantCreate_productErrors } from "@saleor/products/types/VariantCreate";
import { getVariantAttributeInputFromProduct } from "@saleor/products/utils/data";
+import { ProductErrorFragment } from "@saleor/attributes/types/ProductErrorFragment";
import { maybe } from "../../../misc";
import { ProductVariantCreateData_product } from "../../types/ProductVariantCreateData";
import ProductVariantAttributes, {
@@ -39,7 +39,7 @@ export interface ProductVariantCreatePageSubmitData
interface ProductVariantCreatePageProps {
currencySymbol: string;
- errors: VariantCreate_productVariantCreate_productErrors[];
+ errors: ProductErrorFragment[];
header: string;
loading: boolean;
product: ProductVariantCreateData_product;
diff --git a/src/products/components/ProductVariantPrice/ProductVariantPrice.tsx b/src/products/components/ProductVariantPrice/ProductVariantPrice.tsx
index 057985ddd..738c3ea04 100644
--- a/src/products/components/ProductVariantPrice/ProductVariantPrice.tsx
+++ b/src/products/components/ProductVariantPrice/ProductVariantPrice.tsx
@@ -6,8 +6,8 @@ import { useIntl } from "react-intl";
import CardTitle from "@saleor/components/CardTitle";
import PriceField from "@saleor/components/PriceField";
-import { UserError } from "@saleor/types";
-import { getFieldError } from "@saleor/utils/errors";
+import { ProductErrorFragment } from "@saleor/attributes/types/ProductErrorFragment";
+import { getFormErrors, getProductErrorMessage } from "@saleor/utils/errors";
const useStyles = makeStyles(
theme => ({
@@ -24,7 +24,7 @@ interface ProductVariantPriceProps {
currencySymbol?: string;
priceOverride?: string;
costPrice?: string;
- errors: UserError[];
+ errors: ProductErrorFragment[];
loading?: boolean;
onChange(event: any);
}
@@ -38,10 +38,12 @@ const ProductVariantPrice: React.FC = props => {
loading,
onChange
} = props;
- const classes = useStyles(props);
+ const classes = useStyles(props);
const intl = useIntl();
+ const formErrors = getFormErrors(["price_override", "cost_price"], errors);
+
return (
= props => {
({
@@ -21,7 +21,7 @@ const useStyles = makeStyles(
);
interface ProductVariantStockProps {
- errors: UserError[];
+ errors: ProductErrorFragment[];
sku: string;
quantity: string;
stockAllocated?: number;
@@ -31,10 +31,12 @@ interface ProductVariantStockProps {
const ProductVariantStock: React.FC = props => {
const { errors, sku, quantity, stockAllocated, loading, onChange } = props;
- const classes = useStyles(props);
+ const classes = useStyles(props);
const intl = useIntl();
+ const formErrors = getFormErrors(["quantity", "sku"], errors);
+
return (
= props => {
= props => {
description: "product variant stock"
})}
helperText={
- getFieldError(errors, "quantity")
- ? getFieldError(errors, "quantity")
- : !!stockAllocated
- ? intl.formatMessage(
- {
- defaultMessage: "Allocated: {quantity}",
- description: "variant allocated stock"
- },
- {
- quantity: stockAllocated
- }
- )
- : undefined
+ getProductErrorMessage(formErrors.quantity, intl) ||
+ (!!stockAllocated &&
+ intl.formatMessage(
+ {
+ defaultMessage: "Allocated: {quantity}",
+ description: "variant allocated stock"
+ },
+ {
+ quantity: stockAllocated
+ }
+ ))
}
onChange={onChange}
disabled={loading}
@@ -76,8 +76,8 @@ const ProductVariantStock: React.FC = props => {
(productImageCreateMutation);
export const productDeleteMutation = gql`
+ ${productErrorFragment}
mutation ProductDelete($id: ID!) {
productDelete(id: $id) {
- errors {
- field
- message
+ errors: productErrors {
+ ...ProductErrorFragment
}
product {
id
@@ -92,11 +101,11 @@ export const TypedProductDeleteMutation = TypedMutation<
>(productDeleteMutation);
export const productImagesReorder = gql`
+ ${productErrorFragment}
mutation ProductImageReorder($productId: ID!, $imagesIds: [ID]!) {
productImageReorder(productId: $productId, imagesIds: $imagesIds) {
- errors {
- field
- message
+ errors: productErrors {
+ ...ProductErrorFragment
}
product {
id
@@ -116,6 +125,7 @@ export const TypedProductImagesReorder = TypedMutation<
>(productImagesReorder);
export const productUpdateMutation = gql`
+ ${productErrorFragment}
${productFragmentDetails}
mutation ProductUpdate(
$id: ID!
@@ -145,9 +155,8 @@ export const productUpdateMutation = gql`
seo: $seo
}
) {
- errors {
- field
- message
+ errors: productErrors {
+ ...ProductErrorFragment
}
product {
...Product
@@ -161,6 +170,7 @@ export const TypedProductUpdateMutation = TypedMutation<
>(productUpdateMutation);
export const simpleProductUpdateMutation = gql`
+ ${productErrorFragment}
${productFragmentDetails}
${fragmentVariant}
mutation SimpleProductUpdate(
@@ -193,18 +203,16 @@ export const simpleProductUpdateMutation = gql`
seo: $seo
}
) {
- errors {
- field
- message
+ errors: productErrors {
+ ...ProductErrorFragment
}
product {
...Product
}
}
productVariantUpdate(id: $productVariantId, input: $productVariantInput) {
- errors {
- field
- message
+ errors: productErrors {
+ ...ProductErrorFragment
}
productVariant {
...ProductVariant
@@ -218,6 +226,7 @@ export const TypedSimpleProductUpdateMutation = TypedMutation<
>(simpleProductUpdateMutation);
export const productCreateMutation = gql`
+ ${productErrorFragment}
${productFragmentDetails}
mutation ProductCreate(
$attributes: [AttributeValueInput]
@@ -251,9 +260,8 @@ export const productCreateMutation = gql`
seo: $seo
}
) {
- errors {
- field
- message
+ errors: productErrors {
+ ...ProductErrorFragment
}
product {
...Product
@@ -267,11 +275,11 @@ export const TypedProductCreateMutation = TypedMutation<
>(productCreateMutation);
export const variantDeleteMutation = gql`
+ ${productErrorFragment}
mutation VariantDelete($id: ID!) {
productVariantDelete(id: $id) {
- errors {
- field
- message
+ errors: productErrors {
+ ...ProductErrorFragment
}
productVariant {
id
@@ -286,6 +294,7 @@ export const TypedVariantDeleteMutation = TypedMutation<
export const variantUpdateMutation = gql`
${fragmentVariant}
+ ${productErrorFragment}
mutation VariantUpdate(
$id: ID!
$attributes: [AttributeValueInput]
@@ -306,10 +315,8 @@ export const variantUpdateMutation = gql`
trackInventory: $trackInventory
}
) {
- productErrors {
- code
- field
- message
+ errors: productErrors {
+ ...ProductErrorFragment
}
productVariant {
...ProductVariant
@@ -324,12 +331,11 @@ export const TypedVariantUpdateMutation = TypedMutation<
export const variantCreateMutation = gql`
${fragmentVariant}
+ ${productErrorFragment}
mutation VariantCreate($input: ProductVariantCreateInput!) {
productVariantCreate(input: $input) {
- productErrors {
- code
- field
- message
+ errors: productErrors {
+ ...ProductErrorFragment
}
productVariant {
...ProductVariant
@@ -343,8 +349,12 @@ export const TypedVariantCreateMutation = TypedMutation<
>(variantCreateMutation);
export const productImageDeleteMutation = gql`
+ ${productErrorFragment}
mutation ProductImageDelete($id: ID!) {
productImageDelete(id: $id) {
+ errors: productErrors {
+ ...ProductErrorFragment
+ }
product {
id
images {
@@ -360,12 +370,12 @@ export const TypedProductImageDeleteMutation = TypedMutation<
>(productImageDeleteMutation);
export const productImageUpdateMutation = gql`
+ ${productErrorFragment}
${productFragmentDetails}
mutation ProductImageUpdate($id: ID!, $alt: String!) {
productImageUpdate(id: $id, input: { alt: $alt }) {
- errors {
- field
- message
+ errors: productErrors {
+ ...ProductErrorFragment
}
product {
...Product
@@ -380,11 +390,11 @@ export const TypedProductImageUpdateMutation = TypedMutation<
export const variantImageAssignMutation = gql`
${fragmentVariant}
+ ${productErrorFragment}
mutation VariantImageAssign($variantId: ID!, $imageId: ID!) {
variantImageAssign(variantId: $variantId, imageId: $imageId) {
- errors {
- field
- message
+ errors: productErrors {
+ ...ProductErrorFragment
}
productVariant {
...ProductVariant
@@ -399,11 +409,11 @@ export const TypedVariantImageAssignMutation = TypedMutation<
export const variantImageUnassignMutation = gql`
${fragmentVariant}
+ ${productErrorFragment}
mutation VariantImageUnassign($variantId: ID!, $imageId: ID!) {
variantImageUnassign(variantId: $variantId, imageId: $imageId) {
- errors {
- field
- message
+ errors: productErrors {
+ ...ProductErrorFragment
}
productVariant {
...ProductVariant
@@ -417,11 +427,11 @@ export const TypedVariantImageUnassignMutation = TypedMutation<
>(variantImageUnassignMutation);
export const productBulkDeleteMutation = gql`
+ ${productErrorFragment}
mutation productBulkDelete($ids: [ID!]!) {
productBulkDelete(ids: $ids) {
- errors {
- field
- message
+ errors: productErrors {
+ ...ProductErrorFragment
}
}
}
@@ -432,11 +442,11 @@ export const TypedProductBulkDeleteMutation = TypedMutation<
>(productBulkDeleteMutation);
export const productBulkPublishMutation = gql`
+ ${productErrorFragment}
mutation productBulkPublish($ids: [ID!]!, $isPublished: Boolean!) {
productBulkPublish(ids: $ids, isPublished: $isPublished) {
- errors {
- field
- message
+ errors: productErrors {
+ ...ProductErrorFragment
}
}
}
@@ -447,20 +457,14 @@ export const TypedProductBulkPublishMutation = TypedMutation<
>(productBulkPublishMutation);
export const ProductVariantBulkCreateMutation = gql`
+ ${bulkProductErrorFragment}
mutation ProductVariantBulkCreate(
$id: ID!
$inputs: [ProductVariantBulkCreateInput]!
) {
productVariantBulkCreate(product: $id, variants: $inputs) {
- bulkProductErrors {
- field
- message
- code
- index
- }
- errors {
- field
- message
+ errors: bulkProductErrors {
+ ...BulkProductErrorFragment
}
}
}
@@ -471,11 +475,11 @@ export const TypedProductVariantBulkCreateMutation = TypedMutation<
>(ProductVariantBulkCreateMutation);
export const ProductVariantBulkDeleteMutation = gql`
+ ${productErrorFragment}
mutation ProductVariantBulkDelete($ids: [ID!]!) {
productVariantBulkDelete(ids: $ids) {
- errors {
- field
- message
+ errors: productErrors {
+ ...ProductErrorFragment
}
}
}
diff --git a/src/products/types/BulkProductErrorFragment.ts b/src/products/types/BulkProductErrorFragment.ts
new file mode 100644
index 000000000..940f13b10
--- /dev/null
+++ b/src/products/types/BulkProductErrorFragment.ts
@@ -0,0 +1,16 @@
+/* tslint:disable */
+/* eslint-disable */
+// This file was automatically generated and should not be edited.
+
+import { ProductErrorCode } from "./../../types/globalTypes";
+
+// ====================================================
+// GraphQL fragment: BulkProductErrorFragment
+// ====================================================
+
+export interface BulkProductErrorFragment {
+ __typename: "BulkProductError";
+ field: string | null;
+ code: ProductErrorCode;
+ index: number | null;
+}
diff --git a/src/products/types/ProductCreate.ts b/src/products/types/ProductCreate.ts
index e5a191096..c265fd69f 100644
--- a/src/products/types/ProductCreate.ts
+++ b/src/products/types/ProductCreate.ts
@@ -2,16 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { AttributeValueInput, SeoInput, AttributeInputTypeEnum } from "./../../types/globalTypes";
+import { AttributeValueInput, SeoInput, ProductErrorCode, AttributeInputTypeEnum } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: ProductCreate
// ====================================================
export interface ProductCreate_productCreate_errors {
- __typename: "Error";
+ __typename: "ProductError";
+ code: ProductErrorCode;
field: string | null;
- message: string | null;
}
export interface ProductCreate_productCreate_product_category {
diff --git a/src/products/types/ProductDelete.ts b/src/products/types/ProductDelete.ts
index c6c12dacf..3d64102f3 100644
--- a/src/products/types/ProductDelete.ts
+++ b/src/products/types/ProductDelete.ts
@@ -2,14 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { ProductErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: ProductDelete
// ====================================================
export interface ProductDelete_productDelete_errors {
- __typename: "Error";
+ __typename: "ProductError";
+ code: ProductErrorCode;
field: string | null;
- message: string | null;
}
export interface ProductDelete_productDelete_product {
diff --git a/src/products/types/ProductImageCreate.ts b/src/products/types/ProductImageCreate.ts
index 12e5fefc0..c481ea341 100644
--- a/src/products/types/ProductImageCreate.ts
+++ b/src/products/types/ProductImageCreate.ts
@@ -2,16 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { AttributeInputTypeEnum } from "./../../types/globalTypes";
+import { ProductErrorCode, AttributeInputTypeEnum } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: ProductImageCreate
// ====================================================
export interface ProductImageCreate_productImageCreate_errors {
- __typename: "Error";
+ __typename: "ProductError";
+ code: ProductErrorCode;
field: string | null;
- message: string | null;
}
export interface ProductImageCreate_productImageCreate_product_category {
diff --git a/src/products/types/ProductImageDelete.ts b/src/products/types/ProductImageDelete.ts
index 4d55c57a8..a598b34a2 100644
--- a/src/products/types/ProductImageDelete.ts
+++ b/src/products/types/ProductImageDelete.ts
@@ -2,10 +2,18 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { ProductErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: ProductImageDelete
// ====================================================
+export interface ProductImageDelete_productImageDelete_errors {
+ __typename: "ProductError";
+ code: ProductErrorCode;
+ field: string | null;
+}
+
export interface ProductImageDelete_productImageDelete_product_images {
__typename: "ProductImage";
id: string;
@@ -19,6 +27,7 @@ export interface ProductImageDelete_productImageDelete_product {
export interface ProductImageDelete_productImageDelete {
__typename: "ProductImageDelete";
+ errors: ProductImageDelete_productImageDelete_errors[];
product: ProductImageDelete_productImageDelete_product | null;
}
diff --git a/src/products/types/ProductImageReorder.ts b/src/products/types/ProductImageReorder.ts
index 5fc5534f0..cddec7610 100644
--- a/src/products/types/ProductImageReorder.ts
+++ b/src/products/types/ProductImageReorder.ts
@@ -2,14 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { ProductErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: ProductImageReorder
// ====================================================
export interface ProductImageReorder_productImageReorder_errors {
- __typename: "Error";
+ __typename: "ProductError";
+ code: ProductErrorCode;
field: string | null;
- message: string | null;
}
export interface ProductImageReorder_productImageReorder_product_images {
diff --git a/src/products/types/ProductImageUpdate.ts b/src/products/types/ProductImageUpdate.ts
index 3e1b5b5f7..23687fe07 100644
--- a/src/products/types/ProductImageUpdate.ts
+++ b/src/products/types/ProductImageUpdate.ts
@@ -2,16 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { AttributeInputTypeEnum } from "./../../types/globalTypes";
+import { ProductErrorCode, AttributeInputTypeEnum } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: ProductImageUpdate
// ====================================================
export interface ProductImageUpdate_productImageUpdate_errors {
- __typename: "Error";
+ __typename: "ProductError";
+ code: ProductErrorCode;
field: string | null;
- message: string | null;
}
export interface ProductImageUpdate_productImageUpdate_product_category {
diff --git a/src/products/types/ProductUpdate.ts b/src/products/types/ProductUpdate.ts
index 7bdf6af0d..20c745df8 100644
--- a/src/products/types/ProductUpdate.ts
+++ b/src/products/types/ProductUpdate.ts
@@ -2,16 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { AttributeValueInput, SeoInput, AttributeInputTypeEnum } from "./../../types/globalTypes";
+import { AttributeValueInput, SeoInput, ProductErrorCode, AttributeInputTypeEnum } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: ProductUpdate
// ====================================================
export interface ProductUpdate_productUpdate_errors {
- __typename: "Error";
+ __typename: "ProductError";
+ code: ProductErrorCode;
field: string | null;
- message: string | null;
}
export interface ProductUpdate_productUpdate_product_category {
diff --git a/src/products/types/ProductVariantBulkCreate.ts b/src/products/types/ProductVariantBulkCreate.ts
index 8c79b0e15..2dc8867e6 100644
--- a/src/products/types/ProductVariantBulkCreate.ts
+++ b/src/products/types/ProductVariantBulkCreate.ts
@@ -8,23 +8,15 @@ import { ProductVariantBulkCreateInput, ProductErrorCode } from "./../../types/g
// GraphQL mutation operation: ProductVariantBulkCreate
// ====================================================
-export interface ProductVariantBulkCreate_productVariantBulkCreate_bulkProductErrors {
+export interface ProductVariantBulkCreate_productVariantBulkCreate_errors {
__typename: "BulkProductError";
field: string | null;
- message: string | null;
code: ProductErrorCode;
index: number | null;
}
-export interface ProductVariantBulkCreate_productVariantBulkCreate_errors {
- __typename: "Error";
- field: string | null;
- message: string | null;
-}
-
export interface ProductVariantBulkCreate_productVariantBulkCreate {
__typename: "ProductVariantBulkCreate";
- bulkProductErrors: ProductVariantBulkCreate_productVariantBulkCreate_bulkProductErrors[];
errors: ProductVariantBulkCreate_productVariantBulkCreate_errors[];
}
diff --git a/src/products/types/ProductVariantBulkDelete.ts b/src/products/types/ProductVariantBulkDelete.ts
index 903c21fe1..4463eca72 100644
--- a/src/products/types/ProductVariantBulkDelete.ts
+++ b/src/products/types/ProductVariantBulkDelete.ts
@@ -2,14 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { ProductErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: ProductVariantBulkDelete
// ====================================================
export interface ProductVariantBulkDelete_productVariantBulkDelete_errors {
- __typename: "Error";
+ __typename: "ProductError";
+ code: ProductErrorCode;
field: string | null;
- message: string | null;
}
export interface ProductVariantBulkDelete_productVariantBulkDelete {
diff --git a/src/products/types/SimpleProductUpdate.ts b/src/products/types/SimpleProductUpdate.ts
index 861391ead..51c33a7e3 100644
--- a/src/products/types/SimpleProductUpdate.ts
+++ b/src/products/types/SimpleProductUpdate.ts
@@ -2,16 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { AttributeValueInput, ProductVariantInput, SeoInput, AttributeInputTypeEnum } from "./../../types/globalTypes";
+import { AttributeValueInput, ProductVariantInput, SeoInput, ProductErrorCode, AttributeInputTypeEnum } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: SimpleProductUpdate
// ====================================================
export interface SimpleProductUpdate_productUpdate_errors {
- __typename: "Error";
+ __typename: "ProductError";
+ code: ProductErrorCode;
field: string | null;
- message: string | null;
}
export interface SimpleProductUpdate_productUpdate_product_category {
@@ -183,9 +183,9 @@ export interface SimpleProductUpdate_productUpdate {
}
export interface SimpleProductUpdate_productVariantUpdate_errors {
- __typename: "Error";
+ __typename: "ProductError";
+ code: ProductErrorCode;
field: string | null;
- message: string | null;
}
export interface SimpleProductUpdate_productVariantUpdate_productVariant_attributes_attribute_values {
diff --git a/src/products/types/VariantCreate.ts b/src/products/types/VariantCreate.ts
index 7523a6121..da6dd3939 100644
--- a/src/products/types/VariantCreate.ts
+++ b/src/products/types/VariantCreate.ts
@@ -8,11 +8,10 @@ import { ProductVariantCreateInput, ProductErrorCode } from "./../../types/globa
// GraphQL mutation operation: VariantCreate
// ====================================================
-export interface VariantCreate_productVariantCreate_productErrors {
+export interface VariantCreate_productVariantCreate_errors {
__typename: "ProductError";
code: ProductErrorCode;
field: string | null;
- message: string | null;
}
export interface VariantCreate_productVariantCreate_productVariant_attributes_attribute_values {
@@ -114,7 +113,7 @@ export interface VariantCreate_productVariantCreate_productVariant {
export interface VariantCreate_productVariantCreate {
__typename: "ProductVariantCreate";
- productErrors: VariantCreate_productVariantCreate_productErrors[];
+ errors: VariantCreate_productVariantCreate_errors[];
productVariant: VariantCreate_productVariantCreate_productVariant | null;
}
diff --git a/src/products/types/VariantDelete.ts b/src/products/types/VariantDelete.ts
index 38f2f0600..48c85f2c0 100644
--- a/src/products/types/VariantDelete.ts
+++ b/src/products/types/VariantDelete.ts
@@ -2,14 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { ProductErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: VariantDelete
// ====================================================
export interface VariantDelete_productVariantDelete_errors {
- __typename: "Error";
+ __typename: "ProductError";
+ code: ProductErrorCode;
field: string | null;
- message: string | null;
}
export interface VariantDelete_productVariantDelete_productVariant {
diff --git a/src/products/types/VariantImageAssign.ts b/src/products/types/VariantImageAssign.ts
index 1894ecbde..5a5c8ad0a 100644
--- a/src/products/types/VariantImageAssign.ts
+++ b/src/products/types/VariantImageAssign.ts
@@ -2,14 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { ProductErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: VariantImageAssign
// ====================================================
export interface VariantImageAssign_variantImageAssign_errors {
- __typename: "Error";
+ __typename: "ProductError";
+ code: ProductErrorCode;
field: string | null;
- message: string | null;
}
export interface VariantImageAssign_variantImageAssign_productVariant_attributes_attribute_values {
diff --git a/src/products/types/VariantImageUnassign.ts b/src/products/types/VariantImageUnassign.ts
index e90b5a43b..4978ee18b 100644
--- a/src/products/types/VariantImageUnassign.ts
+++ b/src/products/types/VariantImageUnassign.ts
@@ -2,14 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { ProductErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: VariantImageUnassign
// ====================================================
export interface VariantImageUnassign_variantImageUnassign_errors {
- __typename: "Error";
+ __typename: "ProductError";
+ code: ProductErrorCode;
field: string | null;
- message: string | null;
}
export interface VariantImageUnassign_variantImageUnassign_productVariant_attributes_attribute_values {
diff --git a/src/products/types/VariantUpdate.ts b/src/products/types/VariantUpdate.ts
index 6a4e8bcd6..0028a0887 100644
--- a/src/products/types/VariantUpdate.ts
+++ b/src/products/types/VariantUpdate.ts
@@ -8,11 +8,10 @@ import { AttributeValueInput, ProductErrorCode } from "./../../types/globalTypes
// GraphQL mutation operation: VariantUpdate
// ====================================================
-export interface VariantUpdate_productVariantUpdate_productErrors {
+export interface VariantUpdate_productVariantUpdate_errors {
__typename: "ProductError";
code: ProductErrorCode;
field: string | null;
- message: string | null;
}
export interface VariantUpdate_productVariantUpdate_productVariant_attributes_attribute_values {
@@ -114,7 +113,7 @@ export interface VariantUpdate_productVariantUpdate_productVariant {
export interface VariantUpdate_productVariantUpdate {
__typename: "ProductVariantUpdate";
- productErrors: VariantUpdate_productVariantUpdate_productErrors[];
+ errors: VariantUpdate_productVariantUpdate_errors[];
productVariant: VariantUpdate_productVariantUpdate_productVariant | null;
}
diff --git a/src/products/types/productBulkDelete.ts b/src/products/types/productBulkDelete.ts
index 6334e46f7..3164f7b6c 100644
--- a/src/products/types/productBulkDelete.ts
+++ b/src/products/types/productBulkDelete.ts
@@ -2,14 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { ProductErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: productBulkDelete
// ====================================================
export interface productBulkDelete_productBulkDelete_errors {
- __typename: "Error";
+ __typename: "ProductError";
+ code: ProductErrorCode;
field: string | null;
- message: string | null;
}
export interface productBulkDelete_productBulkDelete {
diff --git a/src/products/types/productBulkPublish.ts b/src/products/types/productBulkPublish.ts
index da03ab934..f429764a4 100644
--- a/src/products/types/productBulkPublish.ts
+++ b/src/products/types/productBulkPublish.ts
@@ -2,14 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { ProductErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: productBulkPublish
// ====================================================
export interface productBulkPublish_productBulkPublish_errors {
- __typename: "Error";
+ __typename: "ProductError";
+ code: ProductErrorCode;
field: string | null;
- message: string | null;
}
export interface productBulkPublish_productBulkPublish {
diff --git a/src/products/views/ProductCreate.tsx b/src/products/views/ProductCreate.tsx
index 8bfc63a54..ae7b565e6 100644
--- a/src/products/views/ProductCreate.tsx
+++ b/src/products/views/ProductCreate.tsx
@@ -58,13 +58,6 @@ export const ProductUpdate: React.FC = () => {
})
});
navigate(productUrl(data.productCreate.product.id));
- } else {
- const attributeError = data.productCreate.errors.find(
- err => err.field === "attributes"
- );
- if (!!attributeError) {
- notify({ text: attributeError.message });
- }
}
};
@@ -120,10 +113,7 @@ export const ProductUpdate: React.FC = () => {
[]
).map(edge => edge.node)}
disabled={productCreateOpts.loading}
- errors={maybe(
- () => productCreateOpts.data.productCreate.errors,
- []
- )}
+ errors={productCreateOpts.data?.productCreate.errors || []}
fetchCategories={searchCategory}
fetchCollections={searchCollection}
fetchProductTypes={searchProductTypes}
diff --git a/src/products/views/ProductUpdate/ProductUpdate.tsx b/src/products/views/ProductUpdate/ProductUpdate.tsx
index aee72a004..b478e2caa 100644
--- a/src/products/views/ProductUpdate/ProductUpdate.tsx
+++ b/src/products/views/ProductUpdate/ProductUpdate.tsx
@@ -19,6 +19,7 @@ import useCategorySearch from "@saleor/searches/useCategorySearch";
import useCollectionSearch from "@saleor/searches/useCollectionSearch";
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
import NotFoundPage from "@saleor/components/NotFoundPage";
+import { ProductErrorCode } from "@saleor/types/globalTypes";
import { getMutationState, maybe } from "../../../misc";
import ProductUpdatePage from "../../components/ProductUpdatePage";
import ProductUpdateOperations from "../../containers/ProductUpdateOperations";
@@ -101,13 +102,6 @@ export const ProductUpdate: React.FC = ({ id, params }) => {
notify({
text: intl.formatMessage(commonMessages.savedChanges)
});
- } else {
- const attributeError = data.productUpdate.errors.find(
- err => err.field === "attributes"
- );
- if (!!attributeError) {
- notify({ text: attributeError.message });
- }
}
};
@@ -118,7 +112,7 @@ export const ProductUpdate: React.FC = ({ id, params }) => {
);
if (imageError) {
notify({
- text: imageError.message
+ text: intl.formatMessage(commonMessages.somethingWentWrong)
});
}
};
@@ -339,12 +333,10 @@ export const ProductUpdate: React.FC = ({ id, params }) => {
defaultPrice={maybe(() =>
data.product.basePrice.amount.toFixed(2)
)}
- errors={maybe(
- () =>
- bulkProductVariantCreate.opts.data
- .productVariantBulkCreate.bulkProductErrors,
- []
- )}
+ errors={
+ bulkProductVariantCreate.opts.data
+ ?.productVariantBulkCreate.errors || []
+ }
open={params.action === "create-variants"}
attributes={maybe(
() => data.product.productType.variantAttributes,
diff --git a/src/products/views/ProductVariantCreate.tsx b/src/products/views/ProductVariantCreate.tsx
index 888ad7d79..c2e446ab1 100644
--- a/src/products/views/ProductVariantCreate.tsx
+++ b/src/products/views/ProductVariantCreate.tsx
@@ -6,6 +6,7 @@ import useNavigator from "@saleor/hooks/useNavigator";
import useNotifier from "@saleor/hooks/useNotifier";
import useShop from "@saleor/hooks/useShop";
import NotFoundPage from "@saleor/components/NotFoundPage";
+import { commonMessages } from "@saleor/intl";
import { decimal, maybe } from "../../misc";
import ProductVariantCreatePage, {
ProductVariantCreatePageSubmitData
@@ -35,11 +36,9 @@ export const ProductVariant: React.FC = ({ productId }) => {
}
const handleCreateSuccess = (data: VariantCreate) => {
- if (data.productVariantCreate.productErrors.length === 0) {
+ if (data.productVariantCreate.errors.length === 0) {
notify({
- text: intl.formatMessage({
- defaultMessage: "Product created"
- })
+ text: intl.formatMessage(commonMessages.savedChanges)
});
navigate(
productVariantEditUrl(
@@ -90,18 +89,16 @@ export const ProductVariant: React.FC = ({ productId }) => {
/>
shop.defaultCurrency)}
- errors={maybe(
- () =>
- variantCreateResult.data.productVariantCreate
- .productErrors,
+ errors={
+ variantCreateResult.data?.productVariantCreate.errors ||
[]
- )}
+ }
header={intl.formatMessage({
defaultMessage: "Create Variant",
description: "header"
})}
loading={disableForm}
- product={maybe(() => data.product)}
+ product={data?.product}
onBack={handleBack}
onSubmit={handleSubmit}
onVariantClick={handleVariantClick}
diff --git a/src/utils/errors/product.ts b/src/utils/errors/product.ts
new file mode 100644
index 000000000..3e5e1d9e3
--- /dev/null
+++ b/src/utils/errors/product.ts
@@ -0,0 +1,65 @@
+import { IntlShape, defineMessages } from "react-intl";
+
+import { ProductErrorFragment } from "@saleor/attributes/types/ProductErrorFragment";
+import { ProductErrorCode } from "@saleor/types/globalTypes";
+import { commonMessages } from "@saleor/intl";
+import { BulkProductErrorFragment } from "@saleor/products/types/BulkProductErrorFragment";
+import commonErrorMessages from "./common";
+
+const messages = defineMessages({
+ attributeAlreadyAssigned: {
+ defaultMessage:
+ "This attribute has already been assigned to this product type"
+ },
+ attributeCannotBeAssigned: {
+ defaultMessage: "This attribute cannot be assigned to this product type"
+ },
+ attributeVariantsDisabled: {
+ defaultMessage: "Variants are disabled in this product type"
+ },
+ skuUnique: {
+ defaultMessage: "SKUs must be unique",
+ description: "bulk variant create error"
+ },
+ variantNoDigitalContent: {
+ defaultMessage: "This variant does not have any digital content"
+ }
+});
+
+function getProductErrorMessage(
+ err: Omit | undefined,
+ intl: IntlShape
+): string {
+ if (err) {
+ switch (err.code) {
+ case ProductErrorCode.ATTRIBUTE_ALREADY_ASSIGNED:
+ return intl.formatMessage(messages.attributeAlreadyAssigned);
+ case ProductErrorCode.ATTRIBUTE_CANNOT_BE_ASSIGNED:
+ return intl.formatMessage(messages.attributeCannotBeAssigned);
+ case ProductErrorCode.ATTRIBUTE_VARIANTS_DISABLED:
+ return intl.formatMessage(messages.attributeVariantsDisabled);
+ case ProductErrorCode.GRAPHQL_ERROR:
+ return intl.formatMessage(commonErrorMessages.graphqlError);
+ case ProductErrorCode.REQUIRED:
+ return intl.formatMessage(commonMessages.requiredField);
+ case ProductErrorCode.VARIANT_NO_DIGITAL_CONTENT:
+ return intl.formatMessage(messages.variantNoDigitalContent);
+ default:
+ return intl.formatMessage(commonErrorMessages.unknownError);
+ }
+ }
+
+ return undefined;
+}
+
+export function getBulkProductErrorMessage(
+ err: BulkProductErrorFragment | undefined,
+ intl: IntlShape
+): string {
+ if (err?.code === ProductErrorCode.UNIQUE && err.field === "sku") {
+ return intl.formatMessage(messages.skuUnique);
+ }
+ return getProductErrorMessage(err, intl);
+}
+
+export default getProductErrorMessage;
From 6bacb5fb3aab350d44ac765280b37562a9d0998c Mon Sep 17 00:00:00 2001
From: dominik-zeglen
Date: Mon, 9 Mar 2020 12:22:34 +0100
Subject: [PATCH 07/35] wip
---
.../views/ProductUpdate/ProductUpdate.tsx | 1 -
src/storybook/misc.ts | 2 ++
.../stories/products/ProductUpdatePage.tsx | 9 ++++++---
.../stories/products/ProductVariantCreatePage.tsx | 1 -
src/utils/errors/common.ts | 15 +++++++++++++++
src/utils/errors/product.ts | 2 ++
6 files changed, 25 insertions(+), 5 deletions(-)
create mode 100644 src/utils/errors/common.ts
diff --git a/src/products/views/ProductUpdate/ProductUpdate.tsx b/src/products/views/ProductUpdate/ProductUpdate.tsx
index b478e2caa..4de424226 100644
--- a/src/products/views/ProductUpdate/ProductUpdate.tsx
+++ b/src/products/views/ProductUpdate/ProductUpdate.tsx
@@ -19,7 +19,6 @@ import useCategorySearch from "@saleor/searches/useCategorySearch";
import useCollectionSearch from "@saleor/searches/useCollectionSearch";
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
import NotFoundPage from "@saleor/components/NotFoundPage";
-import { ProductErrorCode } from "@saleor/types/globalTypes";
import { getMutationState, maybe } from "../../../misc";
import ProductUpdatePage from "../../components/ProductUpdatePage";
import ProductUpdateOperations from "../../containers/ProductUpdateOperations";
diff --git a/src/storybook/misc.ts b/src/storybook/misc.ts
index 6a28d4117..b1f96fe36 100644
--- a/src/storybook/misc.ts
+++ b/src/storybook/misc.ts
@@ -1,3 +1,5 @@
+import { ProductErrorFragment } from "@saleor/attributes/types/ProductErrorFragment";
+
export function formError(
field: string,
opts?: Partial>
diff --git a/src/storybook/stories/products/ProductUpdatePage.tsx b/src/storybook/stories/products/ProductUpdatePage.tsx
index a3c0b2d74..4deb5d08e 100644
--- a/src/storybook/stories/products/ProductUpdatePage.tsx
+++ b/src/storybook/stories/products/ProductUpdatePage.tsx
@@ -9,7 +9,7 @@ import ProductUpdatePage, {
} from "@saleor/products/components/ProductUpdatePage";
import { product as productFixture } from "@saleor/products/fixtures";
import { ProductUpdatePageFormData } from "@saleor/products/utils/data";
-import { formError } from "@saleor/storybook/misc";
+import { ProductErrorCode } from "@saleor/types/globalTypes";
import Decorator from "../../Decorator";
const product = productFixture(placeholderImage);
@@ -94,7 +94,6 @@ storiesOf("Views / Products / Product edit", module)
"category",
"chargeTaxes",
"collections",
- "description",
"isPublished",
"name",
"publicationDate",
@@ -102,6 +101,10 @@ storiesOf("Views / Products / Product edit", module)
"seoTitle",
"sku",
"stockQuantity"
- ] as Array).map(formError)}
+ ] as Array).map(field => ({
+ __typename: "ProductError",
+ code: ProductErrorCode.INVALID,
+ field
+ }))}
/>
));
diff --git a/src/storybook/stories/products/ProductVariantCreatePage.tsx b/src/storybook/stories/products/ProductVariantCreatePage.tsx
index 6d42174b3..9269ae5e2 100644
--- a/src/storybook/stories/products/ProductVariantCreatePage.tsx
+++ b/src/storybook/stories/products/ProductVariantCreatePage.tsx
@@ -42,7 +42,6 @@ storiesOf("Views / Products / Create product variant", module)
}
].map(error => ({
__typename: "ProductError",
- message: "Generic form error",
...error
}))}
header="Add variant"
diff --git a/src/utils/errors/common.ts b/src/utils/errors/common.ts
new file mode 100644
index 000000000..332510ff5
--- /dev/null
+++ b/src/utils/errors/common.ts
@@ -0,0 +1,15 @@
+import { defineMessages } from "react-intl";
+
+const commonErrorMessages = defineMessages({
+ graphqlError: {
+ defaultMessage: "API error"
+ },
+ invalid: {
+ defaultMessage: "Invalid value"
+ },
+ unknownError: {
+ defaultMessage: "Unknown error"
+ }
+});
+
+export default commonErrorMessages;
diff --git a/src/utils/errors/product.ts b/src/utils/errors/product.ts
index 3e5e1d9e3..0886770ec 100644
--- a/src/utils/errors/product.ts
+++ b/src/utils/errors/product.ts
@@ -44,6 +44,8 @@ function getProductErrorMessage(
return intl.formatMessage(commonMessages.requiredField);
case ProductErrorCode.VARIANT_NO_DIGITAL_CONTENT:
return intl.formatMessage(messages.variantNoDigitalContent);
+ case ProductErrorCode.INVALID:
+ return intl.formatMessage(commonErrorMessages.invalid);
default:
return intl.formatMessage(commonErrorMessages.unknownError);
}
From bae3e461a7d1125da94f1801cfac1fff73e7745e Mon Sep 17 00:00:00 2001
From: dominik-zeglen
Date: Mon, 9 Mar 2020 15:59:58 +0100
Subject: [PATCH 08/35] Fix types
---
schema.graphql | 82 ++++++++++---------
.../components/ProductStock/ProductStock.tsx | 1 -
.../ProductVariantAttributes.tsx | 4 +-
.../ProductVariantCreate.stories.tsx | 7 +-
.../ProductVariantCreateContent.tsx | 8 +-
.../ProductVariantPage/ProductVariantPage.tsx | 4 +-
src/products/views/ProductVariant.tsx | 8 +-
src/storybook/misc.ts | 2 -
.../stories/attributes/AttributePage.tsx | 12 ++-
.../stories/products/ProductCreatePage.tsx | 8 +-
src/types/globalTypes.ts | 14 +++-
11 files changed, 87 insertions(+), 63 deletions(-)
diff --git a/schema.graphql b/schema.graphql
index 0a4ab2fe4..4edc7a797 100644
--- a/schema.graphql
+++ b/schema.graphql
@@ -493,6 +493,13 @@ type BulkProductError {
index: Int
}
+type BulkStockError {
+ field: String
+ message: String
+ code: ProductErrorCode!
+ index: Int
+}
+
input CatalogueInput {
products: [ID]
categories: [ID]
@@ -2158,10 +2165,6 @@ type Mutation {
deleteWarehouse(id: ID!): WarehouseDelete
assignWarehouseShippingZone(id: ID!, shippingZoneIds: [ID!]!): WarehouseShippingZoneAssign
unassignWarehouseShippingZone(id: ID!, shippingZoneIds: [ID!]!): WarehouseShippingZoneUnassign
- createStock(input: StockInput!): StockCreate
- updateStock(id: ID!, input: StockInput!): StockUpdate
- deleteStock(id: ID!): StockDelete
- bulkDeleteStock(ids: [ID]!): StockBulkDelete
authorizationKeyAdd(input: AuthorizationKeyInput!, keyType: AuthorizationKeyType!): AuthorizationKeyAdd
authorizationKeyDelete(keyType: AuthorizationKeyType!): AuthorizationKeyDelete
staffNotificationRecipientCreate(input: StaffNotificationRecipientInput!): StaffNotificationRecipientCreate
@@ -2253,6 +2256,9 @@ type Mutation {
productVariantDelete(id: ID!): ProductVariantDelete
productVariantBulkCreate(product: ID!, variants: [ProductVariantBulkCreateInput]!): ProductVariantBulkCreate
productVariantBulkDelete(ids: [ID]!): ProductVariantBulkDelete
+ productVariantStocksCreate(stocks: [StockInput!]!, variantId: ID!): ProductVariantStocksCreate
+ productVariantStocksDelete(variantId: ID!, warehouseIds: [ID!]): ProductVariantStocksDelete
+ productVariantStocksUpdate(stocks: [StockInput!]!, variantId: ID!): ProductVariantStocksUpdate
productVariantUpdate(id: ID!, input: ProductVariantInput!): ProductVariantUpdate
productVariantTranslate(id: ID!, input: NameTranslationInput!, languageCode: LanguageCodeEnum!): ProductVariantTranslate
productVariantUpdateMetadata(id: ID!, input: MetaInput!): ProductVariantUpdateMeta @deprecated(reason: "Will be removed in Saleor 2.11. Use the `UpdateMetadata` mutation instead.")
@@ -2444,8 +2450,8 @@ type Order implements Node & ObjectWithMetadata {
voucher: Voucher
giftCards: [GiftCard]
discount: Money
- discountName: String!
- translatedDiscountName: String!
+ discountName: String
+ translatedDiscountName: String
displayGrossPrices: Boolean!
customerNote: String!
weight: Weight
@@ -2489,7 +2495,7 @@ type OrderAddNote {
}
input OrderAddNoteInput {
- message: String
+ message: String!
}
type OrderBulkCancel {
@@ -3218,6 +3224,7 @@ input ProductCreateInput {
quantity: Int
trackInventory: Boolean
productType: ID!
+ stocks: [StockInput!]
}
type ProductDelete {
@@ -3255,6 +3262,7 @@ input ProductFilterInput {
attributes: [AttributeInput]
stockAvailability: StockAvailability
productType: ID
+ stocks: ProductStockFilterInput
search: String
minimalPrice: PriceRangeInput
productTypes: [ID]
@@ -3355,6 +3363,11 @@ type ProductPricingInfo {
priceRangeLocalCurrency: TaxedMoneyRange
}
+input ProductStockFilterInput {
+ warehouseIds: [ID!]
+ quantity: IntRangeInput
+}
+
type ProductTranslatableContent implements Node {
id: ID!
seoTitle: String
@@ -3549,7 +3562,7 @@ type ProductVariant implements Node & ObjectWithMetadata {
images: [ProductImage]
translation(languageCode: LanguageCodeEnum!): ProductVariantTranslation
digitalContent: DigitalContent
- stock(country: String): [Stock]
+ stocks(countryCode: CountryCode): [Stock]
}
type ProductVariantBulkCreate {
@@ -3613,6 +3626,7 @@ input ProductVariantCreateInput {
trackInventory: Boolean
weight: WeightScalar
product: ID!
+ stocks: [StockInput!]
}
type ProductVariantDelete {
@@ -3631,6 +3645,24 @@ input ProductVariantInput {
weight: WeightScalar
}
+type ProductVariantStocksCreate {
+ errors: [Error!]!
+ productVariant: ProductVariant
+ bulkStockErrors: [BulkStockError!]!
+}
+
+type ProductVariantStocksDelete {
+ errors: [Error!]!
+ productVariant: ProductVariant
+ stockErrors: [StockError!]!
+}
+
+type ProductVariantStocksUpdate {
+ errors: [Error!]!
+ productVariant: ProductVariant
+ bulkStockErrors: [BulkStockError!]!
+}
+
type ProductVariantTranslatableContent implements Node {
id: ID!
name: String!
@@ -4341,12 +4373,6 @@ enum StockAvailability {
OUT_OF_STOCK
}
-type StockBulkDelete {
- errors: [Error!]!
- count: Int!
- stockError: [StockError!]!
-}
-
type StockCountableConnection {
pageInfo: PageInfo!
edges: [StockCountableEdge!]!
@@ -4358,18 +4384,13 @@ type StockCountableEdge {
cursor: String!
}
-type StockCreate {
- errors: [Error!]!
- stockErrors: [StockError!]!
- stock: Stock
+type StockError {
+ field: String
+ message: String
+ code: StockErrorCode!
}
-type StockDelete {
- errors: [Error!]!
- stock: Stock
-}
-
-enum StockErorrCode {
+enum StockErrorCode {
ALREADY_EXISTS
GRAPHQL_ERROR
INVALID
@@ -4378,12 +4399,6 @@ enum StockErorrCode {
UNIQUE
}
-type StockError {
- field: String
- message: String
- code: StockErorrCode!
-}
-
input StockFilterInput {
quantity: Float
quantityAllocated: Float
@@ -4391,17 +4406,10 @@ input StockFilterInput {
}
input StockInput {
- productVariant: ID!
warehouse: ID!
quantity: Int
}
-type StockUpdate {
- errors: [Error!]!
- stockError: [StockError!]!
- stock: Stock
-}
-
enum TaxRateType {
ACCOMMODATION
ADMISSION_TO_CULTURAL_EVENTS
diff --git a/src/products/components/ProductStock/ProductStock.tsx b/src/products/components/ProductStock/ProductStock.tsx
index c76609af4..6fce4b609 100644
--- a/src/products/components/ProductStock/ProductStock.tsx
+++ b/src/products/components/ProductStock/ProductStock.tsx
@@ -8,7 +8,6 @@ import { useIntl } from "react-intl";
import CardTitle from "@saleor/components/CardTitle";
import { ProductErrorFragment } from "@saleor/attributes/types/ProductErrorFragment";
import { getFormErrors, getProductErrorMessage } from "@saleor/utils/errors";
-import { maybe } from "../../../misc";
import { ProductDetails_product } from "../../types/ProductDetails";
const useStyles = makeStyles(
diff --git a/src/products/components/ProductVariantAttributes/ProductVariantAttributes.tsx b/src/products/components/ProductVariantAttributes/ProductVariantAttributes.tsx
index d80aece07..b32a7ef2d 100644
--- a/src/products/components/ProductVariantAttributes/ProductVariantAttributes.tsx
+++ b/src/products/components/ProductVariantAttributes/ProductVariantAttributes.tsx
@@ -13,7 +13,7 @@ import SingleAutocompleteSelectField, {
import Skeleton from "@saleor/components/Skeleton";
import { FormsetAtomicData, FormsetChange } from "@saleor/hooks/useFormset";
import { commonMessages } from "@saleor/intl";
-import { VariantCreate_productVariantCreate_productErrors } from "@saleor/products/types/VariantCreate";
+import { VariantCreate_productVariantCreate_errors } from "@saleor/products/types/VariantCreate";
import { ProductErrorCode } from "@saleor/types/globalTypes";
import { ProductVariant_attributes_attribute_values } from "../../types/ProductVariant";
@@ -28,7 +28,7 @@ export type VariantAttributeInput = FormsetAtomicData<
interface ProductVariantAttributesProps {
attributes: VariantAttributeInput[];
disabled: boolean;
- errors: VariantCreate_productVariantCreate_productErrors[];
+ errors: VariantCreate_productVariantCreate_errors[];
onChange: FormsetChange;
}
diff --git a/src/products/components/ProductVariantCreateDialog/ProductVariantCreate.stories.tsx b/src/products/components/ProductVariantCreateDialog/ProductVariantCreate.stories.tsx
index 2caf5fba2..b735d3f0f 100644
--- a/src/products/components/ProductVariantCreateDialog/ProductVariantCreate.stories.tsx
+++ b/src/products/components/ProductVariantCreateDialog/ProductVariantCreate.stories.tsx
@@ -4,7 +4,7 @@ import { storiesOf } from "@storybook/react";
import React from "react";
import { attributes } from "@saleor/attributes/fixtures";
-import { ProductVariantBulkCreate_productVariantBulkCreate_bulkProductErrors } from "@saleor/products/types/ProductVariantBulkCreate";
+import { ProductVariantBulkCreate_productVariantBulkCreate_errors } from "@saleor/products/types/ProductVariantBulkCreate";
import { ProductErrorCode } from "@saleor/types/globalTypes";
import Decorator from "../../../storybook/Decorator";
import { createVariants } from "./createVariants";
@@ -43,13 +43,12 @@ const dataAttributes = selectedAttributes.map(attribute => ({
.filter((_, valueIndex) => valueIndex % 2 !== 1)
}));
-const errors: ProductVariantBulkCreate_productVariantBulkCreate_bulkProductErrors[] = [
+const errors: ProductVariantBulkCreate_productVariantBulkCreate_errors[] = [
{
__typename: "BulkProductError",
code: ProductErrorCode.UNIQUE,
field: "sku",
- index: 3,
- message: "Duplicated SKU."
+ index: 3
}
];
diff --git a/src/products/components/ProductVariantCreateDialog/ProductVariantCreateContent.tsx b/src/products/components/ProductVariantCreateDialog/ProductVariantCreateContent.tsx
index 398b8cf3e..02bc0ae66 100644
--- a/src/products/components/ProductVariantCreateDialog/ProductVariantCreateContent.tsx
+++ b/src/products/components/ProductVariantCreateDialog/ProductVariantCreateContent.tsx
@@ -2,7 +2,7 @@ import { makeStyles } from "@material-ui/core/styles";
import React from "react";
import { ProductDetails_product_productType_variantAttributes } from "@saleor/products/types/ProductDetails";
-import { ProductVariantBulkCreate_productVariantBulkCreate_bulkProductErrors } from "@saleor/products/types/ProductVariantBulkCreate";
+import { ProductVariantBulkCreate_productVariantBulkCreate_errors } from "@saleor/products/types/ProductVariantBulkCreate";
import { isSelected } from "@saleor/utils/lists";
import { ProductVariantCreateFormData } from "./form";
import ProductVariantCreatePrices from "./ProductVariantCreatePrices";
@@ -33,14 +33,12 @@ export interface ProductVariantCreateContentProps {
currencySymbol: string;
data: ProductVariantCreateFormData;
dispatchFormDataAction: React.Dispatch;
- errors: ProductVariantBulkCreate_productVariantBulkCreate_bulkProductErrors[];
+ errors: ProductVariantBulkCreate_productVariantBulkCreate_errors[];
step: ProductVariantCreateStep;
onStepClick: (step: ProductVariantCreateStep) => void;
}
-const ProductVariantCreateContent: React.FC<
- ProductVariantCreateContentProps
-> = props => {
+const ProductVariantCreateContent: React.FC = props => {
const {
attributes,
currencySymbol,
diff --git a/src/products/components/ProductVariantPage/ProductVariantPage.tsx b/src/products/components/ProductVariantPage/ProductVariantPage.tsx
index 8f7ca76ed..25b91284b 100644
--- a/src/products/components/ProductVariantPage/ProductVariantPage.tsx
+++ b/src/products/components/ProductVariantPage/ProductVariantPage.tsx
@@ -12,7 +12,7 @@ import useFormset, {
FormsetChange,
FormsetData
} from "@saleor/hooks/useFormset";
-import { VariantUpdate_productVariantUpdate_productErrors } from "@saleor/products/types/VariantUpdate";
+import { VariantUpdate_productVariantUpdate_errors } from "@saleor/products/types/VariantUpdate";
import { getAttributeInputFromVariant } from "@saleor/products/utils/data";
import { maybe } from "../../../misc";
import { ProductVariant } from "../../types/ProductVariant";
@@ -39,7 +39,7 @@ export interface ProductVariantPageSubmitData
interface ProductVariantPageProps {
variant?: ProductVariant;
- errors: VariantUpdate_productVariantUpdate_productErrors[];
+ errors: VariantUpdate_productVariantUpdate_errors[];
saveButtonBarState: ConfirmButtonTransitionState;
loading?: boolean;
placeholderImage?: string;
diff --git a/src/products/views/ProductVariant.tsx b/src/products/views/ProductVariant.tsx
index 4163cb982..6a68c2d49 100644
--- a/src/products/views/ProductVariant.tsx
+++ b/src/products/views/ProductVariant.tsx
@@ -16,7 +16,7 @@ import ProductVariantOperations from "../containers/ProductVariantOperations";
import { TypedProductVariantQuery } from "../queries";
import {
VariantUpdate,
- VariantUpdate_productVariantUpdate_productErrors
+ VariantUpdate_productVariantUpdate_errors
} from "../types/VariantUpdate";
import {
productUrl,
@@ -40,7 +40,7 @@ export const ProductVariant: React.FC = ({
const notify = useNotifier();
const intl = useIntl();
const [errors, setErrors] = useState<
- VariantUpdate_productVariantUpdate_productErrors[]
+ VariantUpdate_productVariantUpdate_errors[]
>([]);
useEffect(() => {
setErrors([]);
@@ -66,10 +66,10 @@ export const ProductVariant: React.FC = ({
navigate(productUrl(productId));
};
const handleUpdate = (data: VariantUpdate) => {
- if (!data.productVariantUpdate.productErrors.length) {
+ if (data.productVariantUpdate.errors.length === 0) {
notify({ text: intl.formatMessage(commonMessages.savedChanges) });
} else {
- setErrors(data.productVariantUpdate.productErrors);
+ setErrors(data.productVariantUpdate.errors);
}
};
diff --git a/src/storybook/misc.ts b/src/storybook/misc.ts
index b1f96fe36..6a28d4117 100644
--- a/src/storybook/misc.ts
+++ b/src/storybook/misc.ts
@@ -1,5 +1,3 @@
-import { ProductErrorFragment } from "@saleor/attributes/types/ProductErrorFragment";
-
export function formError(
field: string,
opts?: Partial>
diff --git a/src/storybook/stories/attributes/AttributePage.tsx b/src/storybook/stories/attributes/AttributePage.tsx
index e2d8f5b68..68ddf3930 100644
--- a/src/storybook/stories/attributes/AttributePage.tsx
+++ b/src/storybook/stories/attributes/AttributePage.tsx
@@ -5,8 +5,10 @@ import AttributePage, {
AttributePageProps
} from "@saleor/attributes/components/AttributePage";
import { attribute } from "@saleor/attributes/fixtures";
-import { formError } from "@saleor/storybook/misc";
-import { AttributeInputTypeEnum } from "@saleor/types/globalTypes";
+import {
+ AttributeInputTypeEnum,
+ ProductErrorCode
+} from "@saleor/types/globalTypes";
import Decorator from "../../Decorator";
const props: AttributePageProps = {
@@ -39,7 +41,11 @@ storiesOf("Views / Attributes / Attribute details", module)
.add("form errors", () => (
({
+ __typename: "ProductError",
+ code: ProductErrorCode.INVALID,
+ field
+ }))}
/>
))
.add("multiple select input", () => (
diff --git a/src/storybook/stories/products/ProductCreatePage.tsx b/src/storybook/stories/products/ProductCreatePage.tsx
index 1c968c390..306c5eca9 100644
--- a/src/storybook/stories/products/ProductCreatePage.tsx
+++ b/src/storybook/stories/products/ProductCreatePage.tsx
@@ -2,13 +2,13 @@ import { storiesOf } from "@storybook/react";
import React from "react";
import { fetchMoreProps } from "@saleor/fixtures";
+import { ProductErrorCode } from "@saleor/types/globalTypes";
import ProductCreatePage, {
ProductCreatePageSubmitData
} from "../../../products/components/ProductCreatePage";
import { product as productFixture } from "../../../products/fixtures";
import { productTypes } from "../../../productTypes/fixtures";
import Decorator from "../../Decorator";
-import { formError } from "../../misc";
const product = productFixture("");
@@ -60,7 +60,11 @@ storiesOf("Views / Products / Create product", module)
disabled={false}
errors={(["name", "productType", "category", "sku"] as Array<
keyof ProductCreatePageSubmitData
- >).map(formError)}
+ >).map(field => ({
+ __typename: "ProductError",
+ code: ProductErrorCode.INVALID,
+ field
+ }))}
header="Add product"
collections={product.collections}
fetchCategories={() => undefined}
diff --git a/src/types/globalTypes.ts b/src/types/globalTypes.ts
index cdee80d75..67e140b83 100644
--- a/src/types/globalTypes.ts
+++ b/src/types/globalTypes.ts
@@ -929,7 +929,7 @@ export interface NameTranslationInput {
}
export interface OrderAddNoteInput {
- message?: string | null;
+ message: string;
}
export interface OrderDraftFilterInput {
@@ -1026,6 +1026,7 @@ export interface ProductFilterInput {
attributes?: (AttributeInput | null)[] | null;
stockAvailability?: StockAvailability | null;
productType?: string | null;
+ stocks?: ProductStockFilterInput | null;
search?: string | null;
minimalPrice?: PriceRangeInput | null;
productTypes?: (string | null)[] | null;
@@ -1037,6 +1038,11 @@ export interface ProductOrder {
field?: ProductOrderField | null;
}
+export interface ProductStockFilterInput {
+ warehouseIds?: string[] | null;
+ quantity?: IntRangeInput | null;
+}
+
export interface ProductTypeFilterInput {
search?: string | null;
configurable?: ProductTypeConfigurable | null;
@@ -1080,6 +1086,7 @@ export interface ProductVariantCreateInput {
trackInventory?: boolean | null;
weight?: any | null;
product: string;
+ stocks?: StockInput[] | null;
}
export interface ProductVariantInput {
@@ -1208,6 +1215,11 @@ export interface StaffUserInput {
search?: string | null;
}
+export interface StockInput {
+ warehouse: string;
+ quantity?: number | null;
+}
+
export interface TranslationInput {
seoTitle?: string | null;
seoDescription?: string | null;
From 20c4340b8f4e86c82dc7531036416075244841e0 Mon Sep 17 00:00:00 2001
From: dominik-zeglen
Date: Tue, 10 Mar 2020 14:19:09 +0100
Subject: [PATCH 09/35] Update snapshots
---
.../__snapshots__/Stories.test.ts.snap | 178 +++++++++++++++---
1 file changed, 155 insertions(+), 23 deletions(-)
diff --git a/src/storybook/__snapshots__/Stories.test.ts.snap b/src/storybook/__snapshots__/Stories.test.ts.snap
index 0ba09cbb4..8d93f34cd 100644
--- a/src/storybook/__snapshots__/Stories.test.ts.snap
+++ b/src/storybook/__snapshots__/Stories.test.ts.snap
@@ -3738,6 +3738,125 @@ exports[`Storyshots Generics / Multiple select with autocomplete interactive wit
`;
+exports[`Storyshots Generics / Multiple select with autocomplete interactive with error 1`] = `
+
+
+
+
+
+
+
+
+ Value: AF
+
+
+
+
+
+
+
+ Afghanistan
+
+
+
+
+
+
+
+
+`;
+
exports[`Storyshots Generics / Multiple select with autocomplete interactive with load more 1`] = `
- This field is required
+ Invalid value
- This field is required
+ Invalid value
- API error
+ Invalid value
- Duplicated SKU.
+ SKUs must be unique
@@ -92720,6 +92839,7 @@ Ctrl + K"
aria-invalid="false"
class="MuiInputBase-input-id MuiOutlinedInput-input-id MuiInputBase-disabled-id MuiOutlinedInput-disabled-id MuiInputBase-inputAdornedEnd-id MuiOutlinedInput-inputAdornedEnd-id"
disabled=""
+ min="0"
name="basePrice"
type="number"
value="0"
@@ -93784,6 +93904,7 @@ Ctrl + K"
- Generic form error
+ Invalid value
- Generic form error
+ Invalid value
+
+ Invalid value
+
@@ -95116,7 +95243,7 @@ Ctrl + K"
- Generic form error
+ Invalid value
@@ -95190,7 +95317,7 @@ Ctrl + K"
- Generic form error
+ Invalid value
@@ -95211,7 +95338,7 @@ Ctrl + K"
class="MuiFormControl-root-id MuiTextField-root-id MuiFormControl-fullWidth-id"
>
From 93ba9378ef9a74e25a3fc8a725d0b9105b2caeef Mon Sep 17 00:00:00 2001
From: dominik-zeglen
Date: Tue, 10 Mar 2020 14:33:43 +0100
Subject: [PATCH 10/35] Update types
---
src/auth/mutations.ts | 15 ++---
src/auth/types/RequestPasswordReset.ts | 6 +-
src/auth/types/SetPassword.ts | 8 +--
src/customers/mutations.ts | 55 +++++++++++--------
src/customers/types/AccountErrorFragment.ts | 15 +++++
src/customers/types/BulkRemoveCustomers.ts | 6 +-
src/customers/types/CreateCustomer.ts | 6 +-
src/customers/types/CreateCustomerAddress.ts | 6 +-
src/customers/types/RemoveCustomer.ts | 6 +-
src/customers/types/RemoveCustomerAddress.ts | 6 +-
.../types/SetCustomerDefaultAddress.ts | 6 +-
src/customers/types/UpdateCustomer.ts | 6 +-
src/customers/types/UpdateCustomerAddress.ts | 6 +-
src/services/mutations.ts | 35 ++++++------
src/services/types/ServiceCreate.ts | 8 +--
src/services/types/ServiceDelete.ts | 6 +-
src/services/types/ServiceTokenCreate.ts | 8 +--
src/services/types/ServiceTokenDelete.ts | 6 +-
src/services/types/ServiceUpdate.ts | 6 +-
src/staff/mutations.ts | 37 +++++++------
src/staff/types/ChangeStaffPassword.ts | 6 +-
src/staff/types/StaffAvatarDelete.ts | 6 +-
src/staff/types/StaffAvatarUpdate.ts | 6 +-
src/staff/types/StaffMemberAdd.ts | 6 +-
src/staff/types/StaffMemberDelete.ts | 6 +-
src/staff/types/StaffMemberUpdate.ts | 6 +-
src/types/globalTypes.ts | 22 ++++++++
27 files changed, 189 insertions(+), 122 deletions(-)
create mode 100644 src/customers/types/AccountErrorFragment.ts
diff --git a/src/auth/mutations.ts b/src/auth/mutations.ts
index 5138d6c2f..60ca7b91b 100644
--- a/src/auth/mutations.ts
+++ b/src/auth/mutations.ts
@@ -1,5 +1,6 @@
import gql from "graphql-tag";
+import { accountFragmentError } from "@saleor/customers/mutations";
import { TypedMutation } from "../mutations";
import {
RequestPasswordReset,
@@ -64,11 +65,11 @@ export const TypedVerifyTokenMutation = TypedMutation<
>(tokenVerifyMutation);
export const requestPasswordReset = gql`
+ ${accountFragmentError}
mutation RequestPasswordReset($email: String!, $redirectUrl: String!) {
requestPasswordReset(email: $email, redirectUrl: $redirectUrl) {
- errors {
- field
- message
+ errors: accountErrors {
+ ...AccountErrorFragment
}
}
}
@@ -79,14 +80,14 @@ export const RequestPasswordResetMutation = TypedMutation<
>(requestPasswordReset);
export const setPassword = gql`
+ ${accountFragmentError}
${fragmentUser}
mutation SetPassword($email: String!, $password: String!, $token: String!) {
setPassword(email: $email, password: $password, token: $token) {
- token
- errors {
- field
- message
+ errors: accountErrors {
+ ...AccountErrorFragment
}
+ token
user {
...User
}
diff --git a/src/auth/types/RequestPasswordReset.ts b/src/auth/types/RequestPasswordReset.ts
index c011b0794..87ba8684a 100644
--- a/src/auth/types/RequestPasswordReset.ts
+++ b/src/auth/types/RequestPasswordReset.ts
@@ -2,14 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { AccountErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: RequestPasswordReset
// ====================================================
export interface RequestPasswordReset_requestPasswordReset_errors {
- __typename: "Error";
+ __typename: "AccountError";
+ code: AccountErrorCode;
field: string | null;
- message: string | null;
}
export interface RequestPasswordReset_requestPasswordReset {
diff --git a/src/auth/types/SetPassword.ts b/src/auth/types/SetPassword.ts
index 9a4c04509..805728d35 100644
--- a/src/auth/types/SetPassword.ts
+++ b/src/auth/types/SetPassword.ts
@@ -2,16 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { PermissionEnum } from "./../../types/globalTypes";
+import { AccountErrorCode, PermissionEnum } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: SetPassword
// ====================================================
export interface SetPassword_setPassword_errors {
- __typename: "Error";
+ __typename: "AccountError";
+ code: AccountErrorCode;
field: string | null;
- message: string | null;
}
export interface SetPassword_setPassword_user_permissions {
@@ -37,8 +37,8 @@ export interface SetPassword_setPassword_user {
export interface SetPassword_setPassword {
__typename: "SetPassword";
+ errors: SetPassword_setPassword_errors[] | null;
token: string | null;
- errors: (SetPassword_setPassword_errors | null)[];
user: SetPassword_setPassword_user | null;
}
diff --git a/src/customers/mutations.ts b/src/customers/mutations.ts
index 1c80da368..c07d36e89 100644
--- a/src/customers/mutations.ts
+++ b/src/customers/mutations.ts
@@ -36,13 +36,20 @@ import {
UpdateCustomerAddressVariables
} from "./types/UpdateCustomerAddress";
+export const accountFragmentError = gql`
+ fragment AccountErrorFragment on AccountError {
+ code
+ field
+ }
+`;
+
const updateCustomer = gql`
+ ${accountFragmentError}
${customerDetailsFragment}
mutation UpdateCustomer($id: ID!, $input: CustomerInput!) {
customerUpdate(id: $id, input: $input) {
- errors {
- field
- message
+ errors: accountErrors {
+ ...AccountErrorFragment
}
user {
...CustomerDetailsFragment
@@ -56,11 +63,11 @@ export const TypedUpdateCustomerMutation = TypedMutation<
>(updateCustomer);
const createCustomer = gql`
+ ${accountFragmentError}
mutation CreateCustomer($input: UserCreateInput!) {
customerCreate(input: $input) {
- errors {
- field
- message
+ errors: accountErrors {
+ ...AccountErrorFragment
}
user {
id
@@ -74,11 +81,11 @@ export const TypedCreateCustomerMutation = TypedMutation<
>(createCustomer);
const removeCustomer = gql`
+ ${accountFragmentError}
mutation RemoveCustomer($id: ID!) {
customerDelete(id: $id) {
- errors {
- field
- message
+ errors: accountErrors {
+ ...AccountErrorFragment
}
}
}
@@ -89,6 +96,7 @@ export const TypedRemoveCustomerMutation = TypedMutation<
>(removeCustomer);
const setCustomerDefaultAddress = gql`
+ ${accountFragmentError}
${customerAddressesFragment}
mutation SetCustomerDefaultAddress(
$addressId: ID!
@@ -96,9 +104,8 @@ const setCustomerDefaultAddress = gql`
$type: AddressTypeEnum!
) {
addressSetDefault(addressId: $addressId, userId: $userId, type: $type) {
- errors {
- field
- message
+ errors: accountErrors {
+ ...AccountErrorFragment
}
user {
...CustomerAddressesFragment
@@ -112,13 +119,13 @@ export const TypedSetCustomerDefaultAddressMutation = TypedMutation<
>(setCustomerDefaultAddress);
const createCustomerAddress = gql`
+ ${accountFragmentError}
${customerAddressesFragment}
${fragmentAddress}
mutation CreateCustomerAddress($id: ID!, $input: AddressInput!) {
addressCreate(userId: $id, input: $input) {
- errors {
- field
- message
+ errors: accountErrors {
+ ...AccountErrorFragment
}
address {
...AddressFragment
@@ -135,12 +142,12 @@ export const TypedCreateCustomerAddressMutation = TypedMutation<
>(createCustomerAddress);
const updateCustomerAddress = gql`
+ ${accountFragmentError}
${fragmentAddress}
mutation UpdateCustomerAddress($id: ID!, $input: AddressInput!) {
addressUpdate(id: $id, input: $input) {
- errors {
- field
- message
+ errors: accountErrors {
+ ...AccountErrorFragment
}
address {
...AddressFragment
@@ -154,12 +161,12 @@ export const TypedUpdateCustomerAddressMutation = TypedMutation<
>(updateCustomerAddress);
const removeCustomerAddress = gql`
+ ${accountFragmentError}
${customerAddressesFragment}
mutation RemoveCustomerAddress($id: ID!) {
addressDelete(id: $id) {
- errors {
- field
- message
+ errors: accountErrors {
+ ...AccountErrorFragment
}
user {
...CustomerAddressesFragment
@@ -173,11 +180,11 @@ export const TypedRemoveCustomerAddressMutation = TypedMutation<
>(removeCustomerAddress);
export const bulkRemoveCustomers = gql`
+ ${accountFragmentError}
mutation BulkRemoveCustomers($ids: [ID]!) {
customerBulkDelete(ids: $ids) {
- errors {
- field
- message
+ errors: accountErrors {
+ ...AccountErrorFragment
}
}
}
diff --git a/src/customers/types/AccountErrorFragment.ts b/src/customers/types/AccountErrorFragment.ts
new file mode 100644
index 000000000..3b96c2f5c
--- /dev/null
+++ b/src/customers/types/AccountErrorFragment.ts
@@ -0,0 +1,15 @@
+/* tslint:disable */
+/* eslint-disable */
+// This file was automatically generated and should not be edited.
+
+import { AccountErrorCode } from "./../../types/globalTypes";
+
+// ====================================================
+// GraphQL fragment: AccountErrorFragment
+// ====================================================
+
+export interface AccountErrorFragment {
+ __typename: "AccountError";
+ code: AccountErrorCode;
+ field: string | null;
+}
diff --git a/src/customers/types/BulkRemoveCustomers.ts b/src/customers/types/BulkRemoveCustomers.ts
index 5af102d77..206900f35 100644
--- a/src/customers/types/BulkRemoveCustomers.ts
+++ b/src/customers/types/BulkRemoveCustomers.ts
@@ -2,14 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { AccountErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: BulkRemoveCustomers
// ====================================================
export interface BulkRemoveCustomers_customerBulkDelete_errors {
- __typename: "Error";
+ __typename: "AccountError";
+ code: AccountErrorCode;
field: string | null;
- message: string | null;
}
export interface BulkRemoveCustomers_customerBulkDelete {
diff --git a/src/customers/types/CreateCustomer.ts b/src/customers/types/CreateCustomer.ts
index 6f9a4ec3e..6b75e5d8d 100644
--- a/src/customers/types/CreateCustomer.ts
+++ b/src/customers/types/CreateCustomer.ts
@@ -2,16 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { UserCreateInput } from "./../../types/globalTypes";
+import { UserCreateInput, AccountErrorCode } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: CreateCustomer
// ====================================================
export interface CreateCustomer_customerCreate_errors {
- __typename: "Error";
+ __typename: "AccountError";
+ code: AccountErrorCode;
field: string | null;
- message: string | null;
}
export interface CreateCustomer_customerCreate_user {
diff --git a/src/customers/types/CreateCustomerAddress.ts b/src/customers/types/CreateCustomerAddress.ts
index 2dfd3f2d9..5ffafaee9 100644
--- a/src/customers/types/CreateCustomerAddress.ts
+++ b/src/customers/types/CreateCustomerAddress.ts
@@ -2,16 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { AddressInput } from "./../../types/globalTypes";
+import { AddressInput, AccountErrorCode } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: CreateCustomerAddress
// ====================================================
export interface CreateCustomerAddress_addressCreate_errors {
- __typename: "Error";
+ __typename: "AccountError";
+ code: AccountErrorCode;
field: string | null;
- message: string | null;
}
export interface CreateCustomerAddress_addressCreate_address_country {
diff --git a/src/customers/types/RemoveCustomer.ts b/src/customers/types/RemoveCustomer.ts
index ddc504728..ceaddf38a 100644
--- a/src/customers/types/RemoveCustomer.ts
+++ b/src/customers/types/RemoveCustomer.ts
@@ -2,14 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { AccountErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: RemoveCustomer
// ====================================================
export interface RemoveCustomer_customerDelete_errors {
- __typename: "Error";
+ __typename: "AccountError";
+ code: AccountErrorCode;
field: string | null;
- message: string | null;
}
export interface RemoveCustomer_customerDelete {
diff --git a/src/customers/types/RemoveCustomerAddress.ts b/src/customers/types/RemoveCustomerAddress.ts
index 69de7eafa..4d1769f49 100644
--- a/src/customers/types/RemoveCustomerAddress.ts
+++ b/src/customers/types/RemoveCustomerAddress.ts
@@ -2,14 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { AccountErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: RemoveCustomerAddress
// ====================================================
export interface RemoveCustomerAddress_addressDelete_errors {
- __typename: "Error";
+ __typename: "AccountError";
+ code: AccountErrorCode;
field: string | null;
- message: string | null;
}
export interface RemoveCustomerAddress_addressDelete_user_addresses_country {
diff --git a/src/customers/types/SetCustomerDefaultAddress.ts b/src/customers/types/SetCustomerDefaultAddress.ts
index eefe47419..af2058f60 100644
--- a/src/customers/types/SetCustomerDefaultAddress.ts
+++ b/src/customers/types/SetCustomerDefaultAddress.ts
@@ -2,16 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { AddressTypeEnum } from "./../../types/globalTypes";
+import { AddressTypeEnum, AccountErrorCode } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: SetCustomerDefaultAddress
// ====================================================
export interface SetCustomerDefaultAddress_addressSetDefault_errors {
- __typename: "Error";
+ __typename: "AccountError";
+ code: AccountErrorCode;
field: string | null;
- message: string | null;
}
export interface SetCustomerDefaultAddress_addressSetDefault_user_addresses_country {
diff --git a/src/customers/types/UpdateCustomer.ts b/src/customers/types/UpdateCustomer.ts
index f67fe8d00..61f7051c2 100644
--- a/src/customers/types/UpdateCustomer.ts
+++ b/src/customers/types/UpdateCustomer.ts
@@ -2,16 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { CustomerInput } from "./../../types/globalTypes";
+import { CustomerInput, AccountErrorCode } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: UpdateCustomer
// ====================================================
export interface UpdateCustomer_customerUpdate_errors {
- __typename: "Error";
+ __typename: "AccountError";
+ code: AccountErrorCode;
field: string | null;
- message: string | null;
}
export interface UpdateCustomer_customerUpdate_user_defaultShippingAddress_country {
diff --git a/src/customers/types/UpdateCustomerAddress.ts b/src/customers/types/UpdateCustomerAddress.ts
index 73fb000dc..e62b464a1 100644
--- a/src/customers/types/UpdateCustomerAddress.ts
+++ b/src/customers/types/UpdateCustomerAddress.ts
@@ -2,16 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { AddressInput } from "./../../types/globalTypes";
+import { AddressInput, AccountErrorCode } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: UpdateCustomerAddress
// ====================================================
export interface UpdateCustomerAddress_addressUpdate_errors {
- __typename: "Error";
+ __typename: "AccountError";
+ code: AccountErrorCode;
field: string | null;
- message: string | null;
}
export interface UpdateCustomerAddress_addressUpdate_address_country {
diff --git a/src/services/mutations.ts b/src/services/mutations.ts
index 92096ddad..090d6c1ad 100644
--- a/src/services/mutations.ts
+++ b/src/services/mutations.ts
@@ -1,5 +1,6 @@
import gql from "graphql-tag";
+import { accountFragmentError } from "@saleor/customers/mutations";
import { TypedMutation } from "../mutations";
import { serviceDetailsFragment, serviceFragment } from "./queries";
import { ServiceCreate, ServiceCreateVariables } from "./types/ServiceCreate";
@@ -15,14 +16,14 @@ import {
import { ServiceUpdate, ServiceUpdateVariables } from "./types/ServiceUpdate";
const serviceCreateMutation = gql`
+ ${accountFragmentError}
${serviceFragment}
mutation ServiceCreate($input: ServiceAccountInput!) {
serviceAccountCreate(input: $input) {
- errors {
- field
- message
- }
authToken
+ errors: accountErrors {
+ ...AccountErrorFragment
+ }
serviceAccount {
...ServiceFragment
}
@@ -36,11 +37,11 @@ export const ServiceCreateMutation = TypedMutation<
>(serviceCreateMutation);
const serviceDeleteMutation = gql`
+ ${accountFragmentError}
mutation ServiceDelete($id: ID!) {
serviceAccountDelete(id: $id) {
- errors {
- field
- message
+ errors: accountErrors {
+ ...AccountErrorFragment
}
}
}
@@ -51,12 +52,12 @@ export const ServiceDeleteMutation = TypedMutation<
>(serviceDeleteMutation);
const serviceUpdateMutation = gql`
+ ${accountFragmentError}
${serviceDetailsFragment}
mutation ServiceUpdate($id: ID!, $input: ServiceAccountInput!) {
serviceAccountUpdate(id: $id, input: $input) {
- errors {
- field
- message
+ errors: accountErrors {
+ ...AccountErrorFragment
}
serviceAccount {
...ServiceDetailsFragment
@@ -71,13 +72,13 @@ export const ServiceUpdateMutation = TypedMutation<
>(serviceUpdateMutation);
const serviceTokenCreate = gql`
+ ${accountFragmentError}
mutation ServiceTokenCreate($input: ServiceAccountTokenInput!) {
serviceAccountTokenCreate(input: $input) {
- errors {
- field
- message
- }
authToken
+ errors: accountErrors {
+ ...AccountErrorFragment
+ }
}
}
`;
@@ -87,11 +88,11 @@ export const ServiceTokenCreateMutation = TypedMutation<
>(serviceTokenCreate);
const serviceTokenDelete = gql`
+ ${accountFragmentError}
mutation ServiceTokenDelete($id: ID!) {
serviceAccountTokenDelete(id: $id) {
- errors {
- field
- message
+ errors: accountErrors {
+ ...AccountErrorFragment
}
}
}
diff --git a/src/services/types/ServiceCreate.ts b/src/services/types/ServiceCreate.ts
index f9efe54e1..74b3a0aea 100644
--- a/src/services/types/ServiceCreate.ts
+++ b/src/services/types/ServiceCreate.ts
@@ -2,16 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { ServiceAccountInput } from "./../../types/globalTypes";
+import { ServiceAccountInput, AccountErrorCode } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: ServiceCreate
// ====================================================
export interface ServiceCreate_serviceAccountCreate_errors {
- __typename: "Error";
+ __typename: "AccountError";
+ code: AccountErrorCode;
field: string | null;
- message: string | null;
}
export interface ServiceCreate_serviceAccountCreate_serviceAccount {
@@ -23,8 +23,8 @@ export interface ServiceCreate_serviceAccountCreate_serviceAccount {
export interface ServiceCreate_serviceAccountCreate {
__typename: "ServiceAccountCreate";
- errors: ServiceCreate_serviceAccountCreate_errors[];
authToken: string | null;
+ errors: ServiceCreate_serviceAccountCreate_errors[];
serviceAccount: ServiceCreate_serviceAccountCreate_serviceAccount | null;
}
diff --git a/src/services/types/ServiceDelete.ts b/src/services/types/ServiceDelete.ts
index 71e4c2064..a23793c72 100644
--- a/src/services/types/ServiceDelete.ts
+++ b/src/services/types/ServiceDelete.ts
@@ -2,14 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { AccountErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: ServiceDelete
// ====================================================
export interface ServiceDelete_serviceAccountDelete_errors {
- __typename: "Error";
+ __typename: "AccountError";
+ code: AccountErrorCode;
field: string | null;
- message: string | null;
}
export interface ServiceDelete_serviceAccountDelete {
diff --git a/src/services/types/ServiceTokenCreate.ts b/src/services/types/ServiceTokenCreate.ts
index 3698104a2..7529a10c4 100644
--- a/src/services/types/ServiceTokenCreate.ts
+++ b/src/services/types/ServiceTokenCreate.ts
@@ -2,22 +2,22 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { ServiceAccountTokenInput } from "./../../types/globalTypes";
+import { ServiceAccountTokenInput, AccountErrorCode } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: ServiceTokenCreate
// ====================================================
export interface ServiceTokenCreate_serviceAccountTokenCreate_errors {
- __typename: "Error";
+ __typename: "AccountError";
+ code: AccountErrorCode;
field: string | null;
- message: string | null;
}
export interface ServiceTokenCreate_serviceAccountTokenCreate {
__typename: "ServiceAccountTokenCreate";
- errors: ServiceTokenCreate_serviceAccountTokenCreate_errors[];
authToken: string | null;
+ errors: ServiceTokenCreate_serviceAccountTokenCreate_errors[];
}
export interface ServiceTokenCreate {
diff --git a/src/services/types/ServiceTokenDelete.ts b/src/services/types/ServiceTokenDelete.ts
index c0883203a..9cfad5249 100644
--- a/src/services/types/ServiceTokenDelete.ts
+++ b/src/services/types/ServiceTokenDelete.ts
@@ -2,14 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { AccountErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: ServiceTokenDelete
// ====================================================
export interface ServiceTokenDelete_serviceAccountTokenDelete_errors {
- __typename: "Error";
+ __typename: "AccountError";
+ code: AccountErrorCode;
field: string | null;
- message: string | null;
}
export interface ServiceTokenDelete_serviceAccountTokenDelete {
diff --git a/src/services/types/ServiceUpdate.ts b/src/services/types/ServiceUpdate.ts
index eed851a78..d7f3ac964 100644
--- a/src/services/types/ServiceUpdate.ts
+++ b/src/services/types/ServiceUpdate.ts
@@ -2,16 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { ServiceAccountInput, PermissionEnum } from "./../../types/globalTypes";
+import { ServiceAccountInput, AccountErrorCode, PermissionEnum } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: ServiceUpdate
// ====================================================
export interface ServiceUpdate_serviceAccountUpdate_errors {
- __typename: "Error";
+ __typename: "AccountError";
+ code: AccountErrorCode;
field: string | null;
- message: string | null;
}
export interface ServiceUpdate_serviceAccountUpdate_serviceAccount_permissions {
diff --git a/src/staff/mutations.ts b/src/staff/mutations.ts
index ee1dde297..60ada4cd9 100644
--- a/src/staff/mutations.ts
+++ b/src/staff/mutations.ts
@@ -1,6 +1,7 @@
import gql from "graphql-tag";
import makeMutation from "@saleor/hooks/makeMutation";
+import { accountFragmentError } from "@saleor/customers/mutations";
import { TypedMutation } from "../mutations";
import { staffMemberDetailsFragment } from "./queries";
import { StaffAvatarDelete } from "./types/StaffAvatarDelete";
@@ -26,12 +27,12 @@ import {
} from "./types/ChangeStaffPassword";
const staffMemberAddMutation = gql`
+ ${accountFragmentError}
${staffMemberDetailsFragment}
mutation StaffMemberAdd($input: StaffCreateInput!) {
staffCreate(input: $input) {
- errors {
- field
- message
+ errors: accountErrors {
+ ...AccountErrorFragment
}
user {
...StaffMemberDetailsFragment
@@ -45,12 +46,12 @@ export const TypedStaffMemberAddMutation = TypedMutation<
>(staffMemberAddMutation);
const staffMemberUpdateMutation = gql`
+ ${accountFragmentError}
${staffMemberDetailsFragment}
mutation StaffMemberUpdate($id: ID!, $input: StaffInput!) {
staffUpdate(id: $id, input: $input) {
- errors {
- field
- message
+ errors: accountErrors {
+ ...AccountErrorFragment
}
user {
...StaffMemberDetailsFragment
@@ -64,11 +65,11 @@ export const TypedStaffMemberUpdateMutation = TypedMutation<
>(staffMemberUpdateMutation);
const staffMemberDeleteMutation = gql`
+ ${accountFragmentError}
mutation StaffMemberDelete($id: ID!) {
staffDelete(id: $id) {
- errors {
- field
- message
+ errors: accountErrors {
+ ...AccountErrorFragment
}
}
}
@@ -79,11 +80,11 @@ export const TypedStaffMemberDeleteMutation = TypedMutation<
>(staffMemberDeleteMutation);
const staffAvatarUpdateMutation = gql`
+ ${accountFragmentError}
mutation StaffAvatarUpdate($image: Upload!) {
userAvatarUpdate(image: $image) {
- errors {
- field
- message
+ errors: accountErrors {
+ ...AccountErrorFragment
}
user {
id
@@ -100,11 +101,11 @@ export const TypedStaffAvatarUpdateMutation = TypedMutation<
>(staffAvatarUpdateMutation);
const staffAvatarDeleteMutation = gql`
+ ${accountFragmentError}
mutation StaffAvatarDelete {
userAvatarDelete {
- errors {
- field
- message
+ errors: accountErrors {
+ ...AccountErrorFragment
}
user {
id
@@ -121,11 +122,11 @@ export const TypedStaffAvatarDeleteMutation = TypedMutation<
>(staffAvatarDeleteMutation);
const changeStaffPassword = gql`
+ ${accountFragmentError}
mutation ChangeStaffPassword($newPassword: String!, $oldPassword: String!) {
passwordChange(newPassword: $newPassword, oldPassword: $oldPassword) {
- errors {
- field
- message
+ errors: accountErrors {
+ ...AccountErrorFragment
}
}
}
diff --git a/src/staff/types/ChangeStaffPassword.ts b/src/staff/types/ChangeStaffPassword.ts
index 0913c8d27..5df09fe97 100644
--- a/src/staff/types/ChangeStaffPassword.ts
+++ b/src/staff/types/ChangeStaffPassword.ts
@@ -2,14 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { AccountErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: ChangeStaffPassword
// ====================================================
export interface ChangeStaffPassword_passwordChange_errors {
- __typename: "Error";
+ __typename: "AccountError";
+ code: AccountErrorCode;
field: string | null;
- message: string | null;
}
export interface ChangeStaffPassword_passwordChange {
diff --git a/src/staff/types/StaffAvatarDelete.ts b/src/staff/types/StaffAvatarDelete.ts
index b92267979..0d74345e7 100644
--- a/src/staff/types/StaffAvatarDelete.ts
+++ b/src/staff/types/StaffAvatarDelete.ts
@@ -2,14 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { AccountErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: StaffAvatarDelete
// ====================================================
export interface StaffAvatarDelete_userAvatarDelete_errors {
- __typename: "Error";
+ __typename: "AccountError";
+ code: AccountErrorCode;
field: string | null;
- message: string | null;
}
export interface StaffAvatarDelete_userAvatarDelete_user_avatar {
diff --git a/src/staff/types/StaffAvatarUpdate.ts b/src/staff/types/StaffAvatarUpdate.ts
index c58029384..4b0746ad5 100644
--- a/src/staff/types/StaffAvatarUpdate.ts
+++ b/src/staff/types/StaffAvatarUpdate.ts
@@ -2,14 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { AccountErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: StaffAvatarUpdate
// ====================================================
export interface StaffAvatarUpdate_userAvatarUpdate_errors {
- __typename: "Error";
+ __typename: "AccountError";
+ code: AccountErrorCode;
field: string | null;
- message: string | null;
}
export interface StaffAvatarUpdate_userAvatarUpdate_user_avatar {
diff --git a/src/staff/types/StaffMemberAdd.ts b/src/staff/types/StaffMemberAdd.ts
index 214102425..fadf8bb7b 100644
--- a/src/staff/types/StaffMemberAdd.ts
+++ b/src/staff/types/StaffMemberAdd.ts
@@ -2,16 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { StaffCreateInput, PermissionEnum } from "./../../types/globalTypes";
+import { StaffCreateInput, AccountErrorCode, PermissionEnum } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: StaffMemberAdd
// ====================================================
export interface StaffMemberAdd_staffCreate_errors {
- __typename: "Error";
+ __typename: "AccountError";
+ code: AccountErrorCode;
field: string | null;
- message: string | null;
}
export interface StaffMemberAdd_staffCreate_user_avatar {
diff --git a/src/staff/types/StaffMemberDelete.ts b/src/staff/types/StaffMemberDelete.ts
index f90ba0d03..8bf44db45 100644
--- a/src/staff/types/StaffMemberDelete.ts
+++ b/src/staff/types/StaffMemberDelete.ts
@@ -2,14 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { AccountErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: StaffMemberDelete
// ====================================================
export interface StaffMemberDelete_staffDelete_errors {
- __typename: "Error";
+ __typename: "AccountError";
+ code: AccountErrorCode;
field: string | null;
- message: string | null;
}
export interface StaffMemberDelete_staffDelete {
diff --git a/src/staff/types/StaffMemberUpdate.ts b/src/staff/types/StaffMemberUpdate.ts
index 88f3881a2..aabd8ef74 100644
--- a/src/staff/types/StaffMemberUpdate.ts
+++ b/src/staff/types/StaffMemberUpdate.ts
@@ -2,16 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { StaffInput, PermissionEnum } from "./../../types/globalTypes";
+import { StaffInput, AccountErrorCode, PermissionEnum } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: StaffMemberUpdate
// ====================================================
export interface StaffMemberUpdate_staffUpdate_errors {
- __typename: "Error";
+ __typename: "AccountError";
+ code: AccountErrorCode;
field: string | null;
- message: string | null;
}
export interface StaffMemberUpdate_staffUpdate_user_avatar {
diff --git a/src/types/globalTypes.ts b/src/types/globalTypes.ts
index 67e140b83..ec11c64f4 100644
--- a/src/types/globalTypes.ts
+++ b/src/types/globalTypes.ts
@@ -6,6 +6,28 @@
// START Enums and Input Objects
//==============================================================
+export enum AccountErrorCode {
+ ACTIVATE_OWN_ACCOUNT = "ACTIVATE_OWN_ACCOUNT",
+ ACTIVATE_SUPERUSER_ACCOUNT = "ACTIVATE_SUPERUSER_ACCOUNT",
+ ASSIGN_NON_STAFF_MEMBER = "ASSIGN_NON_STAFF_MEMBER",
+ DEACTIVATE_OWN_ACCOUNT = "DEACTIVATE_OWN_ACCOUNT",
+ DEACTIVATE_SUPERUSER_ACCOUNT = "DEACTIVATE_SUPERUSER_ACCOUNT",
+ DELETE_NON_STAFF_USER = "DELETE_NON_STAFF_USER",
+ DELETE_OWN_ACCOUNT = "DELETE_OWN_ACCOUNT",
+ DELETE_STAFF_ACCOUNT = "DELETE_STAFF_ACCOUNT",
+ DELETE_SUPERUSER_ACCOUNT = "DELETE_SUPERUSER_ACCOUNT",
+ GRAPHQL_ERROR = "GRAPHQL_ERROR",
+ INVALID = "INVALID",
+ INVALID_PASSWORD = "INVALID_PASSWORD",
+ NOT_FOUND = "NOT_FOUND",
+ PASSWORD_ENTIRELY_NUMERIC = "PASSWORD_ENTIRELY_NUMERIC",
+ PASSWORD_TOO_COMMON = "PASSWORD_TOO_COMMON",
+ PASSWORD_TOO_SHORT = "PASSWORD_TOO_SHORT",
+ PASSWORD_TOO_SIMILAR = "PASSWORD_TOO_SIMILAR",
+ REQUIRED = "REQUIRED",
+ UNIQUE = "UNIQUE",
+}
+
export enum AddressTypeEnum {
BILLING = "BILLING",
SHIPPING = "SHIPPING",
From 96c98077d8863de92fb469a783c68992989a12c1 Mon Sep 17 00:00:00 2001
From: dominik-zeglen
Date: Wed, 11 Mar 2020 10:55:14 +0100
Subject: [PATCH 11/35] Use error codes in account sections
---
src/components/AddressEdit/AddressEdit.tsx | 82 +++++++++++++------
.../CustomerAddressDialog.tsx | 4 +-
.../CustomerCreateAddress.tsx | 4 +-
.../CustomerCreateDetails.tsx | 33 +++++---
.../CustomerCreateNote/CustomerCreateNote.tsx | 13 +--
.../CustomerCreatePage/CustomerCreatePage.tsx | 4 +-
.../CustomerDetails/CustomerDetails.tsx | 15 ++--
.../CustomerDetailsPage.tsx | 4 +-
.../components/CustomerInfo/CustomerInfo.tsx | 23 +++---
src/customers/views/CustomerCreate.tsx | 16 +---
src/hooks/useAddressValidation.ts | 20 ++---
.../OrderAddressEditDialog.tsx | 4 +-
src/orders/mutations.ts | 16 +++-
src/orders/types/OrderDraftUpdate.ts | 5 +-
src/orders/types/OrderErrorFragment.ts | 15 ++++
src/orders/types/OrderUpdate.ts | 6 +-
.../ServiceCreatePage.stories.tsx | 8 +-
.../ServiceCreatePage/ServiceCreatePage.tsx | 4 +-
.../ServiceDetailsPage.stories.tsx | 8 +-
.../ServiceDetailsPage/ServiceDetailsPage.tsx | 6 +-
.../components/ServiceInfo/ServiceInfo.tsx | 21 +++--
.../StaffAddMemberDialog.tsx | 29 ++++---
.../StaffPasswordResetDialog.tsx | 24 ++++--
.../stories/customers/CustomerCreatePage.tsx | 10 ++-
.../stories/customers/CustomerDetailsPage.tsx | 8 +-
src/types/globalTypes.ts | 23 ++++++
src/utils/errors/account.ts | 56 +++++++++++++
src/utils/errors/order.ts | 28 +++++++
28 files changed, 351 insertions(+), 138 deletions(-)
create mode 100644 src/orders/types/OrderErrorFragment.ts
create mode 100644 src/utils/errors/account.ts
create mode 100644 src/utils/errors/order.ts
diff --git a/src/components/AddressEdit/AddressEdit.tsx b/src/components/AddressEdit/AddressEdit.tsx
index 96ce090c1..041bbd99d 100644
--- a/src/components/AddressEdit/AddressEdit.tsx
+++ b/src/components/AddressEdit/AddressEdit.tsx
@@ -1,12 +1,15 @@
import { makeStyles } from "@material-ui/core/styles";
import TextField from "@material-ui/core/TextField";
import React from "react";
-import { useIntl } from "react-intl";
+import { useIntl, IntlShape } from "react-intl";
import { AddressTypeInput } from "@saleor/customers/types";
import { commonMessages } from "@saleor/intl";
-import { UserError } from "@saleor/types";
-import { getFieldError } from "@saleor/utils/errors";
+import { getFormErrors } from "@saleor/utils/errors";
+import { AccountErrorFragment } from "@saleor/customers/types/AccountErrorFragment";
+import getAccountErrorMessage from "@saleor/utils/errors/account";
+import { OrderErrorFragment } from "@saleor/orders/types/OrderErrorFragment";
+import getOrderErrorMessage from "@saleor/utils/errors/order";
import FormSpacer from "../FormSpacer";
import SingleAutocompleteSelectField, {
SingleAutocompleteChoiceType
@@ -28,11 +31,22 @@ interface AddressEditProps {
countryDisplayValue: string;
data: AddressTypeInput;
disabled?: boolean;
- errors: UserError[];
+ errors: Array;
onChange(event: React.ChangeEvent);
onCountryChange(event: React.ChangeEvent);
}
+function getErrorMessage(
+ err: AccountErrorFragment | OrderErrorFragment,
+ intl: IntlShape
+): string {
+ if (err?.__typename === "AccountError") {
+ return getAccountErrorMessage(err, intl);
+ }
+
+ return getOrderErrorMessage(err, intl);
+}
+
const AddressEdit: React.FC = props => {
const {
countries,
@@ -43,18 +57,36 @@ const AddressEdit: React.FC = props => {
onChange,
onCountryChange
} = props;
- const classes = useStyles(props);
+ const classes = useStyles(props);
const intl = useIntl();
+ const formFields: Array = [
+ "city",
+ "cityArea",
+ "country",
+ "countryArea",
+ "firstName",
+ "lastName",
+ "companyName",
+ "phone",
+ "postalCode",
+ "streetAddress1",
+ "streetAddress2"
+ ];
+ const formErrors = getFormErrors<
+ keyof AddressTypeInput,
+ AccountErrorFragment | OrderErrorFragment
+ >(formFields, errors);
+
return (
<>
= props => {
= props => {
= props => {
= props => {
= props => {
= props => {
= props => {
= props => {
= props => {
;
- errors: UserError[];
+ errors: AccountErrorFragment[];
open: boolean;
variant: "create" | "edit";
onClose: () => void;
diff --git a/src/customers/components/CustomerCreateAddress/CustomerCreateAddress.tsx b/src/customers/components/CustomerCreateAddress/CustomerCreateAddress.tsx
index 2f98fbe18..5ef7e309b 100644
--- a/src/customers/components/CustomerCreateAddress/CustomerCreateAddress.tsx
+++ b/src/customers/components/CustomerCreateAddress/CustomerCreateAddress.tsx
@@ -9,7 +9,7 @@ import AddressEdit from "@saleor/components/AddressEdit";
import CardTitle from "@saleor/components/CardTitle";
import { FormSpacer } from "@saleor/components/FormSpacer";
import { SingleAutocompleteChoiceType } from "@saleor/components/SingleAutocompleteSelectField";
-import { UserError } from "../../../types";
+import { AccountErrorFragment } from "@saleor/customers/types/AccountErrorFragment";
import { AddressTypeInput } from "../../types";
const useStyles = makeStyles(
@@ -26,7 +26,7 @@ export interface CustomerCreateAddressProps {
countryDisplayName: string;
data: AddressTypeInput;
disabled: boolean;
- errors: UserError[];
+ errors: AccountErrorFragment[];
onChange(event: React.ChangeEvent);
onCountryChange(event: React.ChangeEvent);
}
diff --git a/src/customers/components/CustomerCreateDetails/CustomerCreateDetails.tsx b/src/customers/components/CustomerCreateDetails/CustomerCreateDetails.tsx
index f4d8f44ac..785f5ccef 100644
--- a/src/customers/components/CustomerCreateDetails/CustomerCreateDetails.tsx
+++ b/src/customers/components/CustomerCreateDetails/CustomerCreateDetails.tsx
@@ -7,8 +7,9 @@ import { useIntl } from "react-intl";
import CardTitle from "@saleor/components/CardTitle";
import { commonMessages } from "@saleor/intl";
-import { getFieldError } from "@saleor/utils/errors";
-import { UserError } from "../../../types";
+import { getFormErrors } from "@saleor/utils/errors";
+import { AccountErrorFragment } from "@saleor/customers/types/AccountErrorFragment";
+import getAccountErrorMessage from "@saleor/utils/errors/account";
import { CustomerCreatePageFormData } from "../CustomerCreatePage";
const useStyles = makeStyles(
@@ -26,16 +27,21 @@ const useStyles = makeStyles(
export interface CustomerCreateDetailsProps {
data: CustomerCreatePageFormData;
disabled: boolean;
- errors: UserError[];
+ errors: AccountErrorFragment[];
onChange: (event: React.ChangeEvent) => void;
}
const CustomerCreateDetails: React.FC = props => {
const { data, disabled, errors, onChange } = props;
- const classes = useStyles(props);
+ const classes = useStyles(props);
const intl = useIntl();
+ const formErrors = getFormErrors(
+ ["customerFirstName", "customerLastName", "email"],
+ errors
+ );
+
return (
= props => {
= props => {
);
};
+
CustomerCreateDetails.displayName = "CustomerCreateDetails";
export default CustomerCreateDetails;
diff --git a/src/customers/components/CustomerCreateNote/CustomerCreateNote.tsx b/src/customers/components/CustomerCreateNote/CustomerCreateNote.tsx
index 35b00baef..6765547d9 100644
--- a/src/customers/components/CustomerCreateNote/CustomerCreateNote.tsx
+++ b/src/customers/components/CustomerCreateNote/CustomerCreateNote.tsx
@@ -7,15 +7,16 @@ import { FormattedMessage, useIntl } from "react-intl";
import CardTitle from "@saleor/components/CardTitle";
import { FormSpacer } from "@saleor/components/FormSpacer";
-import { UserError } from "@saleor/types";
-import { getFieldError } from "@saleor/utils/errors";
+import { getFormErrors } from "@saleor/utils/errors";
+import getAccountErrorMessage from "@saleor/utils/errors/account";
+import { AccountErrorFragment } from "@saleor/customers/types/AccountErrorFragment";
export interface CustomerCreateNoteProps {
data: {
note: string;
};
disabled: boolean;
- errors: UserError[];
+ errors: AccountErrorFragment[];
onChange: (event: React.ChangeEvent) => void;
}
@@ -27,6 +28,8 @@ const CustomerCreateNote: React.FC = ({
}) => {
const intl = useIntl();
+ const formErrors = getFormErrors(["note"], errors);
+
return (
= ({
void;
onSubmit: (data: CustomerCreatePageSubmitData) => void;
diff --git a/src/customers/components/CustomerDetails/CustomerDetails.tsx b/src/customers/components/CustomerDetails/CustomerDetails.tsx
index d9b180398..6007dfe3f 100644
--- a/src/customers/components/CustomerDetails/CustomerDetails.tsx
+++ b/src/customers/components/CustomerDetails/CustomerDetails.tsx
@@ -11,8 +11,9 @@ import CardTitle from "@saleor/components/CardTitle";
import { ControlledCheckbox } from "@saleor/components/ControlledCheckbox";
import Skeleton from "@saleor/components/Skeleton";
import { maybe } from "@saleor/misc";
-import { UserError } from "@saleor/types";
-import { getFieldError } from "@saleor/utils/errors";
+import { getFormErrors } from "@saleor/utils/errors";
+import getAccountErrorMessage from "@saleor/utils/errors/account";
+import { AccountErrorFragment } from "@saleor/customers/types/AccountErrorFragment";
import { CustomerDetails_user } from "../../types/CustomerDetails";
const useStyles = makeStyles(
@@ -40,16 +41,18 @@ export interface CustomerDetailsProps {
note: string;
};
disabled: boolean;
- errors: UserError[];
+ errors: AccountErrorFragment[];
onChange: (event: React.ChangeEvent) => void;
}
const CustomerDetails: React.FC = props => {
const { customer, data, disabled, errors, onChange } = props;
- const classes = useStyles(props);
+ const classes = useStyles(props);
const intl = useIntl();
+ const formErrors = getFormErrors(["note"], errors);
+
return (
= props => {
/>
void;
onSubmit: (data: CustomerDetailsPageFormData) => void;
diff --git a/src/customers/components/CustomerInfo/CustomerInfo.tsx b/src/customers/components/CustomerInfo/CustomerInfo.tsx
index 9f8cdb596..f0b985921 100644
--- a/src/customers/components/CustomerInfo/CustomerInfo.tsx
+++ b/src/customers/components/CustomerInfo/CustomerInfo.tsx
@@ -10,8 +10,9 @@ import CardTitle from "@saleor/components/CardTitle";
import Grid from "@saleor/components/Grid";
import Hr from "@saleor/components/Hr";
import { commonMessages } from "@saleor/intl";
-import { UserError } from "@saleor/types";
-import { getFieldError } from "@saleor/utils/errors";
+import { AccountErrorFragment } from "@saleor/customers/types/AccountErrorFragment";
+import { getFormErrors } from "@saleor/utils/errors";
+import getAccountErrorMessage from "@saleor/utils/errors/account";
const useStyles = makeStyles(
theme => ({
@@ -35,16 +36,18 @@ export interface CustomerInfoProps {
email: string;
};
disabled: boolean;
- errors: UserError[];
+ errors: AccountErrorFragment[];
onChange: (event: React.ChangeEvent) => void;
}
const CustomerInfo: React.FC = props => {
const { data, disabled, errors, onChange } = props;
- const classes = useStyles(props);
+ const classes = useStyles(props);
const intl = useIntl();
+ const formErrors = getFormErrors(["firstName", "lastName", "email"], errors);
+
return (
= props => {
= props => {
/>
= props => {
= () => {
data.shop.countries, [])}
disabled={loading || createCustomerOpts.loading}
- errors={maybe(() => {
- const errs = createCustomerOpts.data.customerCreate.errors;
- return errs.map(err =>
- err.field.split(":").length > 1
- ? {
- ...err,
- field: err.field.split(":")[1]
- }
- : err
- );
- }, [])}
- saveButtonBar={
- createCustomerOpts.loading ? "loading" : "default"
- }
+ errors={createCustomerOpts.data?.customerCreate.errors || []}
+ saveButtonBar={createCustomerOpts.status}
onBack={() => navigate(customerListUrl())}
onSubmit={formData => {
createCustomer({
diff --git a/src/hooks/useAddressValidation.ts b/src/hooks/useAddressValidation.ts
index ef7ad365a..8db050f74 100644
--- a/src/hooks/useAddressValidation.ts
+++ b/src/hooks/useAddressValidation.ts
@@ -1,27 +1,27 @@
import { useState } from "react";
-import { useIntl } from "react-intl";
import { AddressTypeInput } from "@saleor/customers/types";
-import { commonMessages } from "@saleor/intl";
import { transformFormToAddress } from "@saleor/misc";
-import { UserError } from "@saleor/types";
-import { AddressInput } from "@saleor/types/globalTypes";
+import { AddressInput, AccountErrorCode } from "@saleor/types/globalTypes";
import { add, remove } from "@saleor/utils/lists";
+import { AccountErrorFragment } from "@saleor/customers/types/AccountErrorFragment";
interface UseAddressValidation {
- errors: UserError[];
+ errors: AccountErrorFragment[];
submit: (data: T & AddressTypeInput) => void;
}
function useAddressValidation(
onSubmit: (address: T & AddressInput) => void
): UseAddressValidation {
- const intl = useIntl();
- const [validationErrors, setValidationErrors] = useState([]);
+ const [validationErrors, setValidationErrors] = useState<
+ AccountErrorFragment[]
+ >([]);
- const countryRequiredError = {
- field: "country",
- message: intl.formatMessage(commonMessages.requiredField)
+ const countryRequiredError: AccountErrorFragment = {
+ __typename: "AccountError",
+ code: AccountErrorCode.REQUIRED,
+ field: "country"
};
return {
diff --git a/src/orders/components/OrderAddressEditDialog/OrderAddressEditDialog.tsx b/src/orders/components/OrderAddressEditDialog/OrderAddressEditDialog.tsx
index 5e995e757..22d7e4279 100644
--- a/src/orders/components/OrderAddressEditDialog/OrderAddressEditDialog.tsx
+++ b/src/orders/components/OrderAddressEditDialog/OrderAddressEditDialog.tsx
@@ -18,9 +18,9 @@ import useModalDialogErrors from "@saleor/hooks/useModalDialogErrors";
import useStateFromProps from "@saleor/hooks/useStateFromProps";
import { buttonMessages } from "@saleor/intl";
import { maybe } from "@saleor/misc";
-import { UserError } from "@saleor/types";
import { AddressInput } from "@saleor/types/globalTypes";
import createSingleAutocompleteSelectHandler from "@saleor/utils/handlers/singleAutocompleteSelectChangeHandler";
+import { OrderErrorFragment } from "@saleor/orders/types/OrderErrorFragment";
const useStyles = makeStyles(
{
@@ -35,7 +35,7 @@ interface OrderAddressEditDialogProps {
confirmButtonState: ConfirmButtonTransitionState;
address: AddressTypeInput;
open: boolean;
- errors: UserError[];
+ errors: OrderErrorFragment[];
variant: "billing" | "shipping" | string;
countries?: Array<{
code: string;
diff --git a/src/orders/mutations.ts b/src/orders/mutations.ts
index 4a68ab6ba..16b360e79 100644
--- a/src/orders/mutations.ts
+++ b/src/orders/mutations.ts
@@ -64,6 +64,13 @@ import {
import { OrderUpdate, OrderUpdateVariables } from "./types/OrderUpdate";
import { OrderVoid, OrderVoidVariables } from "./types/OrderVoid";
+export const orderErrorFragment = gql`
+ fragment OrderErrorFragment on OrderError {
+ code
+ field
+ }
+`;
+
const orderCancelMutation = gql`
${fragmentOrderDetails}
mutation OrderCancel($id: ID!, $restock: Boolean!) {
@@ -314,11 +321,11 @@ export const TypedOrderAddNoteMutation = TypedMutation<
const orderUpdateMutation = gql`
${fragmentAddress}
+ ${orderErrorFragment}
mutation OrderUpdate($id: ID!, $input: OrderUpdateInput!) {
orderUpdate(id: $id, input: $input) {
- errors {
- field
- message
+ errors: orderErrors {
+ ...OrderErrorFragment
}
order {
id
@@ -342,7 +349,8 @@ const orderDraftUpdateMutation = gql`
${fragmentOrderDetails}
mutation OrderDraftUpdate($id: ID!, $input: DraftOrderInput!) {
draftOrderUpdate(id: $id, input: $input) {
- errors {
+ errors: orderErrors {
+ code
field
message
}
diff --git a/src/orders/types/OrderDraftUpdate.ts b/src/orders/types/OrderDraftUpdate.ts
index 97353b776..a613167e2 100644
--- a/src/orders/types/OrderDraftUpdate.ts
+++ b/src/orders/types/OrderDraftUpdate.ts
@@ -2,14 +2,15 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { DraftOrderInput, OrderEventsEmailsEnum, OrderEventsEnum, FulfillmentStatus, PaymentChargeStatusEnum, OrderStatus, OrderAction } from "./../../types/globalTypes";
+import { DraftOrderInput, OrderErrorCode, OrderEventsEmailsEnum, OrderEventsEnum, FulfillmentStatus, PaymentChargeStatusEnum, OrderStatus, OrderAction } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: OrderDraftUpdate
// ====================================================
export interface OrderDraftUpdate_draftOrderUpdate_errors {
- __typename: "Error";
+ __typename: "OrderError";
+ code: OrderErrorCode;
field: string | null;
message: string | null;
}
diff --git a/src/orders/types/OrderErrorFragment.ts b/src/orders/types/OrderErrorFragment.ts
new file mode 100644
index 000000000..481de0908
--- /dev/null
+++ b/src/orders/types/OrderErrorFragment.ts
@@ -0,0 +1,15 @@
+/* tslint:disable */
+/* eslint-disable */
+// This file was automatically generated and should not be edited.
+
+import { OrderErrorCode } from "./../../types/globalTypes";
+
+// ====================================================
+// GraphQL fragment: OrderErrorFragment
+// ====================================================
+
+export interface OrderErrorFragment {
+ __typename: "OrderError";
+ code: OrderErrorCode;
+ field: string | null;
+}
diff --git a/src/orders/types/OrderUpdate.ts b/src/orders/types/OrderUpdate.ts
index 19cdcb37f..b199f05e6 100644
--- a/src/orders/types/OrderUpdate.ts
+++ b/src/orders/types/OrderUpdate.ts
@@ -2,16 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { OrderUpdateInput } from "./../../types/globalTypes";
+import { OrderUpdateInput, OrderErrorCode } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: OrderUpdate
// ====================================================
export interface OrderUpdate_orderUpdate_errors {
- __typename: "Error";
+ __typename: "OrderError";
+ code: OrderErrorCode;
field: string | null;
- message: string | null;
}
export interface OrderUpdate_orderUpdate_order_billingAddress_country {
diff --git a/src/services/components/ServiceCreatePage/ServiceCreatePage.stories.tsx b/src/services/components/ServiceCreatePage/ServiceCreatePage.stories.tsx
index b4e1884ec..3f0dce218 100644
--- a/src/services/components/ServiceCreatePage/ServiceCreatePage.stories.tsx
+++ b/src/services/components/ServiceCreatePage/ServiceCreatePage.stories.tsx
@@ -3,7 +3,7 @@ import React from "react";
import { permissions } from "@saleor/fixtures";
import Decorator from "@saleor/storybook/Decorator";
-import { formError } from "@saleor/storybook/misc";
+import { AccountErrorCode } from "@saleor/types/globalTypes";
import ServiceCreatePage, { ServiceCreatePageProps } from "./ServiceCreatePage";
const props: ServiceCreatePageProps = {
@@ -21,6 +21,10 @@ storiesOf("Views / Services / Create service", module)
.add("form errors", () => (
formError(field))}
+ errors={["name"].map(field => ({
+ __typename: "AccountError",
+ code: AccountErrorCode.INVALID,
+ field
+ }))}
/>
));
diff --git a/src/services/components/ServiceCreatePage/ServiceCreatePage.tsx b/src/services/components/ServiceCreatePage/ServiceCreatePage.tsx
index 6a5a0bb8a..d9eaa4e5c 100644
--- a/src/services/components/ServiceCreatePage/ServiceCreatePage.tsx
+++ b/src/services/components/ServiceCreatePage/ServiceCreatePage.tsx
@@ -13,8 +13,8 @@ import PageHeader from "@saleor/components/PageHeader";
import SaveButtonBar from "@saleor/components/SaveButtonBar";
import { ShopInfo_shop_permissions } from "@saleor/components/Shop/types/ShopInfo";
import { sectionNames } from "@saleor/intl";
-import { UserError } from "@saleor/types";
import { PermissionEnum } from "@saleor/types/globalTypes";
+import { AccountErrorFragment } from "@saleor/customers/types/AccountErrorFragment";
import ServiceInfo from "../ServiceInfo";
export interface ServiceCreatePageFormData {
@@ -25,7 +25,7 @@ export interface ServiceCreatePageFormData {
}
export interface ServiceCreatePageProps {
disabled: boolean;
- errors: UserError[];
+ errors: AccountErrorFragment[];
permissions: ShopInfo_shop_permissions[];
saveButtonBarState: ConfirmButtonTransitionState;
onBack: () => void;
diff --git a/src/services/components/ServiceDetailsPage/ServiceDetailsPage.stories.tsx b/src/services/components/ServiceDetailsPage/ServiceDetailsPage.stories.tsx
index dad65167a..f3f705011 100644
--- a/src/services/components/ServiceDetailsPage/ServiceDetailsPage.stories.tsx
+++ b/src/services/components/ServiceDetailsPage/ServiceDetailsPage.stories.tsx
@@ -3,7 +3,7 @@ import React from "react";
import { permissions } from "@saleor/fixtures";
import Decorator from "@saleor/storybook/Decorator";
-import { formError } from "@saleor/storybook/misc";
+import { AccountErrorCode } from "@saleor/types/globalTypes";
import { service } from "../../fixtures";
import ServiceDetailsPage, {
ServiceDetailsPageProps
@@ -34,7 +34,11 @@ storiesOf("Views / Services / Service details", module)
.add("form errors", () => (
formError(field))}
+ errors={["name"].map(field => ({
+ __typename: "AccountError",
+ code: AccountErrorCode.INVALID,
+ field
+ }))}
/>
))
.add("default token", () => (
diff --git a/src/services/components/ServiceDetailsPage/ServiceDetailsPage.tsx b/src/services/components/ServiceDetailsPage/ServiceDetailsPage.tsx
index f2f658356..9e7c96630 100644
--- a/src/services/components/ServiceDetailsPage/ServiceDetailsPage.tsx
+++ b/src/services/components/ServiceDetailsPage/ServiceDetailsPage.tsx
@@ -15,8 +15,8 @@ import { ShopInfo_shop_permissions } from "@saleor/components/Shop/types/ShopInf
import { sectionNames } from "@saleor/intl";
import { maybe } from "@saleor/misc";
import { ServiceDetails_serviceAccount } from "@saleor/services/types/ServiceDetails";
-import { UserError } from "@saleor/types";
import { PermissionEnum } from "@saleor/types/globalTypes";
+import { AccountErrorFragment } from "@saleor/customers/types/AccountErrorFragment";
import ServiceDefaultToken from "../ServiceDefaultToken";
import ServiceInfo from "../ServiceInfo";
import ServiceTokens from "../ServiceTokens";
@@ -30,7 +30,7 @@ export interface ServiceDetailsPageFormData {
export interface ServiceDetailsPageProps {
apiUri: string;
disabled: boolean;
- errors: UserError[];
+ errors: AccountErrorFragment[];
permissions: ShopInfo_shop_permissions[];
saveButtonBarState: ConfirmButtonTransitionState;
service: ServiceDetails_serviceAccount;
@@ -107,7 +107,7 @@ const ServiceDetailsPage: React.FC = props => {
/>
service.tokens)}
+ tokens={service?.tokens}
onCreate={onTokenCreate}
onDelete={onTokenDelete}
/>
diff --git a/src/services/components/ServiceInfo/ServiceInfo.tsx b/src/services/components/ServiceInfo/ServiceInfo.tsx
index 2b43c5600..1dbdba2c3 100644
--- a/src/services/components/ServiceInfo/ServiceInfo.tsx
+++ b/src/services/components/ServiceInfo/ServiceInfo.tsx
@@ -6,22 +6,29 @@ import { useIntl } from "react-intl";
import CardTitle from "@saleor/components/CardTitle";
import { FormChange } from "@saleor/hooks/useForm";
-import { UserError } from "@saleor/types";
-import { getFieldError } from "@saleor/utils/errors";
+import { AccountErrorFragment } from "@saleor/customers/types/AccountErrorFragment";
+import { getFormErrors } from "@saleor/utils/errors";
+import getAccountErrorMessage from "@saleor/utils/errors/account";
export interface ServiceInfoProps {
data: {
name: string;
};
disabled: boolean;
- errors: UserError[];
+ errors: AccountErrorFragment[];
onChange: FormChange;
}
-const ServiceInfo: React.FC = props => {
- const { data, disabled, errors, onChange } = props;
+const ServiceInfo: React.FC = ({
+ data,
+ disabled,
+ errors,
+ onChange
+}) => {
const intl = useIntl();
+ const formErrors = getFormErrors(["name"], errors);
+
return (
= props => {
void;
onConfirm: (data: FormData) => void;
@@ -66,11 +67,16 @@ interface StaffAddMemberDialogProps {
const StaffAddMemberDialog: React.FC = props => {
const { confirmButtonState, errors, open, onClose, onConfirm } = props;
+
const classes = useStyles(props);
const dialogErrors = useModalDialogErrors(errors, open);
-
const intl = useIntl();
+ const formErrors = getFormErrors(
+ ["firstName", "lastName", "email"],
+ dialogErrors
+ );
+
return (
@@ -187,7 +183,7 @@ const SiteSettingsPage: React.FC = props => {
@@ -208,7 +204,7 @@ const SiteSettingsPage: React.FC = props => {
data={data}
displayCountry={displayCountry}
countries={countryChoices}
- errors={formErrors}
+ errors={[...errors, ...validationErrors]}
disabled={disabled}
onChange={change}
onCountryChange={handleCountryChange}
diff --git a/src/siteSettings/mutations.ts b/src/siteSettings/mutations.ts
index 09f7ef0f0..c13b45f7f 100644
--- a/src/siteSettings/mutations.ts
+++ b/src/siteSettings/mutations.ts
@@ -16,16 +16,22 @@ import {
ShopSettingsUpdateVariables
} from "./types/ShopSettingsUpdate";
+const shopErrorFragment = gql`
+ fragment ShopErrorFragment on ShopError {
+ code
+ field
+ }
+`;
const authorizationKeyAdd = gql`
+ ${shopErrorFragment}
${shopFragment}
mutation AuthorizationKeyAdd(
$input: AuthorizationKeyInput!
$keyType: AuthorizationKeyType!
) {
authorizationKeyAdd(input: $input, keyType: $keyType) {
- errors {
- field
- message
+ errors: shopErrors {
+ ...ShopErrorFragment
}
shop {
...ShopFragment
@@ -39,12 +45,12 @@ export const TypedAuthorizationKeyAdd = TypedMutation<
>(authorizationKeyAdd);
const authorizationKeyDelete = gql`
+ ${shopErrorFragment}
${shopFragment}
mutation AuthorizationKeyDelete($keyType: AuthorizationKeyType!) {
authorizationKeyDelete(keyType: $keyType) {
- errors {
- field
- message
+ errors: shopErrors {
+ ...ShopErrorFragment
}
shop {
...ShopFragment
@@ -58,6 +64,7 @@ export const TypedAuthorizationKeyDelete = TypedMutation<
>(authorizationKeyDelete);
const shopSettingsUpdate = gql`
+ ${shopErrorFragment}
${shopFragment}
${fragmentAddress}
mutation ShopSettingsUpdate(
@@ -66,18 +73,16 @@ const shopSettingsUpdate = gql`
$addressInput: AddressInput
) {
shopSettingsUpdate(input: $shopSettingsInput) {
- errors {
- field
- message
+ errors: shopErrors {
+ ...ShopErrorFragment
}
shop {
...ShopFragment
}
}
shopDomainUpdate(input: $shopDomainInput) {
- errors {
- field
- message
+ errors: shopErrors {
+ ...ShopErrorFragment
}
shop {
domain {
@@ -87,9 +92,8 @@ const shopSettingsUpdate = gql`
}
}
shopAddressUpdate(input: $addressInput) {
- errors {
- field
- message
+ errors: shopErrors {
+ ...ShopErrorFragment
}
shop {
companyAddress {
diff --git a/src/siteSettings/types/AuthorizationKeyAdd.ts b/src/siteSettings/types/AuthorizationKeyAdd.ts
index aa1b21e6f..258aabf71 100644
--- a/src/siteSettings/types/AuthorizationKeyAdd.ts
+++ b/src/siteSettings/types/AuthorizationKeyAdd.ts
@@ -2,16 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { AuthorizationKeyInput, AuthorizationKeyType } from "./../../types/globalTypes";
+import { AuthorizationKeyInput, AuthorizationKeyType, ShopErrorCode } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: AuthorizationKeyAdd
// ====================================================
export interface AuthorizationKeyAdd_authorizationKeyAdd_errors {
- __typename: "Error";
+ __typename: "ShopError";
+ code: ShopErrorCode;
field: string | null;
- message: string | null;
}
export interface AuthorizationKeyAdd_authorizationKeyAdd_shop_authorizationKeys {
diff --git a/src/siteSettings/types/AuthorizationKeyDelete.ts b/src/siteSettings/types/AuthorizationKeyDelete.ts
index 7c9fcafea..ccf4f5ba8 100644
--- a/src/siteSettings/types/AuthorizationKeyDelete.ts
+++ b/src/siteSettings/types/AuthorizationKeyDelete.ts
@@ -2,16 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { AuthorizationKeyType } from "./../../types/globalTypes";
+import { AuthorizationKeyType, ShopErrorCode } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: AuthorizationKeyDelete
// ====================================================
export interface AuthorizationKeyDelete_authorizationKeyDelete_errors {
- __typename: "Error";
+ __typename: "ShopError";
+ code: ShopErrorCode;
field: string | null;
- message: string | null;
}
export interface AuthorizationKeyDelete_authorizationKeyDelete_shop_authorizationKeys {
diff --git a/src/siteSettings/types/ShopErrorFragment.ts b/src/siteSettings/types/ShopErrorFragment.ts
new file mode 100644
index 000000000..ae705f05f
--- /dev/null
+++ b/src/siteSettings/types/ShopErrorFragment.ts
@@ -0,0 +1,15 @@
+/* tslint:disable */
+/* eslint-disable */
+// This file was automatically generated and should not be edited.
+
+import { ShopErrorCode } from "./../../types/globalTypes";
+
+// ====================================================
+// GraphQL fragment: ShopErrorFragment
+// ====================================================
+
+export interface ShopErrorFragment {
+ __typename: "ShopError";
+ code: ShopErrorCode;
+ field: string | null;
+}
diff --git a/src/siteSettings/types/ShopSettingsUpdate.ts b/src/siteSettings/types/ShopSettingsUpdate.ts
index b7d30e12b..acc2e1bf1 100644
--- a/src/siteSettings/types/ShopSettingsUpdate.ts
+++ b/src/siteSettings/types/ShopSettingsUpdate.ts
@@ -2,16 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { SiteDomainInput, ShopSettingsInput, AddressInput, AuthorizationKeyType } from "./../../types/globalTypes";
+import { SiteDomainInput, ShopSettingsInput, AddressInput, ShopErrorCode, AuthorizationKeyType } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: ShopSettingsUpdate
// ====================================================
export interface ShopSettingsUpdate_shopSettingsUpdate_errors {
- __typename: "Error";
+ __typename: "ShopError";
+ code: ShopErrorCode;
field: string | null;
- message: string | null;
}
export interface ShopSettingsUpdate_shopSettingsUpdate_shop_authorizationKeys {
@@ -73,9 +73,9 @@ export interface ShopSettingsUpdate_shopSettingsUpdate {
}
export interface ShopSettingsUpdate_shopDomainUpdate_errors {
- __typename: "Error";
+ __typename: "ShopError";
+ code: ShopErrorCode;
field: string | null;
- message: string | null;
}
export interface ShopSettingsUpdate_shopDomainUpdate_shop_domain {
@@ -96,9 +96,9 @@ export interface ShopSettingsUpdate_shopDomainUpdate {
}
export interface ShopSettingsUpdate_shopAddressUpdate_errors {
- __typename: "Error";
+ __typename: "ShopError";
+ code: ShopErrorCode;
field: string | null;
- message: string | null;
}
export interface ShopSettingsUpdate_shopAddressUpdate_shop_companyAddress_country {
diff --git a/src/siteSettings/views/index.tsx b/src/siteSettings/views/index.tsx
index e8e104a69..9ae2347c4 100644
--- a/src/siteSettings/views/index.tsx
+++ b/src/siteSettings/views/index.tsx
@@ -7,7 +7,7 @@ import { commonMessages, sectionNames } from "@saleor/intl";
import { useIntl } from "react-intl";
import { configurationMenuUrl } from "../../configuration";
-import { findInEnum, maybe } from "../../misc";
+import { findInEnum } from "../../misc";
import { AuthorizationKeyType, CountryCode } from "../../types/globalTypes";
import SiteSettingsKeyDialog, {
SiteSettingsKeyDialogForm
@@ -37,7 +37,7 @@ export const SiteSettings: React.FC = ({ params }) => {
const intl = useIntl();
const handleAddKeySuccess = (data: AuthorizationKeyAdd) => {
- if (!maybe(() => data.authorizationKeyAdd.errors.length)) {
+ if (data.authorizationKeyAdd.errors.length === 0) {
notify({
text: intl.formatMessage(commonMessages.savedChanges)
});
@@ -45,7 +45,7 @@ export const SiteSettings: React.FC = ({ params }) => {
}
};
const handleDeleteKeySuccess = (data: AuthorizationKeyDelete) => {
- if (!maybe(() => data.authorizationKeyDelete.errors.length)) {
+ if (data.authorizationKeyDelete.errors.length === 0) {
notify({
text: intl.formatMessage(commonMessages.savedChanges)
});
@@ -64,12 +64,9 @@ export const SiteSettings: React.FC = ({ params }) => {
};
const handleSiteSettingsSuccess = (data: ShopSettingsUpdate) => {
if (
- (!data.shopDomainUpdate.errors ||
- data.shopDomainUpdate.errors.length === 0) &&
- (!data.shopSettingsUpdate.errors ||
- data.shopSettingsUpdate.errors.length === 0) &&
- (!data.shopAddressUpdate.errors ||
- data.shopAddressUpdate.errors.length === 0)
+ data.shopDomainUpdate.errors.length === 0 &&
+ data.shopSettingsUpdate.errors.length === 0 &&
+ data.shopAddressUpdate.errors.length === 0
) {
notify({
text: intl.formatMessage(commonMessages.savedChanges)
@@ -89,21 +86,12 @@ export const SiteSettings: React.FC = ({ params }) => {
>
{(updateShopSettings, updateShopSettingsOpts) => {
const errors = [
- ...maybe(
- () =>
- updateShopSettingsOpts.data.shopDomainUpdate.errors,
- []
- ),
- ...maybe(
- () =>
- updateShopSettingsOpts.data.shopSettingsUpdate.errors,
- []
- ),
- ...maybe(
- () =>
- updateShopSettingsOpts.data.shopAddressUpdate.errors,
- []
- )
+ ...(updateShopSettingsOpts.data?.shopDomainUpdate
+ .errors || []),
+ ...(updateShopSettingsOpts.data?.shopSettingsUpdate
+ .errors || []),
+ ...(updateShopSettingsOpts.data?.shopAddressUpdate
+ .errors || [])
];
const loading =
siteSettings.loading ||
@@ -165,7 +153,7 @@ export const SiteSettings: React.FC = ({ params }) => {
siteSettings.data.shop)}
+ shop={siteSettings.data?.shop}
onBack={() => navigate(configurationMenuUrl)}
onKeyAdd={() =>
navigate(
@@ -183,12 +171,10 @@ export const SiteSettings: React.FC = ({ params }) => {
saveButtonBarState={updateShopSettingsOpts.status}
/>
- addAuthorizationKeyOpts.data.authorizationKeyAdd
- .errors,
- []
- )}
+ errors={
+ addAuthorizationKeyOpts.data?.authorizationKeyAdd
+ .errors || []
+ }
initial={{
key: "",
password: "",
diff --git a/src/utils/errors/shop.ts b/src/utils/errors/shop.ts
new file mode 100644
index 000000000..7e74f7843
--- /dev/null
+++ b/src/utils/errors/shop.ts
@@ -0,0 +1,37 @@
+import { IntlShape, defineMessages } from "react-intl";
+
+import { ShopErrorFragment } from "@saleor/siteSettings/types/ShopErrorFragment";
+import { ShopErrorCode } from "@saleor/types/globalTypes";
+import { commonMessages } from "@saleor/intl";
+import commonErrorMessages from "./common";
+
+const messages = defineMessages({
+ alreadyExists: {
+ defaultMessage: "Authorization key with this type already exists",
+ description: "add authorization key error"
+ }
+});
+
+function getShopErrorMessage(
+ err: Omit | undefined,
+ intl: IntlShape
+): string {
+ if (err) {
+ switch (err.code) {
+ case ShopErrorCode.ALREADY_EXISTS:
+ return intl.formatMessage(messages.alreadyExists);
+ case ShopErrorCode.GRAPHQL_ERROR:
+ return intl.formatMessage(commonErrorMessages.graphqlError);
+ case ShopErrorCode.REQUIRED:
+ return intl.formatMessage(commonMessages.requiredField);
+ case ShopErrorCode.INVALID:
+ return intl.formatMessage(commonErrorMessages.invalid);
+ default:
+ return intl.formatMessage(commonErrorMessages.unknownError);
+ }
+ }
+
+ return undefined;
+}
+
+export default getShopErrorMessage;
From b21b746ee3d397fe8b957268f788061cf63814f8 Mon Sep 17 00:00:00 2001
From: dominik-zeglen
Date: Tue, 17 Mar 2020 19:53:51 +0100
Subject: [PATCH 13/35] Update stories
---
.../__snapshots__/Stories.test.ts.snap | 46 +++++++++----------
.../stories/siteSettings/SiteSettingsPage.tsx | 8 +++-
2 files changed, 29 insertions(+), 25 deletions(-)
diff --git a/src/storybook/__snapshots__/Stories.test.ts.snap b/src/storybook/__snapshots__/Stories.test.ts.snap
index 8d93f34cd..8519634bc 100644
--- a/src/storybook/__snapshots__/Stories.test.ts.snap
+++ b/src/storybook/__snapshots__/Stories.test.ts.snap
@@ -35887,7 +35887,7 @@ exports[`Storyshots Views / Customers / Create customer form errors 1`] = `
- Generic form error
+ Invalid value
@@ -35969,7 +35969,7 @@ exports[`Storyshots Views / Customers / Create customer form errors 1`] = `
- Generic form error
+ Invalid value
@@ -36011,7 +36011,7 @@ exports[`Storyshots Views / Customers / Create customer form errors 1`] = `
- Generic form error
+ Invalid value
@@ -36060,7 +36060,7 @@ exports[`Storyshots Views / Customers / Create customer form errors 1`] = `
- Generic form error
+ Invalid value
@@ -36102,7 +36102,7 @@ exports[`Storyshots Views / Customers / Create customer form errors 1`] = `
- Generic form error
+ Invalid value
@@ -36147,7 +36147,7 @@ exports[`Storyshots Views / Customers / Create customer form errors 1`] = `
- Generic form error
+ Invalid value
- Generic form error
+ Invalid value
- Generic form error
+ Invalid value
@@ -36279,7 +36279,7 @@ exports[`Storyshots Views / Customers / Create customer form errors 1`] = `
- Generic form error
+ Invalid value
@@ -36351,7 +36351,7 @@ exports[`Storyshots Views / Customers / Create customer form errors 1`] = `
- Generic form error
+ Invalid value
@@ -36394,7 +36394,7 @@ exports[`Storyshots Views / Customers / Create customer form errors 1`] = `
- Generic form error
+ Invalid value
@@ -36479,7 +36479,7 @@ exports[`Storyshots Views / Customers / Create customer form errors 1`] = `
- Generic form error
+ Invalid value
@@ -38505,7 +38505,7 @@ exports[`Storyshots Views / Customers / Customer details form errors 1`] = `
- Generic form error
+ Invalid value
- Generic form error
+ Invalid value
@@ -38594,7 +38594,7 @@ exports[`Storyshots Views / Customers / Customer details form errors 1`] = `
- Generic form error
+ Invalid value
@@ -114312,7 +114312,7 @@ exports[`Storyshots Views / Services / Create service form errors 1`] = `
- Generic form error
+ Invalid value
@@ -116627,7 +116627,7 @@ exports[`Storyshots Views / Services / Service details form errors 1`] = `
- Generic form error
+ Invalid value
@@ -123925,7 +123925,7 @@ exports[`Storyshots Views / Site settings / Page form errors 1`] = `
- Generic form error
+ Invalid value
- Generic form error
+ Invalid value
- Generic form error
+ Invalid value
@@ -124102,7 +124102,7 @@ exports[`Storyshots Views / Site settings / Page form errors 1`] = `
- Generic form error
+ Invalid value
- Generic form error
+ Invalid value
- Generic form error
+ Invalid value
diff --git a/src/storybook/stories/siteSettings/SiteSettingsPage.tsx b/src/storybook/stories/siteSettings/SiteSettingsPage.tsx
index 51925caa0..12fce49ac 100644
--- a/src/storybook/stories/siteSettings/SiteSettingsPage.tsx
+++ b/src/storybook/stories/siteSettings/SiteSettingsPage.tsx
@@ -2,12 +2,12 @@ import { Omit } from "@material-ui/core";
import { storiesOf } from "@storybook/react";
import React from "react";
+import { ShopErrorCode } from "@saleor/types/globalTypes";
import SiteSettingsPage, {
SiteSettingsPageProps
} from "../../../siteSettings/components/SiteSettingsPage";
import { shop } from "../../../siteSettings/fixtures";
import Decorator from "../../Decorator";
-import { formError } from "../../misc";
const props: Omit = {
disabled: false,
@@ -36,6 +36,10 @@ storiesOf("Views / Site settings / Page", module)
"defaultMailSenderAddress",
"defaultMailSenderName",
"customerSetPasswordUrl"
- ].map(field => formError(field))}
+ ].map(field => ({
+ __typename: "ShopError",
+ code: ShopErrorCode.INVALID,
+ field
+ }))}
/>
));
From f0b90318fd8dec8b75bc4a0ac441a5e87c21d141 Mon Sep 17 00:00:00 2001
From: dominik-zeglen
Date: Tue, 17 Mar 2020 19:53:58 +0100
Subject: [PATCH 14/35] Update messages
---
locale/defaultMessages.json | 57 ++++++++++++++++++++++++++++++++-----
1 file changed, 50 insertions(+), 7 deletions(-)
diff --git a/locale/defaultMessages.json b/locale/defaultMessages.json
index 8fb6d37a0..c3841f752 100644
--- a/locale/defaultMessages.json
+++ b/locale/defaultMessages.json
@@ -292,6 +292,12 @@
"context": "attributes section name",
"string": "Attributes"
},
+ "src_dot_attributes_dot_attributeSlugUnique": {
+ "string": "Attribute with this slug already exists"
+ },
+ "src_dot_attributes_dot_attributeValueAlreadyExists": {
+ "string": "This value already exists within this attribute"
+ },
"src_dot_attributes_dot_components_dot_AttributeBulkDeleteDialog_dot_1184518529": {
"context": "dialog content",
"string": "{counter,plural,one{Are you sure you want to delete this attribute?} other{Are you sure you want to delete {displayQuantity} attributes?}}"
@@ -477,10 +483,6 @@
"src_dot_attributes_dot_views_dot_AttributeCreate_dot_11941964": {
"string": "Successfully created attribute"
},
- "src_dot_attributes_dot_views_dot_AttributeCreate_dot_354316953": {
- "context": "attribute value edit error",
- "string": "A value named {name} already exists"
- },
"src_dot_attributes_dot_views_dot_AttributeDetails_dot_423042761": {
"context": "attribute value deleted",
"string": "Value deleted"
@@ -836,9 +838,6 @@
"src_dot_collections_dot_views_dot_1152429477": {
"string": "Deleted collection"
},
- "src_dot_collections_dot_views_dot_1597339737": {
- "string": "Created collection"
- },
"src_dot_collections_dot_views_dot_2001540731": {
"string": "Added product to collection"
},
@@ -4745,6 +4744,50 @@
"context": "button",
"string": "Upload image"
},
+ "src_dot_utils_dot_errors_dot_alreadyExists": {
+ "context": "add authorization key error",
+ "string": "Authorization key with this type already exists"
+ },
+ "src_dot_utils_dot_errors_dot_attributeAlreadyAssigned": {
+ "string": "This attribute has already been assigned to this product type"
+ },
+ "src_dot_utils_dot_errors_dot_attributeCannotBeAssigned": {
+ "string": "This attribute cannot be assigned to this product type"
+ },
+ "src_dot_utils_dot_errors_dot_attributeVariantsDisabled": {
+ "string": "Variants are disabled in this product type"
+ },
+ "src_dot_utils_dot_errors_dot_graphqlError": {
+ "string": "API error"
+ },
+ "src_dot_utils_dot_errors_dot_invalid": {
+ "string": "Invalid value"
+ },
+ "src_dot_utils_dot_errors_dot_invalidPassword": {
+ "string": "Invalid password"
+ },
+ "src_dot_utils_dot_errors_dot_passwordNumeric": {
+ "string": "Password cannot be entirely numeric"
+ },
+ "src_dot_utils_dot_errors_dot_skuUnique": {
+ "context": "bulk variant create error",
+ "string": "SKUs must be unique"
+ },
+ "src_dot_utils_dot_errors_dot_tooCommon": {
+ "string": "This password is too commonly used"
+ },
+ "src_dot_utils_dot_errors_dot_tooShort": {
+ "string": "This password is too short"
+ },
+ "src_dot_utils_dot_errors_dot_tooSimilar": {
+ "string": "These passwords are too similar"
+ },
+ "src_dot_utils_dot_errors_dot_unknownError": {
+ "string": "Unknown error"
+ },
+ "src_dot_utils_dot_errors_dot_variantNoDigitalContent": {
+ "string": "This variant does not have any digital content"
+ },
"src_dot_vouchers": {
"context": "vouchers section name",
"string": "Vouchers"
From b2987cddac5ce257f4566467d4f12eed01a74c9c Mon Sep 17 00:00:00 2001
From: dominik-zeglen
Date: Tue, 17 Mar 2020 19:58:55 +0100
Subject: [PATCH 15/35] Fix type errors
---
.../SiteSettingsKeyDialog/SiteSettingsKeyDialog.tsx | 2 +-
src/siteSettings/views/index.tsx | 9 +--------
.../stories/siteSettings/SiteSettingsKeyDialog.tsx | 12 +++++++++---
3 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/src/siteSettings/components/SiteSettingsKeyDialog/SiteSettingsKeyDialog.tsx b/src/siteSettings/components/SiteSettingsKeyDialog/SiteSettingsKeyDialog.tsx
index 7affac29d..11d394df0 100644
--- a/src/siteSettings/components/SiteSettingsKeyDialog/SiteSettingsKeyDialog.tsx
+++ b/src/siteSettings/components/SiteSettingsKeyDialog/SiteSettingsKeyDialog.tsx
@@ -12,7 +12,7 @@ import { FormSpacer } from "@saleor/components/FormSpacer";
import SingleSelectField from "@saleor/components/SingleSelectField";
import { buttonMessages } from "@saleor/intl";
import { DialogProps } from "@saleor/types";
-import { getFieldError, getFormErrors } from "@saleor/utils/errors";
+import { getFormErrors } from "@saleor/utils/errors";
import { ShopErrorFragment } from "@saleor/siteSettings/types/ShopErrorFragment";
import getShopErrorMessage from "@saleor/utils/errors/shop";
import { authorizationKeyTypes } from "../../../misc";
diff --git a/src/siteSettings/views/index.tsx b/src/siteSettings/views/index.tsx
index 9ae2347c4..2d33440d7 100644
--- a/src/siteSettings/views/index.tsx
+++ b/src/siteSettings/views/index.tsx
@@ -51,14 +51,7 @@ export const SiteSettings: React.FC = ({ params }) => {
});
} else {
notify({
- text: intl.formatMessage(
- {
- defaultMessage: "Could not delete authorization key: {errorMessage}"
- },
- {
- errorMessage: data.authorizationKeyDelete.errors[0].message
- }
- )
+ text: intl.formatMessage(commonMessages.somethingWentWrong)
});
}
};
diff --git a/src/storybook/stories/siteSettings/SiteSettingsKeyDialog.tsx b/src/storybook/stories/siteSettings/SiteSettingsKeyDialog.tsx
index 37373abab..dc2bb1b0e 100644
--- a/src/storybook/stories/siteSettings/SiteSettingsKeyDialog.tsx
+++ b/src/storybook/stories/siteSettings/SiteSettingsKeyDialog.tsx
@@ -4,9 +4,11 @@ import React from "react";
import SiteSettingsKeyDialog, {
SiteSettingsKeyDialogProps
} from "../../../siteSettings/components/SiteSettingsKeyDialog";
-import { AuthorizationKeyType } from "../../../types/globalTypes";
+import {
+ AuthorizationKeyType,
+ ShopErrorCode
+} from "../../../types/globalTypes";
import Decorator from "../../Decorator";
-import { formError } from "../../misc";
const props: SiteSettingsKeyDialogProps = {
errors: [],
@@ -26,6 +28,10 @@ storiesOf("SiteSettings / Add key dialog", module)
.add("form errors", () => (
formError(field))}
+ errors={["key", "password", "keyType"].map(field => ({
+ __typename: "ShopError",
+ code: ShopErrorCode.INVALID,
+ field
+ }))}
/>
));
From 5146386ee53ee98e8416788e8e645553457701ae Mon Sep 17 00:00:00 2001
From: dominik-zeglen
Date: Wed, 11 Mar 2020 11:27:15 +0100
Subject: [PATCH 16/35] Update types
---
src/navigation/mutations.ts | 53 +++++++++++++----------
src/navigation/types/MenuBulkDelete.ts | 6 ++-
src/navigation/types/MenuCreate.ts | 6 +--
src/navigation/types/MenuDelete.ts | 6 ++-
src/navigation/types/MenuErrorFragment.ts | 15 +++++++
src/navigation/types/MenuItemCreate.ts | 6 +--
src/navigation/types/MenuItemUpdate.ts | 6 +--
src/navigation/types/MenuUpdate.ts | 14 +++---
src/types/globalTypes.ts | 12 +++++
9 files changed, 80 insertions(+), 44 deletions(-)
create mode 100644 src/navigation/types/MenuErrorFragment.ts
diff --git a/src/navigation/mutations.ts b/src/navigation/mutations.ts
index e678c93ae..5a43533e2 100644
--- a/src/navigation/mutations.ts
+++ b/src/navigation/mutations.ts
@@ -17,12 +17,19 @@ import {
} from "./types/MenuItemUpdate";
import { MenuUpdate, MenuUpdateVariables } from "./types/MenuUpdate";
+const menuErrorFragment = gql`
+ fragment MenuErrorFragment on MenuError {
+ code
+ field
+ }
+`;
+
const menuCreate = gql`
+ ${menuErrorFragment}
mutation MenuCreate($input: MenuCreateInput!) {
menuCreate(input: $input) {
- errors {
- field
- message
+ errors: menuErrors {
+ ...MenuErrorFragment
}
menu {
id
@@ -36,11 +43,11 @@ export const MenuCreateMutation = TypedMutation<
>(menuCreate);
const menuBulkDelete = gql`
+ ${menuErrorFragment}
mutation MenuBulkDelete($ids: [ID]!) {
menuBulkDelete(ids: $ids) {
- errors {
- field
- message
+ errors: menuErrors {
+ ...MenuErrorFragment
}
}
}
@@ -51,11 +58,11 @@ export const MenuBulkDeleteMutation = TypedMutation<
>(menuBulkDelete);
const menuDelete = gql`
+ ${menuErrorFragment}
mutation MenuDelete($id: ID!) {
menuDelete(id: $id) {
- errors {
- field
- message
+ errors: menuErrors {
+ ...MenuErrorFragment
}
}
}
@@ -66,12 +73,12 @@ export const MenuDeleteMutation = TypedMutation<
>(menuDelete);
const menuItemCreate = gql`
+ ${menuErrorFragment}
${menuItemNestedFragment}
mutation MenuItemCreate($input: MenuItemCreateInput!) {
menuItemCreate(input: $input) {
- errors {
- field
- message
+ errors: menuErrors {
+ ...MenuErrorFragment
}
menuItem {
menu {
@@ -90,6 +97,7 @@ export const MenuItemCreateMutation = TypedMutation<
>(menuItemCreate);
const menuUpdate = gql`
+ ${menuErrorFragment}
mutation MenuUpdate(
$id: ID!
$name: String!
@@ -97,23 +105,20 @@ const menuUpdate = gql`
$removeIds: [ID]!
) {
menuUpdate(id: $id, input: { name: $name }) {
- errors {
- field
- message
+ errors: menuErrors {
+ ...MenuErrorFragment
}
}
menuItemMove(menu: $id, moves: $moves) {
- errors {
- field
- message
+ errors: menuErrors {
+ ...MenuErrorFragment
}
}
menuItemBulkDelete(ids: $removeIds) {
- errors {
- field
- message
+ errors: menuErrors {
+ ...MenuErrorFragment
}
}
}
@@ -124,12 +129,12 @@ export const MenuUpdateMutation = TypedMutation<
>(menuUpdate);
const menuItemUpdate = gql`
+ ${menuErrorFragment}
${menuItemFragment}
mutation MenuItemUpdate($id: ID!, $input: MenuItemInput!) {
menuItemUpdate(id: $id, input: $input) {
- errors {
- field
- message
+ errors: menuErrors {
+ ...MenuErrorFragment
}
menuItem {
...MenuItemFragment
diff --git a/src/navigation/types/MenuBulkDelete.ts b/src/navigation/types/MenuBulkDelete.ts
index 17e33b0ec..5effd4d61 100644
--- a/src/navigation/types/MenuBulkDelete.ts
+++ b/src/navigation/types/MenuBulkDelete.ts
@@ -2,14 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { MenuErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: MenuBulkDelete
// ====================================================
export interface MenuBulkDelete_menuBulkDelete_errors {
- __typename: "Error";
+ __typename: "MenuError";
+ code: MenuErrorCode;
field: string | null;
- message: string | null;
}
export interface MenuBulkDelete_menuBulkDelete {
diff --git a/src/navigation/types/MenuCreate.ts b/src/navigation/types/MenuCreate.ts
index f5efdffac..d9b49b4f3 100644
--- a/src/navigation/types/MenuCreate.ts
+++ b/src/navigation/types/MenuCreate.ts
@@ -2,16 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { MenuCreateInput } from "./../../types/globalTypes";
+import { MenuCreateInput, MenuErrorCode } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: MenuCreate
// ====================================================
export interface MenuCreate_menuCreate_errors {
- __typename: "Error";
+ __typename: "MenuError";
+ code: MenuErrorCode;
field: string | null;
- message: string | null;
}
export interface MenuCreate_menuCreate_menu {
diff --git a/src/navigation/types/MenuDelete.ts b/src/navigation/types/MenuDelete.ts
index 466fff507..201828b47 100644
--- a/src/navigation/types/MenuDelete.ts
+++ b/src/navigation/types/MenuDelete.ts
@@ -2,14 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { MenuErrorCode } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL mutation operation: MenuDelete
// ====================================================
export interface MenuDelete_menuDelete_errors {
- __typename: "Error";
+ __typename: "MenuError";
+ code: MenuErrorCode;
field: string | null;
- message: string | null;
}
export interface MenuDelete_menuDelete {
diff --git a/src/navigation/types/MenuErrorFragment.ts b/src/navigation/types/MenuErrorFragment.ts
new file mode 100644
index 000000000..d0e09b856
--- /dev/null
+++ b/src/navigation/types/MenuErrorFragment.ts
@@ -0,0 +1,15 @@
+/* tslint:disable */
+/* eslint-disable */
+// This file was automatically generated and should not be edited.
+
+import { MenuErrorCode } from "./../../types/globalTypes";
+
+// ====================================================
+// GraphQL fragment: MenuErrorFragment
+// ====================================================
+
+export interface MenuErrorFragment {
+ __typename: "MenuError";
+ code: MenuErrorCode;
+ field: string | null;
+}
diff --git a/src/navigation/types/MenuItemCreate.ts b/src/navigation/types/MenuItemCreate.ts
index 8571b994c..c0d044c13 100644
--- a/src/navigation/types/MenuItemCreate.ts
+++ b/src/navigation/types/MenuItemCreate.ts
@@ -2,16 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { MenuItemCreateInput } from "./../../types/globalTypes";
+import { MenuItemCreateInput, MenuErrorCode } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: MenuItemCreate
// ====================================================
export interface MenuItemCreate_menuItemCreate_errors {
- __typename: "Error";
+ __typename: "MenuError";
+ code: MenuErrorCode;
field: string | null;
- message: string | null;
}
export interface MenuItemCreate_menuItemCreate_menuItem_menu_items_category {
diff --git a/src/navigation/types/MenuItemUpdate.ts b/src/navigation/types/MenuItemUpdate.ts
index 56656119c..be2db3080 100644
--- a/src/navigation/types/MenuItemUpdate.ts
+++ b/src/navigation/types/MenuItemUpdate.ts
@@ -2,16 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { MenuItemInput } from "./../../types/globalTypes";
+import { MenuItemInput, MenuErrorCode } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: MenuItemUpdate
// ====================================================
export interface MenuItemUpdate_menuItemUpdate_errors {
- __typename: "Error";
+ __typename: "MenuError";
+ code: MenuErrorCode;
field: string | null;
- message: string | null;
}
export interface MenuItemUpdate_menuItemUpdate_menuItem_category {
diff --git a/src/navigation/types/MenuUpdate.ts b/src/navigation/types/MenuUpdate.ts
index dadf11956..06ffb2b21 100644
--- a/src/navigation/types/MenuUpdate.ts
+++ b/src/navigation/types/MenuUpdate.ts
@@ -2,16 +2,16 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
-import { MenuItemMoveInput } from "./../../types/globalTypes";
+import { MenuItemMoveInput, MenuErrorCode } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: MenuUpdate
// ====================================================
export interface MenuUpdate_menuUpdate_errors {
- __typename: "Error";
+ __typename: "MenuError";
+ code: MenuErrorCode;
field: string | null;
- message: string | null;
}
export interface MenuUpdate_menuUpdate {
@@ -20,9 +20,9 @@ export interface MenuUpdate_menuUpdate {
}
export interface MenuUpdate_menuItemMove_errors {
- __typename: "Error";
+ __typename: "MenuError";
+ code: MenuErrorCode;
field: string | null;
- message: string | null;
}
export interface MenuUpdate_menuItemMove {
@@ -31,9 +31,9 @@ export interface MenuUpdate_menuItemMove {
}
export interface MenuUpdate_menuItemBulkDelete_errors {
- __typename: "Error";
+ __typename: "MenuError";
+ code: MenuErrorCode;
field: string | null;
- message: string | null;
}
export interface MenuUpdate_menuItemBulkDelete {
diff --git a/src/types/globalTypes.ts b/src/types/globalTypes.ts
index 66b279ffd..120fce37e 100644
--- a/src/types/globalTypes.ts
+++ b/src/types/globalTypes.ts
@@ -408,6 +408,18 @@ export enum LanguageCodeEnum {
ZH_HANT = "ZH_HANT",
}
+export enum MenuErrorCode {
+ CANNOT_ASSIGN_NODE = "CANNOT_ASSIGN_NODE",
+ GRAPHQL_ERROR = "GRAPHQL_ERROR",
+ INVALID = "INVALID",
+ INVALID_MENU_ITEM = "INVALID_MENU_ITEM",
+ NOT_FOUND = "NOT_FOUND",
+ NO_MENU_ITEM_PROVIDED = "NO_MENU_ITEM_PROVIDED",
+ REQUIRED = "REQUIRED",
+ TOO_MANY_MENU_ITEMS = "TOO_MANY_MENU_ITEMS",
+ UNIQUE = "UNIQUE",
+}
+
export enum MenuSortField {
ITEMS_COUNT = "ITEMS_COUNT",
NAME = "NAME",
From 61c3eb51fd5ce266394e5b0e771d722f62799cfa Mon Sep 17 00:00:00 2001
From: dominik-zeglen
Date: Wed, 11 Mar 2020 14:03:31 +0100
Subject: [PATCH 17/35] Use error codes in navigation section
---
.../MenuCreateDialog/MenuCreateDialog.tsx | 13 +++++----
.../MenuDetailsPage/MenuDetailsPage.tsx | 4 +++
.../MenuItemDialog/MenuItemDialog.tsx | 27 +++++++++---------
.../MenuProperties/MenuProperties.tsx | 9 ++++++
src/navigation/views/MenuDetails/index.tsx | 5 ++++
.../stories/navigation/MenuCreateDialog.tsx | 11 ++++++--
.../stories/navigation/MenuDetailsPage.tsx | 12 ++++++++
.../stories/navigation/MenuItemDialog.tsx | 8 ++++--
src/utils/errors/menu.ts | 28 +++++++++++++++++++
9 files changed, 95 insertions(+), 22 deletions(-)
create mode 100644 src/utils/errors/menu.ts
diff --git a/src/navigation/components/MenuCreateDialog/MenuCreateDialog.tsx b/src/navigation/components/MenuCreateDialog/MenuCreateDialog.tsx
index c9e2ea9f8..41c0f9f25 100644
--- a/src/navigation/components/MenuCreateDialog/MenuCreateDialog.tsx
+++ b/src/navigation/components/MenuCreateDialog/MenuCreateDialog.tsx
@@ -12,8 +12,9 @@ import ConfirmButton, {
} from "@saleor/components/ConfirmButton";
import Form from "@saleor/components/Form";
import { buttonMessages } from "@saleor/intl";
-import { getFieldError } from "@saleor/utils/errors";
-import { UserError } from "@saleor/types";
+import { MenuErrorFragment } from "@saleor/navigation/types/MenuErrorFragment";
+import { getFormErrors } from "@saleor/utils/errors";
+import getMenuErrorMessage from "@saleor/utils/errors/menu";
export interface MenuCreateDialogFormData {
name: string;
@@ -22,7 +23,7 @@ export interface MenuCreateDialogFormData {
export interface MenuCreateDialogProps {
confirmButtonState: ConfirmButtonTransitionState;
disabled: boolean;
- errors: UserError[];
+ errors: MenuErrorFragment[];
open: boolean;
onClose: () => void;
onConfirm: (data: MenuCreateDialogFormData) => void;
@@ -42,6 +43,8 @@ const MenuCreateDialog: React.FC = ({
}) => {
const intl = useIntl();
+ const formErrors = getFormErrors(["name"], errors);
+
return (