@sentecacommerce-theme/lib 0.12.95 → 0.12.99
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/analytics/Pixel/mainScript.js +2 -1
- package/dist/cjs/api/getSDKConfig.js +4 -2
- package/dist/cjs/api/myCartApi/index.js +8 -2
- package/dist/cjs/config/SentecaProvider.js +3 -1
- package/dist/cjs/hooks/useAvailability/index.js +1 -1
- package/dist/cjs/hooks/useProduct/index.js +15 -5
- package/dist/cjs/listing/api/queries/useListingQuery.js +1 -1
- package/dist/cjs/listing/hooks/useListingMeta.js +49 -40
- package/dist/cjs/listing/hooks/useSlideFilter.js +24 -3
- package/dist/cjs/listing/ssr/prefetchCategories.js +5 -6
- package/dist/cjs/listing/ssr/prefetchPredicate.js +4 -4
- package/dist/cjs/seo/components/TranslationsMeta/index.js +58 -0
- package/dist/cjs/seo/components/index.js +12 -0
- package/dist/cjs/seo/hooks/index.js +14 -0
- package/dist/cjs/seo/hooks/useSeoTranslations.js +90 -0
- package/dist/cjs/ui/components/GridStyles.js +2 -2
- package/dist/cjs/ui/components/RangeSliderInput.js +14 -1
- package/dist/cjs/utils/getLocaleFromPath.js +13 -0
- package/dist/cjs/utils/index.js +12 -0
- package/dist/cjs/utils/isTouchDevice.js +2 -1
- package/dist/esm/analytics/Pixel/mainScript.js +2 -1
- package/dist/esm/api/getSDKConfig.js +5 -3
- package/dist/esm/api/myCartApi/index.js +8 -2
- package/dist/esm/config/SentecaProvider.js +3 -1
- package/dist/esm/hooks/useAvailability/index.js +1 -1
- package/dist/esm/hooks/useProduct/index.js +26 -16
- package/dist/esm/listing/api/queries/useListingQuery.js +1 -1
- package/dist/esm/listing/hooks/useListingMeta.js +49 -40
- package/dist/esm/listing/hooks/useSlideFilter.js +24 -3
- package/dist/esm/listing/ssr/prefetchCategories.js +6 -7
- package/dist/esm/listing/ssr/prefetchPredicate.js +4 -4
- package/dist/esm/seo/components/TranslationsMeta/index.js +48 -0
- package/dist/esm/seo/components/index.js +1 -0
- package/dist/esm/seo/hooks/index.js +1 -0
- package/dist/esm/seo/hooks/useSeoTranslations.js +79 -0
- package/dist/esm/ui/components/GridStyles.js +2 -2
- package/dist/esm/ui/components/RangeSliderInput.js +14 -1
- package/dist/esm/utils/getLocaleFromPath.js +8 -0
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/isTouchDevice.js +2 -1
- package/dist/types/listing/hooks/useSlideFilter.d.ts +4 -0
- package/dist/types/listing/types.d.ts +10 -0
- package/dist/types/seo/components/TranslationsMeta/index.d.ts +1 -0
- package/dist/types/seo/components/index.d.ts +1 -0
- package/dist/types/seo/hooks/index.d.ts +1 -0
- package/dist/types/seo/hooks/useSeoTranslations.d.ts +24 -0
- package/dist/types/ui/components/GridStyles.d.ts +2 -1
- package/dist/types/ui/components/RangeSliderInput.d.ts +2 -1
- package/dist/types/utils/getLocaleFromPath.d.ts +1 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/package.json +4 -4
@@ -148,7 +148,7 @@ var RangeSlideClasses = {
|
|
148
148
|
};
|
149
149
|
exports.RangeSlideClasses = RangeSlideClasses;
|
150
150
|
var RangeSliderInput = function(param) {
|
151
|
-
var defaultValue = param.defaultValue, onChange = param.onChange, _min = param.min, min = _min === void 0 ? 0 : _min, _max = param.max, max = _max === void 0 ? 100 : _max, _step = param.step, step = _step === void 0 ? 1 : _step;
|
151
|
+
var defaultValue = param.defaultValue, onChange = param.onChange, onSlide = param.onSlide, _min = param.min, min = _min === void 0 ? 0 : _min, _max = param.max, max = _max === void 0 ? 100 : _max, _step = param.step, step = _step === void 0 ? 1 : _step;
|
152
152
|
var ref1 = _slicedToArray((0, _react).useState(defaultValue), 2), value = ref1[0], setValue = ref1[1];
|
153
153
|
var inputLeftRef = _react.default.useRef(null);
|
154
154
|
var inputRightRef = _react.default.useRef(null);
|
@@ -161,6 +161,17 @@ var RangeSliderInput = function(param) {
|
|
161
161
|
}, [
|
162
162
|
defaultValue
|
163
163
|
]);
|
164
|
+
var onSlideGeneric = function() {
|
165
|
+
var inputLeft = inputLeftRef.current;
|
166
|
+
var inputRight = inputRightRef.current;
|
167
|
+
if (!inputLeft || !inputRight) return;
|
168
|
+
var leftValue = Math.min(Number(inputLeft.value), Number(inputRight.value) - 1);
|
169
|
+
var rightValue = Math.max(Number(inputRight.value), Number(inputLeft.value) + 1);
|
170
|
+
onSlide === null || onSlide === void 0 ? void 0 : onSlide({
|
171
|
+
left: leftValue,
|
172
|
+
right: rightValue
|
173
|
+
});
|
174
|
+
};
|
164
175
|
var updateLeftValue = (0, _react).useCallback(function() {
|
165
176
|
var inputLeft = inputLeftRef.current;
|
166
177
|
var inputRight = inputRightRef.current;
|
@@ -169,6 +180,7 @@ var RangeSliderInput = function(param) {
|
|
169
180
|
setValue(_objectSpread({}, value, {
|
170
181
|
left: leftValue
|
171
182
|
}));
|
183
|
+
onSlideGeneric();
|
172
184
|
}, [
|
173
185
|
setValue,
|
174
186
|
value
|
@@ -181,6 +193,7 @@ var RangeSliderInput = function(param) {
|
|
181
193
|
setValue(_objectSpread({}, value, {
|
182
194
|
right: rightValue
|
183
195
|
}));
|
196
|
+
onSlideGeneric();
|
184
197
|
}, [
|
185
198
|
setValue,
|
186
199
|
value
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Object.defineProperty(exports, "__esModule", {
|
2
|
+
value: true
|
3
|
+
});
|
4
|
+
exports.getLocaleFromPath = void 0;
|
5
|
+
var _canUseDom = require("./canUseDom");
|
6
|
+
var getLocaleFromPath = function() {
|
7
|
+
if (!(0, _canUseDom).canUseDOM()) return '';
|
8
|
+
var locale = window.location.pathname.split('/')[1] || '';
|
9
|
+
// the allowed standards: bg bg-BG, en en-US/en-UK
|
10
|
+
if (locale.length !== 2 && locale.length !== 5) return '';
|
11
|
+
return locale;
|
12
|
+
};
|
13
|
+
exports.getLocaleFromPath = getLocaleFromPath;
|
package/dist/cjs/utils/index.js
CHANGED
@@ -170,6 +170,18 @@ Object.keys(_adjustColor).forEach(function(key) {
|
|
170
170
|
}
|
171
171
|
});
|
172
172
|
});
|
173
|
+
var _getLocaleFromPath = _interopRequireWildcard(require("./getLocaleFromPath"));
|
174
|
+
Object.keys(_getLocaleFromPath).forEach(function(key) {
|
175
|
+
if (key === "default" || key === "__esModule") return;
|
176
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
177
|
+
if (key in exports && exports[key] === _getLocaleFromPath[key]) return;
|
178
|
+
Object.defineProperty(exports, key, {
|
179
|
+
enumerable: true,
|
180
|
+
get: function() {
|
181
|
+
return _getLocaleFromPath[key];
|
182
|
+
}
|
183
|
+
});
|
184
|
+
});
|
173
185
|
var _calcDiscount = _interopRequireWildcard(require("./calcDiscount"));
|
174
186
|
Object.keys(_calcDiscount).forEach(function(key) {
|
175
187
|
if (key === "default" || key === "__esModule") return;
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
2
2
|
value: true
|
3
3
|
});
|
4
4
|
exports.isTouchDevice = isTouchDevice;
|
5
|
+
var _canUseDom = require("./canUseDom");
|
5
6
|
function isTouchDevice() {
|
6
|
-
return 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0;
|
7
|
+
return (0, _canUseDom).canUseDOM() && ('ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0);
|
7
8
|
}
|
@@ -246,7 +246,8 @@ function _objectSpread(target) {
|
|
246
246
|
mode: 'cors',
|
247
247
|
cache: 'no-cache',
|
248
248
|
headers: {
|
249
|
-
'Content-Type': 'application/json'
|
249
|
+
'Content-Type': 'application/json',
|
250
|
+
'senteca-locale': global.location.pathname.split('/')[1] || ''
|
250
251
|
},
|
251
252
|
body: JSON.stringify(payload)
|
252
253
|
});
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Configuration, HttpClient } from '@sentecacommerce/sdk';
|
2
2
|
import Cookies from 'js-cookie';
|
3
|
-
import { ANONYMOUS_TOKEN_KEY, AUTH_TOKEN_KEY } from '../utils';
|
3
|
+
import { ANONYMOUS_TOKEN_KEY, AUTH_TOKEN_KEY, getLocaleFromPath, canUseDOM } from '../utils';
|
4
4
|
function _defineProperty(obj, key, value) {
|
5
5
|
if (key in obj) {
|
6
6
|
Object.defineProperty(obj, key, {
|
@@ -35,13 +35,15 @@ export var getSDKConfig = function() {
|
|
35
35
|
var defaultConfig = getOptions(options);
|
36
36
|
var headers = ((ref = HttpClient.defaultConfig) === null || ref === void 0 ? void 0 : ref.options.headers) || (defaultConfig === null || defaultConfig === void 0 ? void 0 : defaultConfig.headers) || {};
|
37
37
|
var config = new Configuration(_objectSpread({}, ((ref1 = HttpClient.defaultConfig) === null || ref1 === void 0 ? void 0 : ref1.options) || defaultConfig, options, {
|
38
|
-
headers: _objectSpread({}, headers, options.headers || {}
|
38
|
+
headers: _objectSpread({}, headers, options.headers || {}, {
|
39
|
+
'senteca-locale': getLocaleFromPath()
|
40
|
+
})
|
39
41
|
}));
|
40
42
|
return config;
|
41
43
|
};
|
42
44
|
export var getOptions = function() {
|
43
45
|
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
44
|
-
if (
|
46
|
+
if (!canUseDOM()) {
|
45
47
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
46
48
|
var nodeFetch = require('node-fetch');
|
47
49
|
var ref;
|
@@ -6,6 +6,7 @@ import { readFromLocalStorage, writeToLocalStorage, getTranslatableField } from
|
|
6
6
|
import { getSDKConfig } from '../getSDKConfig';
|
7
7
|
import { syncResponse, getLineItemId, onMutate } from './utils';
|
8
8
|
import { queryKey as promoCodeQueryKey } from '../../api.v2/core/misc/promo-code';
|
9
|
+
import { useIsAuthenticated } from '../..';
|
9
10
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
10
11
|
try {
|
11
12
|
var info = gen[key](arg);
|
@@ -110,6 +111,7 @@ export var MyCartApiFactory = function() {
|
|
110
111
|
}(),
|
111
112
|
useGet: function() {
|
112
113
|
var queryCache = useQueryCache();
|
114
|
+
var isLoading = useIsAuthenticated().isLoading;
|
113
115
|
return useQuery(myCartCacheKeys.useGet, _asyncToGenerator(regeneratorRuntime.mark(function _callee() {
|
114
116
|
var data;
|
115
117
|
return regeneratorRuntime.wrap(function _callee$(_ctx) {
|
@@ -128,12 +130,14 @@ export var MyCartApiFactory = function() {
|
|
128
130
|
}
|
129
131
|
}, _callee);
|
130
132
|
})), {
|
133
|
+
enabled: !isLoading,
|
131
134
|
retry: false,
|
132
|
-
refetchOnMount:
|
135
|
+
refetchOnMount: true,
|
133
136
|
refetchOnWindowFocus: false
|
134
137
|
});
|
135
138
|
},
|
136
139
|
useGetCompact: function() {
|
140
|
+
var isLoading = useIsAuthenticated().isLoading;
|
137
141
|
return useQuery(myCartCacheKeys.useGetCompact, _asyncToGenerator(regeneratorRuntime.mark(function _callee() {
|
138
142
|
var compactBasket;
|
139
143
|
return regeneratorRuntime.wrap(function _callee$(_ctx) {
|
@@ -146,7 +150,9 @@ export var MyCartApiFactory = function() {
|
|
146
150
|
return _ctx.stop();
|
147
151
|
}
|
148
152
|
}, _callee);
|
149
|
-
}))
|
153
|
+
})), {
|
154
|
+
enabled: !isLoading
|
155
|
+
});
|
150
156
|
},
|
151
157
|
useIsExisting: function(productId, variantId, collapseKey) {
|
152
158
|
return useQuery([
|
@@ -4,6 +4,7 @@ import fetch from 'node-fetch';
|
|
4
4
|
import { getOptions } from '../api/getSDKConfig';
|
5
5
|
import { ReactQueryConfigProvider, useQueryCache } from 'react-query';
|
6
6
|
import { removeAnonToken, removeAuthToken } from '../utils/tokens';
|
7
|
+
import { getLocaleFromPath } from '../utils';
|
7
8
|
import { useRouter } from 'next/router';
|
8
9
|
function _defineProperty(obj, key, value) {
|
9
10
|
if (key in obj) {
|
@@ -42,7 +43,8 @@ export function SentecaProvider(param) {
|
|
42
43
|
if (localeData) {
|
43
44
|
options.headers = _objectSpread({}, options.headers || {}, {
|
44
45
|
InterfaceKey: localeData.interfaceKey,
|
45
|
-
StoreKey: localeData.storeKey
|
46
|
+
StoreKey: localeData.storeKey,
|
47
|
+
'senteca-locale': getLocaleFromPath()
|
46
48
|
});
|
47
49
|
}
|
48
50
|
HttpClient.defaultConfig = new Configuration(options);
|
@@ -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
|
}
|
@@ -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,7 +248,7 @@ 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;
|
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 = {
|
@@ -248,24 +258,24 @@ export function ProductProvider(param) {
|
|
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 : (ref13 = product.brands) === null || ref13 === void 0 ? void 0 : (ref14 = ref13[0]) === null || ref14 === void 0 ? void 0 : ref14.resourceId,
|
262
|
+
name: getTranslatableField(product === null || product === void 0 ? void 0 : (ref15 = product.brands) === null || ref15 === void 0 ? void 0 : (ref16 = ref15[0]) === null || ref16 === void 0 ? void 0 : (ref17 = ref16.resource) === null || ref17 === void 0 ? void 0 : ref17.name),
|
263
|
+
slug: getTranslatableField(product === null || product === void 0 ? void 0 : (ref18 = product.brands) === null || ref18 === void 0 ? void 0 : (ref19 = ref18[0]) === null || ref19 === void 0 ? void 0 : (ref20 = ref19.resource) === null || ref20 === void 0 ? void 0 : ref20.slug),
|
264
|
+
logo: 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 : (ref24 = ref23.assets) === null || ref24 === void 0 ? void 0 : (ref25 = ref24[0]) === null || ref25 === void 0 ? void 0 : (ref26 = ref25.sources) === null || ref26 === void 0 ? void 0 : (ref27 = ref26[0]) === null || ref27 === void 0 ? void 0 : ref27.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 : (ref29 = product.categories) === null || ref29 === void 0 ? void 0 : (ref30 = ref29[(product === null || product === void 0 ? void 0 : (ref28 = product.categories) === null || ref28 === void 0 ? void 0 : ref28.length) - 1]) === null || ref30 === void 0 ? void 0 : ref30.resourceId,
|
268
|
+
name: getTranslatableField(product === null || product === void 0 ? void 0 : (ref32 = product.categories) === null || ref32 === void 0 ? void 0 : (ref33 = ref32[(product === null || product === void 0 ? void 0 : (ref31 = product.categories) === null || ref31 === void 0 ? void 0 : ref31.length) - 1]) === null || ref33 === void 0 ? void 0 : (ref34 = ref33.resource) === null || ref34 === void 0 ? void 0 : ref34.name),
|
269
|
+
slug: getTranslatableField(product === null || product === void 0 ? void 0 : (ref36 = product.categories) === null || ref36 === void 0 ? void 0 : (ref37 = ref36[(product === null || product === void 0 ? void 0 : (ref35 = product.categories) === null || ref35 === void 0 ? void 0 : ref35.length) - 1]) === null || ref37 === void 0 ? void 0 : (ref38 = ref37.resource) === null || ref38 === void 0 ? void 0 : ref38.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 : (ref39 = rootCategory.resource) === null || ref39 === void 0 ? void 0 : ref39.name),
|
274
|
+
slug: getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (ref40 = rootCategory.resource) === null || ref40 === void 0 ? void 0 : ref40.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 : (ref41 = selectedVariant.content) === null || ref41 === void 0 ? void 0 : ref41.map(createProductContent).length) ? selectedVariant === null || selectedVariant === void 0 ? void 0 : (ref42 = selectedVariant.content) === null || ref42 === void 0 ? void 0 : ref42.map(createProductContent) : product === null || product === void 0 ? void 0 : (ref43 = product.content) === null || ref43 === void 0 ? void 0 : ref43.map(createProductContent),
|
269
279
|
assets: assetsFieldsToMap(product === null || product === void 0 ? void 0 : product.assets)
|
270
280
|
};
|
271
281
|
return metaObj;
|
@@ -126,7 +126,7 @@ export var useListingQuery = function() {
|
|
126
126
|
predicate: predicate,
|
127
127
|
sort: sort,
|
128
128
|
postFilter: postFilter,
|
129
|
-
slug:
|
129
|
+
slug: aliasedSlug,
|
130
130
|
offset: offset
|
131
131
|
});
|
132
132
|
return useQuery(queryKeys, _asyncToGenerator(regeneratorRuntime.mark(function _callee() {
|
@@ -4,7 +4,6 @@ import { customFieldsToMap, escape, getTranslatableField } from '../../utils';
|
|
4
4
|
import { assetsFieldsToMap } from '../../utils/assetsToMap';
|
5
5
|
import { useRouter } from 'next/router';
|
6
6
|
import { getListingPageType } from '../utils';
|
7
|
-
import { ListingTypesEnum } from '../types';
|
8
7
|
import { useListingAlias } from '../../index';
|
9
8
|
import { useListingFilters } from './useListingFilters';
|
10
9
|
import { useListingCategories } from './useListingCategories';
|
@@ -23,6 +22,33 @@ function _iterableToArray(iter) {
|
|
23
22
|
function _nonIterableSpread() {
|
24
23
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
25
24
|
}
|
25
|
+
function _objectWithoutProperties(source, excluded) {
|
26
|
+
if (source == null) return {};
|
27
|
+
var target = _objectWithoutPropertiesLoose(source, excluded);
|
28
|
+
var key, i;
|
29
|
+
if (Object.getOwnPropertySymbols) {
|
30
|
+
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
31
|
+
for(i = 0; i < sourceSymbolKeys.length; i++){
|
32
|
+
key = sourceSymbolKeys[i];
|
33
|
+
if (excluded.indexOf(key) >= 0) continue;
|
34
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
35
|
+
target[key] = source[key];
|
36
|
+
}
|
37
|
+
}
|
38
|
+
return target;
|
39
|
+
}
|
40
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
41
|
+
if (source == null) return {};
|
42
|
+
var target = {};
|
43
|
+
var sourceKeys = Object.keys(source);
|
44
|
+
var key, i;
|
45
|
+
for(i = 0; i < sourceKeys.length; i++){
|
46
|
+
key = sourceKeys[i];
|
47
|
+
if (excluded.indexOf(key) >= 0) continue;
|
48
|
+
target[key] = source[key];
|
49
|
+
}
|
50
|
+
return target;
|
51
|
+
}
|
26
52
|
function _toConsumableArray(arr) {
|
27
53
|
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
28
54
|
}
|
@@ -80,74 +106,57 @@ export var useListingMeta = function() {
|
|
80
106
|
return result;
|
81
107
|
};
|
82
108
|
function processDisplayName(slug, config, name, breadcrumb, router, aggData, categoriesData) {
|
109
|
+
var ref, ref5;
|
83
110
|
var listingName = getTranslatableField(name);
|
84
111
|
var brandName = getBrandName(router, aggData);
|
85
112
|
var categoryName = getCategoryName(router, categoriesData);
|
86
113
|
var type = getListingPageType(router, slug, config);
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
return "Всички продукти от ".concat(listingName, " за ").concat(attribute);
|
101
|
-
}
|
102
|
-
return "".concat(categoryName, " от ").concat(listingName, " за ").concat(attribute);
|
103
|
-
}
|
104
|
-
}
|
105
|
-
if (type === ListingTypesEnum.Category && brandName) {
|
106
|
-
return "".concat(listingName, " от ").concat(brandName);
|
107
|
-
}
|
108
|
-
if (type === ListingTypesEnum.Brand) {
|
109
|
-
if (!categoryName) {
|
110
|
-
return "Всички продукти от ".concat(listingName);
|
111
|
-
}
|
112
|
-
return "".concat(categoryName, " от ").concat(listingName);
|
113
|
-
}
|
114
|
-
if (type === ListingTypesEnum.Search && (router === null || router === void 0 ? void 0 : router.query.search)) {
|
115
|
-
return "".concat(listingName, " от \"").concat(router.query.search, "\"");
|
116
|
-
}
|
117
|
-
return listingName;
|
114
|
+
var getTitle = config.getTitle, rest = _objectWithoutProperties(config, [
|
115
|
+
"getTitle"
|
116
|
+
]);
|
117
|
+
var title = getTitle === null || getTitle === void 0 ? void 0 : getTitle(type, rest, {
|
118
|
+
category: categoryName,
|
119
|
+
brand: brandName,
|
120
|
+
defaultName: listingName,
|
121
|
+
attribute: (ref = config.titleAliases) === null || ref === void 0 ? void 0 : ref[slug],
|
122
|
+
childAttribute: getTranslatableField(breadcrumb === null || breadcrumb === void 0 ? void 0 : breadcrumb.label),
|
123
|
+
search: router === null || router === void 0 ? void 0 : (ref5 = router.query) === null || ref5 === void 0 ? void 0 : ref5.search,
|
124
|
+
isWithAttribute: Boolean(router === null || router === void 0 ? void 0 : router.query.cat)
|
125
|
+
});
|
126
|
+
return title || listingName;
|
118
127
|
}
|
119
128
|
function getFilterByType(filterType, router) {
|
120
129
|
var filterId = '';
|
121
130
|
if (Array.isArray(router === null || router === void 0 ? void 0 : router.query.filter)) {
|
122
|
-
var ref,
|
131
|
+
var ref, ref6;
|
123
132
|
var filters = (ref = router === null || router === void 0 ? void 0 : router.query.filter) === null || ref === void 0 ? void 0 : ref.filter(function(x) {
|
124
133
|
return x === null || x === void 0 ? void 0 : x.includes(filterType);
|
125
134
|
});
|
126
135
|
if ((filters === null || filters === void 0 ? void 0 : filters.length) && filters.length > 1) {
|
127
136
|
return '';
|
128
137
|
}
|
129
|
-
var filterTerm = (
|
138
|
+
var filterTerm = (ref6 = /\d+/.exec((filters === null || filters === void 0 ? void 0 : filters[0]) || '')) === null || ref6 === void 0 ? void 0 : ref6[0];
|
130
139
|
if (!filterTerm) return '';
|
131
140
|
filterId = filterTerm;
|
132
141
|
} else {
|
133
|
-
var
|
134
|
-
var isFiltered = router === null || router === void 0 ? void 0 : (
|
142
|
+
var ref7, ref8, ref9;
|
143
|
+
var isFiltered = router === null || router === void 0 ? void 0 : (ref7 = router.query) === null || ref7 === void 0 ? void 0 : (ref8 = ref7.filter) === null || ref8 === void 0 ? void 0 : ref8.includes(filterType);
|
135
144
|
if (!isFiltered) {
|
136
145
|
return '';
|
137
146
|
}
|
138
|
-
filterId = (
|
147
|
+
filterId = (ref9 = /(\w+)-(\d+)/.exec(router === null || router === void 0 ? void 0 : router.query.filter)) === null || ref9 === void 0 ? void 0 : ref9[0];
|
139
148
|
}
|
140
149
|
return filterId;
|
141
150
|
}
|
142
151
|
function getBrandName(router, filtersData) {
|
143
|
-
var ref,
|
152
|
+
var ref, ref10, ref11;
|
144
153
|
var brandId = getFilterByType('brand', router);
|
145
154
|
var brand = (ref = filtersData === null || filtersData === void 0 ? void 0 : filtersData.find(function(x) {
|
146
155
|
return x.name === 'Brands';
|
147
|
-
})) === null || ref === void 0 ? void 0 : (
|
156
|
+
})) === null || ref === void 0 ? void 0 : (ref10 = ref.items) === null || ref10 === void 0 ? void 0 : ref10.find(function(x) {
|
148
157
|
return x.data.key === brandId;
|
149
158
|
});
|
150
|
-
return getTranslatableField(brand === null || brand === void 0 ? void 0 : (
|
159
|
+
return getTranslatableField(brand === null || brand === void 0 ? void 0 : (ref11 = brand.meta) === null || ref11 === void 0 ? void 0 : ref11.name);
|
151
160
|
}
|
152
161
|
function getCategoryName(router, categories) {
|
153
162
|
var categoryId = getFilterByType('category', router);
|
@@ -52,7 +52,7 @@ function _unsupportedIterableToArray(o, minLen) {
|
|
52
52
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
53
53
|
}
|
54
54
|
export var useSlideFilter = function(filterName, min, max) {
|
55
|
-
var
|
55
|
+
var ref3;
|
56
56
|
var router = useRouter();
|
57
57
|
var meta = useListingConfig().meta;
|
58
58
|
var slug = useListingAlias(meta).slug;
|
@@ -67,7 +67,7 @@ export var useSlideFilter = function(filterName, min, max) {
|
|
67
67
|
}
|
68
68
|
if (allFilters.includes(filterQuery)) return allFilters;
|
69
69
|
};
|
70
|
-
var filter = (
|
70
|
+
var filter = (ref3 = getFilter()) === null || ref3 === void 0 ? void 0 : ref3.replace(filterQuery, '');
|
71
71
|
var ref1 = _slicedToArray(filter ? filter.split(',') : [
|
72
72
|
min,
|
73
73
|
max
|
@@ -77,9 +77,29 @@ export var useSlideFilter = function(filterName, min, max) {
|
|
77
77
|
to: +to || max
|
78
78
|
}), 2), state = ref2[0], setState = ref2[1];
|
79
79
|
var timeoutRef = useRef();
|
80
|
-
var
|
80
|
+
var getFormattedPriceRange = function(data) {
|
81
81
|
var formattedFrom = Math.min(Math.max(data.from, min), data.to);
|
82
82
|
var formattedTo = Math.max(data.from, Math.min(data.to, max));
|
83
|
+
return {
|
84
|
+
formattedFrom: formattedFrom,
|
85
|
+
formattedTo: formattedTo
|
86
|
+
};
|
87
|
+
};
|
88
|
+
var updateValue = useCallback(function(data) {
|
89
|
+
var ref = getFormattedPriceRange(data), formattedFrom = ref.formattedFrom, formattedTo = ref.formattedTo;
|
90
|
+
setState({
|
91
|
+
from: formattedFrom,
|
92
|
+
to: formattedTo
|
93
|
+
});
|
94
|
+
}, [
|
95
|
+
filterName,
|
96
|
+
max,
|
97
|
+
min,
|
98
|
+
router,
|
99
|
+
slug
|
100
|
+
]);
|
101
|
+
var applyFilter = useCallback(function(data) {
|
102
|
+
var ref = getFormattedPriceRange(data), formattedFrom = ref.formattedFrom, formattedTo = ref.formattedTo;
|
83
103
|
clearTimeout(timeoutRef.current);
|
84
104
|
timeoutRef.current = setTimeout(function() {
|
85
105
|
router.push(createAggregateQuery(getListingPageType(router, slug, meta), router.query.slug, {
|
@@ -101,6 +121,7 @@ export var useSlideFilter = function(filterName, min, max) {
|
|
101
121
|
]);
|
102
122
|
return {
|
103
123
|
value: state,
|
124
|
+
applyFilter: applyFilter,
|
104
125
|
updateValue: updateValue
|
105
126
|
};
|
106
127
|
};
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import regeneratorRuntime from "regenerator-runtime";
|
2
2
|
import { CatalogAggregate } from '@sentecacommerce/sdk';
|
3
|
-
import {
|
3
|
+
import { getListingAlias, getPostFilters } from '../utils';
|
4
4
|
import { prepareAggregateQuery, AggregateRequestEnum, generateAggregateKey } from '../api';
|
5
5
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
6
6
|
try {
|
@@ -36,7 +36,7 @@ export function prefetchCategories(queryCache, router, predicate, aggregates, co
|
|
36
36
|
}
|
37
37
|
function _prefetchCategories() {
|
38
38
|
_prefetchCategories = _asyncToGenerator(regeneratorRuntime.mark(function _callee(queryCache, router, predicate, aggregates, config) {
|
39
|
-
var aggregateKeys, aliasedSlug,
|
39
|
+
var aggregateKeys, aliasedSlug, query, response;
|
40
40
|
return regeneratorRuntime.wrap(function _callee$(_ctx) {
|
41
41
|
while(1)switch(_ctx.prev = _ctx.next){
|
42
42
|
case 0:
|
@@ -45,19 +45,18 @@ function _prefetchCategories() {
|
|
45
45
|
router: router,
|
46
46
|
config: config
|
47
47
|
});
|
48
|
-
slug = getSlug(router, aliasedSlug);
|
49
48
|
query = prepareAggregateQuery({
|
50
49
|
request: AggregateRequestEnum.Categories,
|
51
50
|
router: router,
|
52
51
|
predicate: predicate,
|
53
52
|
slug: aliasedSlug,
|
54
53
|
aggregates: aggregates,
|
55
|
-
postFilter:
|
54
|
+
postFilter: getPostFilters(router),
|
56
55
|
config: config
|
57
56
|
});
|
58
|
-
_ctx.next =
|
57
|
+
_ctx.next = 5;
|
59
58
|
return CatalogAggregate(query);
|
60
|
-
case
|
59
|
+
case 5:
|
61
60
|
response = _ctx.sent;
|
62
61
|
queryCache.setQueryData([
|
63
62
|
AggregateRequestEnum.Categories,
|
@@ -68,7 +67,7 @@ function _prefetchCategories() {
|
|
68
67
|
staleTime: 30000
|
69
68
|
});
|
70
69
|
return _ctx.abrupt("return", response);
|
71
|
-
case
|
70
|
+
case 8:
|
72
71
|
case "end":
|
73
72
|
return _ctx.stop();
|
74
73
|
}
|
@@ -35,20 +35,20 @@ export function prefetchPredicate(queryCache, router, config) {
|
|
35
35
|
}
|
36
36
|
function _prefetchPredicate() {
|
37
37
|
_prefetchPredicate = _asyncToGenerator(regeneratorRuntime.mark(function _callee(queryCache, router, config) {
|
38
|
-
var
|
38
|
+
var aliasedSlug, slug, data, attribute;
|
39
39
|
return regeneratorRuntime.wrap(function _callee$(_ctx) {
|
40
40
|
while(1)switch(_ctx.prev = _ctx.next){
|
41
41
|
case 0:
|
42
|
-
attribute = router.query.cat && router.query.slug;
|
43
42
|
aliasedSlug = getListingAlias({
|
44
43
|
router: router,
|
45
44
|
config: config
|
46
45
|
});
|
47
46
|
slug = getSlug(router, aliasedSlug);
|
48
|
-
_ctx.next =
|
47
|
+
_ctx.next = 4;
|
49
48
|
return processPredicateRequest(slug, router, aliasedSlug);
|
50
|
-
case
|
49
|
+
case 4:
|
51
50
|
data = _ctx.sent;
|
51
|
+
attribute = router.query.cat && aliasedSlug;
|
52
52
|
queryCache.setQueryData([
|
53
53
|
ListingQueryKeysEnum.usePredicate,
|
54
54
|
slug,
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { useSeoTranslations } from '../../hooks/useSeoTranslations';
|
3
|
+
import Head from 'next/head';
|
4
|
+
import { useRouter } from 'next/router';
|
5
|
+
function _extends() {
|
6
|
+
_extends = Object.assign || function(target) {
|
7
|
+
for(var i = 1; i < arguments.length; i++){
|
8
|
+
var source = arguments[i];
|
9
|
+
for(var key in source){
|
10
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
11
|
+
target[key] = source[key];
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
15
|
+
return target;
|
16
|
+
};
|
17
|
+
return _extends.apply(this, arguments);
|
18
|
+
}
|
19
|
+
export var TranslationsMeta = function() {
|
20
|
+
var ref = useSeoTranslations(), translationsMap = ref.translationsMap, allLocales = ref.allLocales, defaultLocale = ref.defaultLocale;
|
21
|
+
var router = useRouter();
|
22
|
+
var defaultTranslation = translationsMap[defaultLocale];
|
23
|
+
var isError = router.route === '/404' || router.route === '/_error';
|
24
|
+
if (isError) return null;
|
25
|
+
var domain = defaultTranslation === null || defaultTranslation === void 0 ? void 0 : defaultTranslation.domain;
|
26
|
+
return(/*#__PURE__*/ React.createElement(Head, null, allLocales === null || allLocales === void 0 ? void 0 : allLocales.map(function(locale) {
|
27
|
+
var translation = translationsMap === null || translationsMap === void 0 ? void 0 : translationsMap[locale];
|
28
|
+
var href = translation === null || translation === void 0 ? void 0 : translation.slug;
|
29
|
+
// go to the same page but with the right locale.
|
30
|
+
// This is for pages that does not have a translated slug
|
31
|
+
// example: /checkout -> /en/checkout, /ro/checkout
|
32
|
+
if (!href) href = "/".concat(locale).concat(router.asPath);
|
33
|
+
return(/*#__PURE__*/ React.createElement("link", _extends({
|
34
|
+
rel: "alternate"
|
35
|
+
}, {
|
36
|
+
hreflang: locale
|
37
|
+
}, {
|
38
|
+
href: domain + href,
|
39
|
+
key: 'Translation__' + href
|
40
|
+
})));
|
41
|
+
}), defaultTranslation && /*#__PURE__*/ React.createElement("link", _extends({
|
42
|
+
rel: "alternate"
|
43
|
+
}, {
|
44
|
+
hreflang: 'x-default'
|
45
|
+
}, {
|
46
|
+
href: "".concat(domain).concat(defaultTranslation === null || defaultTranslation === void 0 ? void 0 : defaultTranslation.slug)
|
47
|
+
}))));
|
48
|
+
};
|