Use translated errors in collections

This commit is contained in:
dominik-zeglen 2020-03-05 15:59:55 +01:00
parent 852bd71beb
commit 2a1abe76b6
16 changed files with 141 additions and 100 deletions

View file

@ -17,7 +17,7 @@ import SeoForm from "@saleor/components/SeoForm";
import VisibilityCard from "@saleor/components/VisibilityCard"; import VisibilityCard from "@saleor/components/VisibilityCard";
import useDateLocalize from "@saleor/hooks/useDateLocalize"; import useDateLocalize from "@saleor/hooks/useDateLocalize";
import { commonMessages, sectionNames } from "@saleor/intl"; import { commonMessages, sectionNames } from "@saleor/intl";
import { UserError } from "../../../types"; import { ProductErrorFragment } from "@saleor/attributes/types/ProductErrorFragment";
import CollectionDetails from "../CollectionDetails/CollectionDetails"; import CollectionDetails from "../CollectionDetails/CollectionDetails";
import { CollectionImage } from "../CollectionImage/CollectionImage"; import { CollectionImage } from "../CollectionImage/CollectionImage";
@ -37,7 +37,7 @@ export interface CollectionCreatePageFormData {
export interface CollectionCreatePageProps { export interface CollectionCreatePageProps {
disabled: boolean; disabled: boolean;
errors: UserError[]; errors: ProductErrorFragment[];
saveButtonBarState: ConfirmButtonTransitionState; saveButtonBarState: ConfirmButtonTransitionState;
onBack: () => void; onBack: () => void;
onSubmit: (data: CollectionCreatePageFormData) => void; onSubmit: (data: CollectionCreatePageFormData) => void;

View file

@ -10,8 +10,8 @@ import FormSpacer from "@saleor/components/FormSpacer";
import RichTextEditor from "@saleor/components/RichTextEditor"; import RichTextEditor from "@saleor/components/RichTextEditor";
import { commonMessages } from "@saleor/intl"; import { commonMessages } from "@saleor/intl";
import { maybe } from "@saleor/misc"; import { maybe } from "@saleor/misc";
import { UserError } from "@saleor/types"; import { getProductErrorMessage, getFormErrors } from "@saleor/utils/errors";
import { getFieldError } from "@saleor/utils/errors"; import { ProductErrorFragment } from "@saleor/attributes/types/ProductErrorFragment";
import { CollectionDetails_collection } from "../../types/CollectionDetails"; import { CollectionDetails_collection } from "../../types/CollectionDetails";
export interface CollectionDetailsProps { export interface CollectionDetailsProps {
@ -21,7 +21,7 @@ export interface CollectionDetailsProps {
name: string; name: string;
}; };
disabled: boolean; disabled: boolean;
errors: UserError[]; errors: ProductErrorFragment[];
onChange: (event: React.ChangeEvent<any>) => void; onChange: (event: React.ChangeEvent<any>) => void;
} }
@ -34,6 +34,8 @@ const CollectionDetails: React.FC<CollectionDetailsProps> = ({
}) => { }) => {
const intl = useIntl(); const intl = useIntl();
const formErrors = getFormErrors(["name", "descriptionJson"], errors);
return ( return (
<Card> <Card>
<CardTitle <CardTitle
@ -49,14 +51,14 @@ const CollectionDetails: React.FC<CollectionDetailsProps> = ({
disabled={disabled} disabled={disabled}
value={data.name} value={data.name}
onChange={onChange} onChange={onChange}
error={!!getFieldError(errors, "name")} error={!!formErrors.name}
helperText={getFieldError(errors, "name")?.message} helperText={getProductErrorMessage(formErrors.name, intl)}
fullWidth fullWidth
/> />
<FormSpacer /> <FormSpacer />
<RichTextEditor <RichTextEditor
error={!!getFieldError(errors, "descriptionJson")} error={!!formErrors.descriptionJson}
helperText={getFieldError(errors, "descriptionJson")?.message} helperText={getProductErrorMessage(formErrors.descriptionJson, intl)}
initial={maybe(() => JSON.parse(collection.descriptionJson))} initial={maybe(() => JSON.parse(collection.descriptionJson))}
label={intl.formatMessage(commonMessages.description)} label={intl.formatMessage(commonMessages.description)}
name="description" name="description"

View file

@ -17,8 +17,9 @@ import SeoForm from "@saleor/components/SeoForm";
import VisibilityCard from "@saleor/components/VisibilityCard"; import VisibilityCard from "@saleor/components/VisibilityCard";
import useDateLocalize from "@saleor/hooks/useDateLocalize"; import useDateLocalize from "@saleor/hooks/useDateLocalize";
import { sectionNames } from "@saleor/intl"; import { sectionNames } from "@saleor/intl";
import { ProductErrorFragment } from "@saleor/attributes/types/ProductErrorFragment";
import { maybe } from "../../../misc"; import { maybe } from "../../../misc";
import { ListActions, PageListProps, UserError } from "../../../types"; import { ListActions, PageListProps } from "../../../types";
import { CollectionDetails_collection } from "../../types/CollectionDetails"; import { CollectionDetails_collection } from "../../types/CollectionDetails";
import CollectionDetails from "../CollectionDetails/CollectionDetails"; import CollectionDetails from "../CollectionDetails/CollectionDetails";
import { CollectionImage } from "../CollectionImage/CollectionImage"; import { CollectionImage } from "../CollectionImage/CollectionImage";
@ -37,7 +38,7 @@ export interface CollectionDetailsPageFormData {
export interface CollectionDetailsPageProps extends PageListProps, ListActions { export interface CollectionDetailsPageProps extends PageListProps, ListActions {
collection: CollectionDetails_collection; collection: CollectionDetails_collection;
errors: UserError[]; errors: ProductErrorFragment[];
isFeatured: boolean; isFeatured: boolean;
saveButtonBarState: ConfirmButtonTransitionState; saveButtonBarState: ConfirmButtonTransitionState;
onBack: () => void; onBack: () => void;

View file

@ -1,5 +1,6 @@
import gql from "graphql-tag"; import gql from "graphql-tag";
import { productErrorFragment } from "@saleor/attributes/mutations";
import { TypedMutation } from "../mutations"; import { TypedMutation } from "../mutations";
import { import {
collectionDetailsFragment, collectionDetailsFragment,
@ -38,17 +39,24 @@ import {
UnassignCollectionProductVariables UnassignCollectionProductVariables
} from "./types/UnassignCollectionProduct"; } from "./types/UnassignCollectionProduct";
export const ShopErrorFragment = gql`
fragment ShopErrorFragment on ShopError {
code
field
}
`;
const collectionUpdate = gql` const collectionUpdate = gql`
${collectionDetailsFragment} ${collectionDetailsFragment}
${productErrorFragment}
mutation CollectionUpdate($id: ID!, $input: CollectionInput!) { mutation CollectionUpdate($id: ID!, $input: CollectionInput!) {
collectionUpdate(id: $id, input: $input) { collectionUpdate(id: $id, input: $input) {
errors {
field
message
}
collection { collection {
...CollectionDetailsFragment ...CollectionDetailsFragment
} }
errors: productErrors {
...ProductErrorFragment
}
} }
} }
`; `;
@ -59,15 +67,16 @@ export const TypedCollectionUpdateMutation = TypedMutation<
const collectionUpdateWithHomepage = gql` const collectionUpdateWithHomepage = gql`
${collectionDetailsFragment} ${collectionDetailsFragment}
${productErrorFragment}
${ShopErrorFragment}
mutation CollectionUpdateWithHomepage( mutation CollectionUpdateWithHomepage(
$id: ID! $id: ID!
$input: CollectionInput! $input: CollectionInput!
$homepageId: ID $homepageId: ID
) { ) {
homepageCollectionUpdate(collection: $homepageId) { homepageCollectionUpdate(collection: $homepageId) {
errors { errors: shopErrors {
field ...ShopErrorFragment
message
} }
shop { shop {
homepageCollection { homepageCollection {
@ -76,13 +85,12 @@ const collectionUpdateWithHomepage = gql`
} }
} }
collectionUpdate(id: $id, input: $input) { collectionUpdate(id: $id, input: $input) {
errors {
field
message
}
collection { collection {
...CollectionDetailsFragment ...CollectionDetailsFragment
} }
errors: productErrors {
...ProductErrorFragment
}
} }
} }
`; `;
@ -93,6 +101,7 @@ export const TypedCollectionUpdateWithHomepageMutation = TypedMutation<
const assignCollectionProduct = gql` const assignCollectionProduct = gql`
${collectionProductFragment} ${collectionProductFragment}
${productErrorFragment}
mutation CollectionAssignProduct( mutation CollectionAssignProduct(
$collectionId: ID! $collectionId: ID!
$productIds: [ID!]! $productIds: [ID!]!
@ -102,10 +111,6 @@ const assignCollectionProduct = gql`
$before: String $before: String
) { ) {
collectionAddProducts(collectionId: $collectionId, products: $productIds) { collectionAddProducts(collectionId: $collectionId, products: $productIds) {
errors {
field
message
}
collection { collection {
id id
products(first: $first, after: $after, before: $before, last: $last) { 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` const createCollection = gql`
${collectionDetailsFragment} ${collectionDetailsFragment}
${productErrorFragment}
mutation CreateCollection($input: CollectionCreateInput!) { mutation CreateCollection($input: CollectionCreateInput!) {
collectionCreate(input: $input) { collectionCreate(input: $input) {
errors {
field
message
}
collection { collection {
...CollectionDetailsFragment ...CollectionDetailsFragment
} }
errors: productErrors {
...ProductErrorFragment
}
} }
} }
`; `;
@ -150,11 +158,11 @@ export const TypedCollectionCreateMutation = TypedMutation<
>(createCollection); >(createCollection);
const removeCollection = gql` const removeCollection = gql`
${productErrorFragment}
mutation RemoveCollection($id: ID!) { mutation RemoveCollection($id: ID!) {
collectionDelete(id: $id) { collectionDelete(id: $id) {
errors { errors: productErrors {
field ...ProductErrorFragment
message
} }
} }
} }
@ -165,6 +173,7 @@ export const TypedCollectionRemoveMutation = TypedMutation<
>(removeCollection); >(removeCollection);
const unassignCollectionProduct = gql` const unassignCollectionProduct = gql`
${productErrorFragment}
mutation UnassignCollectionProduct( mutation UnassignCollectionProduct(
$collectionId: ID! $collectionId: ID!
$productIds: [ID]! $productIds: [ID]!
@ -177,10 +186,6 @@ const unassignCollectionProduct = gql`
collectionId: $collectionId collectionId: $collectionId
products: $productIds products: $productIds
) { ) {
errors {
field
message
}
collection { collection {
id id
products(first: $first, after: $after, before: $before, last: $last) { 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); >(unassignCollectionProduct);
const collectionBulkDelete = gql` const collectionBulkDelete = gql`
${productErrorFragment}
mutation CollectionBulkDelete($ids: [ID]!) { mutation CollectionBulkDelete($ids: [ID]!) {
collectionBulkDelete(ids: $ids) { collectionBulkDelete(ids: $ids) {
errors { errors: productErrors {
field ...ProductErrorFragment
message
} }
} }
} }
@ -230,11 +238,11 @@ export const TypedCollectionBulkDelete = TypedMutation<
>(collectionBulkDelete); >(collectionBulkDelete);
const collectionBulkPublish = gql` const collectionBulkPublish = gql`
${productErrorFragment}
mutation CollectionBulkPublish($ids: [ID]!, $isPublished: Boolean!) { mutation CollectionBulkPublish($ids: [ID]!, $isPublished: Boolean!) {
collectionBulkPublish(ids: $ids, isPublished: $isPublished) { collectionBulkPublish(ids: $ids, isPublished: $isPublished) {
errors { errors: productErrors {
field ...ProductErrorFragment
message
} }
} }
} }

View file

@ -2,16 +2,12 @@
/* eslint-disable */ /* eslint-disable */
// This file was automatically generated and should not be edited. // This file was automatically generated and should not be edited.
import { ProductErrorCode } from "./../../types/globalTypes";
// ==================================================== // ====================================================
// GraphQL mutation operation: CollectionAssignProduct // 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 { export interface CollectionAssignProduct_collectionAddProducts_collection_products_edges_node_productType {
__typename: "ProductType"; __typename: "ProductType";
id: string; id: string;
@ -57,10 +53,16 @@ export interface CollectionAssignProduct_collectionAddProducts_collection {
products: CollectionAssignProduct_collectionAddProducts_collection_products | null; products: CollectionAssignProduct_collectionAddProducts_collection_products | null;
} }
export interface CollectionAssignProduct_collectionAddProducts_errors {
__typename: "ProductError";
code: ProductErrorCode;
field: string | null;
}
export interface CollectionAssignProduct_collectionAddProducts { export interface CollectionAssignProduct_collectionAddProducts {
__typename: "CollectionAddProducts"; __typename: "CollectionAddProducts";
errors: CollectionAssignProduct_collectionAddProducts_errors[];
collection: CollectionAssignProduct_collectionAddProducts_collection | null; collection: CollectionAssignProduct_collectionAddProducts_collection | null;
errors: CollectionAssignProduct_collectionAddProducts_errors[];
} }
export interface CollectionAssignProduct { export interface CollectionAssignProduct {

View file

@ -2,14 +2,16 @@
/* eslint-disable */ /* eslint-disable */
// This file was automatically generated and should not be edited. // This file was automatically generated and should not be edited.
import { ProductErrorCode } from "./../../types/globalTypes";
// ==================================================== // ====================================================
// GraphQL mutation operation: CollectionBulkDelete // GraphQL mutation operation: CollectionBulkDelete
// ==================================================== // ====================================================
export interface CollectionBulkDelete_collectionBulkDelete_errors { export interface CollectionBulkDelete_collectionBulkDelete_errors {
__typename: "Error"; __typename: "ProductError";
code: ProductErrorCode;
field: string | null; field: string | null;
message: string | null;
} }
export interface CollectionBulkDelete_collectionBulkDelete { export interface CollectionBulkDelete_collectionBulkDelete {

View file

@ -2,14 +2,16 @@
/* eslint-disable */ /* eslint-disable */
// This file was automatically generated and should not be edited. // This file was automatically generated and should not be edited.
import { ProductErrorCode } from "./../../types/globalTypes";
// ==================================================== // ====================================================
// GraphQL mutation operation: CollectionBulkPublish // GraphQL mutation operation: CollectionBulkPublish
// ==================================================== // ====================================================
export interface CollectionBulkPublish_collectionBulkPublish_errors { export interface CollectionBulkPublish_collectionBulkPublish_errors {
__typename: "Error"; __typename: "ProductError";
code: ProductErrorCode;
field: string | null; field: string | null;
message: string | null;
} }
export interface CollectionBulkPublish_collectionBulkPublish { export interface CollectionBulkPublish_collectionBulkPublish {

View file

@ -2,18 +2,12 @@
/* eslint-disable */ /* eslint-disable */
// This file was automatically generated and should not be edited. // 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 // GraphQL mutation operation: CollectionUpdate
// ==================================================== // ====================================================
export interface CollectionUpdate_collectionUpdate_errors {
__typename: "Error";
field: string | null;
message: string | null;
}
export interface CollectionUpdate_collectionUpdate_collection_backgroundImage { export interface CollectionUpdate_collectionUpdate_collection_backgroundImage {
__typename: "Image"; __typename: "Image";
alt: string | null; alt: string | null;
@ -32,10 +26,16 @@ export interface CollectionUpdate_collectionUpdate_collection {
seoTitle: string | null; seoTitle: string | null;
} }
export interface CollectionUpdate_collectionUpdate_errors {
__typename: "ProductError";
code: ProductErrorCode;
field: string | null;
}
export interface CollectionUpdate_collectionUpdate { export interface CollectionUpdate_collectionUpdate {
__typename: "CollectionUpdate"; __typename: "CollectionUpdate";
errors: CollectionUpdate_collectionUpdate_errors[];
collection: CollectionUpdate_collectionUpdate_collection | null; collection: CollectionUpdate_collectionUpdate_collection | null;
errors: CollectionUpdate_collectionUpdate_errors[];
} }
export interface CollectionUpdate { export interface CollectionUpdate {

View file

@ -2,16 +2,16 @@
/* eslint-disable */ /* eslint-disable */
// This file was automatically generated and should not be edited. // 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 // GraphQL mutation operation: CollectionUpdateWithHomepage
// ==================================================== // ====================================================
export interface CollectionUpdateWithHomepage_homepageCollectionUpdate_errors { export interface CollectionUpdateWithHomepage_homepageCollectionUpdate_errors {
__typename: "Error"; __typename: "ShopError";
code: ShopErrorCode;
field: string | null; field: string | null;
message: string | null;
} }
export interface CollectionUpdateWithHomepage_homepageCollectionUpdate_shop_homepageCollection { export interface CollectionUpdateWithHomepage_homepageCollectionUpdate_shop_homepageCollection {
@ -30,12 +30,6 @@ export interface CollectionUpdateWithHomepage_homepageCollectionUpdate {
shop: CollectionUpdateWithHomepage_homepageCollectionUpdate_shop | null; shop: CollectionUpdateWithHomepage_homepageCollectionUpdate_shop | null;
} }
export interface CollectionUpdateWithHomepage_collectionUpdate_errors {
__typename: "Error";
field: string | null;
message: string | null;
}
export interface CollectionUpdateWithHomepage_collectionUpdate_collection_backgroundImage { export interface CollectionUpdateWithHomepage_collectionUpdate_collection_backgroundImage {
__typename: "Image"; __typename: "Image";
alt: string | null; alt: string | null;
@ -54,10 +48,16 @@ export interface CollectionUpdateWithHomepage_collectionUpdate_collection {
seoTitle: string | null; seoTitle: string | null;
} }
export interface CollectionUpdateWithHomepage_collectionUpdate_errors {
__typename: "ProductError";
code: ProductErrorCode;
field: string | null;
}
export interface CollectionUpdateWithHomepage_collectionUpdate { export interface CollectionUpdateWithHomepage_collectionUpdate {
__typename: "CollectionUpdate"; __typename: "CollectionUpdate";
errors: CollectionUpdateWithHomepage_collectionUpdate_errors[];
collection: CollectionUpdateWithHomepage_collectionUpdate_collection | null; collection: CollectionUpdateWithHomepage_collectionUpdate_collection | null;
errors: CollectionUpdateWithHomepage_collectionUpdate_errors[];
} }
export interface CollectionUpdateWithHomepage { export interface CollectionUpdateWithHomepage {

View file

@ -2,18 +2,12 @@
/* eslint-disable */ /* eslint-disable */
// This file was automatically generated and should not be edited. // 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 // GraphQL mutation operation: CreateCollection
// ==================================================== // ====================================================
export interface CreateCollection_collectionCreate_errors {
__typename: "Error";
field: string | null;
message: string | null;
}
export interface CreateCollection_collectionCreate_collection_backgroundImage { export interface CreateCollection_collectionCreate_collection_backgroundImage {
__typename: "Image"; __typename: "Image";
alt: string | null; alt: string | null;
@ -32,10 +26,16 @@ export interface CreateCollection_collectionCreate_collection {
seoTitle: string | null; seoTitle: string | null;
} }
export interface CreateCollection_collectionCreate_errors {
__typename: "ProductError";
code: ProductErrorCode;
field: string | null;
}
export interface CreateCollection_collectionCreate { export interface CreateCollection_collectionCreate {
__typename: "CollectionCreate"; __typename: "CollectionCreate";
errors: CreateCollection_collectionCreate_errors[];
collection: CreateCollection_collectionCreate_collection | null; collection: CreateCollection_collectionCreate_collection | null;
errors: CreateCollection_collectionCreate_errors[];
} }
export interface CreateCollection { export interface CreateCollection {

View file

@ -2,14 +2,16 @@
/* eslint-disable */ /* eslint-disable */
// This file was automatically generated and should not be edited. // This file was automatically generated and should not be edited.
import { ProductErrorCode } from "./../../types/globalTypes";
// ==================================================== // ====================================================
// GraphQL mutation operation: RemoveCollection // GraphQL mutation operation: RemoveCollection
// ==================================================== // ====================================================
export interface RemoveCollection_collectionDelete_errors { export interface RemoveCollection_collectionDelete_errors {
__typename: "Error"; __typename: "ProductError";
code: ProductErrorCode;
field: string | null; field: string | null;
message: string | null;
} }
export interface RemoveCollection_collectionDelete { export interface RemoveCollection_collectionDelete {

View file

@ -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;
}

View file

@ -2,16 +2,12 @@
/* eslint-disable */ /* eslint-disable */
// This file was automatically generated and should not be edited. // This file was automatically generated and should not be edited.
import { ProductErrorCode } from "./../../types/globalTypes";
// ==================================================== // ====================================================
// GraphQL mutation operation: UnassignCollectionProduct // 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 { export interface UnassignCollectionProduct_collectionRemoveProducts_collection_products_edges_node_productType {
__typename: "ProductType"; __typename: "ProductType";
id: string; id: string;
@ -57,10 +53,16 @@ export interface UnassignCollectionProduct_collectionRemoveProducts_collection {
products: UnassignCollectionProduct_collectionRemoveProducts_collection_products | null; products: UnassignCollectionProduct_collectionRemoveProducts_collection_products | null;
} }
export interface UnassignCollectionProduct_collectionRemoveProducts_errors {
__typename: "ProductError";
code: ProductErrorCode;
field: string | null;
}
export interface UnassignCollectionProduct_collectionRemoveProducts { export interface UnassignCollectionProduct_collectionRemoveProducts {
__typename: "CollectionRemoveProducts"; __typename: "CollectionRemoveProducts";
errors: UnassignCollectionProduct_collectionRemoveProducts_errors[];
collection: UnassignCollectionProduct_collectionRemoveProducts_collection | null; collection: UnassignCollectionProduct_collectionRemoveProducts_collection | null;
errors: UnassignCollectionProduct_collectionRemoveProducts_errors[];
} }
export interface UnassignCollectionProduct { export interface UnassignCollectionProduct {

View file

@ -4,7 +4,7 @@ import { useIntl } from "react-intl";
import { WindowTitle } from "@saleor/components/WindowTitle"; import { WindowTitle } from "@saleor/components/WindowTitle";
import useNavigator from "@saleor/hooks/useNavigator"; import useNavigator from "@saleor/hooks/useNavigator";
import useNotifier from "@saleor/hooks/useNotifier"; import useNotifier from "@saleor/hooks/useNotifier";
import { maybe } from "../../misc"; import { commonMessages } from "@saleor/intl";
import { CollectionCreateInput } from "../../types/globalTypes"; import { CollectionCreateInput } from "../../types/globalTypes";
import CollectionCreatePage from "../components/CollectionCreatePage/CollectionCreatePage"; import CollectionCreatePage from "../components/CollectionCreatePage/CollectionCreatePage";
import { TypedCollectionCreateMutation } from "../mutations"; import { TypedCollectionCreateMutation } from "../mutations";
@ -19,9 +19,7 @@ export const CollectionCreate: React.FC = () => {
const handleCollectionCreateSuccess = (data: CreateCollection) => { const handleCollectionCreateSuccess = (data: CreateCollection) => {
if (data.collectionCreate.errors.length === 0) { if (data.collectionCreate.errors.length === 0) {
notify({ notify({
text: intl.formatMessage({ text: intl.formatMessage(commonMessages.savedChanges)
defaultMessage: "Created collection"
})
}); });
navigate(collectionUrl(data.collectionCreate.collection.id)); navigate(collectionUrl(data.collectionCreate.collection.id));
} else { } else {
@ -31,7 +29,7 @@ export const CollectionCreate: React.FC = () => {
); );
if (backgroundImageError) { if (backgroundImageError) {
notify({ notify({
text: backgroundImageError.message text: intl.formatMessage(commonMessages.somethingWentWrong)
}); });
} }
} }
@ -47,10 +45,7 @@ export const CollectionCreate: React.FC = () => {
})} })}
/> />
<CollectionCreatePage <CollectionCreatePage
errors={maybe( errors={createCollectionOpts.data?.collectionCreate.errors || []}
() => createCollectionOpts.data.collectionCreate.errors,
[]
)}
onBack={() => navigate(collectionListUrl())} onBack={() => navigate(collectionListUrl())}
disabled={createCollectionOpts.loading} disabled={createCollectionOpts.loading}
onSubmit={formData => onSubmit={formData =>

View file

@ -88,7 +88,7 @@ export const CollectionDetails: React.FC<CollectionDetailsProps> = ({
); );
if (backgroundImageError) { if (backgroundImageError) {
notify({ notify({
text: backgroundImageError.message text: intl.formatMessage(commonMessages.somethingWentWrong)
}); });
} }
} }
@ -204,7 +204,7 @@ export const CollectionDetails: React.FC<CollectionDetailsProps> = ({
onAdd={() => openModal("assign")} onAdd={() => openModal("assign")}
onBack={handleBack} onBack={handleBack}
disabled={loading} disabled={loading}
collection={maybe(() => data.collection)} collection={data?.collection}
errors={ errors={
updateCollection.opts?.data?.collectionUpdate.errors || [] updateCollection.opts?.data?.collectionUpdate.errors || []
} }

View file

@ -563,6 +563,16 @@ export enum ShippingMethodTypeEnum {
WEIGHT = "WEIGHT", 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 { export enum StaffMemberStatus {
ACTIVE = "ACTIVE", ACTIVE = "ACTIVE",
DEACTIVATED = "DEACTIVATED", DEACTIVATED = "DEACTIVATED",