@instockng/storefront-ui 1.0.11 → 1.0.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.
@@ -1 +1 @@
1
- {"version":3,"file":"ShoppingCart.d.ts","sourceRoot":"","sources":["../../src/components/ShoppingCart.tsx"],"names":[],"mappings":"AAkBA,MAAM,WAAW,iBAAiB;IAChC,+BAA+B;IAC/B,MAAM,EAAE,OAAO,CAAC;IAChB,sCAAsC;IACtC,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,wCAAwC;IACxC,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,iDAAiD;IACjD,kBAAkB,CAAC,EAAE,MAAM,IAAI,CAAC;IAChC,wBAAwB;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+BAA+B;IAC/B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,2BAA2B;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,oCAAoC;IACpC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,uCAAuC;IACvC,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,gDAAgD;IAChD,+BAA+B,CAAC,EAAE,MAAM,CAAC;IACzC,uBAAuB;IACvB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,yBAAyB;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,YAAY,CAAC,EAC3B,MAAM,EACN,OAAO,EACP,UAAU,EACV,kBAAkB,EAClB,SAAS,EACT,gBAAuB,EACvB,kBAA+B,EAC/B,oBAA0C,EAC1C,uBAAuB,EACvB,+BAA+B,EAC/B,eAAuB,EACvB,YAAmC,GACpC,EAAE,iBAAiB,2CA2MnB"}
1
+ {"version":3,"file":"ShoppingCart.d.ts","sourceRoot":"","sources":["../../src/components/ShoppingCart.tsx"],"names":[],"mappings":"AAkBA,MAAM,WAAW,iBAAiB;IAChC,+BAA+B;IAC/B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AI,CAAC,CAAC;IAC/C,2BAA2B;IAC3B,cAAc,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,6CAA6C;IAC7C,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,wBAAwB;IACxB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,qCAAqC;IACrC,MAAM,EAAE,OAAO,CAAC;IAChB,0BAA0B;IAC1B,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,2BAA2B;IAC3B,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,eAAO,MAAM,WAAW,kDAA+C,CAAC;AAExE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,SAAS,CAAC;IACpB,qCAAqC;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kDAAkD;IAClD,iBAAiB,CAAC,EAAE,IAAI,CAAC,OAAO,4BAA4B,EAAE,iBAAiB,EAAE,QAAQ,GAAG,SAAS,CAAC,CAAC;CACxG;AAED,wBAAgB,YAAY,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,iBAAiB,EAAE,EAAE,iBAAiB,2CAsOxG;AAED;;GAEG;AACH,wBAAgB,OAAO,qBAMtB"}
package/dist/index105.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import a from "./index93.mjs";
2
+ import a from "./index95.mjs";
3
3
  const e = typeof URLSearchParams < "u" ? URLSearchParams : a;
