From 60fb2266a9c4daacac45e17d5d1ac8e10391fc9c Mon Sep 17 00:00:00 2001 From: dominik-zeglen Date: Sat, 3 Oct 2020 11:52:59 +0200 Subject: [PATCH] Use dedicated error fragment --- schema.graphql | 4 + src/fragments/errors.ts | 8 + src/fragments/types/ProductErrorFragment.ts | 1 - .../ProductErrorWithAttributesFragment.ts | 16 ++ .../ProductAttributes/ProductAttributes.tsx | 10 +- .../ProductCreatePage/ProductCreatePage.tsx | 32 ++- .../ProductUpdatePage/ProductUpdatePage.tsx | 4 +- .../ProductVariantAttributes.tsx | 10 +- .../ProductVariantCreatePage.tsx | 4 +- .../ProductVariantNavigation.tsx | 2 +- .../ProductVariantPage/ProductVariantPage.tsx | 4 +- src/products/mutations.ts | 23 +- src/products/types/ProductCreate.ts | 1 + src/products/types/ProductUpdate.ts | 1 + src/products/types/SimpleProductUpdate.ts | 2 + src/products/types/VariantCreate.ts | 1 + src/products/types/VariantUpdate.ts | 1 + .../__snapshots__/Stories.test.ts.snap | 201 +++++++++++++++--- .../stories/products/ProductCreatePage.tsx | 27 ++- .../stories/products/ProductUpdatePage.tsx | 6 +- .../products/ProductVariantCreatePage.tsx | 6 +- .../stories/products/ProductVariantPage.tsx | 6 +- src/types/globalTypes.ts | 1 + 23 files changed, 296 insertions(+), 75 deletions(-) create mode 100644 src/fragments/types/ProductErrorWithAttributesFragment.ts diff --git a/schema.graphql b/schema.graphql index bb01cb372..ae15c713c 100644 --- a/schema.graphql +++ b/schema.graphql @@ -688,6 +688,7 @@ type BulkProductError { field: String message: String code: ProductErrorCode! + attributes: [ID!] index: Int warehouses: [ID!] } @@ -696,6 +697,7 @@ type BulkStockError { field: String message: String code: ProductErrorCode! + attributes: [ID!] index: Int } @@ -3744,6 +3746,7 @@ type ProductError { field: String message: String code: ProductErrorCode! + attributes: [ID!] } enum ProductErrorCode { @@ -3755,6 +3758,7 @@ enum ProductErrorCode { GRAPHQL_ERROR INVALID NOT_PRODUCTS_IMAGE + NOT_PRODUCTS_VARIANT NOT_FOUND REQUIRED UNIQUE diff --git a/src/fragments/errors.ts b/src/fragments/errors.ts index f4bd5d788..2670f2d6f 100644 --- a/src/fragments/errors.ts +++ b/src/fragments/errors.ts @@ -7,6 +7,14 @@ export const productErrorFragment = gql` } `; +export const productErrorWithAttributesFragment = gql` + ${productErrorFragment} + fragment ProductErrorWithAttributesFragment on ProductError { + ...ProductErrorFragment + attributes + } +`; + export const accountErrorFragment = gql` fragment AccountErrorFragment on AccountError { code diff --git a/src/fragments/types/ProductErrorFragment.ts b/src/fragments/types/ProductErrorFragment.ts index fff392cb5..2f4d1fccb 100644 --- a/src/fragments/types/ProductErrorFragment.ts +++ b/src/fragments/types/ProductErrorFragment.ts @@ -10,7 +10,6 @@ import { ProductErrorCode } from "./../../types/globalTypes"; export interface ProductErrorFragment { __typename: "ProductError"; - attributeId: string | null; code: ProductErrorCode; field: string | null; } diff --git a/src/fragments/types/ProductErrorWithAttributesFragment.ts b/src/fragments/types/ProductErrorWithAttributesFragment.ts new file mode 100644 index 000000000..46c737efa --- /dev/null +++ b/src/fragments/types/ProductErrorWithAttributesFragment.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: ProductErrorWithAttributesFragment +// ==================================================== + +export interface ProductErrorWithAttributesFragment { + __typename: "ProductError"; + code: ProductErrorCode; + field: string | null; + attributes: string[] | null; +} diff --git a/src/products/components/ProductAttributes/ProductAttributes.tsx b/src/products/components/ProductAttributes/ProductAttributes.tsx index a25df70e2..9bae09030 100644 --- a/src/products/components/ProductAttributes/ProductAttributes.tsx +++ b/src/products/components/ProductAttributes/ProductAttributes.tsx @@ -13,7 +13,7 @@ import MultiAutocompleteSelectField, { import SingleAutocompleteSelectField, { SingleAutocompleteChoiceType } from "@saleor/components/SingleAutocompleteSelectField"; -import { ProductErrorFragment } from "@saleor/fragments/types/ProductErrorFragment"; +import { ProductErrorWithAttributesFragment } from "@saleor/fragments/types/ProductErrorWithAttributesFragment"; import { FormsetAtomicData, FormsetChange } from "@saleor/hooks/useFormset"; import { maybe } from "@saleor/misc"; import { ProductDetails_product_attributes_attribute_values } from "@saleor/products/types/ProductDetails"; @@ -35,7 +35,7 @@ export type ProductAttributeInput = FormsetAtomicData< export interface ProductAttributesProps { attributes: ProductAttributeInput[]; disabled: boolean; - errors: ProductErrorFragment[]; + errors: ProductErrorWithAttributesFragment[]; onChange: FormsetChange; onMultiChange: FormsetChange; } @@ -174,8 +174,8 @@ const ProductAttributes: React.FC = ({ <>
{attributes.map((attribute, attributeIndex) => { - const error = errors.find( - err => err.attributeId === attribute.id + const error = errors.find(err => + err.attributes?.includes(attribute.id) ); return ( @@ -201,7 +201,7 @@ const ProductAttributes: React.FC = ({ ).name, attribute.value[0] )} - emptyOption + emptyOption={!attribute.data.isRequired} error={!!error} helperText={getProductErrorMessage(error, intl)} name={`attribute:${attribute.label}`} diff --git a/src/products/components/ProductCreatePage/ProductCreatePage.tsx b/src/products/components/ProductCreatePage/ProductCreatePage.tsx index 21464797b..88377434d 100644 --- a/src/products/components/ProductCreatePage/ProductCreatePage.tsx +++ b/src/products/components/ProductCreatePage/ProductCreatePage.tsx @@ -10,13 +10,14 @@ import { MultiAutocompleteChoiceType } from "@saleor/components/MultiAutocomplet import PageHeader from "@saleor/components/PageHeader"; import SaveButtonBar from "@saleor/components/SaveButtonBar"; import SeoForm from "@saleor/components/SeoForm"; -import { ProductErrorFragment } from "@saleor/fragments/types/ProductErrorFragment"; +import { ProductErrorWithAttributesFragment } from "@saleor/fragments/types/ProductErrorWithAttributesFragment"; import { TaxTypeFragment } from "@saleor/fragments/types/TaxTypeFragment"; import useDateLocalize from "@saleor/hooks/useDateLocalize"; import useFormset from "@saleor/hooks/useFormset"; import useStateFromProps from "@saleor/hooks/useStateFromProps"; import { sectionNames } from "@saleor/intl"; import { + getAttributeInputFromProductType, getChoices, ProductAttributeValueChoices, ProductType @@ -79,7 +80,7 @@ export interface ProductCreatePageSubmitData extends FormData { } interface ProductCreatePageProps { - errors: ProductErrorFragment[]; + errors: ProductErrorWithAttributesFragment[]; collections: SearchCollections_search_edges_node[]; categories: SearchCategories_search_edges_node[]; currency: string; @@ -87,6 +88,7 @@ interface ProductCreatePageProps { fetchMoreCategories: FetchMoreProps; fetchMoreCollections: FetchMoreProps; fetchMoreProductTypes: FetchMoreProps; + initial?: Partial; productTypes?: Array<{ id: string; name: string; @@ -118,6 +120,7 @@ export const ProductCreatePage: React.FC = ({ fetchMoreCollections, fetchMoreProductTypes, header, + initial, productTypes: productTypeChoiceList, saveButtonBarState, warehouses, @@ -130,12 +133,21 @@ export const ProductCreatePage: React.FC = ({ }: ProductCreatePageProps) => { const intl = useIntl(); const localizeDate = useDateLocalize(); + + const initialProductType = productTypeChoiceList?.find( + productType => initial?.productType === productType.id + ); + // Form values const { change: changeAttributeData, data: attributes, set: setAttributeData - } = useFormset([]); + } = useFormset( + initial?.productType + ? getAttributeInputFromProductType(initialProductType) + : [] + ); const { add: addStock, change: changeStockData, @@ -154,6 +166,7 @@ export const ProductCreatePage: React.FC = ({ } = useMetadataChangeTrigger(); const initialData: FormData = { + ...(initial || {}), availableForPurchase: "", basePrice: 0, category: "", @@ -185,14 +198,20 @@ export const ProductCreatePage: React.FC = ({ ProductAttributeValueChoices[] >([]); - const [selectedCategory, setSelectedCategory] = useStateFromProps(""); + const [selectedCategory, setSelectedCategory] = useStateFromProps( + initial?.category || "" + ); const [selectedCollections, setSelectedCollections] = useStateFromProps< MultiAutocompleteChoiceType[] >([]); - const [productType, setProductType] = React.useState(null); - const [selectedTaxType, setSelectedTaxType] = useStateFromProps(null); + const [productType, setProductType] = useStateFromProps( + initialProductType || null + ); + const [selectedTaxType, setSelectedTaxType] = useStateFromProps( + initial?.taxCode || null + ); const categories = getChoices(categoryChoiceList); const collections = getChoices(collectionChoiceList); @@ -274,6 +293,7 @@ export const ProductCreatePage: React.FC = ({ diff --git a/src/products/components/ProductUpdatePage/ProductUpdatePage.tsx b/src/products/components/ProductUpdatePage/ProductUpdatePage.tsx index a4e9fd0d9..b79f8b1bf 100644 --- a/src/products/components/ProductUpdatePage/ProductUpdatePage.tsx +++ b/src/products/components/ProductUpdatePage/ProductUpdatePage.tsx @@ -9,7 +9,7 @@ import Metadata from "@saleor/components/Metadata/Metadata"; import PageHeader from "@saleor/components/PageHeader"; import SaveButtonBar from "@saleor/components/SaveButtonBar"; import SeoForm from "@saleor/components/SeoForm"; -import { ProductErrorFragment } from "@saleor/fragments/types/ProductErrorFragment"; +import { ProductErrorWithAttributesFragment } from "@saleor/fragments/types/ProductErrorWithAttributesFragment"; import { TaxTypeFragment } from "@saleor/fragments/types/TaxTypeFragment"; import { WarehouseFragment } from "@saleor/fragments/types/WarehouseFragment"; import useDateLocalize from "@saleor/hooks/useDateLocalize"; @@ -58,7 +58,7 @@ import ProductVariants from "../ProductVariants"; export interface ProductUpdatePageProps extends ListActions { defaultWeightUnit: string; - errors: ProductErrorFragment[]; + errors: ProductErrorWithAttributesFragment[]; placeholderImage: string; collections: SearchCollections_search_edges_node[]; categories: SearchCategories_search_edges_node[]; diff --git a/src/products/components/ProductVariantAttributes/ProductVariantAttributes.tsx b/src/products/components/ProductVariantAttributes/ProductVariantAttributes.tsx index 552e7d686..a09714220 100644 --- a/src/products/components/ProductVariantAttributes/ProductVariantAttributes.tsx +++ b/src/products/components/ProductVariantAttributes/ProductVariantAttributes.tsx @@ -8,7 +8,7 @@ import SingleAutocompleteSelectField, { SingleAutocompleteChoiceType } from "@saleor/components/SingleAutocompleteSelectField"; import Skeleton from "@saleor/components/Skeleton"; -import { ProductErrorFragment } from "@saleor/fragments/types/ProductErrorFragment"; +import { ProductErrorWithAttributesFragment } from "@saleor/fragments/types/ProductErrorWithAttributesFragment"; import { ProductVariant_attributes_attribute_values } from "@saleor/fragments/types/ProductVariant"; import { FormsetAtomicData, FormsetChange } from "@saleor/hooks/useFormset"; import { commonMessages } from "@saleor/intl"; @@ -27,7 +27,7 @@ export type VariantAttributeInput = FormsetAtomicData< interface ProductVariantAttributesProps { attributes: VariantAttributeInput[]; disabled: boolean; - errors: ProductErrorFragment[]; + errors: ProductErrorWithAttributesFragment[]; onChange: FormsetChange; } @@ -85,8 +85,8 @@ const ProductVariantAttributes: React.FC = ({ ) : ( attributes.map(attribute => { - const error = errors.find( - err => err.attributeId === attribute.id + const error = errors.find(err => + err.attributes?.includes(attribute.id) ); return ( @@ -122,7 +122,7 @@ const ProductVariantAttributes: React.FC = ({ {errors .filter( error => - error.field === "attributes" && error.attributeId === null + error.field === "attributes" && error.attributes === null ) .map(error => ( diff --git a/src/products/components/ProductVariantCreatePage/ProductVariantCreatePage.tsx b/src/products/components/ProductVariantCreatePage/ProductVariantCreatePage.tsx index 8c345e4f2..23a3c1f0a 100644 --- a/src/products/components/ProductVariantCreatePage/ProductVariantCreatePage.tsx +++ b/src/products/components/ProductVariantCreatePage/ProductVariantCreatePage.tsx @@ -7,7 +7,7 @@ import Grid from "@saleor/components/Grid"; import Metadata, { MetadataFormData } from "@saleor/components/Metadata"; import PageHeader from "@saleor/components/PageHeader"; import SaveButtonBar from "@saleor/components/SaveButtonBar"; -import { ProductErrorFragment } from "@saleor/fragments/types/ProductErrorFragment"; +import { ProductErrorWithAttributesFragment } from "@saleor/fragments/types/ProductErrorWithAttributesFragment"; import useFormset, { FormsetChange, FormsetData @@ -48,7 +48,7 @@ export interface ProductVariantCreatePageSubmitData interface ProductVariantCreatePageProps { currencySymbol: string; disabled: boolean; - errors: ProductErrorFragment[]; + errors: ProductErrorWithAttributesFragment[]; header: string; product: ProductVariantCreateData_product; saveButtonBarState: ConfirmButtonTransitionState; diff --git a/src/products/components/ProductVariantNavigation/ProductVariantNavigation.tsx b/src/products/components/ProductVariantNavigation/ProductVariantNavigation.tsx index b091a818e..6d9214d22 100644 --- a/src/products/components/ProductVariantNavigation/ProductVariantNavigation.tsx +++ b/src/products/components/ProductVariantNavigation/ProductVariantNavigation.tsx @@ -131,7 +131,7 @@ const ProductVariantNavigation: React.FC = props classes.tabActive, classes.noHandle, { - [classes.firstVariant]: variants.length === 0 + [classes.firstVariant]: variants?.length === 0 } )} thumbnail={null} diff --git a/src/products/components/ProductVariantPage/ProductVariantPage.tsx b/src/products/components/ProductVariantPage/ProductVariantPage.tsx index 135b4c984..a91167439 100644 --- a/src/products/components/ProductVariantPage/ProductVariantPage.tsx +++ b/src/products/components/ProductVariantPage/ProductVariantPage.tsx @@ -8,7 +8,7 @@ import { MetadataFormData } from "@saleor/components/Metadata"; import Metadata from "@saleor/components/Metadata/Metadata"; import PageHeader from "@saleor/components/PageHeader"; import SaveButtonBar from "@saleor/components/SaveButtonBar"; -import { ProductErrorFragment } from "@saleor/fragments/types/ProductErrorFragment"; +import { ProductErrorWithAttributesFragment } from "@saleor/fragments/types/ProductErrorWithAttributesFragment"; import { ProductVariant } from "@saleor/fragments/types/ProductVariant"; import { WarehouseFragment } from "@saleor/fragments/types/WarehouseFragment"; import useFormset, { @@ -56,7 +56,7 @@ export interface ProductVariantPageSubmitData interface ProductVariantPageProps { defaultWeightUnit: string; variant?: ProductVariant; - errors: ProductErrorFragment[]; + errors: ProductErrorWithAttributesFragment[]; saveButtonBarState: ConfirmButtonTransitionState; loading?: boolean; placeholderImage?: string; diff --git a/src/products/mutations.ts b/src/products/mutations.ts index 45e6ea4fa..1b63cf258 100644 --- a/src/products/mutations.ts +++ b/src/products/mutations.ts @@ -3,6 +3,7 @@ import { bulkStockErrorFragment, exportErrorFragment, productErrorFragment, + productErrorWithAttributesFragment, stockErrorFragment } from "@saleor/fragments/errors"; import { @@ -159,12 +160,12 @@ export const useProductVariantSetDefaultMutation = makeMutation< >(productVariantSetDefault); export const productUpdateMutation = gql` - ${productErrorFragment} + ${productErrorWithAttributesFragment} ${productFragmentDetails} mutation ProductUpdate($id: ID!, $input: ProductInput!) { productUpdate(id: $id, input: $input) { errors: productErrors { - ...ProductErrorFragment + ...ProductErrorWithAttributesFragment } product { ...Product @@ -179,7 +180,7 @@ export const useProductUpdateMutation = makeMutation< export const simpleProductUpdateMutation = gql` ${bulkStockErrorFragment} - ${productErrorFragment} + ${productErrorWithAttributesFragment} ${productFragmentDetails} ${stockErrorFragment} ${fragmentVariant} @@ -194,7 +195,7 @@ export const simpleProductUpdateMutation = gql` ) { productUpdate(id: $id, input: $input) { errors: productErrors { - ...ProductErrorFragment + ...ProductErrorWithAttributesFragment } product { ...Product @@ -202,7 +203,7 @@ export const simpleProductUpdateMutation = gql` } productVariantUpdate(id: $productVariantId, input: $productVariantInput) { errors: productErrors { - ...ProductErrorFragment + ...ProductErrorWithAttributesFragment } productVariant { ...ProductVariant @@ -249,12 +250,12 @@ export const useSimpleProductUpdateMutation = makeMutation< >(simpleProductUpdateMutation); export const productCreateMutation = gql` - ${productErrorFragment} + ${productErrorWithAttributesFragment} ${productFragmentDetails} mutation ProductCreate($input: ProductCreateInput!) { productCreate(input: $input) { errors: productErrors { - ...ProductErrorFragment + ...ProductErrorWithAttributesFragment } product { ...Product @@ -288,7 +289,7 @@ export const useVariantDeleteMutation = makeMutation< export const variantUpdateMutation = gql` ${bulkStockErrorFragment} ${fragmentVariant} - ${productErrorFragment} + ${productErrorWithAttributesFragment} mutation VariantUpdate( $addStocks: [StockInput!]! $removeStocks: [ID!]! @@ -313,7 +314,7 @@ export const variantUpdateMutation = gql` } ) { errors: productErrors { - ...ProductErrorFragment + ...ProductErrorWithAttributesFragment } productVariant { ...ProductVariant @@ -359,11 +360,11 @@ export const useVariantUpdateMutation = makeMutation< export const variantCreateMutation = gql` ${fragmentVariant} - ${productErrorFragment} + ${productErrorWithAttributesFragment} mutation VariantCreate($input: ProductVariantCreateInput!) { productVariantCreate(input: $input) { errors: productErrors { - ...ProductErrorFragment + ...ProductErrorWithAttributesFragment } productVariant { ...ProductVariant diff --git a/src/products/types/ProductCreate.ts b/src/products/types/ProductCreate.ts index f31768995..6db6a62df 100644 --- a/src/products/types/ProductCreate.ts +++ b/src/products/types/ProductCreate.ts @@ -12,6 +12,7 @@ export interface ProductCreate_productCreate_errors { __typename: "ProductError"; code: ProductErrorCode; field: string | null; + attributes: string[] | null; } export interface ProductCreate_productCreate_product_attributes_attribute_values { diff --git a/src/products/types/ProductUpdate.ts b/src/products/types/ProductUpdate.ts index 8da5ceab4..db1c2a1d9 100644 --- a/src/products/types/ProductUpdate.ts +++ b/src/products/types/ProductUpdate.ts @@ -12,6 +12,7 @@ export interface ProductUpdate_productUpdate_errors { __typename: "ProductError"; code: ProductErrorCode; field: string | null; + attributes: string[] | null; } export interface ProductUpdate_productUpdate_product_attributes_attribute_values { diff --git a/src/products/types/SimpleProductUpdate.ts b/src/products/types/SimpleProductUpdate.ts index cbc11614e..ae15c1b09 100644 --- a/src/products/types/SimpleProductUpdate.ts +++ b/src/products/types/SimpleProductUpdate.ts @@ -12,6 +12,7 @@ export interface SimpleProductUpdate_productUpdate_errors { __typename: "ProductError"; code: ProductErrorCode; field: string | null; + attributes: string[] | null; } export interface SimpleProductUpdate_productUpdate_product_attributes_attribute_values { @@ -251,6 +252,7 @@ export interface SimpleProductUpdate_productVariantUpdate_errors { __typename: "ProductError"; code: ProductErrorCode; field: string | null; + attributes: string[] | null; } export interface SimpleProductUpdate_productVariantUpdate_productVariant_metadata { diff --git a/src/products/types/VariantCreate.ts b/src/products/types/VariantCreate.ts index 888b46a09..6d1585bc8 100644 --- a/src/products/types/VariantCreate.ts +++ b/src/products/types/VariantCreate.ts @@ -12,6 +12,7 @@ export interface VariantCreate_productVariantCreate_errors { __typename: "ProductError"; code: ProductErrorCode; field: string | null; + attributes: string[] | null; } export interface VariantCreate_productVariantCreate_productVariant_metadata { diff --git a/src/products/types/VariantUpdate.ts b/src/products/types/VariantUpdate.ts index 9ebe6a027..b5a179ec8 100644 --- a/src/products/types/VariantUpdate.ts +++ b/src/products/types/VariantUpdate.ts @@ -12,6 +12,7 @@ export interface VariantUpdate_productVariantUpdate_errors { __typename: "ProductError"; code: ProductErrorCode; field: string | null; + attributes: string[] | null; } export interface VariantUpdate_productVariantUpdate_productVariant_metadata { diff --git a/src/storybook/__snapshots__/Stories.test.ts.snap b/src/storybook/__snapshots__/Stories.test.ts.snap index a4478f4a0..19c91635c 100644 --- a/src/storybook/__snapshots__/Stories.test.ts.snap +++ b/src/storybook/__snapshots__/Stories.test.ts.snap @@ -140040,6 +140040,152 @@ Ctrl + K"
+
+
+ + Attributes + +
+
+
+
+
+
+
+
+ 1 Attributes +
+
+ +
+
+
+
+
+ Author +
+
+
+
+
+ + +

+ Invalid value +

+
+
+
+
+
+
@@ -140248,8 +140394,8 @@ Ctrl + K" class="MuiFormControl-root-id MuiTextField-root-id MuiFormControl-fullWidth-id" > @@ -140264,7 +140410,7 @@ Ctrl + K" autocomplete="off" class="MuiInputBase-input-id MuiOutlinedInput-input-id MuiInputBase-inputAdornedEnd-id MuiOutlinedInput-inputAdornedEnd-id" type="text" - value="" + value="Candy" />
​ @@ -140299,7 +140445,7 @@ Ctrl + K"

Invalid value

@@ -140976,7 +141122,7 @@ exports[`Storyshots Views / Products / Create product variant add first variant class="MuiTableRow-root-id" >
-
- All attributes should have value -
@@ -145955,7 +146101,7 @@ Ctrl + K" class="MuiFormControl-root-id MuiTextField-root-id MuiFormControl-fullWidth-id" >
@@ -173699,7 +173850,7 @@ exports[`Storyshots Views / Products / Product variant details attribute errors class="MuiFormControl-root-id MuiTextField-root-id MuiFormControl-fullWidth-id" >
-
- All attributes should have value -
diff --git a/src/storybook/stories/products/ProductCreatePage.tsx b/src/storybook/stories/products/ProductCreatePage.tsx index df02a860f..4a1cd132d 100644 --- a/src/storybook/stories/products/ProductCreatePage.tsx +++ b/src/storybook/stories/products/ProductCreatePage.tsx @@ -68,13 +68,23 @@ storiesOf("Views / Products / Create product", module) ).map(field => ({ - __typename: "ProductError", - code: ProductErrorCode.INVALID, - field - }))} + errors={([ + "attributes", + "name", + "productType", + "category", + "sku" + ] as Array).map( + field => ({ + __typename: "ProductError", + attributes: + field === "attributes" + ? [productTypes[0].productAttributes[0].id] + : null, + code: ProductErrorCode.INVALID, + field + }) + )} header="Add product" collections={product.collections} fetchCategories={() => undefined} @@ -83,6 +93,9 @@ storiesOf("Views / Products / Create product", module) fetchMoreCategories={fetchMoreProps} fetchMoreCollections={fetchMoreProps} fetchMoreProductTypes={fetchMoreProps} + initial={{ + productType: productTypes[0].id + }} productTypes={productTypes} categories={[product.category]} onBack={() => undefined} diff --git a/src/storybook/stories/products/ProductUpdatePage.tsx b/src/storybook/stories/products/ProductUpdatePage.tsx index 39f86dd58..92506dfb0 100644 --- a/src/storybook/stories/products/ProductUpdatePage.tsx +++ b/src/storybook/stories/products/ProductUpdatePage.tsx @@ -152,8 +152,10 @@ storiesOf("Views / Products / Product edit", module) ] as Array).map( field => ({ __typename: "ProductError", - attributeId: - field === "attributes" ? product.attributes[0].attribute.id : null, + attributes: + field === "attributes" + ? [product.attributes[0].attribute.id] + : null, code: ProductErrorCode.INVALID, field }) diff --git a/src/storybook/stories/products/ProductVariantCreatePage.tsx b/src/storybook/stories/products/ProductVariantCreatePage.tsx index 94edf107f..f98a34328 100644 --- a/src/storybook/stories/products/ProductVariantCreatePage.tsx +++ b/src/storybook/stories/products/ProductVariantCreatePage.tsx @@ -36,17 +36,17 @@ storiesOf("Views / Products / Create product variant", module) disabled={false} errors={[ { - attributeId: product.productType.variantAttributes[0].id, + attributes: [product.productType.variantAttributes[0].id], code: ProductErrorCode.REQUIRED, field: "attributes" }, { - attributeId: null, + attributes: null, code: ProductErrorCode.UNIQUE, field: "attributes" }, { - attributeId: null, + attributes: null, code: ProductErrorCode.ALREADY_EXISTS, field: "sku" } diff --git a/src/storybook/stories/products/ProductVariantPage.tsx b/src/storybook/stories/products/ProductVariantPage.tsx index a5073e2a1..34e88f346 100644 --- a/src/storybook/stories/products/ProductVariantPage.tsx +++ b/src/storybook/stories/products/ProductVariantPage.tsx @@ -86,17 +86,17 @@ storiesOf("Views / Products / Product variant details", module) saveButtonBarState="default" errors={[ { - attributeId: variant.attributes[0].attribute.id, + attributes: [variant.attributes[0].attribute.id], code: ProductErrorCode.REQUIRED, field: "attributes" }, { - attributeId: null, + attributes: null, code: ProductErrorCode.UNIQUE, field: "attributes" }, { - attributeId: null, + attributes: null, code: ProductErrorCode.ALREADY_EXISTS, field: "sku" } diff --git a/src/types/globalTypes.ts b/src/types/globalTypes.ts index f79be52c5..8d75979a3 100644 --- a/src/types/globalTypes.ts +++ b/src/types/globalTypes.ts @@ -705,6 +705,7 @@ export enum ProductErrorCode { INVALID = "INVALID", NOT_FOUND = "NOT_FOUND", NOT_PRODUCTS_IMAGE = "NOT_PRODUCTS_IMAGE", + NOT_PRODUCTS_VARIANT = "NOT_PRODUCTS_VARIANT", REQUIRED = "REQUIRED", UNIQUE = "UNIQUE", VARIANT_NO_DIGITAL_CONTENT = "VARIANT_NO_DIGITAL_CONTENT",