@springmicro/cart 0.5.2 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@springmicro/cart",
3
3
  "private": false,
4
- "version": "0.5.2",
4
+ "version": "0.5.4",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -24,7 +24,7 @@
24
24
  "@nanostores/persistent": "^0.10.1",
25
25
  "@nanostores/query": "^0.3.3",
26
26
  "@nanostores/react": "^0.7.2",
27
- "@springmicro/utils": "0.5.2",
27
+ "@springmicro/utils": "0.5.4",
28
28
  "dotenv": "^16.4.5",
29
29
  "nanostores": "^0.10.3",
30
30
  "react": "^18.2.0",
@@ -49,5 +49,5 @@
49
49
  "vite-plugin-css-injected-by-js": "^3.5.1",
50
50
  "yup": "^1.4.0"
51
51
  },
52
- "gitHead": "431413a6efc5c939e85c79309967bdc6c88c9ee2"
52
+ "gitHead": "d806bf269ce2cbfa56b32b469d616b42e928ae46"
53
53
  }
@@ -17,7 +17,7 @@ export type ProductCardComponentProps = {
17
17
  product: Product;
18
18
  foundInCart: {
19
19
  product: boolean;
20
- price: boolean;
20
+ price: boolean | null; // If null, price tier was not provided.
21
21
  };
22
22
  pricing;
23
23
  addToCart: (price_index?: number) => void;
@@ -44,12 +44,14 @@ export default function ProductCard({
44
44
 
45
45
  const pi = pricing.findIndex((price) => price.tier_label === priceTierName); // TODO add fail-case for missing price
46
46
 
47
- const priceInCartIndex: number = (cart.items as any[]).findIndex(
48
- (p) => p.price_id === pricing[pi].id
49
- );
50
- const priceFoundInCart = !!~priceInCartIndex;
47
+ const priceInCartIndex: number =
48
+ pi != -1
49
+ ? (cart.items as any[]).findIndex((p) => p.price_id === pricing[pi].id)
50
+ : -1;
51
51
 
52
52
  function addToCartSafe(priceIndex: number = pi) {
53
+ if (priceIndex === -1)
54
+ throw "Price index not found. Provide price index to addToCart OR provide priceTierName to ProductCard.";
53
55
  // Removes the ability to add improper info from the addToCart
54
56
  addToCart({
55
57
  product_id: product.id,
@@ -64,7 +66,7 @@ export default function ProductCard({
64
66
  product,
65
67
  foundInCart: {
66
68
  product: productFoundInCart,
67
- price: priceFoundInCart,
69
+ price: pi != -1 ? !!~priceInCartIndex : null,
68
70
  },
69
71
  pricing,
70
72
  addToCart: addToCartSafe,