@storepecker/storefront-core 1.1.1 → 2.0.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 +4 -3
- package/dist/api/index.d.ts +4 -3
- package/dist/api/index.js +9 -8
- package/dist/{booking-B21s0inO.d.cts → booking-B39Ilxhg.d.ts} +1 -1
- package/dist/{booking-CegE1cje.d.ts → booking-Dk-BoHUB.d.cts} +1 -1
- 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/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 +4 -3
- package/dist/models/index.d.ts +4 -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 +54 -3
- package/dist/utils/index.d.ts +54 -3
- 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/components/index.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../chunk-
|
|
3
|
-
import '../chunk-
|
|
4
|
-
import '../chunk-
|
|
5
|
-
import '../chunk-
|
|
6
|
-
import '../chunk-
|
|
1
|
+
import { timeFromNow, isExpired } from '../chunk-HSF2D56O.js';
|
|
2
|
+
import { useAddressForm } from '../chunk-7R2V4C7Q.js';
|
|
3
|
+
import '../chunk-YY77CUWX.js';
|
|
4
|
+
import { shareLink, convertToCurrency } from '../chunk-YUPBTD4M.js';
|
|
5
|
+
import '../chunk-B7FOXIZN.js';
|
|
6
|
+
import '../chunk-JWKDXFS4.js';
|
|
7
|
+
import '../chunk-WEMNXIRS.js';
|
|
8
|
+
import '../chunk-BQ256JKN.js';
|
|
7
9
|
import '../chunk-JQMLHRWL.js';
|
|
8
10
|
import { forwardRef, useImperativeHandle, useEffect, useState, useRef, useMemo, useCallback } from 'react';
|
|
9
11
|
import clsx from 'clsx';
|
|
10
12
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
13
|
+
import Modal from 'react-responsive-modal';
|
|
14
|
+
import 'react-responsive-modal/styles.css';
|
|
11
15
|
|
|
12
16
|
// src/components/search-dropdown/search-dropdown.module.css
|
|
13
17
|
var search_dropdown_default = {};
|
|
@@ -565,5 +569,116 @@ var AddressForm = forwardRef(
|
|
|
565
569
|
);
|
|
566
570
|
AddressForm.displayName = "AddressForm";
|
|
567
571
|
var address_form_default2 = AddressForm;
|
|
572
|
+
function ShareIcon({
|
|
573
|
+
width = 20,
|
|
574
|
+
height = 23,
|
|
575
|
+
className
|
|
576
|
+
}) {
|
|
577
|
+
return /* @__PURE__ */ jsx(
|
|
578
|
+
"svg",
|
|
579
|
+
{
|
|
580
|
+
width,
|
|
581
|
+
height,
|
|
582
|
+
viewBox: "0 0 20 23",
|
|
583
|
+
fill: "none",
|
|
584
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
585
|
+
className,
|
|
586
|
+
children: /* @__PURE__ */ jsx(
|
|
587
|
+
"path",
|
|
588
|
+
{
|
|
589
|
+
d: "M5.0745 10.357C4.82568 9.90934 4.43524 9.55692 3.96446 9.35513C3.49369 9.15333 2.96923 9.11357 2.47341 9.24209C1.97759 9.37061 1.53848 9.66013 1.22501 10.0652C0.911539 10.4703 0.741455 10.968 0.741455 11.4802C0.741455 11.9924 0.911539 12.4901 1.22501 12.8952C1.53848 13.3003 1.97759 13.5898 2.47341 13.7183C2.96923 13.8469 3.49369 13.8071 3.96446 13.6053C4.43524 13.4035 4.82568 13.0511 5.0745 12.6034M5.0745 10.357C5.25947 10.69 5.36531 11.0723 5.36531 11.4802C5.36531 11.8882 5.25947 12.2715 5.0745 12.6034M5.0745 10.357L14.9045 4.89641M5.0745 12.6034L14.9045 18.064M14.9045 4.89641C15.0486 5.16783 15.2454 5.4078 15.4833 5.60229C15.7213 5.79678 15.9956 5.94187 16.2903 6.0291C16.585 6.11633 16.8941 6.14393 17.1996 6.1103C17.5051 6.07667 17.8008 5.98247 18.0694 5.83323C18.338 5.68398 18.5742 5.48267 18.7642 5.24108C18.9541 4.99948 19.094 4.72244 19.1756 4.42616C19.2572 4.12988 19.279 3.8203 19.2395 3.51552C19.2001 3.21074 19.1003 2.91687 18.946 2.65111C18.6419 2.12739 18.1445 1.74388 17.5606 1.58304C16.9768 1.4222 16.3531 1.49685 15.8237 1.79096C15.2943 2.08507 14.9014 2.57515 14.7295 3.15586C14.5577 3.73656 14.6205 4.36152 14.9045 4.89641ZM14.9045 18.064C14.757 18.3295 14.6632 18.6215 14.6286 18.9232C14.5939 19.225 14.619 19.5306 14.7025 19.8226C14.7859 20.1146 14.9261 20.3874 15.1149 20.6253C15.3038 20.8631 15.5376 21.0615 15.8031 21.209C16.0686 21.3565 16.3606 21.4502 16.6623 21.4849C16.9641 21.5196 17.2697 21.4944 17.5617 21.411C17.8537 21.3276 18.1265 21.1874 18.3644 20.9986C18.6022 20.8097 18.8006 20.5758 18.9481 20.3103C19.246 19.7741 19.3186 19.1415 19.1501 18.5517C18.9816 17.962 18.5857 17.4633 18.0494 17.1654C17.5132 16.8675 16.8806 16.7948 16.2908 16.9634C15.7011 17.1319 15.2024 17.5278 14.9045 18.064Z",
|
|
590
|
+
stroke: "currentColor",
|
|
591
|
+
strokeWidth: "1.5",
|
|
592
|
+
strokeLinecap: "round",
|
|
593
|
+
strokeLinejoin: "round"
|
|
594
|
+
}
|
|
595
|
+
)
|
|
596
|
+
}
|
|
597
|
+
);
|
|
598
|
+
}
|
|
599
|
+
var ShareButton = ({
|
|
600
|
+
product,
|
|
601
|
+
className = "flex space-x-2 items-center hover:text-textSecondary transition-all duration-100",
|
|
602
|
+
iconSize = 22
|
|
603
|
+
}) => {
|
|
604
|
+
const _handleShare = () => {
|
|
605
|
+
shareLink(
|
|
606
|
+
`Buy ${product.name} at ${convertToCurrency(
|
|
607
|
+
Number(product.selling_price)
|
|
608
|
+
)}`,
|
|
609
|
+
product.name
|
|
610
|
+
);
|
|
611
|
+
};
|
|
612
|
+
return /* @__PURE__ */ jsx("div", { className: "flex items-start gap-4", children: /* @__PURE__ */ jsx("button", { className, onClick: _handleShare, children: /* @__PURE__ */ jsx(ShareIcon, { width: iconSize, height: iconSize }) }) });
|
|
613
|
+
};
|
|
614
|
+
var share_button_default = ShareButton;
|
|
615
|
+
var checkIfLimitReached = (attribute) => {
|
|
616
|
+
return isExpired(attribute.expiry_date) || attribute.download_count === 0;
|
|
617
|
+
};
|
|
618
|
+
var DigitalProductDownloadModal = ({ open, onClose, product, downloadAttribute, onDownload, loading }) => {
|
|
619
|
+
return /* @__PURE__ */ jsx(
|
|
620
|
+
Modal,
|
|
621
|
+
{
|
|
622
|
+
classNames: {
|
|
623
|
+
modal: "modal modal-lg modal-confirm",
|
|
624
|
+
closeButton: "modal-close"
|
|
625
|
+
},
|
|
626
|
+
open,
|
|
627
|
+
onClose,
|
|
628
|
+
center: true,
|
|
629
|
+
closeIcon: null,
|
|
630
|
+
children: /* @__PURE__ */ jsxs("div", { className: "modal-body px-4 py-2", children: [
|
|
631
|
+
/* @__PURE__ */ jsxs("span", { className: "text-2xl block mb-2 fw-regular", children: [
|
|
632
|
+
"Download links for ",
|
|
633
|
+
product?.product_name
|
|
634
|
+
] }),
|
|
635
|
+
/* @__PURE__ */ jsx("hr", { className: "mb-4 mt-2" }),
|
|
636
|
+
/* @__PURE__ */ jsx("div", { className: "download-links", children: loading ? Array.from({ length: 3 }).map((_, index) => /* @__PURE__ */ jsx("div", { className: "w-100 rounded-1 mb-3", children: /* @__PURE__ */ jsxs("div", { className: "flex justify-between", children: [
|
|
637
|
+
/* @__PURE__ */ jsxs("div", { className: "w-100", children: [
|
|
638
|
+
/* @__PURE__ */ jsx("div", { className: "shine line w-75" }),
|
|
639
|
+
/* @__PURE__ */ jsx("div", { className: "shine line w-50 mt-2" })
|
|
640
|
+
] }),
|
|
641
|
+
/* @__PURE__ */ jsx("div", { className: "shine w-160 h-32 rounded-1" })
|
|
642
|
+
] }) }, index)) : downloadAttribute.map((attribute, index) => /* @__PURE__ */ jsxs(
|
|
643
|
+
"div",
|
|
644
|
+
{
|
|
645
|
+
className: "flex items-center justify-between mt-3",
|
|
646
|
+
children: [
|
|
647
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
648
|
+
/* @__PURE__ */ jsxs("span", { className: "block text-md lh-1", children: [
|
|
649
|
+
"Download link ",
|
|
650
|
+
index + 1
|
|
651
|
+
] }),
|
|
652
|
+
checkIfLimitReached(attribute) ? /* @__PURE__ */ jsx("span", { className: "text-danger text-sm lh-1", children: "Download link expired." }) : /* @__PURE__ */ jsxs("span", { className: "text-textSecondary text-sm lh-1", children: [
|
|
653
|
+
"Remaining tries: ",
|
|
654
|
+
attribute.download_count,
|
|
655
|
+
" ",
|
|
656
|
+
"\u2022\xA0 Expires",
|
|
657
|
+
" ",
|
|
658
|
+
timeFromNow(attribute.expiry_date)
|
|
659
|
+
] })
|
|
660
|
+
] }),
|
|
661
|
+
/* @__PURE__ */ jsx(
|
|
662
|
+
"button",
|
|
663
|
+
{
|
|
664
|
+
className: "btn btn-text btn-medium",
|
|
665
|
+
onClick: () => onDownload(attribute),
|
|
666
|
+
disabled: checkIfLimitReached(attribute),
|
|
667
|
+
children: "Download"
|
|
668
|
+
}
|
|
669
|
+
)
|
|
670
|
+
]
|
|
671
|
+
},
|
|
672
|
+
`${attribute.download_link}-${index}`
|
|
673
|
+
)) }),
|
|
674
|
+
/* @__PURE__ */ jsxs("p", { className: "text-textSecondary text-sm fw-regular p-2 bg-warning-light rounded-2 mt-4", children: [
|
|
675
|
+
/* @__PURE__ */ jsx("strong", { className: "text-textSecondary", children: "Warning:" }),
|
|
676
|
+
" The download link is time-sensitive and will expire after a set period. You are limited to a specific number of download attempts, with each attempt reducing the remaining tries. To avoid any disruptions, please ensure a stable internet connection before proceeding with the download."
|
|
677
|
+
] })
|
|
678
|
+
] })
|
|
679
|
+
}
|
|
680
|
+
);
|
|
681
|
+
};
|
|
682
|
+
var digital_product_download_modal_default = DigitalProductDownloadModal;
|
|
568
683
|
|
|
569
|
-
export { address_form_default2 as AddressForm, search_dropdown_default2 as SearchDropdown };
|
|
684
|
+
export { address_form_default2 as AddressForm, digital_product_download_modal_default as DigitalProductDownloadModal, search_dropdown_default2 as SearchDropdown, share_button_default as ShareButton, ShareIcon };
|
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;
|