4
4
  export {
5
5
  e as default
package/dist/index29.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import { useQueryClient as s, useMutation as i } from "@tanstack/react-query";
3
- import { useQueryUnwrapped as o } from "./index59.mjs";
3
+ import { useQueryUnwrapped as o } from "./index61.mjs";
4
4
  import { queryKeys as r } from "./index26.mjs";
5
5
  import { updateCart as c, createCart as l, applyDiscount as y, removeDiscount as m, addCartItem as C, updateCartItem as p, removeCartItem as q, checkoutCart as d, fetchCart as f } from "./index23.mjs";
6
6
  function b(e, t) {
package/dist/index3.mjs CHANGED
@@ -1,30 +1,31 @@
1
1
  'use client';
2
- import { jsxs as H, jsx as K } from "react/jsx-runtime";
3
- import { createContext as Y, useState as d, useRef as h, useEffect as c, useCallback as r, useContext as q } from "react";
2
+ import { jsxs as Y, jsx as q } from "react/jsx-runtime";
3
+ import { createContext as z, useState as d, useRef as w, useEffect as a, useCallback as r, useContext as B } from "react";
4
4
  import "./index18.mjs";
5
- import { useGetCart as B, useCreateCart as J, useAddCartItem as Q, useUpdateCartItem as V, useRemoveCartItem as W, useApplyDiscount as X, useRemoveDiscount as Z, useUpdateCart as $, useCheckoutCart as tt } from "./index29.mjs";
5
+ import { useGetCart as J, useCreateCart as Q, useAddCartItem as V, useUpdateCartItem as W, useRemoveCartItem as X, useApplyDiscount as Z, useRemoveDiscount as $, useUpdateCart as tt, useCheckoutCart as et } from "./index29.mjs";
6
6
  import "@tanstack/react-query";
7
- import { ShoppingCart as et } from "./index8.mjs";
8
- const m = "oms_cart_id", y = Y(null);
9
- function ut({ children: a, brandSlug: v, initialCartId: u, shoppingCartProps: S }) {
10
- const [t, s] = d(u || null), [w, p] = d(!1), [D, g] = d(!1), i = h(!1), f = h(!1);
11
- c(() => {
7
+ import { ShoppingCart as rt } from "./index8.mjs";
8
+ const m = "oms_cart_id", D = z(null);
9
+ function it({ children: c, brandSlug: f, initialCartId: u, shoppingCartProps: E }) {
10
+ const [t, s] = d(u || null), [p, C] = d(!1), [M, g] = d(!1), I = w(!1), h = w(!1), l = w(!1);
11
+ a(() => {
12
12
  g(!0);
13
- }, []), c(() => {
14
- if (u || i.current) return;
13
+ }, []), a(() => {
14
+ if (u || I.current) return;
15
+ I.current = !0;
15
16
  const n = new URLSearchParams(window.location.search).get("cartId");
16
17
  if (n) {
17
18
  s(n);
18
19
  return;
19
20
  }
20
- const C = localStorage.getItem(m);
21
- C && s(C);
21
+ const v = localStorage.getItem(m);
22
+ v && s(v);
22
23
  }, [u]);
23
- const { data: E, isLoading: M, error: l, refetch: o } = B(t || "", {
24
+ const { data: A, isLoading: R, error: i, refetch: o } = J(t || "", {
24
25
  enabled: !!t,
25
26
  retry: !1
26
27
  // Don't retry on failure - cart might be invalid/expired
27
- }), A = J({
28
+ }), y = Q({
28
29
  onSuccess: (e) => {
29
30
  if ("error" in e) {
30
31
  console.error("Failed to create cart:", e.error);
@@ -36,33 +37,32 @@ function ut({ children: a, brandSlug: v, initialCartId: u, shoppingCartProps: S
36
37
  console.error("Failed to create cart:", e);
37
38
  }
38
39
  });
39
- c(() => {
40
- if (!i.current && !t && !u) {
41
- i.current = !0;
42
- const e = setTimeout(() => {
43
- i.current && A.mutate(v);
44
- }, 0);
45
- return () => clearTimeout(e);
46
- }
47
- }, []), c(() => {
48
- l && t && !f.current && (f.current = !0, console.warn("Cart fetch failed, clearing invalid cart:", l), Promise.resolve().then(() => {
49
- s(null), typeof window < "u" && localStorage.removeItem(m), f.current = !1;
50
- }));
51
- }, [l, t]);
52
- const x = Q(t || "", {
53
- onSuccess: () => o()
54
- }), P = V(t || "", {
40
+ a(() => {
41
+ if (h.current) return;
42
+ h.current = !0;
43
+ const e = setTimeout(() => {
44
+ !t && !u && y.mutate(f);
45
+ }, 150);
46
+ return () => clearTimeout(e);
47
+ }, []), a(() => {
48
+ i && t && !l.current && (l.current = !0, console.warn("Cart fetch failed, creating new cart:", i), s(null), typeof window < "u" && localStorage.removeItem(m), setTimeout(() => {
49
+ y.mutate(f), l.current = !1;
50
+ }, 100));
51
+ }, [i, t, f]);
52
+ const x = V(t || "", {
55
53
  onSuccess: () => o()
56
- }), R = W(t || "", {
54
+ }), P = W(t || "", {
57
55
  onSuccess: () => o()
58
56
  }), N = X(t || "", {
59
57
  onSuccess: () => o()
60
- }), U = Z(t || "", {
58
+ }), F = Z(t || "", {
59
+ onSuccess: () => o()
60
+ }), T = $(t || "", {
61
61
  onSuccess: () => o()
62
- }), _ = $(t || "", {
62
+ }), U = tt(t || "", {
63
63
  onSuccess: () => o()
64
- }), b = tt(t || "");
65
- c(() => {
64
+ }), _ = et(t || "");
65
+ a(() => {
66
66
  t && typeof window < "u" && localStorage.setItem(m, t);
67
67
  }, [t]);
68
68
  const k = r(
@@ -72,74 +72,74 @@ function ut({ children: a, brandSlug: v, initialCartId: u, shoppingCartProps: S
72
72
  },
73
73
  // eslint-disable-next-line react-hooks/exhaustive-deps
74
74
  [t]
75
- ), F = r(
75
+ ), L = r(
76
76
  async (e, n) => {
77
77
  if (!t) throw new Error("No cart ID");
78
78
  await P.mutateAsync({ itemId: e, quantity: n });
79
79
  },
80
80
  // eslint-disable-next-line react-hooks/exhaustive-deps
81
81
  [t]
82
- ), T = r(
82
+ ), j = r(
83
83
  async (e) => {
84
84
  if (!t) throw new Error("No cart ID");
85
- await R.mutateAsync(e);
85
+ await N.mutateAsync(e);
86
86
  },
87
87
  // eslint-disable-next-line react-hooks/exhaustive-deps
88
88
  [t]
89
- ), j = r(
89
+ ), O = r(
90
90
  async (e) => {
91
91
  if (!t) throw new Error("No cart ID");
92
- await N.mutateAsync({ code: e });
92
+ await F.mutateAsync({ code: e });
93
93
  },
94
94
  // eslint-disable-next-line react-hooks/exhaustive-deps
95
95
  [t]
96
- ), L = r(async () => {
96
+ ), b = r(async () => {
97
97
  if (!t) throw new Error("No cart ID");
98
- await U.mutateAsync();
99
- }, [t]), O = r(() => {
98
+ await T.mutateAsync();
99
+ }, [t]), G = r(() => {
100
100
  s(null), typeof window < "u" && localStorage.removeItem(m);
101
- }, []), z = r(() => {
102
- p(!0);
103
- }, []), I = r(() => {
104
- p(!1);
105
- }, []), G = {
106
- cart: E || null,
101
+ }, []), H = r(() => {
102
+ C(!0);
103
+ }, []), S = r(() => {
104
+ C(!1);
105
+ }, []), K = {
106
+ cart: A || null,
107
107
  cartId: t,
108
- isLoading: M,
109
- error: l,
110
- updateCartMutation: _,
111
- checkoutMutation: b,
108
+ isLoading: R,
109
+ error: i,
110
+ updateCartMutation: U,
111
+ checkoutMutation: _,
112
112
  addItem: k,
113
- updateItem: F,
114
- removeItem: T,
115
- applyDiscount: j,
116
- removeDiscount: L,
117
- clearCart: O,
113
+ updateItem: L,
114
+ removeItem: j,
115
+ applyDiscount: O,
116
+ removeDiscount: b,
117
+ clearCart: G,
118
118
  refetch: o,
119
- isOpen: w,
120
- open: z,
121
- close: I
119
+ isOpen: p,
120
+ open: H,
121
+ close: S
122
122
  };
123
- return /* @__PURE__ */ H(y.Provider, { value: G, children: [
124
- a,
125
- D && /* @__PURE__ */ K(
126
- et,
123
+ return /* @__PURE__ */ Y(D.Provider, { value: K, children: [
124
+ c,
125
+ M && /* @__PURE__ */ q(
126
+ rt,
127
127
  {
128
- isOpen: w,
129
- onClose: I,
130
- ...S
128
+ isOpen: p,
129
+ onClose: S,
130
+ ...E
131
131
  }
132
132
  )
133
133
  ] });
134
134
  }
135
- function it() {
136
- const a = q(y);
137
- if (!a)
135
+ function mt() {
136
+ const c = B(D);
137
+ if (!c)
138
138
  throw new Error("useCart must be used within CartProvider");
139
- return a;
139
+ return c;
140
140
  }
141
141
  export {
142
- y as CartContext,
143
- ut as CartProvider,
144
- it as useCart
142
+ D as CartContext,
143
+ it as CartProvider,
144
+ mt as useCart
145
145
  };
package/dist/index30.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import { useMutation as t } from "@tanstack/react-query";
3
- import { useQueryUnwrapped as u } from "./index59.mjs";
3
+ import { useQueryUnwrapped as u } from "./index61.mjs";
4
4
  import { queryKeys as n } from "./index26.mjs";
5
5
  import { confirmOrder as i, fetchOrder as m } from "./index24.mjs";
6
6
  function y(e, r, o) {
package/dist/index31.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import { useQueryUnwrapped as u } from "./index59.mjs";
2
+ import { useQueryUnwrapped as u } from "./index61.mjs";
3
3
  import { queryKeys as t } from "./index26.mjs";
4
4
  import { fetchProductsByBrand as o, fetchProductBySlug as c } from "./index22.mjs";
5
5
  function n(r, e) {
package/dist/index32.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import { useQueryUnwrapped as o } from "./index59.mjs";
2
+ import { useQueryUnwrapped as o } from "./index61.mjs";
3
3
  import { queryKeys as i } from "./index26.mjs";
4
4
  import { fetchDeliveryZones as t } from "./index25.mjs";
5
5
  function p(e, r) {
package/dist/index44.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import { useQueryClient as y, useMutation as m } from "@tanstack/react-query";
3
- import { useQueryUnwrapped as p } from "./index59.mjs";
3
+ import { useQueryUnwrapped as p } from "./index61.mjs";
4
4
  import { createAdminRpcClients as d, authHeaders as c } from "./index21.mjs";
5
5
  import { queryKeys as i } from "./index26.mjs";
6
6
  import { useApiConfig as l } from "./index19.mjs";
package/dist/index45.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import { useQueryClient as y, useMutation as m } from "@tanstack/react-query";
3
- import { useQueryUnwrapped as b } from "./index59.mjs";
3
+ import { useQueryUnwrapped as b } from "./index61.mjs";
4
4
  import { createAdminRpcClients as u, authHeaders as c } from "./index21.mjs";
5
5
  import { queryKeys as o } from "./index26.mjs";
6
6
  import { useApiConfig as d } from "./index19.mjs";
package/dist/index46.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import { useQueryClient as p, useMutation as y } from "@tanstack/react-query";
3
- import { useQueryUnwrapped as m } from "./index59.mjs";
3
+ import { useQueryUnwrapped as m } from "./index61.mjs";
4
4
  import { createAdminRpcClients as a, authHeaders as c } from "./index21.mjs";
5
5
  import { queryKeys as i } from "./index26.mjs";
6
6
  import { useApiConfig as d } from "./index19.mjs";
package/dist/index47.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import { useQueryClient as y, useMutation as v } from "@tanstack/react-query";
3
- import { useQueryUnwrapped as m } from "./index59.mjs";
3
+ import { useQueryUnwrapped as m } from "./index61.mjs";
4
4
  import { createAdminRpcClients as u, authHeaders as c } from "./index21.mjs";
5
5
  import { queryKeys as i } from "./index26.mjs";
6
6
  import { useApiConfig as d } from "./index19.mjs";
package/dist/index48.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import { useQueryClient as w, useMutation as y } from "@tanstack/react-query";
3
- import { useQueryUnwrapped as d } from "./index59.mjs";
3
+ import { useQueryUnwrapped as d } from "./index61.mjs";
4
4
  import { createAdminRpcClients as i, authHeaders as c } from "./index21.mjs";
5
5
  import { queryKeys as u } from "./index26.mjs";
6
6
  import { useApiConfig as l } from "./index19.mjs";
package/dist/index49.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import { useQueryClient as d, useMutation as v } from "@tanstack/react-query";
3
- import { useQueryUnwrapped as l } from "./index59.mjs";
3
+ import { useQueryUnwrapped as l } from "./index61.mjs";
4
4
  import { createAdminRpcClients as u, authHeaders as c } from "./index21.mjs";
5
5
  import { queryKeys as s } from "./index26.mjs";
6
6
  import { useApiConfig as y } from "./index19.mjs";
package/dist/index50.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import { useQueryUnwrapped as i } from "./index59.mjs";
2
+ import { useQueryUnwrapped as i } from "./index61.mjs";
3
3
  import { createAdminRpcClients as n, authHeaders as u } from "./index21.mjs";
4
4
  import { queryKeys as m } from "./index26.mjs";
5
5
  import { useApiConfig as a } from "./index19.mjs";
package/dist/index51.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import { useQueryUnwrapped as s } from "./index59.mjs";
2
+ import { useQueryUnwrapped as s } from "./index61.mjs";
3
3
  import { createAdminRpcClients as i, authHeaders as u } from "./index21.mjs";
4
4
  import { queryKeys as c } from "./index26.mjs";
5
5
  import { useApiConfig as d } from "./index19.mjs";
package/dist/index52.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import { useQueryClient as l, useMutation as y } from "@tanstack/react-query";
3
- import { useQueryUnwrapped as c } from "./index59.mjs";
3
+ import { useQueryUnwrapped as c } from "./index61.mjs";
4
4
  import { createAdminRpcClients as s, authHeaders as o } from "./index21.mjs";
5
5
  import { queryKeys as i } from "./index26.mjs";
6
6
  import { useApiConfig as u } from "./index19.mjs";
package/dist/index53.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import { useQueryClient as l, useMutation as y } from "@tanstack/react-query";
3
- import { useQueryUnwrapped as C } from "./index59.mjs";
3
+ import { useQueryUnwrapped as C } from "./index61.mjs";
4
4
  import { createAdminRpcClients as c, authHeaders as a } from "./index21.mjs";
5
5
  import { queryKeys as r } from "./index26.mjs";
6
6
  import { useApiConfig as d } from "./index19.mjs";
package/dist/index54.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import { useQueryClient as y, useMutation as v } from "@tanstack/react-query";
3
- import { useQueryUnwrapped as m } from "./index59.mjs";
3
+ import { useQueryUnwrapped as m } from "./index61.mjs";
4
4
  import { createAdminRpcClients as u, authHeaders as l } from "./index21.mjs";
5
5
  import { queryKeys as o } from "./index26.mjs";
6
6
  import { useApiConfig as c } from "./index19.mjs";
package/dist/index58.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use client';
2
- import { getDefaultExportFromCjs as d } from "./index60.mjs";
3
- import { __module as v } from "./index61.mjs";
2
+ import { getDefaultExportFromCjs as d } from "./index59.mjs";
3
+ import { __module as v } from "./index60.mjs";
4
4
  v.exports = function(n) {
5
5
  return g(m(n), n);
6
6
  };
package/dist/index59.mjs CHANGED
@@ -1,8 +1,7 @@
1
1
  'use client';
2
- import { useQuery as e } from "@tanstack/react-query";
3
- function n(r) {
4
- return e(r);
2
+ function e(t) {
3
+ return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
5
4
  }
6
5
  export {
7
- n as useQueryUnwrapped
6
+ e as getDefaultExportFromCjs
8
7
  };
package/dist/index60.mjs CHANGED
@@ -1,7 +1,5 @@
1
1
  'use client';
2
- function e(t) {
3
- return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
4
- }
2
+ var o = { exports: {} };
5
3
  export {
6
- e as getDefaultExportFromCjs
4
+ o as __module
7
5
  };
package/dist/index61.mjs CHANGED
@@ -1,5 +1,8 @@
1
1
  'use client';
2
- var o = { exports: {} };
2
+ import { useQuery as e } from "@tanstack/react-query";
3
+ function n(r) {
4
+ return e(r);
5
+ }
3
6
  export {
4
- o as __module
7
+ n as useQueryUnwrapped
5
8
  };
package/dist/index8.mjs CHANGED
@@ -23,7 +23,7 @@ function W({
23
23
  emptyMessage: I = "Your cart is empty"
24
24
  }) {
25
25
  var x, y, g;
26
- const { cart: t, isLoading: i, error: m } = q(), [D, u] = Y(!1);
26
+ const { cart: t, isLoading: i, error: m } = q(), [S, u] = Y(!1);
27
27
  b(() => (s ? document.body.style.overflow = "hidden" : document.body.style.overflow = "", () => {
28
28
  document.body.style.overflow = "";
29
29
  }), [s]), b(() => {
@@ -32,9 +32,9 @@ function W({
32
32
  };
33
33
  return window.addEventListener("keydown", r), () => window.removeEventListener("keydown", r);
34
34
  }, [s, l]);
35
- const F = ((x = t == null ? void 0 : t.pricing) == null ? void 0 : x.subtotal) || 0, p = ((y = t == null ? void 0 : t.pricing.discount) == null ? void 0 : y.amount) || 0, P = () => {
35
+ const D = ((x = t == null ? void 0 : t.pricing) == null ? void 0 : x.subtotal) || 0, p = ((y = t == null ? void 0 : t.pricing.discount) == null ? void 0 : y.amount) || 0, F = () => {
36
36
  u(!0), d == null || d();
37
- }, S = () => {
37
+ }, P = () => {
38
38
  o == null || o(), l();
39
39
  };
40
40
  return /* @__PURE__ */ a(N, { children: [
@@ -103,7 +103,7 @@ function W({
103
103
  /* @__PURE__ */ a("div", { className: "p-4 space-y-2", children: [
104
104
  /* @__PURE__ */ a("div", { className: "flex justify-between", children: [
105
105
  /* @__PURE__ */ e("span", { className: "text-gray-600", children: "Subtotal" }),
106
- /* @__PURE__ */ e("span", { className: "font-semibold", children: n(F) })
106
+ /* @__PURE__ */ e("span", { className: "font-semibold", children: n(D) })
107
107
  ] }),
108
108
  p > 0 && /* @__PURE__ */ a("div", { className: "flex justify-between text-green-600", children: [
109
109
  /* @__PURE__ */ e("span", { children: "Discount" }),
@@ -126,7 +126,7 @@ function W({
126
126
  /* @__PURE__ */ a(
127
127
  v,
128
128
  {
129
- onClick: P,
129
+ onClick: F,
130
130
  disabled: z || t.items.length === 0,
131
131
  className: c("w-full bg-accent-500 text-white hover:bg-accent-600", E),
132
132
  size: "lg",
@@ -139,7 +139,7 @@ function W({
139
139
  /* @__PURE__ */ e(
140
140
  v,
141
141
  {
142
- onClick: S,
142
+ onClick: P,
143
143
  variant: "outline",
144
144
  className: c("w-full border-gray-300 text-gray-600 hover:bg-gray-100", L),
145
145
  size: "lg",
@@ -155,7 +155,8 @@ function W({
155
155
  /* @__PURE__ */ e(
156
156
  X,
157
157
  {
158
- isOpen: D,
158
+ isOpen: S,
159
+ onSuccess: () => l(),
159
160
  onClose: () => u(!1)
160
161
  }
161
162
  )
package/dist/index81.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import f from "./index64.mjs";
3
- import d from "./index93.mjs";
3
+ import d from "./index95.mjs";
4
4
  function l(e) {
5
5
  return encodeURIComponent(e).replace(/%3A/gi, ":").replace(/%24/g, "$").replace(/%2C/gi, ",").replace(/%20/g, "+");
6
6
  }
package/dist/index83.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import r from "./index94.mjs";
2
+ import r from "./index96.mjs";
3
3
  import p from "./index72.mjs";
4
4
  import l from "./index68.mjs";
5
5
  import m from "./index70.mjs";
package/dist/index84.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use client';
2
- import r from "./index95.mjs";
3
- import f from "./index96.mjs";
2
+ import r from "./index97.mjs";
3
+ import f from "./index98.mjs";
4
4
  function u(l, i, t) {
5
5
  let o = !r(i);
6
6
  return l && (o || t == !1) ? f(l, i) : i;
package/dist/index88.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use client';
2
- import o from "./index97.mjs";
3
- import * as t from "./index98.mjs";
2
+ import o from "./index93.mjs";
3
+ import * as t from "./index94.mjs";
4
4
  const m = {
5
5
  ...t,
6
6
  ...o
package/dist/index93.mjs CHANGED
@@ -1,34 +1,16 @@
1
1
  'use client';
2
- import p from "./index74.mjs";
3
- function i(n) {
4
- const t = {
5
- "!": "%21",
6
- "'": "%27",
7
- "(": "%28",
8
- ")": "%29",
9
- "~": "%7E",
10
- "%20": "+",
11
- "%00": "\0"
12
- };
13
- return encodeURIComponent(n).replace(/[!'()~]|%20|%00/g, function(r) {
14
- return t[r];
15
- });
16
- }
17
- function a(n, t) {
18
- this._pairs = [], n && p(n, this, t);
19
- }
20
- const c = a.prototype;
21
- c.append = function(t, o) {
22
- this._pairs.push([t, o]);
23
- };
24
- c.toString = function(t) {
25
- const o = t ? function(r) {
26
- return t.call(this, r, i);
27
- } : i;
28
- return this._pairs.map(function(e) {
29
- return o(e[0]) + "=" + o(e[1]);
30
- }, "").join("&");
2
+ import o from "./index105.mjs";
3
+ import r from "./index106.mjs";
4
+ import t from "./index107.mjs";
5
+ const l = {
6
+ isBrowser: !0,
7
+ classes: {
8
+ URLSearchParams: o,
9
+ FormData: r,
10
+ Blob: t
11
+ },
12
+ protocols: ["http", "https", "file", "blob", "url", "data"]
31
13
  };
32
14
  export {
33
- a as default
15
+ l as default
34
16
  };
package/dist/index94.mjs CHANGED
@@ -1,14 +1,10 @@
1
1
  'use client';
2
- import i from "./index64.mjs";
3
- import m from "./index68.mjs";
4
- import s from "./index78.mjs";
5
- function h(f, t) {
6
- const o = this || m, r = t || o, n = s.from(r.headers);
7
- let a = r.data;
8
- return i.forEach(f, function(e) {
9
- a = e.call(o, a, n.normalize(), t ? t.status : void 0);
10
- }), n.normalize(), a;
11
- }
2
+ const e = typeof window < "u" && typeof document < "u", o = typeof navigator == "object" && navigator || void 0, n = e && (!o || ["ReactNative", "NativeScript", "NS"].indexOf(o.product) < 0), t = typeof WorkerGlobalScope < "u" && // eslint-disable-next-line no-undef
3
+ self instanceof WorkerGlobalScope && typeof self.importScripts == "function", r = e && window.location.href || "http://localhost";
12
4
  export {
13
- h as default
5
+ e as hasBrowserEnv,
6
+ n as hasStandardBrowserEnv,
7
+ t as hasStandardBrowserWebWorkerEnv,
8
+ o as navigator,
9
+ r as origin
14
10
  };
package/dist/index95.mjs CHANGED
@@ -1,7 +1,34 @@
1
1
  'use client';
2
- function e(t) {
3
- return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(t);
2
+ import p from "./index74.mjs";
3
+ function i(n) {
4
+ const t = {
5
+ "!": "%21",
6
+ "'": "%27",
7
+ "(": "%28",
8
+ ")": "%29",
9
+ "~": "%7E",
10
+ "%20": "+",
11
+ "%00": "\0"
12
+ };
13
+ return encodeURIComponent(n).replace(/[!'()~]|%20|%00/g, function(r) {
14
+ return t[r];
15
+ });
4
16
  }
17
+ function a(n, t) {
18
+ this._pairs = [], n && p(n, this, t);
19
+ }
20
+ const c = a.prototype;
21
+ c.append = function(t, o) {
22
+ this._pairs.push([t, o]);
23
+ };
24
+ c.toString = function(t) {
25
+ const o = t ? function(r) {
26
+ return t.call(this, r, i);
27
+ } : i;
28
+ return this._pairs.map(function(e) {
29
+ return o(e[0]) + "=" + o(e[1]);
30
+ }, "").join("&");
31
+ };
5
32
  export {
6
- e as default
33
+ a as default
7
34
  };
package/dist/index96.mjs CHANGED
@@ -1,7 +1,14 @@
1
1
  'use client';
2
- function n(e, c) {
3
- return c ? e.replace(/\/?\/$/, "") + "/" + c.replace(/^\/+/, "") : e;
2
+ import i from "./index64.mjs";
3
+ import m from "./index68.mjs";
4
+ import s from "./index78.mjs";
5
+ function h(f, t) {
6
+ const o = this || m, r = t || o, n = s.from(r.headers);
7
+ let a = r.data;
8
+ return i.forEach(f, function(e) {
9
+ a = e.call(o, a, n.normalize(), t ? t.status : void 0);
10
+ }), n.normalize(), a;
4
11
  }
5
12
  export {
6
- n as default
13
+ h as default
7
14
  };
package/dist/index97.mjs CHANGED
@@ -1,16 +1,7 @@
1
1
  'use client';
2
- import o from "./index105.mjs";
3
- import r from "./index106.mjs";
4
- import t from "./index107.mjs";
5
- const l = {
6
- isBrowser: !0,
7
- classes: {
8
- URLSearchParams: o,
9
- FormData: r,
10
- Blob: t
11
- },
12
- protocols: ["http", "https", "file", "blob", "url", "data"]
13
- };
2
+ function e(t) {
3
+ return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(t);
4
+ }
14
5
  export {
15
- l as default
6
+ e as default
16
7
  };
package/dist/index98.mjs CHANGED
@@ -1,10 +1,7 @@
1
1
  'use client';
2
- const e = typeof window < "u" && typeof document < "u", o = typeof navigator == "object" && navigator || void 0, n = e && (!o || ["ReactNative", "NativeScript", "NS"].indexOf(o.product) < 0), t = typeof WorkerGlobalScope < "u" && // eslint-disable-next-line no-undef
3
- self instanceof WorkerGlobalScope && typeof self.importScripts == "function", r = e && window.location.href || "http://localhost";
2
+ function n(e, c) {
3
+ return c ? e.replace(/\/?\/$/, "") + "/" + c.replace(/^\/+/, "") : e;
4
+ }
4
5
  export {
5
- e as hasBrowserEnv,
6
- n as hasStandardBrowserEnv,
7
- t as hasStandardBrowserWebWorkerEnv,
8
- o as navigator,
9
- r as origin
6
+ n as default
10
7
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instockng/storefront-ui",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "Pre-built UI components for OMS e-commerce sites",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -66,8 +66,8 @@
66
66
  "tailwindcss": "^4.1.14",
67
67
  "typescript": "^5.3.3",
68
68
  "vite": "^5.4.20",
69
- "@oms/api-client": "1.0.0",
70
- "@oms/shared": "1.0.0"
69
+ "@oms/shared": "1.0.0",
70
+ "@oms/api-client": "1.0.0"
71
71
  },
72
72
  "scripts": {
73
73
  "type-check": "tsc --noEmit",
@@ -255,6 +255,7 @@ export function ShoppingCart({
255
255
  {/* Checkout Modal */}
256
256
  <Checkout
257
257
  isOpen={isCheckoutOpen}
258
+ onSuccess={() => onClose()}
258
259
  onClose={() => setIsCheckoutOpen(false)}
259
260
  />
260
261
  </>
@@ -84,7 +84,8 @@ export function CartProvider({ children, brandSlug, initialCartId, shoppingCartP
84
84
  const [isMounted, setIsMounted] = useState(false);
85
85
 
86
86
  // Use refs to prevent infinite loops
87
- const hasInitializedRef = useRef(false);
87
+ const hasLoadedFromStorageRef = useRef(false);
88
+ const hasAutoCreatedRef = useRef(false);
88
89
  const isHandlingErrorRef = useRef(false);
89
90
 
90
91
  // Set mounted flag on client
@@ -95,7 +96,9 @@ export function CartProvider({ children, brandSlug, initialCartId, shoppingCartP
95
96
  // Load cartId from URL/localStorage after mount (client-side only)
96
97
  // This avoids hydration mismatch between server and client
97
98
  useEffect(() => {
98
- if (initialCartId || hasInitializedRef.current) return;
99
+ if (initialCartId || hasLoadedFromStorageRef.current) return;
100
+
101
+ hasLoadedFromStorageRef.current = true;
99
102
 
100
103
  // Check URL query params first
101
104
  const urlParams = new URLSearchParams(window.location.search);
@@ -134,39 +137,47 @@ export function CartProvider({ children, brandSlug, initialCartId, shoppingCartP
134
137
  },
135
138
  });
136
139
 
137
- // Auto-create cart on mount if no cartId exists - only runs ONCE
138
- // Use a layout effect to run before paint
140
+ // Auto-create cart ONLY on initial mount if no cartId in localStorage
141
+ // After the first mount, we don't auto-create (user must explicitly add items)
139
142
  useEffect(() => {
140
- if (!hasInitializedRef.current && !cartId && !initialCartId) {
141
- hasInitializedRef.current = true;
142
- // Defer cart creation to next tick
143
- const timeoutId = setTimeout(() => {
144
- if (!hasInitializedRef.current) return; // Double check
143
+ // Only run on initial mount
144
+ if (hasAutoCreatedRef.current) return;
145
+
146
+ hasAutoCreatedRef.current = true;
147
+
148
+ // Defer cart creation to allow localStorage to load first
149
+ const timeoutId = setTimeout(() => {
150
+ // Only create if we still don't have a cartId after localStorage loaded
151
+ if (!cartId && !initialCartId) {
145
152
  createCartMutation.mutate(brandSlug);
146
- }, 0);
153
+ }
154
+ }, 150); // Delay to ensure localStorage effect has run
147
155
 
148
- return () => clearTimeout(timeoutId);
149
- }
156
+ return () => clearTimeout(timeoutId);
150
157
  // eslint-disable-next-line react-hooks/exhaustive-deps
151
- }, []);
158
+ }, []); // Empty deps - truly only run once on mount
152
159
 
153
160
  // Handle cart fetch error (invalid/expired cart from URL or localStorage)
154
- // Only clear the cart if there's an error, don't try to create a new one
161
+ // Clear the invalid cart and create a new one
155
162
  useEffect(() => {
156
163
  if (error && cartId && !isHandlingErrorRef.current) {
157
164
  isHandlingErrorRef.current = true;
158
- console.warn('Cart fetch failed, clearing invalid cart:', error);
159
-
160
- // Use a microtask to batch the state updates
161
- Promise.resolve().then(() => {
162
- setCartId(null);
163
- if (typeof window !== 'undefined') {
164
- localStorage.removeItem(CART_ID_KEY);
165
- }
165
+ console.warn('Cart fetch failed, creating new cart:', error);
166
+
167
+ // Clear invalid cart
168
+ setCartId(null);
169
+ if (typeof window !== 'undefined') {
170
+ localStorage.removeItem(CART_ID_KEY);
171
+ }
172
+
173
+ // Create a new cart after clearing the invalid one
174
+ setTimeout(() => {
175
+ createCartMutation.mutate(brandSlug);
166
176
  isHandlingErrorRef.current = false;
167
- });
177
+ }, 100);
168
178
  }
169
- }, [error, cartId]);
179
+ // eslint-disable-next-line react-hooks/exhaustive-deps
180
+ }, [error, cartId, brandSlug]); // Don't include createCartMutation to avoid infinite loop
170
181
 
171
182
  // Mutations
172
183
  const addItemMutation = useAddCartItem(cartId || '', {