@instockng/storefront-ui 1.0.12 → 1.0.13
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/components/Checkout.d.ts.map +1 -1
- package/dist/contexts/CartContext.d.ts +2 -0
- package/dist/contexts/CartContext.d.ts.map +1 -1
- package/dist/index10.mjs +70 -70
- package/dist/index101.mjs +1 -1
- package/dist/index102.mjs +3 -3
- package/dist/index103.mjs +3 -3
- package/dist/index111.mjs +1 -1
- package/dist/index3.mjs +80 -75
- package/dist/index42.mjs +17 -17
- package/dist/index43.mjs +2 -2
- package/dist/index62.mjs +231 -30
- package/dist/index63.mjs +5 -42
- package/dist/index64.mjs +127 -228
- package/dist/index65.mjs +66 -4
- package/dist/index66.mjs +77 -124
- package/dist/index67.mjs +26 -65
- package/dist/index68.mjs +6 -84
- package/dist/index69.mjs +72 -26
- package/dist/index70.mjs +3 -8
- package/dist/index71.mjs +2 -75
- package/dist/index72.mjs +82 -3
- package/dist/index73.mjs +54 -2
- package/dist/index74.mjs +5 -82
- package/dist/index75.mjs +4 -53
- package/dist/index76.mjs +178 -5
- package/dist/index77.mjs +53 -5
- package/dist/index78.mjs +68 -178
- package/dist/index79.mjs +31 -50
- package/dist/index80.mjs +43 -69
- package/dist/index81.mjs +1 -1
- package/dist/index82.mjs +1 -1
- package/dist/index83.mjs +5 -5
- package/dist/index85.mjs +2 -2
- package/dist/index87.mjs +2 -2
- package/dist/index89.mjs +1 -1
- package/dist/index91.mjs +4 -4
- package/dist/index92.mjs +3 -3
- package/dist/index95.mjs +1 -1
- package/dist/index96.mjs +3 -3
- package/dist/index99.mjs +1 -1
- package/dist/test-utils/MockCartProvider.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/components/Checkout.tsx +9 -1
- package/src/contexts/CartContext.tsx +17 -1
- package/src/test-utils/MockCartProvider.tsx +8 -0
package/dist/index80.mjs
CHANGED
|
@@ -1,72 +1,46 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
PayloadTooLarge: 413,
|
|
40
|
-
UriTooLong: 414,
|
|
41
|
-
UnsupportedMediaType: 415,
|
|
42
|
-
RangeNotSatisfiable: 416,
|
|
43
|
-
ExpectationFailed: 417,
|
|
44
|
-
ImATeapot: 418,
|
|
45
|
-
MisdirectedRequest: 421,
|
|
46
|
-
UnprocessableEntity: 422,
|
|
47
|
-
Locked: 423,
|
|
48
|
-
FailedDependency: 424,
|
|
49
|
-
TooEarly: 425,
|
|
50
|
-
UpgradeRequired: 426,
|
|
51
|
-
PreconditionRequired: 428,
|
|
52
|
-
TooManyRequests: 429,
|
|
53
|
-
RequestHeaderFieldsTooLarge: 431,
|
|
54
|
-
UnavailableForLegalReasons: 451,
|
|
55
|
-
InternalServerError: 500,
|
|
56
|
-
NotImplemented: 501,
|
|
57
|
-
BadGateway: 502,
|
|
58
|
-
ServiceUnavailable: 503,
|
|
59
|
-
GatewayTimeout: 504,
|
|
60
|
-
HttpVersionNotSupported: 505,
|
|
61
|
-
VariantAlsoNegotiates: 506,
|
|
62
|
-
InsufficientStorage: 507,
|
|
63
|
-
LoopDetected: 508,
|
|
64
|
-
NotExtended: 510,
|
|
65
|
-
NetworkAuthenticationRequired: 511
|
|
66
|
-
};
|
|
67
|
-
Object.entries(e).forEach(([t, o]) => {
|
|
68
|
-
e[o] = t;
|
|
69
|
-
});
|
|
2
|
+
var s = (e, r) => (e = e.replace(/\/+$/, ""), e = e + "/", r = r.replace(/^\/+/, ""), e + r), p = (e, r) => {
|
|
3
|
+
for (const [n, t] of Object.entries(r)) {
|
|
4
|
+
const c = new RegExp("/:" + n + "(?:{[^/]+})?\\??");
|
|
5
|
+
e = e.replace(c, t ? `/${t}` : "");
|
|
6
|
+
}
|
|
7
|
+
return e;
|
|
8
|
+
}, f = (e) => {
|
|
9
|
+
const r = new URLSearchParams();
|
|
10
|
+
for (const [n, t] of Object.entries(e))
|
|
11
|
+
if (t !== void 0)
|
|
12
|
+
if (Array.isArray(t))
|
|
13
|
+
for (const c of t)
|
|
14
|
+
r.append(n, c);
|
|
15
|
+
else
|
|
16
|
+
r.set(n, t);
|
|
17
|
+
return r;
|
|
18
|
+
}, i = (e, r) => {
|
|
19
|
+
switch (r) {
|
|
20
|
+
case "ws":
|
|
21
|
+
return e.replace(/^http/, "ws");
|
|
22
|
+
case "http":
|
|
23
|
+
return e.replace(/^ws/, "http");
|
|
24
|
+
}
|
|
25
|
+
}, l = (e) => /^https?:\/\/[^\/]+?\/index(?=\?|$)/.test(e) ? e.replace(/\/index(?=\?|$)/, "/") : e.replace(/\/index(?=\?|$)/, "");
|
|
26
|
+
function a(e) {
|
|
27
|
+
return typeof e == "object" && e !== null && !Array.isArray(e);
|
|
28
|
+
}
|
|
29
|
+
function o(e, r) {
|
|
30
|
+
if (!a(e) && !a(r))
|
|
31
|
+
return r;
|
|
32
|
+
const n = { ...e };
|
|
33
|
+
for (const t in r) {
|
|
34
|
+
const c = r[t];
|
|
35
|
+
a(n[t]) && a(c) ? n[t] = o(n[t], c) : n[t] = c;
|
|
36
|
+
}
|
|
37
|
+
return n;
|
|
38
|
+
}
|
|
70
39
|
export {
|
|
71
|
-
|
|
40
|
+
f as buildSearchParams,
|
|
41
|
+
o as deepMerge,
|
|
42
|
+
s as mergePath,
|
|
43
|
+
l as removeIndexString,
|
|
44
|
+
p as replaceUrlParam,
|
|
45
|
+
i as replaceUrlProtocol
|
|
72
46
|
};
|
package/dist/index81.mjs
CHANGED
package/dist/index82.mjs
CHANGED
package/dist/index83.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import r from "./index96.mjs";
|
|
3
|
-
import p from "./
|
|
4
|
-
import l from "./
|
|
5
|
-
import m from "./
|
|
6
|
-
import a from "./
|
|
7
|
-
import o from "./
|
|
3
|
+
import p from "./index70.mjs";
|
|
4
|
+
import l from "./index66.mjs";
|
|
5
|
+
import m from "./index68.mjs";
|
|
6
|
+
import a from "./index76.mjs";
|
|
7
|
+
import o from "./index77.mjs";
|
|
8
8
|
function d(e) {
|
|
9
9
|
if (e.cancelToken && e.cancelToken.throwIfRequested(), e.signal && e.signal.aborted)
|
|
10
10
|
throw new m(null, e);
|
package/dist/index85.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { VERSION as w } from "./
|
|
3
|
-
import s from "./
|
|
2
|
+
import { VERSION as w } from "./index71.mjs";
|
|
3
|
+
import s from "./index73.mjs";
|
|
4
4
|
const l = {};
|
|
5
5
|
["object", "boolean", "number", "function", "string", "symbol"].forEach((n, t) => {
|
|
6
6
|
l[n] = function(o) {
|
package/dist/index87.mjs
CHANGED
package/dist/index89.mjs
CHANGED
package/dist/index91.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import H from "./
|
|
2
|
+
import H from "./index62.mjs";
|
|
3
3
|
import D from "./index99.mjs";
|
|
4
4
|
import L from "./index86.mjs";
|
|
5
|
-
import n from "./
|
|
6
|
-
import y from "./
|
|
5
|
+
import n from "./index73.mjs";
|
|
6
|
+
import y from "./index68.mjs";
|
|
7
7
|
import O from "./index100.mjs";
|
|
8
8
|
import U from "./index88.mjs";
|
|
9
|
-
import q from "./
|
|
9
|
+
import q from "./index76.mjs";
|
|
10
10
|
import { progressEventReducer as A } from "./index101.mjs";
|
|
11
11
|
import v from "./index102.mjs";
|
|
12
12
|
const N = typeof XMLHttpRequest < "u", Q = N && function(s) {
|
package/dist/index92.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import K from "./index88.mjs";
|
|
3
|
-
import t from "./
|
|
4
|
-
import b from "./
|
|
3
|
+
import t from "./index62.mjs";
|
|
4
|
+
import b from "./index73.mjs";
|
|
5
5
|
import ee from "./index103.mjs";
|
|
6
6
|
import { trackStream as z } from "./index104.mjs";
|
|
7
|
-
import te from "./
|
|
7
|
+
import te from "./index76.mjs";
|
|
8
8
|
import { progressEventDecorator as I, progressEventReducer as M, asyncDecorator as j } from "./index101.mjs";
|
|
9
9
|
import se from "./index102.mjs";
|
|
10
10
|
import re from "./index99.mjs";
|
package/dist/index95.mjs
CHANGED
package/dist/index96.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import i from "./
|
|
3
|
-
import m from "./
|
|
4
|
-
import s from "./
|
|
2
|
+
import i from "./index62.mjs";
|
|
3
|
+
import m from "./index66.mjs";
|
|
4
|
+
import s from "./index76.mjs";
|
|
5
5
|
function h(f, t) {
|
|
6
6
|
const o = this || m, r = t || o, n = s.from(r.headers);
|
|
7
7
|
let a = r.data;
|
package/dist/index99.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MockCartProvider.d.ts","sourceRoot":"","sources":["../../src/test-utils/MockCartProvider.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAyB,MAAM,OAAO,CAAC;AAGzD,OAAO,KAAK,EAAE,IAAI,EAAuB,MAAM,iBAAiB,CAAC;AACjE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAiHpE,UAAU,qBAAqB;IAC7B,QAAQ,EAAE,SAAS,CAAC;IACpB,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;IACrB,kDAAkD;IAClD,iBAAiB,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,QAAQ,GAAG,SAAS,CAAC,CAAC;IAClE,mEAAmE;IACnE,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,wBAAgB,gBAAgB,CAAC,EAC/B,QAAQ,EACR,IAAI,EAAE,YAAY,EAClB,SAAiB,EACjB,KAAY,EACZ,iBAAiB,EACjB,UAAiB,GAClB,EAAE,qBAAqB,
|
|
1
|
+
{"version":3,"file":"MockCartProvider.d.ts","sourceRoot":"","sources":["../../src/test-utils/MockCartProvider.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAyB,MAAM,OAAO,CAAC;AAGzD,OAAO,KAAK,EAAE,IAAI,EAAuB,MAAM,iBAAiB,CAAC;AACjE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAiHpE,UAAU,qBAAqB;IAC7B,QAAQ,EAAE,SAAS,CAAC;IACpB,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;IACrB,kDAAkD;IAClD,iBAAiB,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,QAAQ,GAAG,SAAS,CAAC,CAAC;IAClE,mEAAmE;IACnE,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,wBAAgB,gBAAgB,CAAC,EAC/B,QAAQ,EACR,IAAI,EAAE,YAAY,EAClB,SAAiB,EACjB,KAAY,EACZ,iBAAiB,EACjB,UAAiB,GAClB,EAAE,qBAAqB,2CAkSvB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instockng/storefront-ui",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
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/
|
|
70
|
-
"@oms/
|
|
69
|
+
"@oms/api-client": "1.0.0",
|
|
70
|
+
"@oms/shared": "1.0.0"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"type-check": "tsc --noEmit",
|
|
@@ -147,7 +147,7 @@ export function Checkout({
|
|
|
147
147
|
const [completedOrder, setCompletedOrder] = useState<Order | null>(null);
|
|
148
148
|
|
|
149
149
|
// Get cart from CartProvider context (required)
|
|
150
|
-
const { refetch: refetchCart, isLoading: isLoadingCart, cart, updateCartMutation, checkoutMutation } = useCart();
|
|
150
|
+
const { refetch: refetchCart, isLoading: isLoadingCart, cart, updateCartMutation, checkoutMutation, clearAndCreateNewCart } = useCart();
|
|
151
151
|
|
|
152
152
|
// Paystack payment integration
|
|
153
153
|
const paystack = usePaystackPayment({
|
|
@@ -176,6 +176,10 @@ export function Checkout({
|
|
|
176
176
|
|
|
177
177
|
// Store the completed order to show success view
|
|
178
178
|
setCompletedOrder(order as Order);
|
|
179
|
+
|
|
180
|
+
// Clear the cart and create a new one for next purchase
|
|
181
|
+
clearAndCreateNewCart();
|
|
182
|
+
|
|
179
183
|
onSuccess?.(order.id);
|
|
180
184
|
} catch (error) {
|
|
181
185
|
onError?.(error as Error);
|
|
@@ -431,6 +435,10 @@ export function Checkout({
|
|
|
431
435
|
|
|
432
436
|
// Store the completed order to show success view
|
|
433
437
|
setCompletedOrder(order as Order);
|
|
438
|
+
|
|
439
|
+
// Clear the cart and create a new one for next purchase
|
|
440
|
+
clearAndCreateNewCart();
|
|
441
|
+
|
|
434
442
|
onSuccess?.(order.id);
|
|
435
443
|
} catch (error) {
|
|
436
444
|
onError?.(error as Error);
|
|
@@ -50,6 +50,8 @@ interface CartContextValue {
|
|
|
50
50
|
removeDiscount: () => Promise<void>;
|
|
51
51
|
/** Clear cart (removes from localStorage) */
|
|
52
52
|
clearCart: () => void;
|
|
53
|
+
/** Clear cart and create a new one immediately */
|
|
54
|
+
clearAndCreateNewCart: () => void;
|
|
53
55
|
/** Refresh cart data */
|
|
54
56
|
refetch: () => void;
|
|
55
57
|
/** Whether the cart modal is open */
|
|
@@ -135,6 +137,7 @@ export function CartProvider({ children, brandSlug, initialCartId, shoppingCartP
|
|
|
135
137
|
onError: (error) => {
|
|
136
138
|
console.error('Failed to create cart:', error);
|
|
137
139
|
},
|
|
140
|
+
retry: 10,
|
|
138
141
|
});
|
|
139
142
|
|
|
140
143
|
// Auto-create cart ONLY on initial mount if no cartId in localStorage
|
|
@@ -147,8 +150,11 @@ export function CartProvider({ children, brandSlug, initialCartId, shoppingCartP
|
|
|
147
150
|
|
|
148
151
|
// Defer cart creation to allow localStorage to load first
|
|
149
152
|
const timeoutId = setTimeout(() => {
|
|
153
|
+
// Check localStorage directly (don't rely on state due to closure)
|
|
154
|
+
const storedCartId = typeof window !== 'undefined' ? localStorage.getItem(CART_ID_KEY) : null;
|
|
155
|
+
|
|
150
156
|
// Only create if we still don't have a cartId after localStorage loaded
|
|
151
|
-
if (!
|
|
157
|
+
if (!storedCartId && !initialCartId) {
|
|
152
158
|
createCartMutation.mutate(brandSlug);
|
|
153
159
|
}
|
|
154
160
|
}, 150); // Delay to ensure localStorage effect has run
|
|
@@ -202,6 +208,7 @@ export function CartProvider({ children, brandSlug, initialCartId, shoppingCartP
|
|
|
202
208
|
|
|
203
209
|
const updateCartMutation = useUpdateCart(cartId || '', {
|
|
204
210
|
onSuccess: () => refetch(),
|
|
211
|
+
retry: 3
|
|
205
212
|
});
|
|
206
213
|
|
|
207
214
|
const checkoutMutation = useCheckoutCart(cartId || '');
|
|
@@ -262,6 +269,14 @@ export function CartProvider({ children, brandSlug, initialCartId, shoppingCartP
|
|
|
262
269
|
}
|
|
263
270
|
}, []);
|
|
264
271
|
|
|
272
|
+
const clearAndCreateNewCart = useCallback(() => {
|
|
273
|
+
clearCart();
|
|
274
|
+
|
|
275
|
+
// Create a new cart immediately
|
|
276
|
+
createCartMutation.mutate(brandSlug);
|
|
277
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
278
|
+
}, [brandSlug]);
|
|
279
|
+
|
|
265
280
|
const open = useCallback(() => {
|
|
266
281
|
setIsOpen(true);
|
|
267
282
|
}, []);
|
|
@@ -283,6 +298,7 @@ export function CartProvider({ children, brandSlug, initialCartId, shoppingCartP
|
|
|
283
298
|
applyDiscount,
|
|
284
299
|
removeDiscount,
|
|
285
300
|
clearCart,
|
|
301
|
+
clearAndCreateNewCart,
|
|
286
302
|
refetch,
|
|
287
303
|
isOpen,
|
|
288
304
|
open,
|
|
@@ -400,6 +400,14 @@ export function MockCartProvider({
|
|
|
400
400
|
}));
|
|
401
401
|
},
|
|
402
402
|
|
|
403
|
+
clearAndCreateNewCart: () => {
|
|
404
|
+
console.log('Mock clearAndCreateNewCart');
|
|
405
|
+
setCart(prev => ({
|
|
406
|
+
...prev,
|
|
407
|
+
items: [],
|
|
408
|
+
}));
|
|
409
|
+
},
|
|
410
|
+
|
|
403
411
|
refetch: () => {
|
|
404
412
|
console.log('Mock refetch');
|
|
405
413
|
},
|