@springmicro/cart 0.7.10 → 0.7.11
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/dist/index.js +1148 -1129
- package/dist/index.umd.cjs +45 -45
- package/package.json +3 -3
- package/src/ProductCard.tsx +46 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@springmicro/cart",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.11",
|
|
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.7.
|
|
27
|
+
"@springmicro/utils": "^0.7.11",
|
|
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": "
|
|
52
|
+
"gitHead": "83e40d99497f8016d112147e64bf69f9ae852d6d"
|
|
53
53
|
}
|
package/src/ProductCard.tsx
CHANGED
|
@@ -23,6 +23,13 @@ export type ProductCardComponentProps = {
|
|
|
23
23
|
addToCart: (price_index?: number) => void;
|
|
24
24
|
removeFromCart: (price?: boolean) => void;
|
|
25
25
|
disabled?: boolean;
|
|
26
|
+
findInCart?: (
|
|
27
|
+
product_id: number,
|
|
28
|
+
price_id?: number
|
|
29
|
+
) => {
|
|
30
|
+
product: boolean;
|
|
31
|
+
price: number | null; // If null, price id was not provided or the price wasn't found.
|
|
32
|
+
};
|
|
26
33
|
};
|
|
27
34
|
|
|
28
35
|
export default function ProductCard({
|
|
@@ -33,11 +40,47 @@ export default function ProductCard({
|
|
|
33
40
|
}: {
|
|
34
41
|
product: Product;
|
|
35
42
|
component?: React.FC<ProductCardComponentProps>;
|
|
36
|
-
priceTierName?: string; // Might have incomplete code for cases where the tier name doesn't match.
|
|
37
43
|
disabled?: boolean;
|
|
38
|
-
}
|
|
44
|
+
} & (
|
|
45
|
+
| {
|
|
46
|
+
priceTierName?: string; // Might have incomplete code for cases where the tier name doesn't match.
|
|
47
|
+
pricing: never;
|
|
48
|
+
}
|
|
49
|
+
| {
|
|
50
|
+
priceTierName: never;
|
|
51
|
+
pricing; // pricing or array of pricings
|
|
52
|
+
}
|
|
53
|
+
)) {
|
|
39
54
|
const cart = JSON.parse(useStore(cartStore));
|
|
40
55
|
|
|
56
|
+
function findInCart(
|
|
57
|
+
product_id: number,
|
|
58
|
+
price_id?: number
|
|
59
|
+
): {
|
|
60
|
+
product: boolean;
|
|
61
|
+
price: number | null; // If null, price id was not provided.
|
|
62
|
+
} {
|
|
63
|
+
const productInCartIndex: number = (cart.items as any[]).findIndex(
|
|
64
|
+
(p) => p.product_id === product_id
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
if (price_id == null) {
|
|
68
|
+
return {
|
|
69
|
+
product: !!~productInCartIndex,
|
|
70
|
+
price: null,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const priceInCartIndex: number = (cart.items as any[]).findIndex(
|
|
75
|
+
(p) => p.price_id === price_id
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
product: !!~productInCartIndex,
|
|
80
|
+
price: priceInCartIndex != -1 ? priceInCartIndex : null,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
41
84
|
const productInCartIndex: number = (cart.items as any[]).findIndex(
|
|
42
85
|
(p) => p.product_id === product.id
|
|
43
86
|
);
|
|
@@ -77,6 +120,7 @@ export default function ProductCard({
|
|
|
77
120
|
removeFromCart: (price?: boolean) => {
|
|
78
121
|
removeFromCart(price ? priceInCartIndex : productInCartIndex);
|
|
79
122
|
},
|
|
123
|
+
findInCart,
|
|
80
124
|
};
|
|
81
125
|
|
|
82
126
|
if (component !== undefined) {
|