diff --git a/CHANGELOG.md b/CHANGELOG.md index 409e21ca3..664aead0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ All notable, unreleased changes to this project will be documented in this file. - Add shipping methods to translation section - #864 by @marekchoinski - New Miscellaneous and Product refunds - #870 by @orzechdev - Add zip code exclusion - #877 by @dominik-zeglen +- Update quantity column in Inventory part of Product Variant view - #904 by @dominik-zeglen # 2.11.1 diff --git a/locale/defaultMessages.json b/locale/defaultMessages.json index b5c5490e2..babedb700 100644 --- a/locale/defaultMessages.json +++ b/locale/defaultMessages.json @@ -4863,10 +4863,6 @@ "context": "tabel column header", "string": "Warehouse Name" }, - "src_dot_products_dot_components_dot_ProductStocks_dot_2729628316": { - "context": "tabel column header", - "string": "Quantity Available" - }, "src_dot_products_dot_components_dot_ProductStocks_dot_2796503714": { "context": "header", "string": "Quantity" @@ -6696,6 +6692,14 @@ "src_dot_yes": { "string": "Yes" }, + "tableColAllocated": { + "context": "table column header, allocated product quantity", + "string": "Allocated" + }, + "tableColQuantity": { + "context": "table column header", + "string": "Quantity" + }, "voucherDetailsUnassignCategory": { "context": "unassign category from voucher, button", "string": "Unassign" diff --git a/src/products/components/ProductStocks/ProductStocks.tsx b/src/products/components/ProductStocks/ProductStocks.tsx index 121f80afc..b1564c0de 100644 --- a/src/products/components/ProductStocks/ProductStocks.tsx +++ b/src/products/components/ProductStocks/ProductStocks.tsx @@ -33,7 +33,13 @@ import createNonNegativeValueChangeHandler from "@saleor/utils/handlers/nonNegat import React from "react"; import { FormattedMessage, useIntl } from "react-intl"; -export type ProductStockInput = FormsetAtomicData; +export interface ProductStockFormsetData { + quantityAllocated: number; +} +export type ProductStockInput = FormsetAtomicData< + ProductStockFormsetData, + string +>; export interface ProductStockFormData { sku: string; trackInventory: boolean; @@ -62,7 +68,7 @@ const useStyles = makeStyles( colName: {}, colQuantity: { textAlign: "right", - width: 200 + width: 150 }, editWarehouses: { marginRight: -theme.spacing() @@ -71,9 +77,6 @@ const useStyles = makeStyles( padding: theme.spacing(1.5), textAlign: "right" }, - inputComponent: { - width: 100 - }, menuItem: { "&:not(:last-of-type)": { marginBottom: theme.spacing(2) @@ -223,6 +226,11 @@ const ProductStocks: React.FC = ({ {warehouses?.length > 0 && ( + + + + + @@ -233,8 +241,16 @@ const ProductStocks: React.FC = ({ + + + @@ -251,9 +267,11 @@ const ProductStocks: React.FC = ({ {stock.label} + + {stock.data.quantityAllocated} + = ({ })} {warehousesToAssign.length > 0 && ( - + + stocks: FormsetData ) => { if (product?.productType?.hasVariants) { return { addStocks: [], removeStocks: [], updateStocks: [] }; diff --git a/src/products/components/ProductVariantPage/form.tsx b/src/products/components/ProductVariantPage/form.tsx index 8e905bd35..eb9c1fce7 100644 --- a/src/products/components/ProductVariantPage/form.tsx +++ b/src/products/components/ProductVariantPage/form.tsx @@ -114,7 +114,11 @@ function useProductVariantUpdateForm( const handleStockAdd = (id: string) => { triggerChange(); stocks.add({ - data: null, + data: { + quantityAllocated: + variant?.stocks?.find(stock => stock.warehouse.id === id) + ?.quantityAllocated || 0 + }, id, label: opts.warehouses.find(warehouse => warehouse.id === id).name, value: "0" diff --git a/src/products/utils/data.ts b/src/products/utils/data.ts index 0c8fd7626..6e12826ba 100644 --- a/src/products/utils/data.ts +++ b/src/products/utils/data.ts @@ -112,7 +112,9 @@ export function getStockInputFromVariant( ): ProductStockInput[] { return ( variant?.stocks.map(stock => ({ - data: null, + data: { + quantityAllocated: stock.quantityAllocated + }, id: stock.warehouse.id, label: stock.warehouse.name, value: stock.quantity.toString() @@ -137,7 +139,9 @@ export function getStockInputFromProduct( product: ProductDetails_product ): ProductStockInput[] { return product?.variants[0]?.stocks.map(stock => ({ - data: null, + data: { + quantityAllocated: stock?.quantityAllocated + }, id: stock.warehouse.id, label: stock.warehouse.name, value: stock.quantity.toString() diff --git a/src/storybook/__snapshots__/Stories.test.ts.snap b/src/storybook/__snapshots__/Stories.test.ts.snap index 4bc4c697f..d874fd1c6 100644 --- a/src/storybook/__snapshots__/Stories.test.ts.snap +++ b/src/storybook/__snapshots__/Stories.test.ts.snap @@ -163594,6 +163594,17 @@ exports[`Storyshots Views / Products / Create product variant add first variant
+ + + + + @@ -163610,7 +163621,13 @@ exports[`Storyshots Views / Products / Create product variant add first variant class="MuiTableCell-root-id MuiTableCell-head-id ProductStocks-colQuantity-id" scope="col" > - Quantity Available + Allocated + + + + + + @@ -164670,7 +164698,13 @@ exports[`Storyshots Views / Products / Create product variant default 1`] = ` class="MuiTableCell-root-id MuiTableCell-head-id ProductStocks-colQuantity-id" scope="col" > - Quantity Available + Allocated + + + + + + @@ -166620,7 +166665,13 @@ exports[`Storyshots Views / Products / Create product variant when loading data class="MuiTableCell-root-id MuiTableCell-head-id ProductStocks-colQuantity-id" scope="col" > - Quantity Available + Allocated + + + + + + @@ -167698,7 +167760,13 @@ exports[`Storyshots Views / Products / Create product variant with errors 1`] = class="MuiTableCell-root-id MuiTableCell-head-id ProductStocks-colQuantity-id" scope="col" > - Quantity Available + Allocated + + + + + + @@ -172047,7 +172126,13 @@ exports[`Storyshots Views / Products / Product edit no stock and no variants 1`] class="MuiTableCell-root-id MuiTableCell-head-id ProductStocks-colQuantity-id" scope="col" > - Quantity Available + Allocated + + + + + + @@ -175444,7 +175540,13 @@ exports[`Storyshots Views / Products / Product edit no variants 1`] = ` class="MuiTableCell-root-id MuiTableCell-head-id ProductStocks-colQuantity-id" scope="col" > - Quantity Available + Allocated + + + + + + + @@ -178643,7 +178766,13 @@ exports[`Storyshots Views / Products / Product edit when loading data 1`] = ` class="MuiTableCell-root-id MuiTableCell-head-id ProductStocks-colQuantity-id" scope="col" > - Quantity Available + Allocated + + + + + + @@ -181773,7 +181913,13 @@ exports[`Storyshots Views / Products / Product edit when product has no variants class="MuiTableCell-root-id MuiTableCell-head-id ProductStocks-colQuantity-id" scope="col" > - Quantity Available + Allocated + + + + + + + @@ -194609,7 +194776,13 @@ exports[`Storyshots Views / Products / Product variant details attribute errors class="MuiTableCell-root-id MuiTableCell-head-id ProductStocks-colQuantity-id" scope="col" > - Quantity Available + Allocated + + + + + + + @@ -197586,7 +197780,13 @@ exports[`Storyshots Views / Products / Product variant details when loaded data class="MuiTableCell-root-id MuiTableCell-head-id ProductStocks-colQuantity-id" scope="col" > - Quantity Available + Allocated + + + + + + + @@ -198849,7 +199070,13 @@ exports[`Storyshots Views / Products / Product variant details when loading data class="MuiTableCell-root-id MuiTableCell-head-id ProductStocks-colQuantity-id" scope="col" > - Quantity Available + Allocated + +
+ Quantity
+
+ Quantity
+
+ Quantity
+
+ Quantity
+
+ Quantity
+
+ Quantity C our wares + + 0 +
Be stocked
+ 2 +
+
+ Quantity
+
+ Quantity C our wares + + 0 +
Be stocked
+ 2 +
+
+ Quantity Warehouse 1 + + 1 +
Warehouse 2
+ 2 +
+
+ Quantity Warehouse 1 + + 1 +
Warehouse 2
+ 2 +
+
+ Quantity