wip
This commit is contained in:
parent
ff74c566ab
commit
6bacb5fb3a
6 changed files with 25 additions and 5 deletions
|
@ -19,7 +19,6 @@ import useCategorySearch from "@saleor/searches/useCategorySearch";
|
||||||
import useCollectionSearch from "@saleor/searches/useCollectionSearch";
|
import useCollectionSearch from "@saleor/searches/useCollectionSearch";
|
||||||
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import NotFoundPage from "@saleor/components/NotFoundPage";
|
import NotFoundPage from "@saleor/components/NotFoundPage";
|
||||||
import { ProductErrorCode } from "@saleor/types/globalTypes";
|
|
||||||
import { getMutationState, maybe } from "../../../misc";
|
import { getMutationState, maybe } from "../../../misc";
|
||||||
import ProductUpdatePage from "../../components/ProductUpdatePage";
|
import ProductUpdatePage from "../../components/ProductUpdatePage";
|
||||||
import ProductUpdateOperations from "../../containers/ProductUpdateOperations";
|
import ProductUpdateOperations from "../../containers/ProductUpdateOperations";
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { ProductErrorFragment } from "@saleor/attributes/types/ProductErrorFragment";
|
||||||
|
|
||||||
export function formError<TErrorPayload>(
|
export function formError<TErrorPayload>(
|
||||||
field: string,
|
field: string,
|
||||||
opts?: Partial<Omit<TErrorPayload, "field" | "message">>
|
opts?: Partial<Omit<TErrorPayload, "field" | "message">>
|
||||||
|
|
|
@ -9,7 +9,7 @@ import ProductUpdatePage, {
|
||||||
} from "@saleor/products/components/ProductUpdatePage";
|
} from "@saleor/products/components/ProductUpdatePage";
|
||||||
import { product as productFixture } from "@saleor/products/fixtures";
|
import { product as productFixture } from "@saleor/products/fixtures";
|
||||||
import { ProductUpdatePageFormData } from "@saleor/products/utils/data";
|
import { ProductUpdatePageFormData } from "@saleor/products/utils/data";
|
||||||
import { formError } from "@saleor/storybook/misc";
|
import { ProductErrorCode } from "@saleor/types/globalTypes";
|
||||||
import Decorator from "../../Decorator";
|
import Decorator from "../../Decorator";
|
||||||
|
|
||||||
const product = productFixture(placeholderImage);
|
const product = productFixture(placeholderImage);
|
||||||
|
@ -94,7 +94,6 @@ storiesOf("Views / Products / Product edit", module)
|
||||||
"category",
|
"category",
|
||||||
"chargeTaxes",
|
"chargeTaxes",
|
||||||
"collections",
|
"collections",
|
||||||
"description",
|
|
||||||
"isPublished",
|
"isPublished",
|
||||||
"name",
|
"name",
|
||||||
"publicationDate",
|
"publicationDate",
|
||||||
|
@ -102,6 +101,10 @@ storiesOf("Views / Products / Product edit", module)
|
||||||
"seoTitle",
|
"seoTitle",
|
||||||
"sku",
|
"sku",
|
||||||
"stockQuantity"
|
"stockQuantity"
|
||||||
] as Array<keyof ProductUpdatePageFormData>).map(formError)}
|
] as Array<keyof ProductUpdatePageFormData>).map(field => ({
|
||||||
|
__typename: "ProductError",
|
||||||
|
code: ProductErrorCode.INVALID,
|
||||||
|
field
|
||||||
|
}))}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|
|
@ -42,7 +42,6 @@ storiesOf("Views / Products / Create product variant", module)
|
||||||
}
|
}
|
||||||
].map(error => ({
|
].map(error => ({
|
||||||
__typename: "ProductError",
|
__typename: "ProductError",
|
||||||
message: "Generic form error",
|
|
||||||
...error
|
...error
|
||||||
}))}
|
}))}
|
||||||
header="Add variant"
|
header="Add variant"
|
||||||
|
|
15
src/utils/errors/common.ts
Normal file
15
src/utils/errors/common.ts
Normal file
|
@ -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;
|
|
@ -44,6 +44,8 @@ function getProductErrorMessage(
|
||||||
return intl.formatMessage(commonMessages.requiredField);
|
return intl.formatMessage(commonMessages.requiredField);
|
||||||
case ProductErrorCode.VARIANT_NO_DIGITAL_CONTENT:
|
case ProductErrorCode.VARIANT_NO_DIGITAL_CONTENT:
|
||||||
return intl.formatMessage(messages.variantNoDigitalContent);
|
return intl.formatMessage(messages.variantNoDigitalContent);
|
||||||
|
case ProductErrorCode.INVALID:
|
||||||
|
return intl.formatMessage(commonErrorMessages.invalid);
|
||||||
default:
|
default:
|
||||||
return intl.formatMessage(commonErrorMessages.unknownError);
|
return intl.formatMessage(commonErrorMessages.unknownError);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue