Skip to content

Commit

Permalink
Update logic based on new API fields
Browse files Browse the repository at this point in the history
  • Loading branch information
GrzegorzDerdak committed Oct 28, 2020
1 parent 9036294 commit f80f6e4
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 23 deletions.
22 changes: 18 additions & 4 deletions src/orders/components/OrderFulfillPage/OrderFulfillPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { renderCollection } from "@saleor/misc";
import { FulfillOrder_orderFulfill_errors } from "@saleor/orders/types/FulfillOrder";
import {
OrderFulfillData_order,
OrderFulfillData_order_allocation,
OrderFulfillData_order_lines
} from "@saleor/orders/types/OrderFulfillData";
import {
Expand Down Expand Up @@ -257,7 +258,7 @@ const OrderFulfillPage: React.FC<OrderFulfillPageProps> = props => {
<TableBody>
{renderCollection(
order?.lines.filter(line => getRemainingQuantity(line) > 0),
(line, lineIndex) => {
(line: OrderFulfillData_order_lines, lineIndex) => {
if (!line) {
return (
<TableRow key={lineIndex}>
Expand Down Expand Up @@ -340,6 +341,18 @@ const OrderFulfillPage: React.FC<OrderFulfillPageProps> = props => {
);
}

const allocation: OrderFulfillData_order_allocation = line.allocations.find(
allocation =>
allocation.warehouse.id === warehouse.id
);

const availableQuantity = allocation
? warehouseStock.quantity -
allocation.quantity +
line.quantity
: warehouseStock.quantity -
warehouseStock.quantityAllocated;

return (
<TableCell
className={classes.colQuantity}
Expand All @@ -357,7 +370,7 @@ const OrderFulfillPage: React.FC<OrderFulfillPageProps> = props => {
),
max: (
line.variant.trackInventory &&
warehouseStock.quantity
availableQuantity
).toString(),
min: 0,
style: { textAlign: "right" }
Expand All @@ -384,7 +397,7 @@ const OrderFulfillPage: React.FC<OrderFulfillPageProps> = props => {
overfulfill ||
(line.variant.trackInventory &&
formsetStock.quantity >
warehouseStock.quantityAllocated) ||
availableQuantity) ||
!!errors?.find(
err =>
err.warehouse === warehouse.id &&
Expand All @@ -399,14 +412,15 @@ const OrderFulfillPage: React.FC<OrderFulfillPageProps> = props => {
<div
className={classes.remainingQuantity}
>
/ {warehouseStock.quantityAllocated}
/ {availableQuantity}
</div>
)
}}
/>
</TableCell>
);
})}

<TableCell
className={classes.colQuantityTotal}
key="total"
Expand Down
3 changes: 3 additions & 0 deletions src/orders/components/OrderFulfillPage/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const orderToFulfill: OrderFulfillData_order = {
productName: "T-Shirt",
quantity: 3,
quantityFulfilled: 1,
allocations: [],
variant: {
__typename: "ProductVariant",
id: "UHJvZHVjdFZhcmlhbnQ6Mjk2",
Expand Down Expand Up @@ -76,6 +77,7 @@ export const orderToFulfill: OrderFulfillData_order = {
productName: "Lemon Juice",
quantity: 4,
quantityFulfilled: 0,
allocations: [],
variant: {
__typename: "ProductVariant",
id: "UHJvZHVjdFZhcmlhbnQ6MTgx",
Expand Down Expand Up @@ -130,6 +132,7 @@ export const orderToFulfill: OrderFulfillData_order = {
productName: "Orange Juice",
quantity: 3,
quantityFulfilled: 2,
allocations: [],
variant: {
__typename: "ProductVariant",
id: "UHJvZHVjdFZhcmlhbnQ6MTgy",
Expand Down
6 changes: 6 additions & 0 deletions src/orders/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ const orderFulfillData = gql`
isShippingRequired
productName
quantity
allocations {
quantity
warehouse {
id
}
}
quantityFulfilled
variant {
id
Expand Down
13 changes: 13 additions & 0 deletions src/orders/types/OrderFulfillData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface OrderFulfillData_order_lines {
productName: string;
quantity: number;
quantityFulfilled: number;
allocations: OrderFulfillData_order_allocation[];
variant: OrderFulfillData_order_lines_variant | null;
thumbnail: OrderFulfillData_order_lines_thumbnail | null;
}
Expand All @@ -70,3 +71,15 @@ export interface OrderFulfillData {
export interface OrderFulfillDataVariables {
orderId: string;
}

export interface OrderFulfillData_order_allocation {
__typename: "Allocation";
id: string;
quantity: number;
warehouse: OrderFulfillData_order_allocation_warehouse;
}

export interface OrderFulfillData_order_allocation_warehouse {
__typename: "Warehouse";
id: string;
}
38 changes: 19 additions & 19 deletions src/storybook/__snapshots__/Stories.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -85627,7 +85627,7 @@ exports[`Storyshots Views / Orders / Fulfill order default 1`] = `
<input
aria-invalid="false"
class="MuiInputBase-input-id MuiOutlinedInput-input-id OrderFulfillPage-quantityInnerInput-id MuiInputBase-inputAdornedEnd-id MuiOutlinedInput-inputAdornedEnd-id"
max="760"
max="758"
min="0"
style="text-align:right"
type="number"
Expand All @@ -85636,7 +85636,7 @@ exports[`Storyshots Views / Orders / Fulfill order default 1`] = `
<div
class="OrderFulfillPage-remainingQuantity-id"
>
/ 2
/ 758
</div>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -85667,7 +85667,7 @@ exports[`Storyshots Views / Orders / Fulfill order default 1`] = `
<input
aria-invalid="false"
class="MuiInputBase-input-id MuiOutlinedInput-input-id OrderFulfillPage-quantityInnerInput-id MuiInputBase-inputAdornedEnd-id MuiOutlinedInput-inputAdornedEnd-id"
max="760"
max="727"
min="0"
style="text-align:right"
type="number"
Expand All @@ -85676,7 +85676,7 @@ exports[`Storyshots Views / Orders / Fulfill order default 1`] = `
<div
class="OrderFulfillPage-remainingQuantity-id"
>
/ 33
/ 727
</div>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -85707,7 +85707,7 @@ exports[`Storyshots Views / Orders / Fulfill order default 1`] = `
<input
aria-invalid="false"
class="MuiInputBase-input-id MuiOutlinedInput-input-id OrderFulfillPage-quantityInnerInput-id MuiInputBase-inputAdornedEnd-id MuiOutlinedInput-inputAdornedEnd-id"
max="760"
max="756"
min="0"
style="text-align:right"
type="number"
Expand All @@ -85716,7 +85716,7 @@ exports[`Storyshots Views / Orders / Fulfill order default 1`] = `
<div
class="OrderFulfillPage-remainingQuantity-id"
>
/ 4
/ 756
</div>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -85801,7 +85801,7 @@ exports[`Storyshots Views / Orders / Fulfill order default 1`] = `
<div
class="OrderFulfillPage-remainingQuantity-id"
>
/ 0
/ 587
</div>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -85837,7 +85837,7 @@ exports[`Storyshots Views / Orders / Fulfill order default 1`] = `
<input
aria-invalid="false"
class="MuiInputBase-input-id MuiOutlinedInput-input-id OrderFulfillPage-quantityInnerInput-id MuiInputBase-inputAdornedEnd-id MuiOutlinedInput-inputAdornedEnd-id"
max="587"
max="586"
min="0"
style="text-align:right"
type="number"
Expand All @@ -85846,7 +85846,7 @@ exports[`Storyshots Views / Orders / Fulfill order default 1`] = `
<div
class="OrderFulfillPage-remainingQuantity-id"
>
/ 1
/ 586
</div>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -86280,7 +86280,7 @@ exports[`Storyshots Views / Orders / Fulfill order error 1`] = `
<input
aria-invalid="false"
class="MuiInputBase-input-id MuiOutlinedInput-input-id OrderFulfillPage-quantityInnerInput-id MuiInputBase-inputAdornedEnd-id MuiOutlinedInput-inputAdornedEnd-id"
max="760"
max="758"
min="0"
style="text-align:right"
type="number"
Expand All @@ -86289,7 +86289,7 @@ exports[`Storyshots Views / Orders / Fulfill order error 1`] = `
<div
class="OrderFulfillPage-remainingQuantity-id"
>
/ 2
/ 758
</div>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -86320,7 +86320,7 @@ exports[`Storyshots Views / Orders / Fulfill order error 1`] = `
<input
aria-invalid="false"
class="MuiInputBase-input-id MuiOutlinedInput-input-id OrderFulfillPage-quantityInnerInput-id MuiInputBase-inputAdornedEnd-id MuiOutlinedInput-inputAdornedEnd-id"
max="760"
max="727"
min="0"
style="text-align:right"
type="number"
Expand All @@ -86329,7 +86329,7 @@ exports[`Storyshots Views / Orders / Fulfill order error 1`] = `
<div
class="OrderFulfillPage-remainingQuantity-id"
>
/ 33
/ 727
</div>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -86360,7 +86360,7 @@ exports[`Storyshots Views / Orders / Fulfill order error 1`] = `
<input
aria-invalid="false"
class="MuiInputBase-input-id MuiOutlinedInput-input-id OrderFulfillPage-quantityInnerInput-id MuiInputBase-inputAdornedEnd-id MuiOutlinedInput-inputAdornedEnd-id"
max="760"
max="756"
min="0"
style="text-align:right"
type="number"
Expand All @@ -86369,7 +86369,7 @@ exports[`Storyshots Views / Orders / Fulfill order error 1`] = `
<div
class="OrderFulfillPage-remainingQuantity-id"
>
/ 4
/ 756
</div>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -86454,7 +86454,7 @@ exports[`Storyshots Views / Orders / Fulfill order error 1`] = `
<div
class="OrderFulfillPage-remainingQuantity-id"
>
/ 0
/ 587
</div>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -86490,7 +86490,7 @@ exports[`Storyshots Views / Orders / Fulfill order error 1`] = `
<input
aria-invalid="false"
class="MuiInputBase-input-id MuiOutlinedInput-input-id OrderFulfillPage-quantityInnerInput-id MuiInputBase-inputAdornedEnd-id MuiOutlinedInput-inputAdornedEnd-id"
max="587"
max="586"
min="0"
style="text-align:right"
type="number"
Expand All @@ -86499,7 +86499,7 @@ exports[`Storyshots Views / Orders / Fulfill order error 1`] = `
<div
class="OrderFulfillPage-remainingQuantity-id"
>
/ 1
/ 586
</div>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -87058,7 +87058,7 @@ exports[`Storyshots Views / Orders / Fulfill order one warehouse 1`] = `
<div
class="OrderFulfillPage-remainingQuantity-id"
>
/ 0
/ 587
</div>
<fieldset
aria-hidden="true"
Expand Down

0 comments on commit f80f6e4

Please sign in to comment.