Skip to content

Commit

Permalink
Merge pull request #511 from mirumee/fix/available-stock
Browse files Browse the repository at this point in the history
Fix available stock card
  • Loading branch information
maarcingebala authored Apr 29, 2020
2 parents c41e7b8 + 58d4df7 commit 1d42b62
Show file tree
Hide file tree
Showing 19 changed files with 39 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/products/components/ProductVariants/ProductVariants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,10 @@ export const ProductVariants: React.FC<ProductVariantsProps> = props => {
const isSelected = variant ? isChecked(variant.id) : false;
const numAvailable =
variant && variant.stocks
? variant.stocks.reduce((acc, s) => acc + s.quantity, 0)
? variant.stocks.reduce(
(acc, s) => acc + s.quantity - s.quantityAllocated,
0
)
: null;

return (
Expand Down
5 changes: 5 additions & 0 deletions src/products/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,14 @@ export const product: (
__typename: "Stock",
id: "1",
quantity: 1,
quantityAllocated: 0,
warehouse: warehouseList[0]
},
{
__typename: "Stock",
id: "2",
quantity: 4,
quantityAllocated: 2,
warehouse: warehouseList[1]
}
],
Expand Down Expand Up @@ -301,6 +303,7 @@ export const product: (
__typename: "Stock",
id: "1",
quantity: 13,
quantityAllocated: 2,
warehouse: warehouseList[0]
}
],
Expand Down Expand Up @@ -1253,6 +1256,7 @@ export const variant = (placeholderImage: string): ProductVariant => ({
__typename: "Stock",
id: "1",
quantity: 1,
quantityAllocated: 1,
warehouse: {
__typename: "Warehouse",
id: "123",
Expand All @@ -1263,6 +1267,7 @@ export const variant = (placeholderImage: string): ProductVariant => ({
__typename: "Stock",
id: "2",
quantity: 4,
quantityAllocated: 2,
warehouse: {
__typename: "Warehouse",
id: "1234",
Expand Down
1 change: 1 addition & 0 deletions src/products/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const stockFragment = gql`
fragment StockFragment on Stock {
id
quantity
quantityAllocated
warehouse {
id
name
Expand Down
2 changes: 2 additions & 0 deletions src/products/types/AddOrRemoveStocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface AddOrRemoveStocks_productVariantStocksCreate_productVariant_sto
__typename: "Stock";
id: string;
quantity: number;
quantityAllocated: number;
warehouse: AddOrRemoveStocks_productVariantStocksCreate_productVariant_stocks_warehouse;
}

Expand Down Expand Up @@ -56,6 +57,7 @@ export interface AddOrRemoveStocks_productVariantStocksDelete_productVariant_sto
__typename: "Stock";
id: string;
quantity: number;
quantityAllocated: number;
warehouse: AddOrRemoveStocks_productVariantStocksDelete_productVariant_stocks_warehouse;
}

Expand Down
1 change: 1 addition & 0 deletions src/products/types/Product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export interface Product_variants_stocks {
__typename: "Stock";
id: string;
quantity: number;
quantityAllocated: number;
warehouse: Product_variants_stocks_warehouse;
}

Expand Down
1 change: 1 addition & 0 deletions src/products/types/ProductCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export interface ProductCreate_productCreate_product_variants_stocks {
__typename: "Stock";
id: string;
quantity: number;
quantityAllocated: number;
warehouse: ProductCreate_productCreate_product_variants_stocks_warehouse;
}

Expand Down
1 change: 1 addition & 0 deletions src/products/types/ProductDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export interface ProductDetails_product_variants_stocks {
__typename: "Stock";
id: string;
quantity: number;
quantityAllocated: number;
warehouse: ProductDetails_product_variants_stocks_warehouse;
}

Expand Down
1 change: 1 addition & 0 deletions src/products/types/ProductImageCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export interface ProductImageCreate_productImageCreate_product_variants_stocks {
__typename: "Stock";
id: string;
quantity: number;
quantityAllocated: number;
warehouse: ProductImageCreate_productImageCreate_product_variants_stocks_warehouse;
}

Expand Down
1 change: 1 addition & 0 deletions src/products/types/ProductImageUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export interface ProductImageUpdate_productImageUpdate_product_variants_stocks {
__typename: "Stock";
id: string;
quantity: number;
quantityAllocated: number;
warehouse: ProductImageUpdate_productImageUpdate_product_variants_stocks_warehouse;
}

Expand Down
1 change: 1 addition & 0 deletions src/products/types/ProductUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export interface ProductUpdate_productUpdate_product_variants_stocks {
__typename: "Stock";
id: string;
quantity: number;
quantityAllocated: number;
warehouse: ProductUpdate_productUpdate_product_variants_stocks_warehouse;
}

Expand Down
1 change: 1 addition & 0 deletions src/products/types/ProductVariant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export interface ProductVariant_stocks {
__typename: "Stock";
id: string;
quantity: number;
quantityAllocated: number;
warehouse: ProductVariant_stocks_warehouse;
}

Expand Down
1 change: 1 addition & 0 deletions src/products/types/ProductVariantDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export interface ProductVariantDetails_productVariant_stocks {
__typename: "Stock";
id: string;
quantity: number;
quantityAllocated: number;
warehouse: ProductVariantDetails_productVariant_stocks_warehouse;
}

Expand Down
5 changes: 5 additions & 0 deletions src/products/types/SimpleProductUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export interface SimpleProductUpdate_productUpdate_product_variants_stocks {
__typename: "Stock";
id: string;
quantity: number;
quantityAllocated: number;
warehouse: SimpleProductUpdate_productUpdate_product_variants_stocks_warehouse;
}

Expand Down Expand Up @@ -307,6 +308,7 @@ export interface SimpleProductUpdate_productVariantUpdate_productVariant_stocks
__typename: "Stock";
id: string;
quantity: number;
quantityAllocated: number;
warehouse: SimpleProductUpdate_productVariantUpdate_productVariant_stocks_warehouse;
}

Expand Down Expand Up @@ -430,6 +432,7 @@ export interface SimpleProductUpdate_productVariantStocksCreate_productVariant_s
__typename: "Stock";
id: string;
quantity: number;
quantityAllocated: number;
warehouse: SimpleProductUpdate_productVariantStocksCreate_productVariant_stocks_warehouse;
}

Expand Down Expand Up @@ -552,6 +555,7 @@ export interface SimpleProductUpdate_productVariantStocksDelete_productVariant_s
__typename: "Stock";
id: string;
quantity: number;
quantityAllocated: number;
warehouse: SimpleProductUpdate_productVariantStocksDelete_productVariant_stocks_warehouse;
}

Expand Down Expand Up @@ -675,6 +679,7 @@ export interface SimpleProductUpdate_productVariantStocksUpdate_productVariant_s
__typename: "Stock";
id: string;
quantity: number;
quantityAllocated: number;
warehouse: SimpleProductUpdate_productVariantStocksUpdate_productVariant_stocks_warehouse;
}

Expand Down
1 change: 1 addition & 0 deletions src/products/types/StockFragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ export interface StockFragment {
__typename: "Stock";
id: string;
quantity: number;
quantityAllocated: number;
warehouse: StockFragment_warehouse;
}
1 change: 1 addition & 0 deletions src/products/types/VariantCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export interface VariantCreate_productVariantCreate_productVariant_stocks {
__typename: "Stock";
id: string;
quantity: number;
quantityAllocated: number;
warehouse: VariantCreate_productVariantCreate_productVariant_stocks_warehouse;
}

Expand Down
1 change: 1 addition & 0 deletions src/products/types/VariantImageAssign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export interface VariantImageAssign_variantImageAssign_productVariant_stocks {
__typename: "Stock";
id: string;
quantity: number;
quantityAllocated: number;
warehouse: VariantImageAssign_variantImageAssign_productVariant_stocks_warehouse;
}

Expand Down
1 change: 1 addition & 0 deletions src/products/types/VariantImageUnassign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export interface VariantImageUnassign_variantImageUnassign_productVariant_stocks
__typename: "Stock";
id: string;
quantity: number;
quantityAllocated: number;
warehouse: VariantImageUnassign_variantImageUnassign_productVariant_stocks_warehouse;
}

Expand Down
2 changes: 2 additions & 0 deletions src/products/types/VariantUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export interface VariantUpdate_productVariantUpdate_productVariant_stocks {
__typename: "Stock";
id: string;
quantity: number;
quantityAllocated: number;
warehouse: VariantUpdate_productVariantUpdate_productVariant_stocks_warehouse;
}

Expand Down Expand Up @@ -230,6 +231,7 @@ export interface VariantUpdate_productVariantStocksUpdate_productVariant_stocks
__typename: "Stock";
id: string;
quantity: number;
quantityAllocated: number;
warehouse: VariantUpdate_productVariantStocksUpdate_productVariant_stocks_warehouse;
}

Expand Down
16 changes: 8 additions & 8 deletions src/storybook/__snapshots__/Stories.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -111482,7 +111482,7 @@ Ctrl + K"
class="MuiTableCell-root-id MuiTableCell-body-id ProductVariants-colInventory-id"
data-tc="inventory"
>
5 available at 2 locations
3 available at 2 locations
</td>
</tr>
<tr
Expand Down Expand Up @@ -111519,7 +111519,7 @@ Ctrl + K"
class="MuiTableCell-root-id MuiTableCell-body-id ProductVariants-colInventory-id"
data-tc="inventory"
>
13 available at 1 location
11 available at 1 location
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -113043,7 +113043,7 @@ Ctrl + K"
class="MuiTableCell-root-id MuiTableCell-body-id ProductVariants-colInventory-id"
data-tc="inventory"
>
5 available at 2 locations
3 available at 2 locations
</td>
</tr>
<tr
Expand Down Expand Up @@ -113080,7 +113080,7 @@ Ctrl + K"
class="MuiTableCell-root-id MuiTableCell-body-id ProductVariants-colInventory-id"
data-tc="inventory"
>
13 available at 1 location
11 available at 1 location
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -118480,7 +118480,7 @@ Ctrl + K"
class="MuiTableCell-root-id MuiTableCell-body-id ProductVariants-colInventory-id"
data-tc="inventory"
>
5 available at 2 locations
3 available at 2 locations
</td>
</tr>
<tr
Expand Down Expand Up @@ -118517,7 +118517,7 @@ Ctrl + K"
class="MuiTableCell-root-id MuiTableCell-body-id ProductVariants-colInventory-id"
data-tc="inventory"
>
13 available at 1 location
11 available at 1 location
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -121360,7 +121360,7 @@ Ctrl + K"
class="MuiTableCell-root-id MuiTableCell-body-id ProductVariants-colInventory-id"
data-tc="inventory"
>
5 available at 2 locations
3 available at 2 locations
</td>
</tr>
<tr
Expand Down Expand Up @@ -121397,7 +121397,7 @@ Ctrl + K"
class="MuiTableCell-root-id MuiTableCell-body-id ProductVariants-colInventory-id"
data-tc="inventory"
>
13 available at 1 location
11 available at 1 location
</td>
</tr>
</tbody>
Expand Down

0 comments on commit 1d42b62

Please sign in to comment.