@growupsell/react-ecommerce-core 2.0.16 → 2.0.18
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/{chunk-ID4JKOXT.js → chunk-FOGKAOV4.js} +169 -105
- package/dist/chunk-FOGKAOV4.js.map +1 -0
- package/dist/index.cjs +170 -104
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +39 -14
- package/dist/index.d.ts +39 -14
- package/dist/index.js +1 -1
- package/dist/provider.cjs +170 -104
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.d.cts +1 -1
- package/dist/provider.d.ts +1 -1
- package/dist/provider.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-ID4JKOXT.js.map +0 -1
|
@@ -2,7 +2,7 @@ import { BusinessConfigContext } from './chunk-SP77KIKJ.js';
|
|
|
2
2
|
import { createContext, useState, useContext, useEffect, useMemo, useRef, useCallback } from 'react';
|
|
3
3
|
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
import { WAApi, api } from '@growupsell/api';
|
|
5
|
-
import { retrieveThemeContent, updateThemeContent, getCustomPageContent, splitCustomPageContent, createCustomerSession, getBusinessSetting, getRewardPointBusinessConfig, getOrderBusinessConfig, updateCustomPageContent, mergeCustomPageContent } from '@growupsell/api/api';
|
|
5
|
+
import { retrieveThemeContent, updateThemeContent, getCustomPageContent, splitCustomPageContent, readHeroSectionValue, createCustomerSession, getBusinessSetting, getRewardPointBusinessConfig, getOrderBusinessConfig, updateCustomPageContent, mergeCustomPageContent } from '@growupsell/api/api';
|
|
6
6
|
import 'lodash';
|
|
7
7
|
|
|
8
8
|
var StorageContext = createContext({
|
|
@@ -554,10 +554,18 @@ var CartProvider = (props) => {
|
|
|
554
554
|
);
|
|
555
555
|
};
|
|
556
556
|
var useCart = () => useContext(CartContext);
|
|
557
|
+
var getRouteCategoryId = () => {
|
|
558
|
+
if (typeof window === "undefined") return null;
|
|
559
|
+
const match = window.location.pathname.match(/\/products\/[^/]+\/(\d+)\/?$/);
|
|
560
|
+
if (!match) return null;
|
|
561
|
+
const id = Number(match[1]);
|
|
562
|
+
return Number.isFinite(id) ? id : null;
|
|
563
|
+
};
|
|
557
564
|
var FilterContext = createContext({
|
|
558
565
|
selectedCategoryId: [],
|
|
559
566
|
addCategoryFilterId: () => null,
|
|
560
567
|
removeCategoryFilterId: () => null,
|
|
568
|
+
replaceCategoryFilterIds: () => null,
|
|
561
569
|
menuList: [],
|
|
562
570
|
productLoading: true,
|
|
563
571
|
currentPage: 1,
|
|
@@ -581,6 +589,9 @@ var FilterContext = createContext({
|
|
|
581
589
|
selectedVariants: [],
|
|
582
590
|
updateSelectedVariants: () => null,
|
|
583
591
|
variantLoading: false,
|
|
592
|
+
selectedSpecifications: [],
|
|
593
|
+
updateSpecificationOption: () => null,
|
|
594
|
+
setSelectedSpecifications: () => null,
|
|
584
595
|
total: 0,
|
|
585
596
|
limit: 10,
|
|
586
597
|
offset: 0
|
|
@@ -607,9 +618,11 @@ var FilterProvider = (props) => {
|
|
|
607
618
|
const [variantList, setVariantList] = useState([]);
|
|
608
619
|
const [selectedVariants, setSelectedVariants] = useState([]);
|
|
609
620
|
const [variantLoading, setVariantLoading] = useState(false);
|
|
621
|
+
const [selectedSpecifications, setSelectedSpecifications] = useState([]);
|
|
610
622
|
const [limit, setLimit] = useState(10);
|
|
611
623
|
const [offset, setOffset] = useState(0);
|
|
612
624
|
const [total, setTotal] = useState(0);
|
|
625
|
+
const waitingForRouteCategory = useRef(getRouteCategoryId() != null);
|
|
613
626
|
const fetchBrandList = async () => {
|
|
614
627
|
setBrandLoading(true);
|
|
615
628
|
let body = {
|
|
@@ -633,15 +646,39 @@ var FilterProvider = (props) => {
|
|
|
633
646
|
});
|
|
634
647
|
setCurrentPage(1);
|
|
635
648
|
};
|
|
636
|
-
const
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
649
|
+
const replaceCategoryFilterIds = (ids) => {
|
|
650
|
+
const unique = Array.from(new Set(ids.filter((id) => Number.isFinite(id))));
|
|
651
|
+
setSelectedCategoryId(unique);
|
|
652
|
+
setCurrentPage(1);
|
|
653
|
+
setOffset(0);
|
|
654
|
+
setMenuList([]);
|
|
655
|
+
setProductLoading(true);
|
|
656
|
+
waitingForRouteCategory.current = false;
|
|
641
657
|
};
|
|
658
|
+
const categoryFilterKey = selectedCategoryId.length === 1 ? selectedCategoryId[0] : void 0;
|
|
642
659
|
useEffect(() => {
|
|
643
|
-
|
|
644
|
-
|
|
660
|
+
let active = true;
|
|
661
|
+
(async () => {
|
|
662
|
+
if (!filterConfig) {
|
|
663
|
+
setFilterConfigLoading(true);
|
|
664
|
+
}
|
|
665
|
+
try {
|
|
666
|
+
const response = await api.getProductFilterConfig(categoryFilterKey);
|
|
667
|
+
if (active) {
|
|
668
|
+
setFilterConfig(response);
|
|
669
|
+
}
|
|
670
|
+
} catch (error) {
|
|
671
|
+
console.log(error);
|
|
672
|
+
} finally {
|
|
673
|
+
if (active) {
|
|
674
|
+
setFilterConfigLoading(false);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
})();
|
|
678
|
+
return () => {
|
|
679
|
+
active = false;
|
|
680
|
+
};
|
|
681
|
+
}, [categoryFilterKey]);
|
|
645
682
|
const removeCategoryFilterId = (id) => {
|
|
646
683
|
setSelectedCategoryId((x) => {
|
|
647
684
|
return x.filter((o) => o !== id);
|
|
@@ -659,6 +696,7 @@ var FilterProvider = (props) => {
|
|
|
659
696
|
max_price: selectedMaxPrice,
|
|
660
697
|
brand_ids: selectedCategoryId.length > 0 ? selectedBrandId : null,
|
|
661
698
|
variants: selectedCategoryId.length > 0 ? selectedVariants : null,
|
|
699
|
+
specifications: selectedSpecifications,
|
|
662
700
|
limit,
|
|
663
701
|
offset
|
|
664
702
|
};
|
|
@@ -680,6 +718,21 @@ var FilterProvider = (props) => {
|
|
|
680
718
|
return [...prevIds, id];
|
|
681
719
|
});
|
|
682
720
|
};
|
|
721
|
+
const updateSpecificationOption = (keyId, option) => {
|
|
722
|
+
setSelectedSpecifications((prev) => {
|
|
723
|
+
const current = prev.find((item) => item.id === keyId);
|
|
724
|
+
if (!current) {
|
|
725
|
+
return [...prev, { id: keyId, values: [option] }];
|
|
726
|
+
}
|
|
727
|
+
const values = current.values.includes(option) ? current.values.filter((value) => value !== option) : [...current.values, option];
|
|
728
|
+
if (values.length === 0) {
|
|
729
|
+
return prev.filter((item) => item.id !== keyId);
|
|
730
|
+
}
|
|
731
|
+
return prev.map(
|
|
732
|
+
(item) => item.id === keyId ? { ...item, values } : item
|
|
733
|
+
);
|
|
734
|
+
});
|
|
735
|
+
};
|
|
683
736
|
const updateSelectedVariants = (label) => {
|
|
684
737
|
setSelectedVariants((prevVariants) => {
|
|
685
738
|
if (prevVariants.includes(label)) {
|
|
@@ -698,9 +751,10 @@ var FilterProvider = (props) => {
|
|
|
698
751
|
setVariantLoading(false);
|
|
699
752
|
};
|
|
700
753
|
useEffect(() => {
|
|
701
|
-
if (
|
|
702
|
-
|
|
703
|
-
|
|
754
|
+
if (filterConfigLoading) return;
|
|
755
|
+
if (waitingForRouteCategory.current && selectedCategoryId.length === 0) return;
|
|
756
|
+
waitingForRouteCategory.current = false;
|
|
757
|
+
fetchProductList();
|
|
704
758
|
}, [
|
|
705
759
|
selectedCategoryId,
|
|
706
760
|
currentPage,
|
|
@@ -711,9 +765,31 @@ var FilterProvider = (props) => {
|
|
|
711
765
|
selectedMaxPrice,
|
|
712
766
|
selectedBrandId,
|
|
713
767
|
selectedVariants,
|
|
768
|
+
selectedSpecifications,
|
|
714
769
|
limit,
|
|
715
770
|
offset
|
|
716
771
|
]);
|
|
772
|
+
useEffect(() => {
|
|
773
|
+
const keys = filterConfig?.specifications ?? [];
|
|
774
|
+
const allowed = new Map(
|
|
775
|
+
keys.map((key) => [
|
|
776
|
+
key.id,
|
|
777
|
+
new Set(key.options ?? [])
|
|
778
|
+
])
|
|
779
|
+
);
|
|
780
|
+
setSelectedSpecifications((prev) => {
|
|
781
|
+
const next = prev.map((item) => ({
|
|
782
|
+
...item,
|
|
783
|
+
values: item.values.filter((value) => allowed.get(item.id)?.has(value))
|
|
784
|
+
})).filter((item) => item.values.length > 0 && allowed.has(item.id));
|
|
785
|
+
if (next.length === prev.length && next.every(
|
|
786
|
+
(item, index) => item.id === prev[index].id && item.values.length === prev[index].values.length && item.values.every((value, valueIndex) => value === prev[index].values[valueIndex])
|
|
787
|
+
)) {
|
|
788
|
+
return prev;
|
|
789
|
+
}
|
|
790
|
+
return next;
|
|
791
|
+
});
|
|
792
|
+
}, [filterConfig]);
|
|
717
793
|
const handlePageChange = (newOffset) => {
|
|
718
794
|
setOffset(newOffset);
|
|
719
795
|
};
|
|
@@ -731,6 +807,7 @@ var FilterProvider = (props) => {
|
|
|
731
807
|
setMenuList,
|
|
732
808
|
addCategoryFilterId,
|
|
733
809
|
removeCategoryFilterId,
|
|
810
|
+
replaceCategoryFilterIds,
|
|
734
811
|
menuList,
|
|
735
812
|
productLoading,
|
|
736
813
|
currentPage,
|
|
@@ -753,6 +830,9 @@ var FilterProvider = (props) => {
|
|
|
753
830
|
selectedVariants,
|
|
754
831
|
updateSelectedVariants,
|
|
755
832
|
variantLoading,
|
|
833
|
+
selectedSpecifications,
|
|
834
|
+
updateSpecificationOption,
|
|
835
|
+
setSelectedSpecifications,
|
|
756
836
|
total,
|
|
757
837
|
limit,
|
|
758
838
|
offset
|
|
@@ -937,6 +1017,7 @@ var HomeConfigProvider = (props) => {
|
|
|
937
1017
|
});
|
|
938
1018
|
const { token } = useThemeEdit();
|
|
939
1019
|
const themeConfig = useContext(BusinessConfigContext);
|
|
1020
|
+
const themeId = themeConfig.theme.id;
|
|
940
1021
|
const [themeConfigData, setThemeConfigData] = useState(
|
|
941
1022
|
props.initialThemeContent ?? {}
|
|
942
1023
|
);
|
|
@@ -944,16 +1025,13 @@ var HomeConfigProvider = (props) => {
|
|
|
944
1025
|
const updateRef = useRef(false);
|
|
945
1026
|
const [loading, setLoading] = useState(!hasInitial);
|
|
946
1027
|
const getThemeConfig = useCallback(async () => {
|
|
947
|
-
if (!
|
|
948
|
-
setLoading(
|
|
949
|
-
} else {
|
|
1028
|
+
if (hasInitial || !themeId) {
|
|
1029
|
+
if (!themeId) setLoading(false);
|
|
950
1030
|
return;
|
|
951
1031
|
}
|
|
1032
|
+
setLoading(true);
|
|
952
1033
|
try {
|
|
953
|
-
const response = await retrieveThemeContent(
|
|
954
|
-
themeConfig.theme.id,
|
|
955
|
-
props.page
|
|
956
|
-
);
|
|
1034
|
+
const response = await retrieveThemeContent(themeId, props.page);
|
|
957
1035
|
setThemeConfigData(response);
|
|
958
1036
|
if (response?.data && Array.isArray(response.data)) {
|
|
959
1037
|
setSelectedConfig(
|
|
@@ -968,7 +1046,7 @@ var HomeConfigProvider = (props) => {
|
|
|
968
1046
|
} finally {
|
|
969
1047
|
setLoading(false);
|
|
970
1048
|
}
|
|
971
|
-
}, [
|
|
1049
|
+
}, [themeId, hasInitial, props.page]);
|
|
972
1050
|
const onUpdateThemeContent = useCallback(
|
|
973
1051
|
async (configToUpdate = selectedConfig) => {
|
|
974
1052
|
try {
|
|
@@ -979,16 +1057,9 @@ var HomeConfigProvider = (props) => {
|
|
|
979
1057
|
};
|
|
980
1058
|
if (updateRef.current) return;
|
|
981
1059
|
updateRef.current = true;
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
props.page,
|
|
986
|
-
token
|
|
987
|
-
);
|
|
988
|
-
const updatedResponse = await retrieveThemeContent(
|
|
989
|
-
themeConfig.theme.id,
|
|
990
|
-
props.page
|
|
991
|
-
);
|
|
1060
|
+
if (!themeId) return;
|
|
1061
|
+
await updateThemeContent(body, themeId, props.page, token);
|
|
1062
|
+
const updatedResponse = await retrieveThemeContent(themeId, props.page);
|
|
992
1063
|
setThemeConfigData(updatedResponse);
|
|
993
1064
|
} catch (error) {
|
|
994
1065
|
console.error("Error updating theme content:", error);
|
|
@@ -996,7 +1067,7 @@ var HomeConfigProvider = (props) => {
|
|
|
996
1067
|
updateRef.current = false;
|
|
997
1068
|
}
|
|
998
1069
|
},
|
|
999
|
-
[isInitialized, token,
|
|
1070
|
+
[isInitialized, token, themeId, selectedConfig]
|
|
1000
1071
|
);
|
|
1001
1072
|
const addConfig = useCallback(
|
|
1002
1073
|
async (config) => {
|
|
@@ -1062,73 +1133,76 @@ var HomeConfigProvider = (props) => {
|
|
|
1062
1133
|
);
|
|
1063
1134
|
};
|
|
1064
1135
|
var useHomeConfig = () => useContext(HomeConfigContext);
|
|
1065
|
-
var
|
|
1136
|
+
var HERO_SECTION_SLUG = "hero_section";
|
|
1137
|
+
function resolveHeroSection(sectionRow) {
|
|
1138
|
+
if (sectionRow == null) return null;
|
|
1139
|
+
const data = sectionRow.data !== void 0 ? sectionRow.data : sectionRow;
|
|
1140
|
+
if (!data || typeof data !== "object" || Array.isArray(data)) return null;
|
|
1141
|
+
if (typeof data.type !== "string" || !data.type) return null;
|
|
1142
|
+
return { type: data.type, data: data.data };
|
|
1143
|
+
}
|
|
1144
|
+
var HomeConfigHeroSectionContext = createContext({
|
|
1066
1145
|
loading: true,
|
|
1067
|
-
|
|
1068
|
-
|
|
1146
|
+
heroSection: null,
|
|
1147
|
+
onUpdateHeroSection: async () => void 0
|
|
1069
1148
|
});
|
|
1070
|
-
var
|
|
1071
|
-
const
|
|
1072
|
-
|
|
1073
|
-
const [heroSliderConfigData, setHeroSliderConfigData] = useState(
|
|
1074
|
-
() => hasInitial ? props.initialThemeContent.data : []
|
|
1149
|
+
var HomeConfigHeroSectionProvider = (props) => {
|
|
1150
|
+
const [heroSection, setHeroSection] = useState(
|
|
1151
|
+
() => props.heroContentFetched ? resolveHeroSection(props.initialHeroSection) : null
|
|
1075
1152
|
);
|
|
1153
|
+
const [loading, setLoading] = useState(!props.heroContentFetched);
|
|
1076
1154
|
const { token } = useThemeEdit();
|
|
1077
1155
|
const themeConfig = useContext(BusinessConfigContext);
|
|
1078
|
-
const
|
|
1079
|
-
|
|
1156
|
+
const themeId = themeConfig.theme.id;
|
|
1157
|
+
const loadHeroSection = useCallback(async () => {
|
|
1158
|
+
if (props.heroContentFetched || !themeId) {
|
|
1159
|
+
if (!themeId) setLoading(false);
|
|
1080
1160
|
return;
|
|
1081
1161
|
}
|
|
1082
1162
|
setLoading(true);
|
|
1083
1163
|
try {
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1164
|
+
let sectionRow = null;
|
|
1165
|
+
try {
|
|
1166
|
+
sectionRow = await retrieveThemeContent(themeId, HERO_SECTION_SLUG);
|
|
1167
|
+
} catch {
|
|
1168
|
+
sectionRow = null;
|
|
1169
|
+
}
|
|
1170
|
+
setHeroSection(resolveHeroSection(sectionRow));
|
|
1089
1171
|
} catch (error) {
|
|
1090
|
-
console.error("Error fetching hero
|
|
1172
|
+
console.error("Error fetching hero section:", error);
|
|
1091
1173
|
} finally {
|
|
1092
1174
|
setLoading(false);
|
|
1093
1175
|
}
|
|
1094
|
-
}, [
|
|
1176
|
+
}, [props.heroContentFetched, themeId]);
|
|
1095
1177
|
useEffect(() => {
|
|
1096
|
-
|
|
1097
|
-
}, [
|
|
1098
|
-
const
|
|
1178
|
+
loadHeroSection();
|
|
1179
|
+
}, [loadHeroSection]);
|
|
1180
|
+
const onUpdateHeroSection = async (next) => {
|
|
1099
1181
|
setLoading(true);
|
|
1100
1182
|
try {
|
|
1101
1183
|
const body = {
|
|
1102
|
-
data:
|
|
1103
|
-
slug:
|
|
1184
|
+
data: next ? { type: next.type, data: next.data } : { type: null, data: null },
|
|
1185
|
+
slug: HERO_SECTION_SLUG,
|
|
1104
1186
|
platform: typeof window !== "undefined" ? "website" : "app"
|
|
1105
1187
|
};
|
|
1106
|
-
await updateThemeContent(
|
|
1107
|
-
|
|
1108
|
-
themeConfig?.theme?.id,
|
|
1109
|
-
"hero_slider",
|
|
1110
|
-
token
|
|
1111
|
-
);
|
|
1112
|
-
const updatedResponse = await retrieveThemeContent(
|
|
1113
|
-
themeConfig.theme.id,
|
|
1114
|
-
"hero_slider"
|
|
1115
|
-
);
|
|
1116
|
-
setHeroSliderConfigData(updatedResponse.data);
|
|
1188
|
+
await updateThemeContent(body, themeId, HERO_SECTION_SLUG, token);
|
|
1189
|
+
setHeroSection(next);
|
|
1117
1190
|
} catch (error) {
|
|
1118
|
-
console.error("Error updating
|
|
1191
|
+
console.error("Error updating hero section:", error);
|
|
1192
|
+
throw error;
|
|
1119
1193
|
} finally {
|
|
1120
1194
|
setLoading(false);
|
|
1121
1195
|
}
|
|
1122
1196
|
};
|
|
1123
1197
|
return /* @__PURE__ */ jsx(
|
|
1124
|
-
|
|
1198
|
+
HomeConfigHeroSectionContext.Provider,
|
|
1125
1199
|
{
|
|
1126
|
-
value: { loading,
|
|
1200
|
+
value: { loading, heroSection, onUpdateHeroSection },
|
|
1127
1201
|
children: props.children
|
|
1128
1202
|
}
|
|
1129
1203
|
);
|
|
1130
1204
|
};
|
|
1131
|
-
var
|
|
1205
|
+
var useHomeConfigHeroSection = () => useContext(HomeConfigHeroSectionContext);
|
|
1132
1206
|
var CustomPageConfigContext = createContext({
|
|
1133
1207
|
selectedConfig: [],
|
|
1134
1208
|
setSelectedConfig: () => null,
|
|
@@ -1136,28 +1210,26 @@ var CustomPageConfigContext = createContext({
|
|
|
1136
1210
|
updateConfig: () => null,
|
|
1137
1211
|
removeConfig: () => null,
|
|
1138
1212
|
moveConfig: () => null,
|
|
1139
|
-
heroSliderConfigData: [],
|
|
1140
|
-
onUpdateHeroSlider: async () => void 0,
|
|
1141
1213
|
loading: true
|
|
1142
1214
|
});
|
|
1143
1215
|
var CustomPageConfigProvider = (props) => {
|
|
1144
1216
|
const { token } = useThemeEdit();
|
|
1145
1217
|
const [selectedConfig, setSelectedConfig] = useState([]);
|
|
1146
|
-
const [
|
|
1218
|
+
const [heroSection, setHeroSection] = useState(null);
|
|
1147
1219
|
const [loading, setLoading] = useState(true);
|
|
1148
1220
|
const selectedConfigRef = useRef([]);
|
|
1149
|
-
const
|
|
1221
|
+
const heroSectionRef = useRef(null);
|
|
1150
1222
|
const saveQueueRef = useRef(Promise.resolve());
|
|
1151
1223
|
const load = useCallback(async () => {
|
|
1152
1224
|
setLoading(true);
|
|
1153
1225
|
try {
|
|
1154
1226
|
const row = await getCustomPageContent(props.pageId, token);
|
|
1155
1227
|
const fromContent = splitCustomPageContent(row?.content);
|
|
1156
|
-
const
|
|
1228
|
+
const hero = row?.hero_content !== void 0 && row?.hero_content !== null ? readHeroSectionValue(row.hero_content) : fromContent.heroSection;
|
|
1157
1229
|
selectedConfigRef.current = fromContent.blocks;
|
|
1158
|
-
|
|
1230
|
+
heroSectionRef.current = hero;
|
|
1159
1231
|
setSelectedConfig(fromContent.blocks);
|
|
1160
|
-
|
|
1232
|
+
setHeroSection(hero);
|
|
1161
1233
|
} catch (e) {
|
|
1162
1234
|
console.error("Error loading custom page content:", e);
|
|
1163
1235
|
} finally {
|
|
@@ -1165,16 +1237,16 @@ var CustomPageConfigProvider = (props) => {
|
|
|
1165
1237
|
}
|
|
1166
1238
|
}, [props.pageId, token]);
|
|
1167
1239
|
const persistLatest = useCallback(
|
|
1168
|
-
(
|
|
1240
|
+
() => {
|
|
1169
1241
|
const run = async () => {
|
|
1170
1242
|
try {
|
|
1171
1243
|
const blocks = selectedConfigRef.current;
|
|
1172
|
-
const
|
|
1244
|
+
const hero = heroSectionRef.current;
|
|
1173
1245
|
await updateCustomPageContent(
|
|
1174
1246
|
props.pageId,
|
|
1175
1247
|
{
|
|
1176
|
-
content: mergeCustomPageContent(blocks,
|
|
1177
|
-
|
|
1248
|
+
content: mergeCustomPageContent(blocks, hero),
|
|
1249
|
+
hero_content: hero ? { type: hero.type, data: hero.data } : { type: null, data: null }
|
|
1178
1250
|
},
|
|
1179
1251
|
token
|
|
1180
1252
|
);
|
|
@@ -1233,12 +1305,11 @@ var CustomPageConfigProvider = (props) => {
|
|
|
1233
1305
|
},
|
|
1234
1306
|
[persistLatest]
|
|
1235
1307
|
);
|
|
1236
|
-
const
|
|
1237
|
-
async (
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
await persistLatest(true);
|
|
1308
|
+
const onUpdateHeroSection = useCallback(
|
|
1309
|
+
async (next) => {
|
|
1310
|
+
heroSectionRef.current = next;
|
|
1311
|
+
setHeroSection(next);
|
|
1312
|
+
await persistLatest();
|
|
1242
1313
|
},
|
|
1243
1314
|
[persistLatest]
|
|
1244
1315
|
);
|
|
@@ -1255,14 +1326,12 @@ var CustomPageConfigProvider = (props) => {
|
|
|
1255
1326
|
updateConfig,
|
|
1256
1327
|
removeConfig,
|
|
1257
1328
|
moveConfig,
|
|
1258
|
-
heroSliderConfigData,
|
|
1259
|
-
onUpdateHeroSlider,
|
|
1260
1329
|
loading
|
|
1261
1330
|
},
|
|
1262
1331
|
children: /* @__PURE__ */ jsx(
|
|
1263
|
-
|
|
1332
|
+
HomeConfigHeroSectionContext.Provider,
|
|
1264
1333
|
{
|
|
1265
|
-
value: { loading,
|
|
1334
|
+
value: { loading, heroSection, onUpdateHeroSection },
|
|
1266
1335
|
children: props.children
|
|
1267
1336
|
}
|
|
1268
1337
|
)
|
|
@@ -1423,17 +1492,16 @@ var HeaderFooterProvider = (props) => {
|
|
|
1423
1492
|
);
|
|
1424
1493
|
const { token } = useThemeEdit();
|
|
1425
1494
|
const themeConfig = useBusiness();
|
|
1495
|
+
const themeId = themeConfig.theme.id;
|
|
1426
1496
|
const [loading, setLoading] = useState(!hasInitial);
|
|
1427
1497
|
const getThemeConfig = useCallback(async () => {
|
|
1428
|
-
if (hasInitial) {
|
|
1498
|
+
if (hasInitial || !themeId) {
|
|
1499
|
+
if (!themeId) setLoading(false);
|
|
1429
1500
|
return;
|
|
1430
1501
|
}
|
|
1431
1502
|
setLoading(true);
|
|
1432
1503
|
try {
|
|
1433
|
-
const response = await api.retrieveThemeContent(
|
|
1434
|
-
themeConfig.theme.id,
|
|
1435
|
-
props.page
|
|
1436
|
-
);
|
|
1504
|
+
const response = await api.retrieveThemeContent(themeId, props.page);
|
|
1437
1505
|
response.slug === "header" && setHeaderConfig(response.data);
|
|
1438
1506
|
response.slug === "footer" && setFooterConfig(response.data);
|
|
1439
1507
|
response.slug === "announcement" && setAnnouncementConfig(response.data);
|
|
@@ -1442,7 +1510,7 @@ var HeaderFooterProvider = (props) => {
|
|
|
1442
1510
|
} finally {
|
|
1443
1511
|
setLoading(false);
|
|
1444
1512
|
}
|
|
1445
|
-
}, [
|
|
1513
|
+
}, [themeId, hasInitial, props.page]);
|
|
1446
1514
|
const onUpdateThemeContent = useCallback(
|
|
1447
1515
|
async (configToUpdate) => {
|
|
1448
1516
|
try {
|
|
@@ -1451,14 +1519,10 @@ var HeaderFooterProvider = (props) => {
|
|
|
1451
1519
|
slug: props.page,
|
|
1452
1520
|
platform: typeof window !== "undefined" ? "website" : "app"
|
|
1453
1521
|
};
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
themeConfig.theme.id,
|
|
1457
|
-
props.page,
|
|
1458
|
-
token
|
|
1459
|
-
);
|
|
1522
|
+
if (!themeId) return;
|
|
1523
|
+
await api.updateThemeContent(body, themeId, props.page, token);
|
|
1460
1524
|
const updatedResponse = await api.retrieveThemeContent(
|
|
1461
|
-
|
|
1525
|
+
themeId,
|
|
1462
1526
|
props.page
|
|
1463
1527
|
);
|
|
1464
1528
|
updatedResponse.slug === "header" && setHeaderConfig(updatedResponse.data);
|
|
@@ -1470,7 +1534,7 @@ var HeaderFooterProvider = (props) => {
|
|
|
1470
1534
|
setLoading(false);
|
|
1471
1535
|
}
|
|
1472
1536
|
},
|
|
1473
|
-
[props.page,
|
|
1537
|
+
[props.page, themeId, token]
|
|
1474
1538
|
);
|
|
1475
1539
|
useEffect(() => {
|
|
1476
1540
|
getThemeConfig();
|
|
@@ -1943,6 +2007,6 @@ var BaseProvider = ({
|
|
|
1943
2007
|
return /* @__PURE__ */ jsx(StorageProvider, { storage, children: /* @__PURE__ */ jsx(ToastSupportProvider, { value: toast, children: /* @__PURE__ */ jsx(BusinessConfigProvider, { data: businessConfig, baseURL, children: /* @__PURE__ */ jsx(ReferralCodeProvider, { referralCodeFromUrl, children: /* @__PURE__ */ jsx(ThemeEditProvider, { isThemeEdit: isEdit, token, isHeader, isFooter, isAnnouncementBar, children: /* @__PURE__ */ jsx(BusinessMediaProvider, { children: /* @__PURE__ */ jsx(CustomerConfigProvider, { children: /* @__PURE__ */ jsx(AuthProvider, { children: /* @__PURE__ */ jsx(ModalProvider, { children: /* @__PURE__ */ jsx(LiveSupportWidgetProvider, { children: businessConfig.category.type == "retail" ? /* @__PURE__ */ jsx(ProductConfigProvider, { children: /* @__PURE__ */ jsx(CartWishlistRefreshProvider, { children: /* @__PURE__ */ jsx(CartProvider, { children: /* @__PURE__ */ jsx(WishlistProvider, { children: /* @__PURE__ */ jsx(FilterProvider, { children: /* @__PURE__ */ jsx(Fragment, { children }) }) }) }) }) }) : /* @__PURE__ */ jsx(MenuCartProvider, { children: /* @__PURE__ */ jsx(MenuFilterProvider, { children: /* @__PURE__ */ jsx(Fragment, { children }) }) }) }) }) }) }) }) }) }) }) }) });
|
|
1944
2008
|
};
|
|
1945
2009
|
|
|
1946
|
-
export { AuthContext, AuthProvider, BaseProvider, BusinessConfigProvider, BusinessMediaContext, BusinessMediaProvider, CartContext, CartProvider, CartWishlistRefreshContext, CartWishlistRefreshProvider, CustomPageConfigContext, CustomPageConfigProvider, CustomerConfigContext, CustomerConfigProvider, FilterContext, FilterProvider, HeaderFooterContext, HeaderFooterProvider, HomeConfigContext,
|
|
1947
|
-
//# sourceMappingURL=chunk-
|
|
1948
|
-
//# sourceMappingURL=chunk-
|
|
2010
|
+
export { AuthContext, AuthProvider, BaseProvider, BusinessConfigProvider, BusinessMediaContext, BusinessMediaProvider, CartContext, CartProvider, CartWishlistRefreshContext, CartWishlistRefreshProvider, CustomPageConfigContext, CustomPageConfigProvider, CustomerConfigContext, CustomerConfigProvider, FilterContext, FilterProvider, HERO_SECTION_SLUG, HeaderFooterContext, HeaderFooterProvider, HomeConfigContext, HomeConfigHeroSectionContext, HomeConfigHeroSectionProvider, HomeConfigProvider, LiveSupportWidgetProvider, MenuCartContext, MenuCartProvider, MenuFilterContext, MenuFilterProvider, ModalProvider, ProductConfigContext, ProductConfigProvider, ProductDetailContext, ProductDetailProvider, ReferralCodeProvider, StorageContext, StorageProvider, ThemeEditContext, ThemeEditProvider, ToastSupportProvider, WishlistContext, WishlistProvider, resolveHeroSection, useAuth, useBusiness, useBusinessContext, useBusinessMedia, useCart, useCartWishlistRefresh, useCustomPageConfig, useCustomer, useFilter, useHeaderFooter, useHomeConfig, useHomeConfigHeroSection, useLiveSupportWidget, useMenuCart, useMenuFilter, useModal, useProductConfig, useProductDetail, useReferralCode, useStorage, useThemeEdit, useToastSupport, useWishlist };
|
|
2011
|
+
//# sourceMappingURL=chunk-FOGKAOV4.js.map
|
|
2012
|
+
//# sourceMappingURL=chunk-FOGKAOV4.js.map
|