@sentecacommerce-theme/lib 0.12.98 → 0.12.102
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/cjs/hooks/useAggregateResult/index.js +5 -1
- package/dist/cjs/hooks/useAvailability/index.js +1 -1
- package/dist/cjs/hooks/useClearAllFilters/index.js +2 -0
- package/dist/cjs/hooks/useProduct/index.js +36 -26
- package/dist/cjs/listing/hooks/useListingFilters.js +7 -1
- package/dist/cjs/listing/hooks/useSlideFilter.js +3 -1
- package/dist/cjs/listing/ssr/prefetchCategories.js +1 -1
- package/dist/cjs/user/api/queries/useGetMyLoyaltyCardQuery.js +49 -3
- package/dist/cjs/utils/getSelectedFilters.js +3 -1
- package/dist/esm/hooks/useAggregateResult/index.js +5 -1
- package/dist/esm/hooks/useAvailability/index.js +1 -1
- package/dist/esm/hooks/useClearAllFilters/index.js +2 -0
- package/dist/esm/hooks/useProduct/index.js +28 -18
- package/dist/esm/listing/hooks/useListingFilters.js +7 -1
- package/dist/esm/listing/hooks/useSlideFilter.js +3 -1
- package/dist/esm/listing/ssr/prefetchCategories.js +1 -1
- package/dist/esm/user/api/queries/useGetMyLoyaltyCardQuery.js +44 -3
- package/dist/esm/utils/getSelectedFilters.js +3 -1
- package/dist/types/hooks/useProduct/index.d.ts +2 -1
- package/package.json +4 -4
@@ -91,7 +91,9 @@ var useAggregateResult = function(type, aggregates, slug, predicate, query) {
|
|
91
91
|
aggType: a.filterDefinition,
|
92
92
|
aggKey: filterKey,
|
93
93
|
aggOperator: operatorMap[a.aggregationType]
|
94
|
-
}, selected, router)
|
94
|
+
}, selected, router), undefined, {
|
95
|
+
shallow: true
|
96
|
+
});
|
95
97
|
}
|
96
98
|
},
|
97
99
|
]);
|
@@ -108,6 +110,8 @@ var useAggregateResult = function(type, aggregates, slug, predicate, query) {
|
|
108
110
|
query: _objectSpread({}, router.query, {
|
109
111
|
filter: filterByType(router.query.filter, a.filterDefinition)
|
110
112
|
})
|
113
|
+
}, undefined, {
|
114
|
+
shallow: true
|
111
115
|
});
|
112
116
|
},
|
113
117
|
type: a.aggregationType
|
@@ -70,7 +70,7 @@ var useAvailability = function(param) {
|
|
70
70
|
setStatus(ProductQuantityStatusEnum.OutOfStock);
|
71
71
|
return;
|
72
72
|
}
|
73
|
-
if (
|
73
|
+
if (quantity - (quantityInBasket || 0) < 1) {
|
74
74
|
setStatus(ProductQuantityStatusEnum.MaxQuantityReached);
|
75
75
|
return;
|
76
76
|
}
|
@@ -104,40 +104,40 @@ function _unsupportedIterableToArray(o, minLen) {
|
|
104
104
|
var ProductStateContext = /*#__PURE__*/ _react.default.createContext(undefined);
|
105
105
|
var CountDispatchContext = /*#__PURE__*/ _react.default.createContext(undefined);
|
106
106
|
function ProductProvider(param) {
|
107
|
-
var product = param.product, children = param.children, defaultVariantId = param.defaultVariantId;
|
108
|
-
var
|
107
|
+
var product = param.product, children = param.children, defaultVariantId = param.defaultVariantId, _includeBrandInName = param.includeBrandInName, includeBrandInName = _includeBrandInName === void 0 ? false : _includeBrandInName;
|
108
|
+
var ref42 = _slicedToArray(_react.default.useState(false), 2), mounted = ref42[0], setMounted = ref42[1];
|
109
109
|
var ref1 = _slicedToArray(_react.default.useState(getCombinationsAndAttributeRules), 2), ref2 = ref1[0], combinations = ref2.combinations, attributeRules = ref2.attributeRules, setCombinationsAndAttributeRules = ref1[1];
|
110
110
|
var ref3 = _slicedToArray(_react.default.useState(getVariantsWithInventory), 2), variants = ref3[0], setVariants = ref3[1];
|
111
111
|
var ref4 = _slicedToArray(_react.default.useState(getDefaultVariant), 2), selectedVariant = ref4[0], setSelectedVariant = ref4[1];
|
112
112
|
var metaData = _react.default.useMemo(function() {
|
113
|
-
var ref, ref5, ref6, ref7, ref8, ref9, ref10, ref11, ref12, ref13, ref14, ref15, ref16, ref17, ref18, ref19, ref20, ref21, ref22, ref23, ref24, ref25, ref26, ref27, ref28, ref29, ref30, ref31, ref32, ref33, ref34, ref35;
|
113
|
+
var ref, ref5, ref6, ref7, ref8, ref9, ref10, ref11, ref12, ref13, ref14, ref15, ref16, ref17, ref18, ref19, ref20, ref21, ref22, ref23, ref24, ref25, ref26, ref27, ref28, ref29, ref30, ref31, ref32, ref33, ref34, ref35, ref36, ref37, ref38, ref39, ref40, ref41;
|
114
114
|
var rootCategory = product === null || product === void 0 ? void 0 : (ref = product.categories) === null || ref === void 0 ? void 0 : ref[0];
|
115
115
|
var rootCategoryId = rootCategory === null || rootCategory === void 0 ? void 0 : rootCategory.resourceId;
|
116
116
|
var metaObj = {
|
117
117
|
_id: product === null || product === void 0 ? void 0 : product._id,
|
118
|
-
name: (0, _).getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.name) || (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : product.name),
|
118
|
+
name: includeBrandInName && (product === null || product === void 0 ? void 0 : (ref5 = product.brands) === null || ref5 === void 0 ? void 0 : (ref6 = ref5[0]) === null || ref6 === void 0 ? void 0 : (ref7 = ref6.resource) === null || ref7 === void 0 ? void 0 : ref7.name) ? "".concat((0, _).getTranslatableField(product === null || product === void 0 ? void 0 : (ref8 = product.brands) === null || ref8 === void 0 ? void 0 : (ref9 = ref8[0]) === null || ref9 === void 0 ? void 0 : (ref10 = ref9.resource) === null || ref10 === void 0 ? void 0 : ref10.name), " ").concat((0, _).getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.name) || (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : product.name)) : (0, _).getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.name) || (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : product.name),
|
119
119
|
slug: (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : product.slug),
|
120
120
|
description: (0, _).getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.description) || (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : product.description),
|
121
121
|
shortDescription: (0, _).getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.metaDescription) || (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : product.metaDescription),
|
122
122
|
brand: {
|
123
|
-
_id: product === null || product === void 0 ? void 0 : (
|
124
|
-
name: (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : (
|
125
|
-
slug: (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : (
|
126
|
-
logo: product === null || product === void 0 ? void 0 : (
|
123
|
+
_id: product === null || product === void 0 ? void 0 : (ref11 = product.brands) === null || ref11 === void 0 ? void 0 : (ref12 = ref11[0]) === null || ref12 === void 0 ? void 0 : ref12.resourceId,
|
124
|
+
name: (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : (ref13 = product.brands) === null || ref13 === void 0 ? void 0 : (ref14 = ref13[0]) === null || ref14 === void 0 ? void 0 : (ref15 = ref14.resource) === null || ref15 === void 0 ? void 0 : ref15.name),
|
125
|
+
slug: (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : (ref16 = product.brands) === null || ref16 === void 0 ? void 0 : (ref17 = ref16[0]) === null || ref17 === void 0 ? void 0 : (ref18 = ref17.resource) === null || ref18 === void 0 ? void 0 : ref18.slug),
|
126
|
+
logo: product === null || product === void 0 ? void 0 : (ref19 = product.brands) === null || ref19 === void 0 ? void 0 : (ref20 = ref19[0]) === null || ref20 === void 0 ? void 0 : (ref21 = ref20.resource) === null || ref21 === void 0 ? void 0 : (ref22 = ref21.assets) === null || ref22 === void 0 ? void 0 : (ref23 = ref22[0]) === null || ref23 === void 0 ? void 0 : (ref24 = ref23.sources) === null || ref24 === void 0 ? void 0 : (ref25 = ref24[0]) === null || ref25 === void 0 ? void 0 : ref25.url
|
127
127
|
},
|
128
128
|
category: {
|
129
|
-
_id: product === null || product === void 0 ? void 0 : (
|
130
|
-
name: (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : (
|
131
|
-
slug: (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : (
|
129
|
+
_id: product === null || product === void 0 ? void 0 : (ref27 = product.categories) === null || ref27 === void 0 ? void 0 : (ref28 = ref27[(product === null || product === void 0 ? void 0 : (ref26 = product.categories) === null || ref26 === void 0 ? void 0 : ref26.length) - 1]) === null || ref28 === void 0 ? void 0 : ref28.resourceId,
|
130
|
+
name: (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : (ref30 = product.categories) === null || ref30 === void 0 ? void 0 : (ref31 = ref30[(product === null || product === void 0 ? void 0 : (ref29 = product.categories) === null || ref29 === void 0 ? void 0 : ref29.length) - 1]) === null || ref31 === void 0 ? void 0 : (ref32 = ref31.resource) === null || ref32 === void 0 ? void 0 : ref32.name),
|
131
|
+
slug: (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : (ref34 = product.categories) === null || ref34 === void 0 ? void 0 : (ref35 = ref34[(product === null || product === void 0 ? void 0 : (ref33 = product.categories) === null || ref33 === void 0 ? void 0 : ref33.length) - 1]) === null || ref35 === void 0 ? void 0 : (ref36 = ref35.resource) === null || ref36 === void 0 ? void 0 : ref36.slug)
|
132
132
|
},
|
133
133
|
rootCategory: {
|
134
134
|
_id: rootCategoryId,
|
135
|
-
name: (0, _).getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (
|
136
|
-
slug: (0, _).getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (
|
135
|
+
name: (0, _).getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (ref37 = rootCategory.resource) === null || ref37 === void 0 ? void 0 : ref37.name),
|
136
|
+
slug: (0, _).getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (ref38 = rootCategory.resource) === null || ref38 === void 0 ? void 0 : ref38.slug)
|
137
137
|
},
|
138
138
|
categories: (0, _utils).formatCategories(product === null || product === void 0 ? void 0 : product.categories, rootCategoryId),
|
139
139
|
reviewRatingStatistics: product === null || product === void 0 ? void 0 : product.reviewRatingStatistics,
|
140
|
-
content: Boolean(selectedVariant === null || selectedVariant === void 0 ? void 0 : (
|
140
|
+
content: Boolean(selectedVariant === null || selectedVariant === void 0 ? void 0 : (ref39 = selectedVariant.content) === null || ref39 === void 0 ? void 0 : ref39.map(_utils.createProductContent).length) ? selectedVariant === null || selectedVariant === void 0 ? void 0 : (ref40 = selectedVariant.content) === null || ref40 === void 0 ? void 0 : ref40.map(_utils.createProductContent) : product === null || product === void 0 ? void 0 : (ref41 = product.content) === null || ref41 === void 0 ? void 0 : ref41.map(_utils.createProductContent),
|
141
141
|
assets: (0, _assetsToMap).assetsFieldsToMap(product === null || product === void 0 ? void 0 : product.assets)
|
142
142
|
};
|
143
143
|
return metaObj;
|
@@ -190,20 +190,20 @@ function ProductProvider(param) {
|
|
190
190
|
variants
|
191
191
|
]);
|
192
192
|
function getVariantsWithInventory() {
|
193
|
-
var
|
194
|
-
var variantsWithInventory = product === null || product === void 0 ? void 0 : (
|
195
|
-
var
|
193
|
+
var ref46;
|
194
|
+
var variantsWithInventory = product === null || product === void 0 ? void 0 : (ref46 = product.variants) === null || ref46 === void 0 ? void 0 : ref46.reduce(function(map, _, index, arr) {
|
195
|
+
var ref47, ref43, ref44, ref45;
|
196
196
|
var currentVariant = arr[index];
|
197
197
|
var mappedAttributes = (0, _utils).createMappedAttributes(currentVariant);
|
198
198
|
var mappedOptions = (0, _utils).createMappedOptions(currentVariant === null || currentVariant === void 0 ? void 0 : currentVariant.availableOptions) || [];
|
199
|
-
var isAvailable = currentVariant === null || currentVariant === void 0 ? void 0 : (
|
199
|
+
var isAvailable = currentVariant === null || currentVariant === void 0 ? void 0 : (ref47 = currentVariant.inventorySnapshot) === null || ref47 === void 0 ? void 0 : ref47.canOrder;
|
200
200
|
var updatedVariant = _objectSpread({}, currentVariant, {
|
201
201
|
inventory: {
|
202
|
-
hasAvailableQuantity: (
|
203
|
-
availableQuantity: (
|
202
|
+
hasAvailableQuantity: (ref43 = currentVariant.inventorySnapshot) === null || ref43 === void 0 ? void 0 : ref43.canOrder,
|
203
|
+
availableQuantity: (ref44 = currentVariant.inventorySnapshot) === null || ref44 === void 0 ? void 0 : ref44.availableQuantity
|
204
204
|
},
|
205
205
|
isAvailable: isAvailable ? true : false,
|
206
|
-
quantity: isAvailable ? currentVariant === null || currentVariant === void 0 ? void 0 : (
|
206
|
+
quantity: isAvailable ? currentVariant === null || currentVariant === void 0 ? void 0 : (ref45 = currentVariant.inventorySnapshot) === null || ref45 === void 0 ? void 0 : ref45.availableQuantity : 0,
|
207
207
|
attributes: mappedAttributes,
|
208
208
|
options: mappedOptions,
|
209
209
|
selectedOptions: [],
|
@@ -317,16 +317,26 @@ function ProductProvider(param) {
|
|
317
317
|
return variants === null || variants === void 0 ? void 0 : variants[id];
|
318
318
|
}
|
319
319
|
function getVariantByCombination(key, value) {
|
320
|
-
var
|
321
|
-
var
|
322
|
-
|
320
|
+
var ref48;
|
321
|
+
var split = value === null || value === void 0 ? void 0 : value.split(':');
|
322
|
+
if ((split === null || split === void 0 ? void 0 : split[0]) === 'collapseKey') {
|
323
|
+
var id = Object.keys(variants).find(function(el) {
|
324
|
+
var ref;
|
325
|
+
return variants[el].collapseKey === (split === null || split === void 0 ? void 0 : split[1]) && ((ref = variants[el].attributes.find(function(attr) {
|
326
|
+
return attr.name === 'size';
|
327
|
+
})) === null || ref === void 0 ? void 0 : ref.value) === key;
|
328
|
+
});
|
329
|
+
return variants[id];
|
330
|
+
}
|
331
|
+
var id3 = (ref48 = combinations[key]) === null || ref48 === void 0 ? void 0 : ref48.params[value];
|
332
|
+
return variants === null || variants === void 0 ? void 0 : variants[id3];
|
323
333
|
}
|
324
334
|
function getCustomFieldValue(field) {
|
325
335
|
return customFields === null || customFields === void 0 ? void 0 : customFields[field];
|
326
336
|
}
|
327
337
|
function getCombinationsForAttributeRule(key, id) {
|
328
|
-
var ref,
|
329
|
-
var result = attributeRules === null || attributeRules === void 0 ? void 0 : (ref = attributeRules[key]) === null || ref === void 0 ? void 0 : (
|
338
|
+
var ref, ref49;
|
339
|
+
var result = attributeRules === null || attributeRules === void 0 ? void 0 : (ref = attributeRules[key]) === null || ref === void 0 ? void 0 : (ref49 = ref.values) === null || ref49 === void 0 ? void 0 : ref49[id];
|
330
340
|
return result;
|
331
341
|
}
|
332
342
|
var collapsedImages = (0, _utils).createCollapseKeyImagesMap(product);
|
@@ -136,6 +136,8 @@ function ListingFiltersProvider(param) {
|
|
136
136
|
query: _objectSpread({}, router.query, {
|
137
137
|
filter: filterByType(router.query.filter, filter)
|
138
138
|
})
|
139
|
+
}, undefined, {
|
140
|
+
shallow: true
|
139
141
|
});
|
140
142
|
},
|
141
143
|
type: type
|
@@ -155,6 +157,8 @@ function ListingFiltersProvider(param) {
|
|
155
157
|
router.push({
|
156
158
|
pathname: router.pathname,
|
157
159
|
query: query
|
160
|
+
}, undefined, {
|
161
|
+
shallow: true
|
158
162
|
});
|
159
163
|
};
|
160
164
|
var selectedFilters = _react.default.useMemo(function() {
|
@@ -197,7 +201,9 @@ function generateFilters(param) {
|
|
197
201
|
aggType: filter,
|
198
202
|
aggKey: filterKey,
|
199
203
|
aggOperator: filtersOperatorsMap[type]
|
200
|
-
}, Boolean(selected), router)
|
204
|
+
}, Boolean(selected), router), undefined, {
|
205
|
+
shallow: true
|
206
|
+
});
|
201
207
|
}
|
202
208
|
};
|
203
209
|
});
|
@@ -110,7 +110,9 @@ var useSlideFilter = function(filterName, min, max) {
|
|
110
110
|
aggType: filterName,
|
111
111
|
aggKey: "".concat(formattedFrom, ",").concat(formattedTo),
|
112
112
|
aggOperator: _useListingFilters.filtersOperatorsMap.stats
|
113
|
-
}, false, router, true)
|
113
|
+
}, false, router, true), undefined, {
|
114
|
+
shallow: true
|
115
|
+
});
|
114
116
|
}, 500);
|
115
117
|
setState({
|
116
118
|
from: formattedFrom,
|
@@ -2,12 +2,58 @@ Object.defineProperty(exports, "__esModule", {
|
|
2
2
|
value: true
|
3
3
|
});
|
4
4
|
exports.useGetMyLoyaltyCardQuery = void 0;
|
5
|
+
var _regeneratorRuntime = _interopRequireDefault(require("regenerator-runtime"));
|
5
6
|
var _sdk = require("@sentecacommerce/sdk");
|
6
7
|
var _reactQuery = require("react-query");
|
8
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
9
|
+
try {
|
10
|
+
var info = gen[key](arg);
|
11
|
+
var value = info.value;
|
12
|
+
} catch (error) {
|
13
|
+
reject(error);
|
14
|
+
return;
|
15
|
+
}
|
16
|
+
if (info.done) {
|
17
|
+
resolve(value);
|
18
|
+
} else {
|
19
|
+
Promise.resolve(value).then(_next, _throw);
|
20
|
+
}
|
21
|
+
}
|
22
|
+
function _asyncToGenerator(fn) {
|
23
|
+
return function() {
|
24
|
+
var self = this, args = arguments;
|
25
|
+
return new Promise(function(resolve, reject) {
|
26
|
+
var gen = fn.apply(self, args);
|
27
|
+
function _next(value) {
|
28
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
29
|
+
}
|
30
|
+
function _throw(err) {
|
31
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
32
|
+
}
|
33
|
+
_next(undefined);
|
34
|
+
});
|
35
|
+
};
|
36
|
+
}
|
37
|
+
function _interopRequireDefault(obj) {
|
38
|
+
return obj && obj.__esModule ? obj : {
|
39
|
+
default: obj
|
40
|
+
};
|
41
|
+
}
|
7
42
|
var useGetMyLoyaltyCardQuery = function(callback) {
|
8
|
-
return (0, _reactQuery).useQuery('get-loyalty-card-key', function() {
|
9
|
-
return (
|
10
|
-
|
43
|
+
return (0, _reactQuery).useQuery('get-loyalty-card-key', _asyncToGenerator(_regeneratorRuntime.default.mark(function _callee() {
|
44
|
+
return _regeneratorRuntime.default.wrap(function _callee$(_ctx) {
|
45
|
+
while(1)switch(_ctx.prev = _ctx.next){
|
46
|
+
case 0:
|
47
|
+
return _ctx.abrupt("return", (0, _sdk).MyWalletGetByType('loyalty-program'));
|
48
|
+
case 1:
|
49
|
+
case "end":
|
50
|
+
return _ctx.stop();
|
51
|
+
}
|
52
|
+
}, _callee);
|
53
|
+
})), {
|
54
|
+
refetchOnMount: false,
|
55
|
+
refetchOnWindowFocus: false,
|
56
|
+
retry: false,
|
11
57
|
onSuccess: function() {
|
12
58
|
var ref;
|
13
59
|
return callback === null || callback === void 0 ? void 0 : (ref = callback.onSuccess) === null || ref === void 0 ? void 0 : ref.call(callback);
|
@@ -99,7 +99,9 @@ var getSelectedFilters = function(router, slug, data, config) {
|
|
99
99
|
aggType: key,
|
100
100
|
aggKey: "".concat(valueFrom, ",").concat(valueTo),
|
101
101
|
aggOperator: _listing.filtersOperatorsMap.stats
|
102
|
-
}, true, router)
|
102
|
+
}, true, router), undefined, {
|
103
|
+
shallow: true
|
104
|
+
});
|
103
105
|
},
|
104
106
|
selected: true,
|
105
107
|
data: _objectSpread({}, data.raw, {
|
@@ -87,7 +87,9 @@ export var useAggregateResult = function(type, aggregates, slug, predicate, quer
|
|
87
87
|
aggType: a.filterDefinition,
|
88
88
|
aggKey: filterKey,
|
89
89
|
aggOperator: operatorMap[a.aggregationType]
|
90
|
-
}, selected, router)
|
90
|
+
}, selected, router), undefined, {
|
91
|
+
shallow: true
|
92
|
+
});
|
91
93
|
}
|
92
94
|
},
|
93
95
|
]);
|
@@ -104,6 +106,8 @@ export var useAggregateResult = function(type, aggregates, slug, predicate, quer
|
|
104
106
|
query: _objectSpread({}, router.query, {
|
105
107
|
filter: filterByType(router.query.filter, a.filterDefinition)
|
106
108
|
})
|
109
|
+
}, undefined, {
|
110
|
+
shallow: true
|
107
111
|
});
|
108
112
|
},
|
109
113
|
type: a.aggregationType
|
@@ -65,7 +65,7 @@ export var useAvailability = function(param) {
|
|
65
65
|
setStatus(ProductQuantityStatusEnum.OutOfStock);
|
66
66
|
return;
|
67
67
|
}
|
68
|
-
if (
|
68
|
+
if (quantity - (quantityInBasket || 0) < 1) {
|
69
69
|
setStatus(ProductQuantityStatusEnum.MaxQuantityReached);
|
70
70
|
return;
|
71
71
|
}
|
@@ -92,7 +92,7 @@ function _unsupportedIterableToArray(o, minLen) {
|
|
92
92
|
var ProductStateContext = /*#__PURE__*/ React.createContext(undefined);
|
93
93
|
var CountDispatchContext = /*#__PURE__*/ React.createContext(undefined);
|
94
94
|
export function ProductProvider(param) {
|
95
|
-
var product = param.product, children = param.children, defaultVariantId = param.defaultVariantId;
|
95
|
+
var product = param.product, children = param.children, defaultVariantId = param.defaultVariantId, _includeBrandInName = param.includeBrandInName, includeBrandInName = _includeBrandInName === void 0 ? false : _includeBrandInName;
|
96
96
|
var getVariantsWithInventory = function getVariantsWithInventory() {
|
97
97
|
var ref9;
|
98
98
|
var variantsWithInventory = product === null || product === void 0 ? void 0 : (ref9 = product.variants) === null || ref9 === void 0 ? void 0 : ref9.reduce(function(map, _, index, arr) {
|
@@ -221,16 +221,26 @@ export function ProductProvider(param) {
|
|
221
221
|
return variants === null || variants === void 0 ? void 0 : variants[id];
|
222
222
|
};
|
223
223
|
var getVariantByCombination = function getVariantByCombination(key, value) {
|
224
|
-
var
|
225
|
-
var
|
226
|
-
|
224
|
+
var ref11;
|
225
|
+
var split = value === null || value === void 0 ? void 0 : value.split(':');
|
226
|
+
if ((split === null || split === void 0 ? void 0 : split[0]) === 'collapseKey') {
|
227
|
+
var id = Object.keys(variants).find(function(el) {
|
228
|
+
var ref;
|
229
|
+
return variants[el].collapseKey === (split === null || split === void 0 ? void 0 : split[1]) && ((ref = variants[el].attributes.find(function(attr) {
|
230
|
+
return attr.name === 'size';
|
231
|
+
})) === null || ref === void 0 ? void 0 : ref.value) === key;
|
232
|
+
});
|
233
|
+
return variants[id];
|
234
|
+
}
|
235
|
+
var id3 = (ref11 = combinations[key]) === null || ref11 === void 0 ? void 0 : ref11.params[value];
|
236
|
+
return variants === null || variants === void 0 ? void 0 : variants[id3];
|
227
237
|
};
|
228
238
|
var getCustomFieldValue = function getCustomFieldValue(field) {
|
229
239
|
return customFields === null || customFields === void 0 ? void 0 : customFields[field];
|
230
240
|
};
|
231
241
|
var getCombinationsForAttributeRule = function getCombinationsForAttributeRule(key, id) {
|
232
|
-
var ref,
|
233
|
-
var result = attributeRules === null || attributeRules === void 0 ? void 0 : (ref = attributeRules[key]) === null || ref === void 0 ? void 0 : (
|
242
|
+
var ref, ref12;
|
243
|
+
var result = attributeRules === null || attributeRules === void 0 ? void 0 : (ref = attributeRules[key]) === null || ref === void 0 ? void 0 : (ref12 = ref.values) === null || ref12 === void 0 ? void 0 : ref12[id];
|
234
244
|
return result;
|
235
245
|
};
|
236
246
|
var ref5 = _slicedToArray(React.useState(false), 2), mounted = ref5[0], setMounted = ref5[1];
|
@@ -238,34 +248,34 @@ export function ProductProvider(param) {
|
|
238
248
|
var ref3 = _slicedToArray(React.useState(getVariantsWithInventory), 2), variants = ref3[0], setVariants = ref3[1];
|
239
249
|
var ref4 = _slicedToArray(React.useState(getDefaultVariant), 2), selectedVariant = ref4[0], setSelectedVariant = ref4[1];
|
240
250
|
var metaData = React.useMemo(function() {
|
241
|
-
var ref,
|
251
|
+
var ref, ref13, ref14, ref15, ref16, ref17, ref18, ref19, ref20, ref21, ref22, ref23, ref24, ref25, ref26, ref27, ref28, ref29, ref30, ref31, ref32, ref33, ref34, ref35, ref36, ref37, ref38, ref39, ref40, ref41, ref42, ref43, ref44, ref45, ref46, ref47, ref48, ref49;
|
242
252
|
var rootCategory = product === null || product === void 0 ? void 0 : (ref = product.categories) === null || ref === void 0 ? void 0 : ref[0];
|
243
253
|
var rootCategoryId = rootCategory === null || rootCategory === void 0 ? void 0 : rootCategory.resourceId;
|
244
254
|
var metaObj = {
|
245
255
|
_id: product === null || product === void 0 ? void 0 : product._id,
|
246
|
-
name: getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.name) || getTranslatableField(product === null || product === void 0 ? void 0 : product.name),
|
256
|
+
name: includeBrandInName && (product === null || product === void 0 ? void 0 : (ref13 = product.brands) === null || ref13 === void 0 ? void 0 : (ref14 = ref13[0]) === null || ref14 === void 0 ? void 0 : (ref15 = ref14.resource) === null || ref15 === void 0 ? void 0 : ref15.name) ? "".concat(getTranslatableField(product === null || product === void 0 ? void 0 : (ref16 = product.brands) === null || ref16 === void 0 ? void 0 : (ref17 = ref16[0]) === null || ref17 === void 0 ? void 0 : (ref18 = ref17.resource) === null || ref18 === void 0 ? void 0 : ref18.name), " ").concat(getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.name) || getTranslatableField(product === null || product === void 0 ? void 0 : product.name)) : getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.name) || getTranslatableField(product === null || product === void 0 ? void 0 : product.name),
|
247
257
|
slug: getTranslatableField(product === null || product === void 0 ? void 0 : product.slug),
|
248
258
|
description: getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.description) || getTranslatableField(product === null || product === void 0 ? void 0 : product.description),
|
249
259
|
shortDescription: getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.metaDescription) || getTranslatableField(product === null || product === void 0 ? void 0 : product.metaDescription),
|
250
260
|
brand: {
|
251
|
-
_id: product === null || product === void 0 ? void 0 : (
|
252
|
-
name: getTranslatableField(product === null || product === void 0 ? void 0 : (
|
253
|
-
slug: getTranslatableField(product === null || product === void 0 ? void 0 : (
|
254
|
-
logo: product === null || product === void 0 ? void 0 : (
|
261
|
+
_id: product === null || product === void 0 ? void 0 : (ref19 = product.brands) === null || ref19 === void 0 ? void 0 : (ref20 = ref19[0]) === null || ref20 === void 0 ? void 0 : ref20.resourceId,
|
262
|
+
name: getTranslatableField(product === null || product === void 0 ? void 0 : (ref21 = product.brands) === null || ref21 === void 0 ? void 0 : (ref22 = ref21[0]) === null || ref22 === void 0 ? void 0 : (ref23 = ref22.resource) === null || ref23 === void 0 ? void 0 : ref23.name),
|
263
|
+
slug: getTranslatableField(product === null || product === void 0 ? void 0 : (ref24 = product.brands) === null || ref24 === void 0 ? void 0 : (ref25 = ref24[0]) === null || ref25 === void 0 ? void 0 : (ref26 = ref25.resource) === null || ref26 === void 0 ? void 0 : ref26.slug),
|
264
|
+
logo: product === null || product === void 0 ? void 0 : (ref27 = product.brands) === null || ref27 === void 0 ? void 0 : (ref28 = ref27[0]) === null || ref28 === void 0 ? void 0 : (ref29 = ref28.resource) === null || ref29 === void 0 ? void 0 : (ref30 = ref29.assets) === null || ref30 === void 0 ? void 0 : (ref31 = ref30[0]) === null || ref31 === void 0 ? void 0 : (ref32 = ref31.sources) === null || ref32 === void 0 ? void 0 : (ref33 = ref32[0]) === null || ref33 === void 0 ? void 0 : ref33.url
|
255
265
|
},
|
256
266
|
category: {
|
257
|
-
_id: product === null || product === void 0 ? void 0 : (
|
258
|
-
name: getTranslatableField(product === null || product === void 0 ? void 0 : (
|
259
|
-
slug: getTranslatableField(product === null || product === void 0 ? void 0 : (
|
267
|
+
_id: product === null || product === void 0 ? void 0 : (ref35 = product.categories) === null || ref35 === void 0 ? void 0 : (ref36 = ref35[(product === null || product === void 0 ? void 0 : (ref34 = product.categories) === null || ref34 === void 0 ? void 0 : ref34.length) - 1]) === null || ref36 === void 0 ? void 0 : ref36.resourceId,
|
268
|
+
name: getTranslatableField(product === null || product === void 0 ? void 0 : (ref38 = product.categories) === null || ref38 === void 0 ? void 0 : (ref39 = ref38[(product === null || product === void 0 ? void 0 : (ref37 = product.categories) === null || ref37 === void 0 ? void 0 : ref37.length) - 1]) === null || ref39 === void 0 ? void 0 : (ref40 = ref39.resource) === null || ref40 === void 0 ? void 0 : ref40.name),
|
269
|
+
slug: getTranslatableField(product === null || product === void 0 ? void 0 : (ref42 = product.categories) === null || ref42 === void 0 ? void 0 : (ref43 = ref42[(product === null || product === void 0 ? void 0 : (ref41 = product.categories) === null || ref41 === void 0 ? void 0 : ref41.length) - 1]) === null || ref43 === void 0 ? void 0 : (ref44 = ref43.resource) === null || ref44 === void 0 ? void 0 : ref44.slug)
|
260
270
|
},
|
261
271
|
rootCategory: {
|
262
272
|
_id: rootCategoryId,
|
263
|
-
name: getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (
|
264
|
-
slug: getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (
|
273
|
+
name: getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (ref45 = rootCategory.resource) === null || ref45 === void 0 ? void 0 : ref45.name),
|
274
|
+
slug: getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (ref46 = rootCategory.resource) === null || ref46 === void 0 ? void 0 : ref46.slug)
|
265
275
|
},
|
266
276
|
categories: formatCategories(product === null || product === void 0 ? void 0 : product.categories, rootCategoryId),
|
267
277
|
reviewRatingStatistics: product === null || product === void 0 ? void 0 : product.reviewRatingStatistics,
|
268
|
-
content: Boolean(selectedVariant === null || selectedVariant === void 0 ? void 0 : (
|
278
|
+
content: Boolean(selectedVariant === null || selectedVariant === void 0 ? void 0 : (ref47 = selectedVariant.content) === null || ref47 === void 0 ? void 0 : ref47.map(createProductContent).length) ? selectedVariant === null || selectedVariant === void 0 ? void 0 : (ref48 = selectedVariant.content) === null || ref48 === void 0 ? void 0 : ref48.map(createProductContent) : product === null || product === void 0 ? void 0 : (ref49 = product.content) === null || ref49 === void 0 ? void 0 : ref49.map(createProductContent),
|
269
279
|
assets: assetsFieldsToMap(product === null || product === void 0 ? void 0 : product.assets)
|
270
280
|
};
|
271
281
|
return metaObj;
|
@@ -125,6 +125,8 @@ export function ListingFiltersProvider(param) {
|
|
125
125
|
query: _objectSpread({}, router.query, {
|
126
126
|
filter: filterByType(router.query.filter, filter)
|
127
127
|
})
|
128
|
+
}, undefined, {
|
129
|
+
shallow: true
|
128
130
|
});
|
129
131
|
},
|
130
132
|
type: type
|
@@ -144,6 +146,8 @@ export function ListingFiltersProvider(param) {
|
|
144
146
|
router.push({
|
145
147
|
pathname: router.pathname,
|
146
148
|
query: query
|
149
|
+
}, undefined, {
|
150
|
+
shallow: true
|
147
151
|
});
|
148
152
|
};
|
149
153
|
var selectedFilters = React.useMemo(function() {
|
@@ -186,7 +190,9 @@ function generateFilters(param) {
|
|
186
190
|
aggType: filter,
|
187
191
|
aggKey: filterKey,
|
188
192
|
aggOperator: filtersOperatorsMap[type]
|
189
|
-
}, Boolean(selected), router)
|
193
|
+
}, Boolean(selected), router), undefined, {
|
194
|
+
shallow: true
|
195
|
+
});
|
190
196
|
}
|
191
197
|
};
|
192
198
|
});
|
@@ -106,7 +106,9 @@ export var useSlideFilter = function(filterName, min, max) {
|
|
106
106
|
aggType: filterName,
|
107
107
|
aggKey: "".concat(formattedFrom, ",").concat(formattedTo),
|
108
108
|
aggOperator: filtersOperatorsMap.stats
|
109
|
-
}, false, router, true)
|
109
|
+
}, false, router, true), undefined, {
|
110
|
+
shallow: true
|
111
|
+
});
|
110
112
|
}, 500);
|
111
113
|
setState({
|
112
114
|
from: formattedFrom,
|
@@ -1,9 +1,50 @@
|
|
1
|
+
import regeneratorRuntime from "regenerator-runtime";
|
1
2
|
import { MyWalletGetByType } from '@sentecacommerce/sdk';
|
2
3
|
import { useQuery } from 'react-query';
|
4
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
5
|
+
try {
|
6
|
+
var info = gen[key](arg);
|
7
|
+
var value = info.value;
|
8
|
+
} catch (error) {
|
9
|
+
reject(error);
|
10
|
+
return;
|
11
|
+
}
|
12
|
+
if (info.done) {
|
13
|
+
resolve(value);
|
14
|
+
} else {
|
15
|
+
Promise.resolve(value).then(_next, _throw);
|
16
|
+
}
|
17
|
+
}
|
18
|
+
function _asyncToGenerator(fn) {
|
19
|
+
return function() {
|
20
|
+
var self = this, args = arguments;
|
21
|
+
return new Promise(function(resolve, reject) {
|
22
|
+
var gen = fn.apply(self, args);
|
23
|
+
function _next(value) {
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
25
|
+
}
|
26
|
+
function _throw(err) {
|
27
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
28
|
+
}
|
29
|
+
_next(undefined);
|
30
|
+
});
|
31
|
+
};
|
32
|
+
}
|
3
33
|
export var useGetMyLoyaltyCardQuery = function(callback) {
|
4
|
-
return useQuery('get-loyalty-card-key', function() {
|
5
|
-
return
|
6
|
-
|
34
|
+
return useQuery('get-loyalty-card-key', _asyncToGenerator(regeneratorRuntime.mark(function _callee() {
|
35
|
+
return regeneratorRuntime.wrap(function _callee$(_ctx) {
|
36
|
+
while(1)switch(_ctx.prev = _ctx.next){
|
37
|
+
case 0:
|
38
|
+
return _ctx.abrupt("return", MyWalletGetByType('loyalty-program'));
|
39
|
+
case 1:
|
40
|
+
case "end":
|
41
|
+
return _ctx.stop();
|
42
|
+
}
|
43
|
+
}, _callee);
|
44
|
+
})), {
|
45
|
+
refetchOnMount: false,
|
46
|
+
refetchOnWindowFocus: false,
|
47
|
+
retry: false,
|
7
48
|
onSuccess: function() {
|
8
49
|
var ref;
|
9
50
|
return callback === null || callback === void 0 ? void 0 : (ref = callback.onSuccess) === null || ref === void 0 ? void 0 : ref.call(callback);
|
@@ -95,7 +95,9 @@ export var getSelectedFilters = function(router, slug, data, config) {
|
|
95
95
|
aggType: key,
|
96
96
|
aggKey: "".concat(valueFrom, ",").concat(valueTo),
|
97
97
|
aggOperator: filtersOperatorsMap.stats
|
98
|
-
}, true, router)
|
98
|
+
}, true, router), undefined, {
|
99
|
+
shallow: true
|
100
|
+
});
|
99
101
|
},
|
100
102
|
selected: true,
|
101
103
|
data: _objectSpread({}, data.raw, {
|
@@ -128,6 +128,7 @@ declare type ProductProviderProps = {
|
|
128
128
|
expand?: string;
|
129
129
|
project?: string;
|
130
130
|
};
|
131
|
+
includeBrandInName?: boolean;
|
131
132
|
};
|
132
133
|
declare type ProductStateContextType = {
|
133
134
|
attributeRules: AttributeRulesMap;
|
@@ -163,7 +164,7 @@ declare type CountFunctionsContextType = {
|
|
163
164
|
};
|
164
165
|
getProductVideos: () => VideoType[];
|
165
166
|
};
|
166
|
-
export declare function ProductProvider({ product, children, defaultVariantId, }: ProductProviderProps): JSX.Element;
|
167
|
+
export declare function ProductProvider({ product, children, defaultVariantId, includeBrandInName, }: ProductProviderProps): JSX.Element;
|
167
168
|
export declare function useProductState(): ProductStateContextType;
|
168
169
|
export declare function useProductFunctions(): CountFunctionsContextType;
|
169
170
|
export declare function useProduct(slug: string, config?: getProductBySlugConfig): import("react-query").QueryResult<ProductDTO, unknown>;
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sentecacommerce-theme/lib",
|
3
3
|
"sideEffects": false,
|
4
|
-
"version": "0.12.
|
4
|
+
"version": "0.12.102",
|
5
5
|
"main": "dist/cjs/index.js",
|
6
6
|
"module": "dist/esm/index.js",
|
7
7
|
"types": "dist/types/index.d.ts",
|
@@ -31,13 +31,13 @@
|
|
31
31
|
"watch:cjs": "swc src --out-dir dist/cjs -w",
|
32
32
|
"watch:esm": "swc src --out-dir dist/esm --no-swcrc -w"
|
33
33
|
},
|
34
|
-
"gitHead": "
|
34
|
+
"gitHead": "7aaa7eea3096b99cb27329634cbef9951fcdef15",
|
35
35
|
"peerDependencies": {
|
36
36
|
"react-query": "^2.26.2"
|
37
37
|
},
|
38
38
|
"dependencies": {
|
39
|
-
"@sentecacommerce-theme/base": "^0.12.
|
40
|
-
"@sentecacommerce-theme/cms": "^0.12.
|
39
|
+
"@sentecacommerce-theme/base": "^0.12.102",
|
40
|
+
"@sentecacommerce-theme/cms": "^0.12.102",
|
41
41
|
"@sentecacommerce/sdk": "2.0.161",
|
42
42
|
"body-scroll-lock": "^3.1.5",
|
43
43
|
"copy-to-clipboard": "^3.3.1",
|