@springmicro/cart 0.7.10 → 0.7.12

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.7.10",
4
+ "version": "0.7.12",
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.10",
27
+ "@springmicro/utils": "^0.7.12",
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": "f890b911cb1d65082aec5d408fb2346ffad71c63"
52
+ "gitHead": "fd84f6ddb8ef2f0e9ec15c7078bfd8a4d65e864b"
53
53
  }
@@ -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) {
@@ -215,18 +215,23 @@ export default function ReviewAndCalculateTaxes({
215
215
  invoiceId
216
216
  )
217
217
  .then(async (data) => {
218
- dev && console.log("Checkout submitted");
218
+ dev && console.log("Checkout submitted.", data);
219
+
219
220
  if (data instanceof Response) {
220
221
  setFormError(true);
221
222
  const { detail: errorData } = await data.json();
222
- // dev && alert(data.statusText);
223
- // console.log(errorData);
224
- // TODO display issues
225
- if (!errorData.valid) setPrecheckErrors(errorData.errors);
223
+
224
+ if (!errorData.valid) {
225
+ dev && console.log("Precheck invalid", errorData);
226
+ setPrecheckErrors(errorData.errors);
227
+ }
226
228
  } else {
229
+ dev && console.log("Checkout returned status code 200");
230
+
227
231
  // success
228
232
  setSuccessData(data);
229
233
  onPlacement && onPlacement();
234
+
230
235
  // Get the current URL
231
236
  const currentUrl = new URL(window.location.href);
232
237
  // Set the query parameter 'showReceipt' to '1'
@@ -349,7 +354,9 @@ export default function ReviewAndCalculateTaxes({
349
354
 
350
355
  // const res = await submitFunc(values);
351
356
  submitFunc(values)
352
- .then((v) => {})
357
+ .then((v) => {
358
+ dev && console.log("Submit success", v);
359
+ })
353
360
  .catch((e) => {
354
361
  dev && console.log("Submit errors", e);
355
362
  });