diff --git a/CHANGELOG.md b/CHANGELOG.md index 52a9c6a40..8130d8585 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,11 @@ All notable, unreleased changes to this project will be documented in this file. - Move fragments to separate directory to avoid circular imports - #592 by @dominik-zeglen - Add order invoices management - #570 by @orzechdev +## 2.10.1 + +- Add weight field and fix warehouse country selection - #597 by @dominik-zeglen +- Fix weight based rate update - #604 by @dominik-zeglen + ## 2.10.0 - Fix minor bugs - #244 by @dominik-zeglen diff --git a/README.md b/README.md index 158a54afd..e017afe64 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ $ cd saleor-dashboard To use the official stable release, checkout to a release tag: ``` -$ git checkout 2.10.0 +$ git checkout 2.10.1 ``` See the list of all releases here: https://github.com/mirumee/saleor-dashboard/releases/ diff --git a/locale/defaultMessages.json b/locale/defaultMessages.json index ccba72831..98c451854 100644 --- a/locale/defaultMessages.json +++ b/locale/defaultMessages.json @@ -3704,6 +3704,14 @@ "src_dot_products_dot_components_dot_ProductPricing_dot_3015886868": { "string": "Charge taxes for this item" }, + "src_dot_products_dot_components_dot_ProductShipping_dot_1325966144": { + "context": "product shipping", + "string": "Shipping" + }, + "src_dot_products_dot_components_dot_ProductShipping_dot_746695941": { + "context": "product weight", + "string": "Weight" + }, "src_dot_products_dot_components_dot_ProductStocks_dot_2585918415": { "string": "SKU (Stock Keeping Unit)" }, @@ -3741,14 +3749,6 @@ "src_dot_products_dot_components_dot_ProductUpdatePage_dot_2706108815": { "string": "Add search engine title and description to make this product easier to find" }, - "src_dot_products_dot_components_dot_ProductVariantAttributes_dot_1536841622": { - "context": "product attribute error", - "string": "All attributes should have value" - }, - "src_dot_products_dot_components_dot_ProductVariantAttributes_dot_258966189": { - "context": "product attribute error", - "string": "This variant already exists" - }, "src_dot_products_dot_components_dot_ProductVariantCreatePage_dot_2853608829": { "context": "button", "string": "Save variant" @@ -5134,6 +5134,10 @@ "src_dot_utils_dot_errors_dot_attributeCannotBeAssigned": { "string": "This attribute cannot be assigned to this product type" }, + "src_dot_utils_dot_errors_dot_attributeRequired": { + "context": "product attribute error", + "string": "All attributes should have value" + }, "src_dot_utils_dot_errors_dot_attributeVariantsDisabled": { "string": "Variants are disabled in this product type" }, @@ -5262,6 +5266,10 @@ "src_dot_utils_dot_errors_dot_variantNoDigitalContent": { "string": "This variant does not have any digital content" }, + "src_dot_utils_dot_errors_dot_variantUnique": { + "context": "product attribute error", + "string": "This variant already exists" + }, "src_dot_vouchers": { "context": "vouchers section name", "string": "Vouchers" diff --git a/package-lock.json b/package-lock.json index 80141135e..dd31665d9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "saleor-dashboard", - "version": "2.10.0", + "version": "2.10.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index e49d07810..11c885c52 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "saleor-dashboard", - "version": "2.10.0", + "version": "2.10.1", "main": "src/index.tsx", "repository": { "type": "git", diff --git a/src/components/Timeline/TimelineNote.tsx b/src/components/Timeline/TimelineNote.tsx index bdeb5cdef..28203686a 100644 --- a/src/components/Timeline/TimelineNote.tsx +++ b/src/components/Timeline/TimelineNote.tsx @@ -79,14 +79,16 @@ export const TimelineNote: React.FC = props => { return (
- - - + {user && ( + + + + )}
- {user.email} + {user?.email} diff --git a/src/fragments/products.ts b/src/fragments/products.ts index 499127ab1..9cd61d0d7 100644 --- a/src/fragments/products.ts +++ b/src/fragments/products.ts @@ -1,5 +1,7 @@ import gql from "graphql-tag"; +import { weightFragment } from "./weight"; + export const stockFragment = gql` fragment StockFragment on Stock { id @@ -102,6 +104,7 @@ export const productFragmentDetails = gql` ${fragmentMoney} ${productVariantAttributesFragment} ${stockFragment} + ${weightFragment} fragment Product on Product { ...ProductVariantAttributesFragment name @@ -167,6 +170,9 @@ export const productFragmentDetails = gql` name hasVariants } + weight { + ...WeightFragment + } } `; @@ -174,6 +180,7 @@ export const fragmentVariant = gql` ${fragmentMoney} ${fragmentProductImage} ${stockFragment} + ${weightFragment} fragment ProductVariant on ProductVariant { id attributes { @@ -229,5 +236,8 @@ export const fragmentVariant = gql` ...StockFragment } trackInventory + weight { + ...WeightFragment + } } `; diff --git a/src/fragments/types/Product.ts b/src/fragments/types/Product.ts index cf2a0e75d..2d37388eb 100644 --- a/src/fragments/types/Product.ts +++ b/src/fragments/types/Product.ts @@ -168,6 +168,12 @@ export interface Product_variants { trackInventory: boolean; } +export interface Product_weight { + __typename: "Weight"; + unit: string; + value: number; +} + export interface Product { __typename: "Product"; id: string; @@ -188,4 +194,5 @@ export interface Product { publicationDate: any | null; images: (Product_images | null)[] | null; variants: (Product_variants | null)[] | null; + weight: Product_weight | null; } diff --git a/src/fragments/types/ProductVariant.ts b/src/fragments/types/ProductVariant.ts index 4a6b1d939..709b2600f 100644 --- a/src/fragments/types/ProductVariant.ts +++ b/src/fragments/types/ProductVariant.ts @@ -103,6 +103,12 @@ export interface ProductVariant_stocks { warehouse: ProductVariant_stocks_warehouse; } +export interface ProductVariant_weight { + __typename: "Weight"; + unit: string; + value: number; +} + export interface ProductVariant { __typename: "ProductVariant"; id: string; @@ -115,4 +121,5 @@ export interface ProductVariant { sku: string; stocks: (ProductVariant_stocks | null)[] | null; trackInventory: boolean; + weight: ProductVariant_weight | null; } diff --git a/src/fragments/types/WeightFragment.ts b/src/fragments/types/WeightFragment.ts new file mode 100644 index 000000000..7984fb6f3 --- /dev/null +++ b/src/fragments/types/WeightFragment.ts @@ -0,0 +1,13 @@ +/* tslint:disable */ +/* eslint-disable */ +// This file was automatically generated and should not be edited. + +// ==================================================== +// GraphQL fragment: WeightFragment +// ==================================================== + +export interface WeightFragment { + __typename: "Weight"; + unit: string; + value: number; +} diff --git a/src/fragments/weight.ts b/src/fragments/weight.ts new file mode 100644 index 000000000..67fb2870f --- /dev/null +++ b/src/fragments/weight.ts @@ -0,0 +1,8 @@ +import gql from "graphql-tag"; + +export const weightFragment = gql` + fragment WeightFragment on Weight { + unit + value + } +`; diff --git a/src/misc.ts b/src/misc.ts index 4d64e317d..933fcc916 100644 --- a/src/misc.ts +++ b/src/misc.ts @@ -59,6 +59,10 @@ export function decimal(value: string | number) { return value; } +export function weight(value: string) { + return value === "" ? null : parseFloat(value); +} + export const removeDoubleSlashes = (url: string) => url.replace(/([^:]\/)\/+/g, "$1"); diff --git a/src/orders/fixtures.ts b/src/orders/fixtures.ts index a33d861ef..afa99300e 100644 --- a/src/orders/fixtures.ts +++ b/src/orders/fixtures.ts @@ -820,8 +820,8 @@ export const order = (placeholder: string): OrderDetails_order => ({ date: "2018-09-17T13:22:24.376193+00:00", email: null, emailType: null, - invoiceNumber: "23/07/2020", id: "T3JkZXJFdmVudDoyMQ==", + invoiceNumber: "23/07/2020", message: null, quantity: 1, type: OrderEventsEnum.FULFILLMENT_FULFILLED_ITEMS, @@ -830,6 +830,32 @@ export const order = (placeholder: string): OrderDetails_order => ({ email: "admin@example.com", id: "QWRkcmVzczoxNQ==" } + }, + { + __typename: "OrderEvent", + amount: null, + date: "2019-09-17T13:22:24.376193+00:00", + email: null, + emailType: null, + id: "T3JkZXJFdmVudDo0", + invoiceNumber: "23/07/2020", + message: "This is note", + quantity: null, + type: OrderEventsEnum.NOTE_ADDED, + user: null + }, + { + __typename: "OrderEvent", + amount: null, + date: "2019-09-17T13:22:24.376193+00:00", + email: null, + emailType: null, + id: "T3JkZXJFdmVudDo1", + invoiceNumber: "24/07/2020", + message: "This is note", + quantity: null, + type: OrderEventsEnum.NOTE_ADDED, + user: null } ], fulfillments: [ diff --git a/src/productTypes/components/ProductTypeCreatePage/ProductTypeCreatePage.tsx b/src/productTypes/components/ProductTypeCreatePage/ProductTypeCreatePage.tsx index 419e7d9e8..93506b17e 100644 --- a/src/productTypes/components/ProductTypeCreatePage/ProductTypeCreatePage.tsx +++ b/src/productTypes/components/ProductTypeCreatePage/ProductTypeCreatePage.tsx @@ -105,7 +105,7 @@ const ProductTypeCreatePage: React.FC = ({
diff --git a/src/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx b/src/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx index 36d64cbf3..469695f1e 100644 --- a/src/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx +++ b/src/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx @@ -199,7 +199,7 @@ const ProductTypeDetailsPage: React.FC = ({
diff --git a/src/productTypes/components/ProductTypeShipping/ProductTypeShipping.tsx b/src/productTypes/components/ProductTypeShipping/ProductTypeShipping.tsx index fab8f1721..4d054524b 100644 --- a/src/productTypes/components/ProductTypeShipping/ProductTypeShipping.tsx +++ b/src/productTypes/components/ProductTypeShipping/ProductTypeShipping.tsx @@ -6,21 +6,19 @@ import { ControlledCheckbox } from "@saleor/components/ControlledCheckbox"; import React from "react"; import { useIntl } from "react-intl"; -import { WeightUnitsEnum } from "../../../types/globalTypes"; - interface ProductTypeShippingProps { data: { isShippingRequired: boolean; weight: number | null; }; - defaultWeightUnit: WeightUnitsEnum; + weightUnit: string; disabled: boolean; onChange: (event: React.ChangeEvent) => void; } const ProductTypeShipping: React.FC = ({ data, - defaultWeightUnit, + weightUnit, disabled, onChange }) => { @@ -48,7 +46,7 @@ const ProductTypeShipping: React.FC = ({ {data.isShippingRequired && ( ; header: string; saveButtonBarState: ConfirmButtonTransitionState; + weightUnit: string; warehouses: SearchWarehouses_search_edges_node[]; fetchCategories: (data: string) => void; fetchCollections: (data: string) => void; @@ -107,6 +110,7 @@ export const ProductCreatePage: React.FC = ({ warehouses, onBack, fetchProductTypes, + weightUnit, onSubmit }: ProductCreatePageProps) => { const intl = useIntl(); @@ -143,7 +147,8 @@ export const ProductCreatePage: React.FC = ({ seoTitle: "", sku: null, stockQuantity: null, - trackInventory: false + trackInventory: false, + weight: "" }; // Display values @@ -234,6 +239,13 @@ export const ProductCreatePage: React.FC = ({ {!!productType && !productType.hasVariants && ( <> + ) => void; +} + +const ProductShipping: React.FC = props => { + const { data, disabled, errors, weightUnit, onChange } = props; + + const intl = useIntl(); + + const formErrors = getFormErrors(["weight"], errors); + + return ( + + + + + {weightUnit} + ), + inputProps: { + min: 0 + } + }} + /> + + + + ); +}; +ProductShipping.displayName = "ProductShipping"; +export default ProductShipping; diff --git a/src/products/components/ProductShipping/index.ts b/src/products/components/ProductShipping/index.ts new file mode 100644 index 000000000..e69de29bb diff --git a/src/products/components/ProductUpdatePage/ProductUpdatePage.tsx b/src/products/components/ProductUpdatePage/ProductUpdatePage.tsx index eff25a7c5..00cd8e1ce 100644 --- a/src/products/components/ProductUpdatePage/ProductUpdatePage.tsx +++ b/src/products/components/ProductUpdatePage/ProductUpdatePage.tsx @@ -48,10 +48,12 @@ import ProductDetailsForm from "../ProductDetailsForm"; import ProductImages from "../ProductImages"; import ProductOrganization from "../ProductOrganization"; import ProductPricing from "../ProductPricing"; +import ProductShipping from "../ProductShipping/ProductShipping"; import ProductStocks, { ProductStockInput } from "../ProductStocks"; import ProductVariants from "../ProductVariants"; export interface ProductUpdatePageProps extends ListActions { + defaultWeightUnit: string; errors: ProductErrorFragment[]; placeholderImage: string; collections: SearchCollections_search_edges_node[]; @@ -89,6 +91,7 @@ export interface ProductUpdatePageSubmitData extends ProductUpdatePageFormData { } export const ProductUpdatePage: React.FC = ({ + defaultWeightUnit, disabled, categories: categoryChoiceList, collections: collectionChoiceList, @@ -278,33 +281,43 @@ export const ProductUpdatePage: React.FC = ({ toggleAll={toggleAll} /> ) : ( - { - triggerChange(); - changeStockData(id, value); - }} - onFormDataChange={change} - onWarehouseStockAdd={id => { - triggerChange(); - addStock({ - data: null, - id, - label: warehouses.find( - warehouse => warehouse.id === id - ).name, - value: "0" - }); - }} - onWarehouseStockDelete={id => { - triggerChange(); - removeStock(id); - }} - /> + <> + + + { + triggerChange(); + changeStockData(id, value); + }} + onFormDataChange={change} + onWarehouseStockAdd={id => { + triggerChange(); + addStock({ + data: null, + id, + label: warehouses.find( + warehouse => warehouse.id === id + ).name, + value: "0" + }); + }} + onWarehouseStockDelete={id => { + triggerChange(); + removeStock(id); + }} + /> + )} = ({ attributes, disabled, @@ -87,8 +74,6 @@ const ProductVariantAttributes: React.FC = ({ }) => { const intl = useIntl(); - const translatedErrors = translateErrors(intl); - return ( = ({ .filter(error => error.field === "attributes") .map(error => ( - {translatedErrors[error.code]} + {getProductVariantAttributeErrorMessage(error, intl)} ))} diff --git a/src/products/components/ProductVariantCreatePage/ProductVariantCreatePage.tsx b/src/products/components/ProductVariantCreatePage/ProductVariantCreatePage.tsx index d4df87e0d..87b43bf85 100644 --- a/src/products/components/ProductVariantCreatePage/ProductVariantCreatePage.tsx +++ b/src/products/components/ProductVariantCreatePage/ProductVariantCreatePage.tsx @@ -18,6 +18,7 @@ import { useIntl } from "react-intl"; import { maybe } from "../../../misc"; import { ProductVariantCreateData_product } from "../../types/ProductVariantCreateData"; +import ProductShipping from "../ProductShipping/ProductShipping"; import ProductStocks, { ProductStockInput } from "../ProductStocks"; import ProductVariantAttributes, { VariantAttributeInputData @@ -32,6 +33,7 @@ interface ProductVariantCreatePageFormData { quantity: string; sku: string; trackInventory: boolean; + weight: string; } export interface ProductVariantCreatePageSubmitData @@ -48,6 +50,7 @@ interface ProductVariantCreatePageProps { product: ProductVariantCreateData_product; saveButtonBarState: ConfirmButtonTransitionState; warehouses: SearchWarehouses_search_edges_node[]; + weightUnit: string; onBack: () => void; onSubmit: (data: ProductVariantCreatePageSubmitData) => void; onVariantClick: (variantId: string) => void; @@ -61,6 +64,7 @@ const ProductVariantCreatePage: React.FC = ({ product, saveButtonBarState, warehouses, + weightUnit, onBack, onSubmit, onVariantClick @@ -86,7 +90,8 @@ const ProductVariantCreatePage: React.FC = ({ price: "", quantity: "0", sku: "", - trackInventory: true + trackInventory: true, + weight: "" }; const handleSubmit = (data: ProductVariantCreatePageFormData) => @@ -137,6 +142,14 @@ const ProductVariantCreatePage: React.FC = ({ onChange={change} /> + + = ({ + defaultWeightUnit, errors, loading, header, @@ -112,7 +116,8 @@ const ProductVariantPage: React.FC = ({ costPrice: maybe(() => variant.costPrice.amount.toString(), ""), price: maybe(() => variant.price.amount.toString(), ""), sku: maybe(() => variant.sku, ""), - trackInventory: variant?.trackInventory + trackInventory: variant?.trackInventory, + weight: variant?.weight?.value.toString() || "" }; const handleSubmit = (data: ProductVariantPageFormData) => { @@ -195,6 +200,14 @@ const ProductVariantPage: React.FC = ({ onChange={change} /> + + ({ } } ], - trackInventory: true + trackInventory: true, + weight: { + __typename: "Weight", + unit: "kg", + value: 6 + } }); export const variantImages = (placeholderImage: string) => variant(placeholderImage).images; diff --git a/src/products/mutations.ts b/src/products/mutations.ts index e4d38590a..255d8d1c7 100644 --- a/src/products/mutations.ts +++ b/src/products/mutations.ts @@ -192,6 +192,7 @@ export const simpleProductUpdateMutation = gql` $addStocks: [StockInput!]! $deleteStocks: [ID!]! $updateStocks: [StockInput!]! + $weight: WeightScalar ) { productUpdate( id: $id @@ -206,6 +207,7 @@ export const simpleProductUpdateMutation = gql` name: $name basePrice: $basePrice seo: $seo + weight: $weight } ) { errors: productErrors { @@ -281,6 +283,7 @@ export const productCreateMutation = gql` $seo: SeoInput $stocks: [StockInput!]! $trackInventory: Boolean! + $weight: WeightScalar ) { productCreate( input: { @@ -298,6 +301,7 @@ export const productCreateMutation = gql` seo: $seo stocks: $stocks trackInventory: $trackInventory + weight: $weight } ) { errors: productErrors { @@ -346,6 +350,7 @@ export const variantUpdateMutation = gql` $sku: String $trackInventory: Boolean! $stocks: [StockInput!]! + $weight: WeightScalar ) { productVariantUpdate( id: $id @@ -355,6 +360,7 @@ export const variantUpdateMutation = gql` price: $price sku: $sku trackInventory: $trackInventory + weight: $weight } ) { errors: productErrors { diff --git a/src/products/types/ProductCreate.ts b/src/products/types/ProductCreate.ts index 7c169bb7b..44ebccfc7 100644 --- a/src/products/types/ProductCreate.ts +++ b/src/products/types/ProductCreate.ts @@ -174,6 +174,12 @@ export interface ProductCreate_productCreate_product_variants { trackInventory: boolean; } +export interface ProductCreate_productCreate_product_weight { + __typename: "Weight"; + unit: string; + value: number; +} + export interface ProductCreate_productCreate_product { __typename: "Product"; id: string; @@ -194,6 +200,7 @@ export interface ProductCreate_productCreate_product { publicationDate: any | null; images: (ProductCreate_productCreate_product_images | null)[] | null; variants: (ProductCreate_productCreate_product_variants | null)[] | null; + weight: ProductCreate_productCreate_product_weight | null; } export interface ProductCreate_productCreate { @@ -221,4 +228,5 @@ export interface ProductCreateVariables { seo?: SeoInput | null; stocks: StockInput[]; trackInventory: boolean; + weight?: any | null; } diff --git a/src/products/types/ProductDetails.ts b/src/products/types/ProductDetails.ts index 6182eb1bf..936925a36 100644 --- a/src/products/types/ProductDetails.ts +++ b/src/products/types/ProductDetails.ts @@ -168,6 +168,12 @@ export interface ProductDetails_product_variants { trackInventory: boolean; } +export interface ProductDetails_product_weight { + __typename: "Weight"; + unit: string; + value: number; +} + export interface ProductDetails_product { __typename: "Product"; id: string; @@ -188,6 +194,7 @@ export interface ProductDetails_product { publicationDate: any | null; images: (ProductDetails_product_images | null)[] | null; variants: (ProductDetails_product_variants | null)[] | null; + weight: ProductDetails_product_weight | null; } export interface ProductDetails { diff --git a/src/products/types/ProductImageCreate.ts b/src/products/types/ProductImageCreate.ts index 5e9d14d45..a816e820b 100644 --- a/src/products/types/ProductImageCreate.ts +++ b/src/products/types/ProductImageCreate.ts @@ -174,6 +174,12 @@ export interface ProductImageCreate_productImageCreate_product_variants { trackInventory: boolean; } +export interface ProductImageCreate_productImageCreate_product_weight { + __typename: "Weight"; + unit: string; + value: number; +} + export interface ProductImageCreate_productImageCreate_product { __typename: "Product"; id: string; @@ -194,6 +200,7 @@ export interface ProductImageCreate_productImageCreate_product { publicationDate: any | null; images: (ProductImageCreate_productImageCreate_product_images | null)[] | null; variants: (ProductImageCreate_productImageCreate_product_variants | null)[] | null; + weight: ProductImageCreate_productImageCreate_product_weight | null; } export interface ProductImageCreate_productImageCreate { diff --git a/src/products/types/ProductImageUpdate.ts b/src/products/types/ProductImageUpdate.ts index a21a344e0..0c8a40dd7 100644 --- a/src/products/types/ProductImageUpdate.ts +++ b/src/products/types/ProductImageUpdate.ts @@ -174,6 +174,12 @@ export interface ProductImageUpdate_productImageUpdate_product_variants { trackInventory: boolean; } +export interface ProductImageUpdate_productImageUpdate_product_weight { + __typename: "Weight"; + unit: string; + value: number; +} + export interface ProductImageUpdate_productImageUpdate_product { __typename: "Product"; id: string; @@ -194,6 +200,7 @@ export interface ProductImageUpdate_productImageUpdate_product { publicationDate: any | null; images: (ProductImageUpdate_productImageUpdate_product_images | null)[] | null; variants: (ProductImageUpdate_productImageUpdate_product_variants | null)[] | null; + weight: ProductImageUpdate_productImageUpdate_product_weight | null; } export interface ProductImageUpdate_productImageUpdate { diff --git a/src/products/types/ProductUpdate.ts b/src/products/types/ProductUpdate.ts index b8667ff60..6a1192164 100644 --- a/src/products/types/ProductUpdate.ts +++ b/src/products/types/ProductUpdate.ts @@ -174,6 +174,12 @@ export interface ProductUpdate_productUpdate_product_variants { trackInventory: boolean; } +export interface ProductUpdate_productUpdate_product_weight { + __typename: "Weight"; + unit: string; + value: number; +} + export interface ProductUpdate_productUpdate_product { __typename: "Product"; id: string; @@ -194,6 +200,7 @@ export interface ProductUpdate_productUpdate_product { publicationDate: any | null; images: (ProductUpdate_productUpdate_product_images | null)[] | null; variants: (ProductUpdate_productUpdate_product_variants | null)[] | null; + weight: ProductUpdate_productUpdate_product_weight | null; } export interface ProductUpdate_productUpdate { diff --git a/src/products/types/ProductVariantDetails.ts b/src/products/types/ProductVariantDetails.ts index 6ab4b9e59..7ee7eda80 100644 --- a/src/products/types/ProductVariantDetails.ts +++ b/src/products/types/ProductVariantDetails.ts @@ -103,6 +103,12 @@ export interface ProductVariantDetails_productVariant_stocks { warehouse: ProductVariantDetails_productVariant_stocks_warehouse; } +export interface ProductVariantDetails_productVariant_weight { + __typename: "Weight"; + unit: string; + value: number; +} + export interface ProductVariantDetails_productVariant { __typename: "ProductVariant"; id: string; @@ -115,6 +121,7 @@ export interface ProductVariantDetails_productVariant { sku: string; stocks: (ProductVariantDetails_productVariant_stocks | null)[] | null; trackInventory: boolean; + weight: ProductVariantDetails_productVariant_weight | null; } export interface ProductVariantDetails { diff --git a/src/products/types/SimpleProductUpdate.ts b/src/products/types/SimpleProductUpdate.ts index c0f7f7aef..8851d67e3 100644 --- a/src/products/types/SimpleProductUpdate.ts +++ b/src/products/types/SimpleProductUpdate.ts @@ -174,6 +174,12 @@ export interface SimpleProductUpdate_productUpdate_product_variants { trackInventory: boolean; } +export interface SimpleProductUpdate_productUpdate_product_weight { + __typename: "Weight"; + unit: string; + value: number; +} + export interface SimpleProductUpdate_productUpdate_product { __typename: "Product"; id: string; @@ -194,6 +200,7 @@ export interface SimpleProductUpdate_productUpdate_product { publicationDate: any | null; images: (SimpleProductUpdate_productUpdate_product_images | null)[] | null; variants: (SimpleProductUpdate_productUpdate_product_variants | null)[] | null; + weight: SimpleProductUpdate_productUpdate_product_weight | null; } export interface SimpleProductUpdate_productUpdate { @@ -305,6 +312,12 @@ export interface SimpleProductUpdate_productVariantUpdate_productVariant_stocks warehouse: SimpleProductUpdate_productVariantUpdate_productVariant_stocks_warehouse; } +export interface SimpleProductUpdate_productVariantUpdate_productVariant_weight { + __typename: "Weight"; + unit: string; + value: number; +} + export interface SimpleProductUpdate_productVariantUpdate_productVariant { __typename: "ProductVariant"; id: string; @@ -317,6 +330,7 @@ export interface SimpleProductUpdate_productVariantUpdate_productVariant { sku: string; stocks: (SimpleProductUpdate_productVariantUpdate_productVariant_stocks | null)[] | null; trackInventory: boolean; + weight: SimpleProductUpdate_productVariantUpdate_productVariant_weight | null; } export interface SimpleProductUpdate_productVariantUpdate { @@ -429,6 +443,12 @@ export interface SimpleProductUpdate_productVariantStocksCreate_productVariant_s warehouse: SimpleProductUpdate_productVariantStocksCreate_productVariant_stocks_warehouse; } +export interface SimpleProductUpdate_productVariantStocksCreate_productVariant_weight { + __typename: "Weight"; + unit: string; + value: number; +} + export interface SimpleProductUpdate_productVariantStocksCreate_productVariant { __typename: "ProductVariant"; id: string; @@ -441,6 +461,7 @@ export interface SimpleProductUpdate_productVariantStocksCreate_productVariant { sku: string; stocks: (SimpleProductUpdate_productVariantStocksCreate_productVariant_stocks | null)[] | null; trackInventory: boolean; + weight: SimpleProductUpdate_productVariantStocksCreate_productVariant_weight | null; } export interface SimpleProductUpdate_productVariantStocksCreate { @@ -552,6 +573,12 @@ export interface SimpleProductUpdate_productVariantStocksDelete_productVariant_s warehouse: SimpleProductUpdate_productVariantStocksDelete_productVariant_stocks_warehouse; } +export interface SimpleProductUpdate_productVariantStocksDelete_productVariant_weight { + __typename: "Weight"; + unit: string; + value: number; +} + export interface SimpleProductUpdate_productVariantStocksDelete_productVariant { __typename: "ProductVariant"; id: string; @@ -564,6 +591,7 @@ export interface SimpleProductUpdate_productVariantStocksDelete_productVariant { sku: string; stocks: (SimpleProductUpdate_productVariantStocksDelete_productVariant_stocks | null)[] | null; trackInventory: boolean; + weight: SimpleProductUpdate_productVariantStocksDelete_productVariant_weight | null; } export interface SimpleProductUpdate_productVariantStocksDelete { @@ -676,6 +704,12 @@ export interface SimpleProductUpdate_productVariantStocksUpdate_productVariant_s warehouse: SimpleProductUpdate_productVariantStocksUpdate_productVariant_stocks_warehouse; } +export interface SimpleProductUpdate_productVariantStocksUpdate_productVariant_weight { + __typename: "Weight"; + unit: string; + value: number; +} + export interface SimpleProductUpdate_productVariantStocksUpdate_productVariant { __typename: "ProductVariant"; id: string; @@ -688,6 +722,7 @@ export interface SimpleProductUpdate_productVariantStocksUpdate_productVariant { sku: string; stocks: (SimpleProductUpdate_productVariantStocksUpdate_productVariant_stocks | null)[] | null; trackInventory: boolean; + weight: SimpleProductUpdate_productVariantStocksUpdate_productVariant_weight | null; } export interface SimpleProductUpdate_productVariantStocksUpdate { @@ -721,4 +756,5 @@ export interface SimpleProductUpdateVariables { addStocks: StockInput[]; deleteStocks: string[]; updateStocks: StockInput[]; + weight?: any | null; } diff --git a/src/products/types/VariantCreate.ts b/src/products/types/VariantCreate.ts index 1770067a7..f9bd6a80a 100644 --- a/src/products/types/VariantCreate.ts +++ b/src/products/types/VariantCreate.ts @@ -111,6 +111,12 @@ export interface VariantCreate_productVariantCreate_productVariant_stocks { warehouse: VariantCreate_productVariantCreate_productVariant_stocks_warehouse; } +export interface VariantCreate_productVariantCreate_productVariant_weight { + __typename: "Weight"; + unit: string; + value: number; +} + export interface VariantCreate_productVariantCreate_productVariant { __typename: "ProductVariant"; id: string; @@ -123,6 +129,7 @@ export interface VariantCreate_productVariantCreate_productVariant { sku: string; stocks: (VariantCreate_productVariantCreate_productVariant_stocks | null)[] | null; trackInventory: boolean; + weight: VariantCreate_productVariantCreate_productVariant_weight | null; } export interface VariantCreate_productVariantCreate { diff --git a/src/products/types/VariantImageAssign.ts b/src/products/types/VariantImageAssign.ts index 96e0d5f98..33e8ba952 100644 --- a/src/products/types/VariantImageAssign.ts +++ b/src/products/types/VariantImageAssign.ts @@ -111,6 +111,12 @@ export interface VariantImageAssign_variantImageAssign_productVariant_stocks { warehouse: VariantImageAssign_variantImageAssign_productVariant_stocks_warehouse; } +export interface VariantImageAssign_variantImageAssign_productVariant_weight { + __typename: "Weight"; + unit: string; + value: number; +} + export interface VariantImageAssign_variantImageAssign_productVariant { __typename: "ProductVariant"; id: string; @@ -123,6 +129,7 @@ export interface VariantImageAssign_variantImageAssign_productVariant { sku: string; stocks: (VariantImageAssign_variantImageAssign_productVariant_stocks | null)[] | null; trackInventory: boolean; + weight: VariantImageAssign_variantImageAssign_productVariant_weight | null; } export interface VariantImageAssign_variantImageAssign { diff --git a/src/products/types/VariantImageUnassign.ts b/src/products/types/VariantImageUnassign.ts index f373d96d7..8a4b21ced 100644 --- a/src/products/types/VariantImageUnassign.ts +++ b/src/products/types/VariantImageUnassign.ts @@ -111,6 +111,12 @@ export interface VariantImageUnassign_variantImageUnassign_productVariant_stocks warehouse: VariantImageUnassign_variantImageUnassign_productVariant_stocks_warehouse; } +export interface VariantImageUnassign_variantImageUnassign_productVariant_weight { + __typename: "Weight"; + unit: string; + value: number; +} + export interface VariantImageUnassign_variantImageUnassign_productVariant { __typename: "ProductVariant"; id: string; @@ -123,6 +129,7 @@ export interface VariantImageUnassign_variantImageUnassign_productVariant { sku: string; stocks: (VariantImageUnassign_variantImageUnassign_productVariant_stocks | null)[] | null; trackInventory: boolean; + weight: VariantImageUnassign_variantImageUnassign_productVariant_weight | null; } export interface VariantImageUnassign_variantImageUnassign { diff --git a/src/products/types/VariantUpdate.ts b/src/products/types/VariantUpdate.ts index 69abc6cea..107c0a3c2 100644 --- a/src/products/types/VariantUpdate.ts +++ b/src/products/types/VariantUpdate.ts @@ -111,6 +111,12 @@ export interface VariantUpdate_productVariantUpdate_productVariant_stocks { warehouse: VariantUpdate_productVariantUpdate_productVariant_stocks_warehouse; } +export interface VariantUpdate_productVariantUpdate_productVariant_weight { + __typename: "Weight"; + unit: string; + value: number; +} + export interface VariantUpdate_productVariantUpdate_productVariant { __typename: "ProductVariant"; id: string; @@ -123,6 +129,7 @@ export interface VariantUpdate_productVariantUpdate_productVariant { sku: string; stocks: (VariantUpdate_productVariantUpdate_productVariant_stocks | null)[] | null; trackInventory: boolean; + weight: VariantUpdate_productVariantUpdate_productVariant_weight | null; } export interface VariantUpdate_productVariantUpdate { @@ -235,6 +242,12 @@ export interface VariantUpdate_productVariantStocksUpdate_productVariant_stocks warehouse: VariantUpdate_productVariantStocksUpdate_productVariant_stocks_warehouse; } +export interface VariantUpdate_productVariantStocksUpdate_productVariant_weight { + __typename: "Weight"; + unit: string; + value: number; +} + export interface VariantUpdate_productVariantStocksUpdate_productVariant { __typename: "ProductVariant"; id: string; @@ -247,6 +260,7 @@ export interface VariantUpdate_productVariantStocksUpdate_productVariant { sku: string; stocks: (VariantUpdate_productVariantStocksUpdate_productVariant_stocks | null)[] | null; trackInventory: boolean; + weight: VariantUpdate_productVariantStocksUpdate_productVariant_weight | null; } export interface VariantUpdate_productVariantStocksUpdate { @@ -337,4 +351,5 @@ export interface VariantUpdateVariables { sku?: string | null; trackInventory: boolean; stocks: StockInput[]; + weight?: any | null; } diff --git a/src/products/utils/data.ts b/src/products/utils/data.ts index e0ac8391f..1db290718 100644 --- a/src/products/utils/data.ts +++ b/src/products/utils/data.ts @@ -181,6 +181,7 @@ export interface ProductUpdatePageFormData { seoTitle: string; sku: string; trackInventory: boolean; + weight: string; } export function getProductUpdatePageFormData( @@ -210,7 +211,8 @@ export function getProductUpdatePageFormData( : undefined, "" ), - trackInventory: !!product?.variants[0]?.trackInventory + trackInventory: !!product?.variants[0]?.trackInventory, + weight: product?.weight?.value.toString() || "" }; } diff --git a/src/products/views/ProductCreate.tsx b/src/products/views/ProductCreate.tsx index 0ef9ee3db..342596a34 100644 --- a/src/products/views/ProductCreate.tsx +++ b/src/products/views/ProductCreate.tsx @@ -10,7 +10,7 @@ import { useWarehouseList } from "@saleor/warehouses/queries"; import React from "react"; import { useIntl } from "react-intl"; -import { decimal, maybe } from "../../misc"; +import { decimal, maybe, weight } from "../../misc"; import ProductCreatePage, { ProductCreatePageSubmitData } from "../components/ProductCreatePage"; @@ -96,7 +96,8 @@ export const ProductCreateView: React.FC = () => { quantity: parseInt(stock.value, 0), warehouse: stock.id })), - trackInventory: formData.trackInventory + trackInventory: formData.trackInventory, + weight: weight(formData.weight) } }); }; @@ -158,6 +159,7 @@ export const ProductCreateView: React.FC = () => { warehouses={ warehouses.data?.warehouses.edges.map(edge => edge.node) || [] } + weightUnit={shop?.defaultWeightUnit} /> ); diff --git a/src/products/views/ProductUpdate/ProductUpdate.tsx b/src/products/views/ProductUpdate/ProductUpdate.tsx index 131fa6d07..77b4ea440 100644 --- a/src/products/views/ProductUpdate/ProductUpdate.tsx +++ b/src/products/views/ProductUpdate/ProductUpdate.tsx @@ -9,6 +9,7 @@ import { DEFAULT_INITIAL_SEARCH_DATA } from "@saleor/config"; import useBulkActions from "@saleor/hooks/useBulkActions"; import useNavigator from "@saleor/hooks/useNavigator"; import useNotifier from "@saleor/hooks/useNotifier"; +import useShop from "@saleor/hooks/useShop"; import { commonMessages } from "@saleor/intl"; import useCategorySearch from "@saleor/searches/useCategorySearch"; import useCollectionSearch from "@saleor/searches/useCollectionSearch"; @@ -75,6 +76,7 @@ export const ProductUpdate: React.FC = ({ id, params }) => { first: 50 } }); + const shop = useShop(); const [openModal, closeModal] = createDialogActionHandlers< ProductUrlDialog, @@ -217,6 +219,7 @@ export const ProductUpdate: React.FC = ({ id, params }) => { = ({ productId, params }) => { + const shop = useShop(); const navigate = useNavigator(); const notify = useNotifier(); const intl = useIntl(); @@ -133,6 +135,7 @@ export const ProductVariant: React.FC = ({ <> = ({ stocks: data.updateStocks.map( mapFormsetStockToStockInput ), - trackInventory: data.trackInventory + trackInventory: data.trackInventory, + weight: weight(data.weight) }) } onVariantClick={variantId => { diff --git a/src/products/views/ProductVariantCreate.tsx b/src/products/views/ProductVariantCreate.tsx index 2d9466a7d..5e5cef09a 100644 --- a/src/products/views/ProductVariantCreate.tsx +++ b/src/products/views/ProductVariantCreate.tsx @@ -8,7 +8,7 @@ import { useWarehouseList } from "@saleor/warehouses/queries"; import React from "react"; import { useIntl } from "react-intl"; -import { decimal } from "../../misc"; +import { decimal, weight } from "../../misc"; import ProductVariantCreatePage, { ProductVariantCreatePageSubmitData } from "../components/ProductVariantCreatePage"; @@ -83,7 +83,8 @@ export const ProductVariant: React.FC = ({ quantity: parseInt(stock.value, 0), warehouse: stock.id })), - trackInventory: true + trackInventory: true, + weight: weight(formData.weight) } } }); @@ -121,6 +122,7 @@ export const ProductVariant: React.FC = ({ edge => edge.node ) || [] } + weightUnit={shop?.defaultWeightUnit} /> ); diff --git a/src/shipping/views/ShippingZoneDetails/data.ts b/src/shipping/views/ShippingZoneDetails/data.ts index 809dd0d46..95879b5ed 100644 --- a/src/shipping/views/ShippingZoneDetails/data.ts +++ b/src/shipping/views/ShippingZoneDetails/data.ts @@ -1,10 +1,15 @@ import { CreateShippingRateVariables } from "@saleor/shipping/types/CreateShippingRate"; +import { ShippingZone_shippingZone_shippingMethods } from "@saleor/shipping/types/ShippingZone"; import { UpdateShippingRateVariables } from "@saleor/shipping/types/UpdateShippingRate"; import { ShippingZoneUrlQueryParams } from "@saleor/shipping/urls"; import { ShippingMethodTypeEnum } from "@saleor/types/globalTypes"; import { FormData as ShippingZoneRateDialogFormData } from "../../components/ShippingZoneRateDialog"; +function getValue(value: string, hasLimits: boolean): number | null { + return hasLimits ? null : parseFloat(value); +} + export function getCreateShippingRateVariables( data: ShippingZoneRateDialogFormData, params: ShippingZoneUrlQueryParams, @@ -14,28 +19,20 @@ export function getCreateShippingRateVariables( input: { maximumOrderPrice: params.type === ShippingMethodTypeEnum.PRICE - ? data.noLimits - ? null - : parseFloat(data.maxValue) + ? getValue(data.maxValue, data.noLimits) : null, maximumOrderWeight: params.type === ShippingMethodTypeEnum.WEIGHT - ? data.noLimits - ? null - : parseFloat(data.maxValue) + ? getValue(data.maxValue, data.noLimits) : null, minimumOrderPrice: params.type === ShippingMethodTypeEnum.PRICE - ? data.noLimits - ? null - : parseFloat(data.minValue) + ? getValue(data.maxValue, data.noLimits) : null, minimumOrderWeight: params.type === ShippingMethodTypeEnum.WEIGHT - ? data.noLimits - ? null - : parseFloat(data.minValue) + ? getValue(data.minValue, data.noLimits) : null, name: data.name, price: data.isFree ? 0 : parseFloat(data.price), @@ -47,25 +44,36 @@ export function getCreateShippingRateVariables( export function getUpdateShippingRateVariables( data: ShippingZoneRateDialogFormData, - params: ShippingZoneUrlQueryParams, - id: string + shippingRate: ShippingZone_shippingZone_shippingMethods, + shippingZoneId: string ): UpdateShippingRateVariables { - const isPriceType = data.type === ShippingMethodTypeEnum.PRICE; - const parsedMinValue = parseFloat(data.minValue); - const parsedMaxValue = parseFloat(data.maxValue); - const isPriceSet = !data.noLimits && isPriceType; - const isWeightSet = !data.noLimits && !isPriceType; - return { - id: params.id, + const base: UpdateShippingRateVariables = { + id: shippingRate.id, input: { - maximumOrderPrice: isPriceSet ? parsedMaxValue : null, - maximumOrderWeight: isWeightSet ? parsedMaxValue : null, - minimumOrderPrice: isPriceSet ? parsedMinValue : null, - minimumOrderWeight: isWeightSet ? parsedMinValue : null, name: data.name, price: data.isFree ? 0 : parseFloat(data.price), - shippingZone: id, - type: data.type + shippingZone: shippingZoneId, + type: shippingRate.type + } + }; + + if (shippingRate.type === ShippingMethodTypeEnum.PRICE) { + return { + ...base, + input: { + ...base.input, + maximumOrderPrice: getValue(data.maxValue, data.noLimits), + minimumOrderPrice: getValue(data.minValue, data.noLimits) + } + }; + } + + return { + ...base, + input: { + ...base.input, + maximumOrderWeight: getValue(data.maxValue, data.noLimits), + minimumOrderWeight: getValue(data.minValue, data.noLimits) } }; } diff --git a/src/shipping/views/ShippingZoneDetails/index.tsx b/src/shipping/views/ShippingZoneDetails/index.tsx index d2e6f5a21..1ebaf32cc 100644 --- a/src/shipping/views/ShippingZoneDetails/index.tsx +++ b/src/shipping/views/ShippingZoneDetails/index.tsx @@ -227,9 +227,15 @@ const ShippingZoneDetails: React.FC = ({ disabled={updateShippingRateOpts.loading} errors={updateShippingRateOpts.data?.shippingPriceUpdate.errors || []} onClose={closeModal} - onSubmit={data => + onSubmit={submitData => updateShippingRate({ - variables: getUpdateShippingRateVariables(data, params, id) + variables: getUpdateShippingRateVariables( + submitData, + data?.shippingZone?.shippingMethods.find( + shippingMethod => shippingMethod.id === params.id + ), + id + ) }) } open={params.action === "edit-rate"} diff --git a/src/storybook/__snapshots__/Stories.test.ts.snap b/src/storybook/__snapshots__/Stories.test.ts.snap index a6510e533..029ec1c32 100644 --- a/src/storybook/__snapshots__/Stories.test.ts.snap +++ b/src/storybook/__snapshots__/Stories.test.ts.snap @@ -9299,6 +9299,76 @@ exports[`Storyshots Orders / OrderHistory default 1`] = ` +
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
@@ -67159,6 +67229,76 @@ exports[`Storyshots Views / Orders / Order details cancelled 1`] = `
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
@@ -68285,6 +68425,76 @@ exports[`Storyshots Views / Orders / Order details default 1`] = `
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
@@ -69441,6 +69651,76 @@ exports[`Storyshots Views / Orders / Order details fulfilled 1`] = `
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
@@ -71228,6 +71508,76 @@ exports[`Storyshots Views / Orders / Order details no customer note 1`] = `
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
@@ -72384,6 +72734,76 @@ exports[`Storyshots Views / Orders / Order details no payment 1`] = `
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
@@ -73540,6 +73960,76 @@ exports[`Storyshots Views / Orders / Order details no shipping address 1`] = `
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
@@ -74696,6 +75186,76 @@ exports[`Storyshots Views / Orders / Order details partially fulfilled 1`] = `
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
@@ -75852,6 +76412,76 @@ exports[`Storyshots Views / Orders / Order details payment confirmed 1`] = `
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
@@ -77008,6 +77638,76 @@ exports[`Storyshots Views / Orders / Order details payment error 1`] = `
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
@@ -78164,6 +78864,76 @@ exports[`Storyshots Views / Orders / Order details pending payment 1`] = `
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
@@ -79320,6 +80090,76 @@ exports[`Storyshots Views / Orders / Order details refunded payment 1`] = `
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
@@ -80476,6 +81316,76 @@ exports[`Storyshots Views / Orders / Order details rejected payment 1`] = `
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
@@ -81632,6 +82542,76 @@ exports[`Storyshots Views / Orders / Order details unfulfilled 1`] = `
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
+
+
+
+
+ +
+
+
+
+
+ This is note +
+
+
+
@@ -109964,6 +110944,84 @@ exports[`Storyshots Views / Products / Create product variant add first variant
+
+
+ + Shipping + +
+
+
+
+
+
+
+ +
+ +
+
+ kg +
+
+ +
+
+
+
+
+
@@ -110558,6 +111616,84 @@ exports[`Storyshots Views / Products / Create product variant default 1`] = `
+
+
+ + Shipping + +
+
+
+
+
+
+
+ +
+ +
+
+ kg +
+
+ +
+
+
+
+
+
@@ -111076,6 +112212,85 @@ exports[`Storyshots Views / Products / Create product variant when loading data
+
+
+ + Shipping + +
+
+
+
+
+
+
+ +
+ +
+
+ kg +
+
+ +
+
+
+
+
+
@@ -111686,6 +112901,84 @@ exports[`Storyshots Views / Products / Create product variant with errors 1`] =
+
+
+ + Shipping + +
+
+
+
+
+
+
+ +
+ +
+
+ kg +
+
+ +
+
+
+
+
+
@@ -116221,6 +117514,84 @@ Ctrl + K"
+
+
+ + Shipping + +
+
+
+
+
+
+
+ +
+ +
+
+ kg +
+
+ +
+
+
+
+
+
@@ -118018,6 +119389,84 @@ Ctrl + K"
+
+
+ + Shipping + +
+
+
+
+
+
+
+ +
+ +
+
+ kg +
+
+ +
+
+
+
+
+
@@ -120971,6 +122420,85 @@ Ctrl + K"
+
+
+ + Shipping + +
+
+
+
+
+
+
+ +
+ +
+
+ kg +
+
+ +
+
+
+
+
+
@@ -124360,6 +125888,84 @@ Ctrl + K"
+
+
+ + Shipping + +
+
+
+
+
+
+
+ +
+ +
+
+ kg +
+
+ +
+
+
+
+
+
@@ -131245,6 +132851,84 @@ exports[`Storyshots Views / Products / Product variant details attribute errors
+
+
+ + Shipping + +
+
+
+
+
+
+
+ +
+ +
+
+ kg +
+
+ +
+
+
+
+
+
@@ -132137,6 +133821,84 @@ exports[`Storyshots Views / Products / Product variant details when loaded data
+
+
+ + Shipping + +
+
+
+
+
+
+
+ +
+ +
+
+ kg +
+
+ +
+
+
+
+
+
@@ -132795,6 +134557,85 @@ exports[`Storyshots Views / Products / Product variant details when loading data
+
+
+ + Shipping + +
+
+
+
+
+
+
+ +
+ +
+
+ kg +
+
+ +
+
+
+
+
+
@@ -153552,8 +155393,8 @@ exports[`Storyshots Views / Warehouses / Warehouse details default 1`] = ` class="MuiFormControl-root-id MuiTextField-root-id MuiFormControl-fullWidth-id" > @@ -153568,7 +155409,7 @@ exports[`Storyshots Views / Warehouses / Warehouse details default 1`] = ` autocomplete="none" class="MuiInputBase-input-id MuiOutlinedInput-input-id MuiInputBase-inputAdornedEnd-id MuiOutlinedInput-inputAdornedEnd-id" type="text" - value="" + value="Szwecja" />
​ @@ -154111,8 +155952,8 @@ exports[`Storyshots Views / Warehouses / Warehouse details form errors 1`] = ` class="MuiFormControl-root-id MuiTextField-root-id MuiFormControl-fullWidth-id" > @@ -154127,7 +155968,7 @@ exports[`Storyshots Views / Warehouses / Warehouse details form errors 1`] = ` autocomplete="none" class="MuiInputBase-input-id MuiOutlinedInput-input-id MuiInputBase-inputAdornedEnd-id MuiOutlinedInput-inputAdornedEnd-id" type="text" - value="" + value="Szwecja" />
​ @@ -154162,7 +156003,7 @@ exports[`Storyshots Views / Warehouses / Warehouse details form errors 1`] = `

Invalid value

diff --git a/src/storybook/stories/products/ProductCreatePage.tsx b/src/storybook/stories/products/ProductCreatePage.tsx index 9aaa25526..789bcc42f 100644 --- a/src/storybook/stories/products/ProductCreatePage.tsx +++ b/src/storybook/stories/products/ProductCreatePage.tsx @@ -34,6 +34,7 @@ storiesOf("Views / Products / Create product", module) onSubmit={() => undefined} saveButtonBarState="default" warehouses={warehouseList} + weightUnit="kg" /> )) .add("When loading", () => ( @@ -55,6 +56,7 @@ storiesOf("Views / Products / Create product", module) onSubmit={() => undefined} saveButtonBarState="default" warehouses={undefined} + weightUnit="kg" /> )) .add("form errors", () => ( @@ -82,5 +84,6 @@ storiesOf("Views / Products / Create product", module) onSubmit={() => undefined} saveButtonBarState="default" warehouses={warehouseList} + weightUnit="kg" /> )); diff --git a/src/storybook/stories/products/ProductUpdatePage.tsx b/src/storybook/stories/products/ProductUpdatePage.tsx index aec849dd5..7c00bcf01 100644 --- a/src/storybook/stories/products/ProductUpdatePage.tsx +++ b/src/storybook/stories/products/ProductUpdatePage.tsx @@ -19,6 +19,7 @@ const props: ProductUpdatePageProps = { ...listActionsProps, categories: [product.category], collections, + defaultWeightUnit: "kg", disabled: false, errors: [], fetchCategories: () => undefined, diff --git a/src/storybook/stories/products/ProductVariantCreatePage.tsx b/src/storybook/stories/products/ProductVariantCreatePage.tsx index 613818bd3..fee28f4a7 100644 --- a/src/storybook/stories/products/ProductVariantCreatePage.tsx +++ b/src/storybook/stories/products/ProductVariantCreatePage.tsx @@ -15,6 +15,7 @@ storiesOf("Views / Products / Create product variant", module) .add("default", () => ( ( ( ( ( ( ( undefined} diff --git a/src/utils/errors/product.ts b/src/utils/errors/product.ts index 215db391b..976010a4b 100644 --- a/src/utils/errors/product.ts +++ b/src/utils/errors/product.ts @@ -14,15 +14,26 @@ const messages = defineMessages({ attributeCannotBeAssigned: { defaultMessage: "This attribute cannot be assigned to this product type" }, + attributeRequired: { + defaultMessage: "All attributes should have value", + description: "product attribute error" + }, attributeVariantsDisabled: { defaultMessage: "Variants are disabled in this product type" }, + duplicatedInputItem: { + defaultMessage: "Variant with these attributes already exists" + }, skuUnique: { defaultMessage: "SKUs must be unique", description: "bulk variant create error" }, variantNoDigitalContent: { defaultMessage: "This variant does not have any digital content" + }, + variantUnique: { + defaultMessage: "This variant already exists", + description: "product attribute error" } }); @@ -38,6 +49,8 @@ function getProductErrorMessage( return intl.formatMessage(messages.attributeCannotBeAssigned); case ProductErrorCode.ATTRIBUTE_VARIANTS_DISABLED: return intl.formatMessage(messages.attributeVariantsDisabled); + case ProductErrorCode.DUPLICATED_INPUT_ITEM: + return intl.formatMessage(messages.duplicatedInputItem); case ProductErrorCode.GRAPHQL_ERROR: return intl.formatMessage(commonErrorMessages.graphqlError); case ProductErrorCode.REQUIRED: @@ -54,6 +67,24 @@ function getProductErrorMessage( return undefined; } +export function getProductVariantAttributeErrorMessage( + err: Omit | undefined, + intl: IntlShape +): string { + if (err) { + switch (err.code) { + case ProductErrorCode.REQUIRED: + return intl.formatMessage(messages.attributeRequired); + case ProductErrorCode.UNIQUE: + return intl.formatMessage(messages.variantUnique); + default: + return getProductErrorMessage(err, intl); + } + } + + return undefined; +} + export function getBulkProductErrorMessage( err: BulkProductErrorFragment | undefined, intl: IntlShape diff --git a/src/warehouses/components/WarehouseDetailsPage/WarehouseDetailsPage.tsx b/src/warehouses/components/WarehouseDetailsPage/WarehouseDetailsPage.tsx index 066857d24..188ed4f51 100644 --- a/src/warehouses/components/WarehouseDetailsPage/WarehouseDetailsPage.tsx +++ b/src/warehouses/components/WarehouseDetailsPage/WarehouseDetailsPage.tsx @@ -51,7 +51,9 @@ const WarehouseDetailsPage: React.FC = ({ onSubmit }) => { const intl = useIntl(); - const [displayCountry, setDisplayCountry] = useStateFromProps(""); + const [displayCountry, setDisplayCountry] = useStateFromProps( + warehouse?.address?.country.country || "" + ); const { errors: validationErrors,