From cbdda30a3aa87e826f3504650c46638022e5033d Mon Sep 17 00:00:00 2001 From: Grzegorz Derdak Date: Wed, 28 Oct 2020 12:42:28 +0100 Subject: [PATCH] Update logic based on new API fields --- .../OrderFulfillPage/OrderFulfillPage.tsx | 20 ++++++++-- .../components/OrderFulfillPage/fixtures.ts | 3 ++ src/orders/queries.ts | 6 +++ src/orders/types/OrderFulfillData.ts | 13 +++++++ .../__snapshots__/Stories.test.ts.snap | 38 +++++++++---------- 5 files changed, 57 insertions(+), 23 deletions(-) diff --git a/src/orders/components/OrderFulfillPage/OrderFulfillPage.tsx b/src/orders/components/OrderFulfillPage/OrderFulfillPage.tsx index ffa1fdbb2..eb882f046 100644 --- a/src/orders/components/OrderFulfillPage/OrderFulfillPage.tsx +++ b/src/orders/components/OrderFulfillPage/OrderFulfillPage.tsx @@ -257,7 +257,7 @@ const OrderFulfillPage: React.FC = props => { {renderCollection( order?.lines.filter(line => getRemainingQuantity(line) > 0), - (line, lineIndex) => { + (line: OrderFulfillData_order_lines, lineIndex) => { if (!line) { return ( @@ -340,6 +340,17 @@ const OrderFulfillPage: React.FC = props => { ); } + const warehouseAllocation = line.allocations.find( + allocation => + allocation.warehouse.id === warehouse.id + ); + const allocatedQuantityForLine = + warehouseAllocation?.quantity || 0; + const availableQuantity = + warehouseStock.quantity - + warehouseStock.quantityAllocated + + allocatedQuantityForLine; + return ( = props => { ), max: ( line.variant.trackInventory && - warehouseStock.quantity + availableQuantity ).toString(), min: 0, style: { textAlign: "right" } @@ -384,7 +395,7 @@ const OrderFulfillPage: React.FC = props => { overfulfill || (line.variant.trackInventory && formsetStock.quantity > - warehouseStock.quantityAllocated) || + availableQuantity) || !!errors?.find( err => err.warehouse === warehouse.id && @@ -399,7 +410,7 @@ const OrderFulfillPage: React.FC = props => {
- / {warehouseStock.quantityAllocated} + / {availableQuantity}
) }} @@ -407,6 +418,7 @@ const OrderFulfillPage: React.FC = props => {
); })} + - / 2 + / 758