@storepecker/storefront-core 1.2.0 → 2.1.0
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/api/index.cjs +76 -75
- package/dist/api/index.d.cts +5 -3
- package/dist/api/index.d.ts +5 -3
- package/dist/api/index.js +9 -8
- package/dist/{booking-CegE1cje.d.ts → booking-BgZoXUBv.d.cts} +2 -41
- package/dist/{booking-B21s0inO.d.cts → booking-CZ59BXk3.d.ts} +2 -41
- package/dist/cart-BY8D8w-s.d.cts +90 -0
- package/dist/cart-GuhgeBBt.d.ts +90 -0
- package/dist/checkout/index.cjs +38 -37
- package/dist/checkout/index.d.cts +2 -1
- package/dist/checkout/index.d.ts +2 -1
- package/dist/checkout/index.js +6 -5
- package/dist/{chunk-34KV265H.cjs → chunk-26A3EBZI.cjs} +20 -20
- package/dist/chunk-2AHH3XBW.cjs +47 -0
- package/dist/{chunk-K5B62JZO.cjs → chunk-47XTPPII.cjs} +4 -4
- package/dist/chunk-4C4NTH6O.js +41 -0
- package/dist/{chunk-UM24VDYB.js → chunk-7R2V4C7Q.js} +2 -2
- package/dist/{chunk-CSISWBZZ.js → chunk-B7FOXIZN.js} +1 -1
- package/dist/chunk-BBRB475I.cjs +43 -0
- package/dist/chunk-BBRXE57K.cjs +50 -0
- package/dist/{chunk-QCQCFYYR.js → chunk-BHOXJGIE.js} +1 -1
- package/dist/chunk-BQ256JKN.js +39 -0
- package/dist/{chunk-7UH6REGV.js → chunk-C7ZJZEEN.js} +1 -1
- package/dist/{chunk-A6IO3HIN.cjs → chunk-FMHR5ABF.cjs} +28 -28
- package/dist/{chunk-JHGXIIBZ.cjs → chunk-G3R7ZVAG.cjs} +7 -7
- package/dist/{chunk-4MJMNIAB.js → chunk-GHABOHLA.js} +1 -1
- package/dist/chunk-GTV42PDK.cjs +46 -0
- package/dist/chunk-HEFA67WK.js +42 -0
- package/dist/chunk-HSF2D56O.js +40 -0
- package/dist/{chunk-GB3HW6DM.js → chunk-JWKDXFS4.js} +1 -1
- package/dist/{chunk-KWKHHRRJ.cjs → chunk-KKQKHG26.cjs} +3 -3
- package/dist/{chunk-QM73PI5L.cjs → chunk-N3ZCCKXV.cjs} +10 -10
- package/dist/{chunk-GQTO5ZE2.cjs → chunk-NE3ZHELZ.cjs} +0 -46
- package/dist/chunk-PWYWNRVO.cjs +150 -0
- package/dist/{chunk-E7WPE3PV.js → chunk-QAC72HKO.js} +1 -1
- package/dist/{chunk-CFF632IQ.cjs → chunk-SMHJRNCR.cjs} +4 -4
- package/dist/chunk-UOFTDL4D.js +146 -0
- package/dist/chunk-WEMNXIRS.js +47 -0
- package/dist/{chunk-LC5ZAUKL.cjs → chunk-XLQAALMU.cjs} +10 -10
- package/dist/{chunk-Z7LHRD3V.js → chunk-Y6NFUWTH.js} +3 -3
- package/dist/{chunk-LBGIUNM6.js → chunk-YY77CUWX.js} +1 -1
- package/dist/{chunk-UXLUE3HW.cjs → chunk-ZO2HREQL.cjs} +2 -2
- package/dist/collections-CenI9AlQ.d.cts +40 -0
- package/dist/collections-CenI9AlQ.d.ts +40 -0
- package/dist/components/index.cjs +126 -7
- package/dist/components/index.d.cts +35 -8
- package/dist/components/index.d.ts +35 -8
- package/dist/components/index.js +122 -7
- package/dist/hooks/index.cjs +368 -27
- package/dist/hooks/index.d.cts +83 -3
- package/dist/hooks/index.d.ts +83 -3
- package/dist/hooks/index.js +352 -14
- package/dist/middleware/index.cjs +47 -0
- package/dist/middleware/index.d.cts +8 -0
- package/dist/middleware/index.d.ts +8 -0
- package/dist/middleware/index.js +44 -0
- package/dist/models/index.d.cts +5 -3
- package/dist/models/index.d.ts +5 -3
- package/dist/{cart-VaCKkJ1C.d.cts → product-Dfi0ke-4.d.cts} +1 -88
- package/dist/{cart-VaCKkJ1C.d.ts → product-Dfi0ke-4.d.ts} +1 -88
- package/dist/store/index.cjs +17 -85
- package/dist/store/index.d.cts +22 -2
- package/dist/store/index.d.ts +22 -2
- package/dist/store/index.js +7 -82
- package/dist/utils/index.cjs +80 -65
- package/dist/utils/index.d.cts +72 -7
- package/dist/utils/index.d.ts +72 -7
- package/dist/utils/index.js +20 -43
- package/dist/{wishlist-FG8tgn76.d.ts → wishlist-DHOvXmJj.d.cts} +1 -1
- package/dist/{wishlist-CkAhLpbI.d.cts → wishlist-LfdFxddw.d.ts} +1 -1
- package/package.json +24 -5
- package/dist/chunk-7DQIKSGY.js +0 -40
- package/dist/chunk-FLBJKM6G.js +0 -83
- package/dist/chunk-S3WIGYDS.cjs +0 -42
package/dist/hooks/index.cjs
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
require('../chunk-
|
|
7
|
-
var
|
|
8
|
-
var
|
|
3
|
+
var chunkKKQKHG26_cjs = require('../chunk-KKQKHG26.cjs');
|
|
4
|
+
var chunk2AHH3XBW_cjs = require('../chunk-2AHH3XBW.cjs');
|
|
5
|
+
var chunkPWYWNRVO_cjs = require('../chunk-PWYWNRVO.cjs');
|
|
6
|
+
var chunk26A3EBZI_cjs = require('../chunk-26A3EBZI.cjs');
|
|
7
|
+
var chunkSMHJRNCR_cjs = require('../chunk-SMHJRNCR.cjs');
|
|
8
|
+
var chunkXLQAALMU_cjs = require('../chunk-XLQAALMU.cjs');
|
|
9
|
+
var chunkFMHR5ABF_cjs = require('../chunk-FMHR5ABF.cjs');
|
|
9
10
|
require('../chunk-K44JZ5NL.cjs');
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
require('../chunk-4CVKE6CC.cjs');
|
|
13
|
-
require('../chunk-
|
|
14
|
-
require('../chunk-
|
|
15
|
-
require('../chunk-
|
|
11
|
+
var chunkN3ZCCKXV_cjs = require('../chunk-N3ZCCKXV.cjs');
|
|
12
|
+
var chunkG3R7ZVAG_cjs = require('../chunk-G3R7ZVAG.cjs');
|
|
13
|
+
var chunk4CVKE6CC_cjs = require('../chunk-4CVKE6CC.cjs');
|
|
14
|
+
require('../chunk-47XTPPII.cjs');
|
|
15
|
+
require('../chunk-ZO2HREQL.cjs');
|
|
16
|
+
require('../chunk-BBRXE57K.cjs');
|
|
17
|
+
require('../chunk-NE3ZHELZ.cjs');
|
|
16
18
|
require('../chunk-N3CTXRFT.cjs');
|
|
17
19
|
var react = require('react');
|
|
20
|
+
var axios = require('axios');
|
|
18
21
|
|
|
19
22
|
var useAddress = () => {
|
|
20
23
|
const [data, setData] = react.useState([]);
|
|
@@ -24,7 +27,7 @@ var useAddress = () => {
|
|
|
24
27
|
const fetchData = react.useCallback(async () => {
|
|
25
28
|
try {
|
|
26
29
|
setIsLoading(true);
|
|
27
|
-
const result = await
|
|
30
|
+
const result = await chunkG3R7ZVAG_cjs.getAddresses("/store/customer_address/");
|
|
28
31
|
setData(result || []);
|
|
29
32
|
setError(null);
|
|
30
33
|
} catch (err) {
|
|
@@ -49,7 +52,7 @@ var useCart = (addressId) => {
|
|
|
49
52
|
async (addrId) => {
|
|
50
53
|
try {
|
|
51
54
|
setIsLoading(true);
|
|
52
|
-
const result = await
|
|
55
|
+
const result = await chunk26A3EBZI_cjs.getCart("/customer/cart/", addrId ?? addressId);
|
|
53
56
|
setData(result);
|
|
54
57
|
setError(null);
|
|
55
58
|
} catch (err) {
|
|
@@ -80,7 +83,7 @@ var useOrders = (filters) => {
|
|
|
80
83
|
try {
|
|
81
84
|
setIsLoading(true);
|
|
82
85
|
const url = `/customer/order/?${queryString}`;
|
|
83
|
-
const result = await
|
|
86
|
+
const result = await chunkFMHR5ABF_cjs.getOrders(url);
|
|
84
87
|
setData(result);
|
|
85
88
|
setError(null);
|
|
86
89
|
} catch (err) {
|
|
@@ -117,7 +120,7 @@ function useGetProducts(initialFilter, options) {
|
|
|
117
120
|
apiParams[key] = value;
|
|
118
121
|
}
|
|
119
122
|
}
|
|
120
|
-
const result = await
|
|
123
|
+
const result = await chunk26A3EBZI_cjs.getProductList(endpoint, apiParams);
|
|
121
124
|
setData(result);
|
|
122
125
|
if (modeRef.current === "append" && isLoadMoreRef.current) {
|
|
123
126
|
setProducts((prev) => [...prev, ...result.results || []]);
|
|
@@ -185,7 +188,7 @@ var useGetProductDetails = (slug) => {
|
|
|
185
188
|
const fetchData = react.useCallback(async () => {
|
|
186
189
|
try {
|
|
187
190
|
setIsLoading(true);
|
|
188
|
-
const result = await
|
|
191
|
+
const result = await chunk26A3EBZI_cjs.getProductDetail("/inventory/products/", slug);
|
|
189
192
|
setData(result);
|
|
190
193
|
} catch (err) {
|
|
191
194
|
} finally {
|
|
@@ -208,7 +211,7 @@ var useGetProductCategories = () => {
|
|
|
208
211
|
const fetchData = async () => {
|
|
209
212
|
try {
|
|
210
213
|
setIsLoading(true);
|
|
211
|
-
const result = await
|
|
214
|
+
const result = await chunk26A3EBZI_cjs.getProductCategories("/store/categories");
|
|
212
215
|
setData(result || []);
|
|
213
216
|
} catch (err) {
|
|
214
217
|
setError(err);
|
|
@@ -228,7 +231,7 @@ var useUserDetails = () => {
|
|
|
228
231
|
const fetchData = react.useCallback(async () => {
|
|
229
232
|
try {
|
|
230
233
|
setIsLoading(true);
|
|
231
|
-
const result = await
|
|
234
|
+
const result = await chunkKKQKHG26_cjs.getUserDetails("/users/store/profile/");
|
|
232
235
|
setData(result);
|
|
233
236
|
setError(null);
|
|
234
237
|
} catch (err) {
|
|
@@ -253,7 +256,7 @@ var useWishlist = () => {
|
|
|
253
256
|
const fetchData = react.useCallback(async () => {
|
|
254
257
|
try {
|
|
255
258
|
setIsLoading(true);
|
|
256
|
-
const result = await
|
|
259
|
+
const result = await chunk26A3EBZI_cjs.getWishlist("/customer/wishlist/");
|
|
257
260
|
setData(result);
|
|
258
261
|
setError(null);
|
|
259
262
|
} catch (err) {
|
|
@@ -311,7 +314,7 @@ function useCheckoutPayment(options) {
|
|
|
311
314
|
const [isConfirmingPayment, setIsConfirmingPayment] = react.useState(false);
|
|
312
315
|
const [showSuccessModal, setShowSuccessModal] = react.useState(false);
|
|
313
316
|
const [showFailureModal, setShowFailureModal] = react.useState(false);
|
|
314
|
-
const resetCartCount =
|
|
317
|
+
const resetCartCount = chunkPWYWNRVO_cjs.useCartStore((s) => s.resetCartCount);
|
|
315
318
|
const callbacks = {
|
|
316
319
|
onSuccess: (order) => {
|
|
317
320
|
setOrderSummary(order);
|
|
@@ -334,7 +337,7 @@ function useCheckoutPayment(options) {
|
|
|
334
337
|
try {
|
|
335
338
|
setIsPlacingOrder(true);
|
|
336
339
|
const isCod = paymentMethod === "cod";
|
|
337
|
-
const response = await
|
|
340
|
+
const response = await chunkFMHR5ABF_cjs.placeOrder(
|
|
338
341
|
addressId,
|
|
339
342
|
options.phonepeRedirectUrl,
|
|
340
343
|
isCod,
|
|
@@ -343,7 +346,7 @@ function useCheckoutPayment(options) {
|
|
|
343
346
|
);
|
|
344
347
|
const order = response.data;
|
|
345
348
|
setOrderSummary(order);
|
|
346
|
-
|
|
349
|
+
chunkXLQAALMU_cjs.processPayment(order, paymentMethod, callbacks);
|
|
347
350
|
} catch {
|
|
348
351
|
setShowFailureModal(true);
|
|
349
352
|
} finally {
|
|
@@ -373,7 +376,7 @@ function useCheckoutCoupon(options) {
|
|
|
373
376
|
const refreshCoupons = react.useCallback(async () => {
|
|
374
377
|
setIsLoading(true);
|
|
375
378
|
try {
|
|
376
|
-
const coupons = await
|
|
379
|
+
const coupons = await chunkXLQAALMU_cjs.fetchAvailableCoupons();
|
|
377
380
|
setAvailableCoupons(coupons);
|
|
378
381
|
} catch {
|
|
379
382
|
} finally {
|
|
@@ -385,7 +388,7 @@ function useCheckoutCoupon(options) {
|
|
|
385
388
|
setError(null);
|
|
386
389
|
setIsApplying(true);
|
|
387
390
|
try {
|
|
388
|
-
const coupon = await
|
|
391
|
+
const coupon = await chunkXLQAALMU_cjs.applyCheckoutCoupon(code, callbacks);
|
|
389
392
|
setAppliedCoupon(coupon);
|
|
390
393
|
} catch (err) {
|
|
391
394
|
setError(err instanceof Error ? err.message : "Failed to apply coupon");
|
|
@@ -398,7 +401,7 @@ function useCheckoutCoupon(options) {
|
|
|
398
401
|
const removeCouponHandler = react.useCallback(async () => {
|
|
399
402
|
if (!appliedCoupon) return;
|
|
400
403
|
try {
|
|
401
|
-
await
|
|
404
|
+
await chunkXLQAALMU_cjs.removeCheckoutCoupon(appliedCoupon.coupon_code, callbacks);
|
|
402
405
|
setAppliedCoupon(null);
|
|
403
406
|
setError(null);
|
|
404
407
|
} catch {
|
|
@@ -420,20 +423,358 @@ function useCheckoutCoupon(options) {
|
|
|
420
423
|
refreshCoupons
|
|
421
424
|
};
|
|
422
425
|
}
|
|
426
|
+
function useVariantSelector(options) {
|
|
427
|
+
const { product, productAttributes, onVariantChange } = options;
|
|
428
|
+
const [selectedVariant, setSelectedVariant] = react.useState(
|
|
429
|
+
product.attributes ?? {}
|
|
430
|
+
);
|
|
431
|
+
const [isSizeChartModalOpen, setIsSizeChartModalOpen] = react.useState(false);
|
|
432
|
+
react.useEffect(() => {
|
|
433
|
+
setSelectedVariant(product.attributes);
|
|
434
|
+
}, [product]);
|
|
435
|
+
const attributeKeys = react.useMemo(
|
|
436
|
+
() => Object.keys(productAttributes ?? {}),
|
|
437
|
+
[productAttributes]
|
|
438
|
+
);
|
|
439
|
+
const handleVariantSelected = react.useCallback(
|
|
440
|
+
(variantType, variant) => {
|
|
441
|
+
const newSelectedVariants = {
|
|
442
|
+
...selectedVariant,
|
|
443
|
+
[variantType]: variant
|
|
444
|
+
};
|
|
445
|
+
const matchedVariant = chunk2AHH3XBW_cjs.findMatchingVariant(
|
|
446
|
+
product.variantAttributes,
|
|
447
|
+
attributeKeys,
|
|
448
|
+
newSelectedVariants
|
|
449
|
+
);
|
|
450
|
+
if (matchedVariant) {
|
|
451
|
+
if (matchedVariant.slug === selectedVariant.slug)
|
|
452
|
+
return;
|
|
453
|
+
setSelectedVariant(matchedVariant);
|
|
454
|
+
onVariantChange?.(matchedVariant.slug);
|
|
455
|
+
} else {
|
|
456
|
+
const similarVariant = chunk2AHH3XBW_cjs.findSimilarVariant(
|
|
457
|
+
product.variantAttributes,
|
|
458
|
+
variantType,
|
|
459
|
+
variant
|
|
460
|
+
);
|
|
461
|
+
if (similarVariant) {
|
|
462
|
+
setSelectedVariant(similarVariant);
|
|
463
|
+
onVariantChange?.(similarVariant.slug);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
},
|
|
467
|
+
[selectedVariant, product.variantAttributes, attributeKeys, onVariantChange]
|
|
468
|
+
);
|
|
469
|
+
const checkIfVariantAvailable = react.useCallback(
|
|
470
|
+
(variantType, variant) => {
|
|
471
|
+
if (!product.variants || product.variants.length === 0 || !productAttributes)
|
|
472
|
+
return false;
|
|
473
|
+
return chunk2AHH3XBW_cjs.isVariantCombinationAvailable(
|
|
474
|
+
product.variantAttributes,
|
|
475
|
+
attributeKeys,
|
|
476
|
+
selectedVariant,
|
|
477
|
+
variantType,
|
|
478
|
+
variant
|
|
479
|
+
);
|
|
480
|
+
},
|
|
481
|
+
[
|
|
482
|
+
product.variants,
|
|
483
|
+
product.variantAttributes,
|
|
484
|
+
productAttributes,
|
|
485
|
+
attributeKeys,
|
|
486
|
+
selectedVariant
|
|
487
|
+
]
|
|
488
|
+
);
|
|
489
|
+
const toggleSizeChartModal = react.useCallback(() => {
|
|
490
|
+
setIsSizeChartModalOpen((prev) => !prev);
|
|
491
|
+
}, []);
|
|
492
|
+
return {
|
|
493
|
+
selectedVariant,
|
|
494
|
+
handleVariantSelected,
|
|
495
|
+
checkIfVariantAvailable,
|
|
496
|
+
isColorType: chunk2AHH3XBW_cjs.isColorVariantType,
|
|
497
|
+
isSizeChartModalOpen,
|
|
498
|
+
toggleSizeChartModal
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
function useShopCheckout(options) {
|
|
502
|
+
const { product, onNavigateToCart, onToast } = options;
|
|
503
|
+
const { addToCart, setCart } = chunkPWYWNRVO_cjs.useCartStore();
|
|
504
|
+
const isUserAuthenticated = chunkPWYWNRVO_cjs.useAuthStore((s) => s.isAuthenticated);
|
|
505
|
+
const [isWishlisted, setIsWishlisted] = react.useState(product.is_wishlisted);
|
|
506
|
+
const [isAddedToCart, setIsAddedToCart] = react.useState(false);
|
|
507
|
+
const [loading, setLoading] = react.useState(false);
|
|
508
|
+
const [quantity, setQuantity] = react.useState(1);
|
|
509
|
+
const [showLoginModal, setShowLoginModal] = react.useState(false);
|
|
510
|
+
const [showNotifyMeModal, setShowNotifyMeModal] = react.useState(false);
|
|
511
|
+
const [categories, setCategories] = react.useState([]);
|
|
512
|
+
react.useEffect(() => {
|
|
513
|
+
const fetchCategories = async () => {
|
|
514
|
+
try {
|
|
515
|
+
const response = await chunk26A3EBZI_cjs.getCategories();
|
|
516
|
+
setCategories(response.data);
|
|
517
|
+
} catch (error) {
|
|
518
|
+
console.log(error);
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
fetchCategories();
|
|
522
|
+
}, []);
|
|
523
|
+
const productCustomizations = react.useMemo(() => {
|
|
524
|
+
return product.product.customizations ?? [];
|
|
525
|
+
}, [product]);
|
|
526
|
+
const handleAddToCart = react.useCallback(async () => {
|
|
527
|
+
if (isAddedToCart) {
|
|
528
|
+
onNavigateToCart?.();
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
if (isUserAuthenticated) {
|
|
532
|
+
setLoading(true);
|
|
533
|
+
try {
|
|
534
|
+
await addToCart([{ variant_id: product.id, quantity }]);
|
|
535
|
+
setIsAddedToCart(true);
|
|
536
|
+
} catch (error) {
|
|
537
|
+
console.log(error);
|
|
538
|
+
} finally {
|
|
539
|
+
setLoading(false);
|
|
540
|
+
}
|
|
541
|
+
} else {
|
|
542
|
+
chunkSMHJRNCR_cjs.cart_default.add(product);
|
|
543
|
+
const localCartItems = chunkSMHJRNCR_cjs.cart_default.get();
|
|
544
|
+
if (localCartItems) {
|
|
545
|
+
setCart(localCartItems);
|
|
546
|
+
}
|
|
547
|
+
setIsAddedToCart(true);
|
|
548
|
+
}
|
|
549
|
+
}, [
|
|
550
|
+
isAddedToCart,
|
|
551
|
+
isUserAuthenticated,
|
|
552
|
+
product,
|
|
553
|
+
quantity,
|
|
554
|
+
addToCart,
|
|
555
|
+
setCart,
|
|
556
|
+
onNavigateToCart
|
|
557
|
+
]);
|
|
558
|
+
const handleCustomizationSubmit = react.useCallback(
|
|
559
|
+
async (data) => {
|
|
560
|
+
if (isAddedToCart) {
|
|
561
|
+
onNavigateToCart?.();
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
const customizePayload = [];
|
|
565
|
+
Object.keys(data).forEach((key) => {
|
|
566
|
+
if (data[key]) {
|
|
567
|
+
customizePayload.push({
|
|
568
|
+
customization_option: Number(key),
|
|
569
|
+
customer_input: data[key],
|
|
570
|
+
product_variant: product.id
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
if (isUserAuthenticated) {
|
|
575
|
+
setLoading(true);
|
|
576
|
+
try {
|
|
577
|
+
await addToCart(
|
|
578
|
+
[{ variant_id: product.id, quantity }],
|
|
579
|
+
customizePayload
|
|
580
|
+
);
|
|
581
|
+
setIsAddedToCart(true);
|
|
582
|
+
} catch (error) {
|
|
583
|
+
console.log(error);
|
|
584
|
+
} finally {
|
|
585
|
+
setLoading(false);
|
|
586
|
+
}
|
|
587
|
+
} else {
|
|
588
|
+
chunkSMHJRNCR_cjs.cart_default.add(product);
|
|
589
|
+
const localCartItems = chunkSMHJRNCR_cjs.cart_default.get();
|
|
590
|
+
if (localCartItems) {
|
|
591
|
+
setCart(localCartItems);
|
|
592
|
+
}
|
|
593
|
+
setIsAddedToCart(true);
|
|
594
|
+
}
|
|
595
|
+
},
|
|
596
|
+
[
|
|
597
|
+
isAddedToCart,
|
|
598
|
+
isUserAuthenticated,
|
|
599
|
+
product,
|
|
600
|
+
quantity,
|
|
601
|
+
addToCart,
|
|
602
|
+
setCart,
|
|
603
|
+
onNavigateToCart
|
|
604
|
+
]
|
|
605
|
+
);
|
|
606
|
+
const handleQuantityChange = react.useCallback((value) => {
|
|
607
|
+
setQuantity(value);
|
|
608
|
+
}, []);
|
|
609
|
+
const handleShare = react.useCallback(() => {
|
|
610
|
+
chunk4CVKE6CC_cjs.shareLink(
|
|
611
|
+
`Buy ${product.name} at ${chunk4CVKE6CC_cjs.convertToCurrency(
|
|
612
|
+
Number(product.selling_price)
|
|
613
|
+
)}`,
|
|
614
|
+
product.name
|
|
615
|
+
);
|
|
616
|
+
}, [product]);
|
|
617
|
+
const handleLogin = react.useCallback(() => {
|
|
618
|
+
setShowLoginModal(true);
|
|
619
|
+
}, []);
|
|
620
|
+
const closeLoginModal = react.useCallback(() => {
|
|
621
|
+
setShowLoginModal(false);
|
|
622
|
+
}, []);
|
|
623
|
+
const handleNotifyMe = react.useCallback(() => {
|
|
624
|
+
setShowNotifyMeModal(true);
|
|
625
|
+
}, []);
|
|
626
|
+
const handleNotifyMeFormSubmit = react.useCallback(
|
|
627
|
+
async (values) => {
|
|
628
|
+
try {
|
|
629
|
+
const response = await chunk26A3EBZI_cjs.notifyProductStock({
|
|
630
|
+
...values,
|
|
631
|
+
variant_slug: product.slug
|
|
632
|
+
});
|
|
633
|
+
if (response.data) {
|
|
634
|
+
setShowNotifyMeModal(false);
|
|
635
|
+
onToast?.("Thank you for subscribing to our newsletter", "success");
|
|
636
|
+
}
|
|
637
|
+
} catch (error) {
|
|
638
|
+
console.log(error);
|
|
639
|
+
}
|
|
640
|
+
},
|
|
641
|
+
[product.slug, onToast]
|
|
642
|
+
);
|
|
643
|
+
const handleNotifyMeModalClose = react.useCallback(() => {
|
|
644
|
+
setShowNotifyMeModal(false);
|
|
645
|
+
}, []);
|
|
646
|
+
const handleWishlistUpdated = react.useCallback(
|
|
647
|
+
(status) => {
|
|
648
|
+
setIsWishlisted(status === "add");
|
|
649
|
+
onToast?.(
|
|
650
|
+
status === "add" ? "Added to wishlist" : "Removed from wishlist",
|
|
651
|
+
"success"
|
|
652
|
+
);
|
|
653
|
+
},
|
|
654
|
+
[onToast]
|
|
655
|
+
);
|
|
656
|
+
return {
|
|
657
|
+
isWishlisted,
|
|
658
|
+
isAddedToCart,
|
|
659
|
+
loading,
|
|
660
|
+
quantity,
|
|
661
|
+
showLoginModal,
|
|
662
|
+
showNotifyMeModal,
|
|
663
|
+
categories,
|
|
664
|
+
isUserAuthenticated,
|
|
665
|
+
productCustomizations,
|
|
666
|
+
handleAddToCart,
|
|
667
|
+
handleCustomizationSubmit,
|
|
668
|
+
handleQuantityChange,
|
|
669
|
+
handleShare,
|
|
670
|
+
handleLogin,
|
|
671
|
+
closeLoginModal,
|
|
672
|
+
handleNotifyMe,
|
|
673
|
+
handleNotifyMeFormSubmit,
|
|
674
|
+
handleNotifyMeModalClose,
|
|
675
|
+
handleWishlistUpdated,
|
|
676
|
+
isOutOfStock: product.stock_quantity === 0 && !product.booking_service,
|
|
677
|
+
isLowStock: product.stock_quantity > 0 && product.stock_quantity < 5
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
function useCoupon(options = {}) {
|
|
681
|
+
const { onCouponStatusChange } = options;
|
|
682
|
+
const [isCouponModalOpen, setIsCouponModalOpen] = react.useState(false);
|
|
683
|
+
const [availableCoupons, setAvailableCoupons] = react.useState([]);
|
|
684
|
+
const [appliedCoupon, setAppliedCoupon] = react.useState(null);
|
|
685
|
+
const [couponApplyingLoading, setCouponApplyingLoading] = react.useState(false);
|
|
686
|
+
const [couponApplyingError, setCouponApplyingError] = react.useState(
|
|
687
|
+
null
|
|
688
|
+
);
|
|
689
|
+
react.useEffect(() => {
|
|
690
|
+
const fetchCoupons = async () => {
|
|
691
|
+
try {
|
|
692
|
+
const response = await chunkFMHR5ABF_cjs.getCoupons();
|
|
693
|
+
if (response.data) {
|
|
694
|
+
setAvailableCoupons(response.data);
|
|
695
|
+
}
|
|
696
|
+
} catch (error) {
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
const fetchAppliedCoupon2 = async () => {
|
|
700
|
+
try {
|
|
701
|
+
const response = await chunkFMHR5ABF_cjs.getAppliedCoupon();
|
|
702
|
+
if (response.data) {
|
|
703
|
+
setAppliedCoupon(response.data);
|
|
704
|
+
}
|
|
705
|
+
} catch (error) {
|
|
706
|
+
}
|
|
707
|
+
};
|
|
708
|
+
fetchCoupons();
|
|
709
|
+
fetchAppliedCoupon2();
|
|
710
|
+
}, []);
|
|
711
|
+
const handleViewCoupons = react.useCallback(() => {
|
|
712
|
+
setIsCouponModalOpen(true);
|
|
713
|
+
}, []);
|
|
714
|
+
const handleCloseCouponModal = react.useCallback(() => {
|
|
715
|
+
setIsCouponModalOpen(false);
|
|
716
|
+
}, []);
|
|
717
|
+
const handleApplyCoupon = react.useCallback(
|
|
718
|
+
async (code) => {
|
|
719
|
+
try {
|
|
720
|
+
setCouponApplyingLoading(true);
|
|
721
|
+
setCouponApplyingError(null);
|
|
722
|
+
const response = await chunkFMHR5ABF_cjs.applyCoupon(code);
|
|
723
|
+
if (response.data) {
|
|
724
|
+
onCouponStatusChange?.(response.data.coupon);
|
|
725
|
+
setAppliedCoupon(response.data.coupon);
|
|
726
|
+
}
|
|
727
|
+
} catch (error) {
|
|
728
|
+
if (error instanceof axios.AxiosError) {
|
|
729
|
+
setCouponApplyingError(error.response?.data?.detail ?? null);
|
|
730
|
+
}
|
|
731
|
+
} finally {
|
|
732
|
+
setCouponApplyingLoading(false);
|
|
733
|
+
}
|
|
734
|
+
},
|
|
735
|
+
[onCouponStatusChange]
|
|
736
|
+
);
|
|
737
|
+
const handleRemoveCoupon = react.useCallback(async () => {
|
|
738
|
+
if (!appliedCoupon) return;
|
|
739
|
+
try {
|
|
740
|
+
const response = await chunkFMHR5ABF_cjs.removeCoupon(appliedCoupon.coupon_code);
|
|
741
|
+
if (response.data) {
|
|
742
|
+
setAppliedCoupon(null);
|
|
743
|
+
onCouponStatusChange?.(null);
|
|
744
|
+
}
|
|
745
|
+
} catch (error) {
|
|
746
|
+
console.log(error);
|
|
747
|
+
}
|
|
748
|
+
}, [appliedCoupon, onCouponStatusChange]);
|
|
749
|
+
return {
|
|
750
|
+
isCouponModalOpen,
|
|
751
|
+
availableCoupons,
|
|
752
|
+
appliedCoupon,
|
|
753
|
+
couponApplyingLoading,
|
|
754
|
+
couponApplyingError,
|
|
755
|
+
handleViewCoupons,
|
|
756
|
+
handleCloseCouponModal,
|
|
757
|
+
handleApplyCoupon,
|
|
758
|
+
handleRemoveCoupon
|
|
759
|
+
};
|
|
760
|
+
}
|
|
423
761
|
|
|
424
762
|
Object.defineProperty(exports, "useAddressForm", {
|
|
425
763
|
enumerable: true,
|
|
426
|
-
get: function () { return
|
|
764
|
+
get: function () { return chunkN3ZCCKXV_cjs.useAddressForm; }
|
|
427
765
|
});
|
|
428
766
|
exports.useAddress = useAddress;
|
|
429
767
|
exports.useCart = useCart;
|
|
430
768
|
exports.useCheckoutCoupon = useCheckoutCoupon;
|
|
431
769
|
exports.useCheckoutPayment = useCheckoutPayment;
|
|
770
|
+
exports.useCoupon = useCoupon;
|
|
432
771
|
exports.useGetProductCategories = useGetProductCategories;
|
|
433
772
|
exports.useGetProductDetails = useGetProductDetails;
|
|
434
773
|
exports.useGetProducts = useGetProducts;
|
|
435
774
|
exports.useOrders = useOrders;
|
|
436
775
|
exports.useProductDetailModal = useProductDetailModal;
|
|
437
776
|
exports.useServiceFormModal = useServiceFormModal;
|
|
777
|
+
exports.useShopCheckout = useShopCheckout;
|
|
438
778
|
exports.useUserDetails = useUserDetails;
|
|
779
|
+
exports.useVariantSelector = useVariantSelector;
|
|
439
780
|
exports.useWishlist = useWishlist;
|
package/dist/hooks/index.d.cts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { A as Address } from '../address-DQEZzyUG.cjs';
|
|
2
|
-
import { C as Cart,
|
|
2
|
+
import { C as Cart, b as Category, c as Coupon } from '../cart-BY8D8w-s.cjs';
|
|
3
3
|
import { O as Order } from '../orders-DHJhJ3xz.cjs';
|
|
4
|
-
import {
|
|
4
|
+
import { b as Product, c as ProductDetail, A as Attributes } from '../product-Dfi0ke-4.cjs';
|
|
5
|
+
import { U as User, W as Wishlist } from '../wishlist-DHOvXmJj.cjs';
|
|
5
6
|
export { U as UseAddressFormOptions, a as UseAddressFormReturn, u as useAddressForm } from '../useAddressForm-DgkCP1nG.cjs';
|
|
6
7
|
import 'react-toastify';
|
|
7
8
|
import 'react';
|
|
@@ -134,4 +135,83 @@ interface UseCheckoutCouponReturn {
|
|
|
134
135
|
*/
|
|
135
136
|
declare function useCheckoutCoupon(options: UseCheckoutCouponOptions): UseCheckoutCouponReturn;
|
|
136
137
|
|
|
137
|
-
|
|
138
|
+
interface UseVariantSelectorOptions {
|
|
139
|
+
/** The current product detail. */
|
|
140
|
+
product: ProductDetail.Root;
|
|
141
|
+
/** Product attributes map (variant type → choices). */
|
|
142
|
+
productAttributes: Record<string, ProductDetail.ProductAttribute[]>;
|
|
143
|
+
/** Called when a new variant is resolved. Theme handles navigation/callback. */
|
|
144
|
+
onVariantChange?: (slug: string) => void;
|
|
145
|
+
}
|
|
146
|
+
interface UseVariantSelectorReturn {
|
|
147
|
+
/** The currently selected variant attributes (includes slug). */
|
|
148
|
+
selectedVariant: Attributes;
|
|
149
|
+
/** Call this when the user clicks a variant option. */
|
|
150
|
+
handleVariantSelected: (variantType: string, variant: {
|
|
151
|
+
name: string;
|
|
152
|
+
value: string;
|
|
153
|
+
}) => void;
|
|
154
|
+
/** Check if a specific variant choice is available given the current selection. */
|
|
155
|
+
checkIfVariantAvailable: (variantType: string, variant: {
|
|
156
|
+
name: string;
|
|
157
|
+
value: string;
|
|
158
|
+
}) => boolean;
|
|
159
|
+
/** Check if a variant type is a color type ("color" or "colors"). */
|
|
160
|
+
isColorType: (variantType: string) => boolean;
|
|
161
|
+
/** Size chart modal open state. */
|
|
162
|
+
isSizeChartModalOpen: boolean;
|
|
163
|
+
/** Toggle the size chart modal. */
|
|
164
|
+
toggleSizeChartModal: () => void;
|
|
165
|
+
}
|
|
166
|
+
declare function useVariantSelector(options: UseVariantSelectorOptions): UseVariantSelectorReturn;
|
|
167
|
+
|
|
168
|
+
interface UseShopCheckoutOptions {
|
|
169
|
+
product: ProductDetail.Root;
|
|
170
|
+
/** Called after successfully adding to cart or when navigating to cart. */
|
|
171
|
+
onNavigateToCart?: () => void;
|
|
172
|
+
/** Called when a toast/notification should be shown. */
|
|
173
|
+
onToast?: (message: string, type?: "success" | "error") => void;
|
|
174
|
+
}
|
|
175
|
+
interface UseShopCheckoutReturn {
|
|
176
|
+
isWishlisted: boolean;
|
|
177
|
+
isAddedToCart: boolean;
|
|
178
|
+
loading: boolean;
|
|
179
|
+
quantity: number;
|
|
180
|
+
showLoginModal: boolean;
|
|
181
|
+
showNotifyMeModal: boolean;
|
|
182
|
+
categories: Category.Root[];
|
|
183
|
+
isUserAuthenticated: boolean;
|
|
184
|
+
productCustomizations: ProductDetail.Customization[];
|
|
185
|
+
handleAddToCart: () => Promise<void>;
|
|
186
|
+
handleCustomizationSubmit: (data: any) => Promise<void>;
|
|
187
|
+
handleQuantityChange: (value: number) => void;
|
|
188
|
+
handleShare: () => void;
|
|
189
|
+
handleLogin: () => void;
|
|
190
|
+
closeLoginModal: () => void;
|
|
191
|
+
handleNotifyMe: () => void;
|
|
192
|
+
handleNotifyMeFormSubmit: (values: any) => Promise<void>;
|
|
193
|
+
handleNotifyMeModalClose: () => void;
|
|
194
|
+
handleWishlistUpdated: (status: "add" | "remove") => void;
|
|
195
|
+
isOutOfStock: boolean;
|
|
196
|
+
isLowStock: boolean;
|
|
197
|
+
}
|
|
198
|
+
declare function useShopCheckout(options: UseShopCheckoutOptions): UseShopCheckoutReturn;
|
|
199
|
+
|
|
200
|
+
interface UseCouponOptions {
|
|
201
|
+
/** Called when coupon status changes (applied or removed). */
|
|
202
|
+
onCouponStatusChange?: (coupon: Coupon | null) => void;
|
|
203
|
+
}
|
|
204
|
+
interface UseCouponReturn {
|
|
205
|
+
isCouponModalOpen: boolean;
|
|
206
|
+
availableCoupons: Coupon[];
|
|
207
|
+
appliedCoupon: Coupon | null;
|
|
208
|
+
couponApplyingLoading: boolean;
|
|
209
|
+
couponApplyingError: string | null;
|
|
210
|
+
handleViewCoupons: () => void;
|
|
211
|
+
handleCloseCouponModal: () => void;
|
|
212
|
+
handleApplyCoupon: (code: string) => Promise<void>;
|
|
213
|
+
handleRemoveCoupon: () => Promise<void>;
|
|
214
|
+
}
|
|
215
|
+
declare function useCoupon(options?: UseCouponOptions): UseCouponReturn;
|
|
216
|
+
|
|
217
|
+
export { type PaginationMode, type UseCheckoutCouponOptions, type UseCheckoutCouponReturn, type UseCheckoutPaymentOptions, type UseCheckoutPaymentReturn, type UseCouponOptions, type UseCouponReturn, type UseGetProductsOptions, type UseGetProductsReturn, type UseShopCheckoutOptions, type UseShopCheckoutReturn, type UseVariantSelectorOptions, type UseVariantSelectorReturn, useAddress, useCart, useCheckoutCoupon, useCheckoutPayment, useCoupon, useGetProductCategories, useGetProductDetails, useGetProducts, useOrders, useProductDetailModal, useServiceFormModal, useShopCheckout, useUserDetails, useVariantSelector, useWishlist };
|