@bonlineza/luxity-lib 2.36.1-beta.3 → 2.36.1-uk-platform.1

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.
@@ -116,143 +116,6 @@
116
116
  }
117
117
  }
118
118
 
119
- var cssUnit = {
120
- cm: true,
121
- mm: true,
122
- in: true,
123
- px: true,
124
- pt: true,
125
- pc: true,
126
- em: true,
127
- ex: true,
128
- ch: true,
129
- rem: true,
130
- vw: true,
131
- vh: true,
132
- vmin: true,
133
- vmax: true,
134
- "%": true,
135
- };
136
- /**
137
- * If size is a number, append px to the value as default unit.
138
- * If size is a string, validate against list of valid units.
139
- * If unit is valid, return size as is.
140
- * If unit is invalid, console warn issue, replace with px as the unit.
141
- *
142
- * @param {(number | string)} size
143
- * @return {LengthObject} LengthObject
144
- */
145
- function parseLengthAndUnit(size) {
146
- if (typeof size === "number") {
147
- return {
148
- value: size,
149
- unit: "px",
150
- };
151
- }
152
- var value;
153
- var valueString = (size.match(/^[0-9.]*/) || "").toString();
154
- if (valueString.includes(".")) {
155
- value = parseFloat(valueString);
156
- }
157
- else {
158
- value = parseInt(valueString, 10);
159
- }
160
- var unit = (size.match(/[^0-9]*$/) || "").toString();
161
- if (cssUnit[unit]) {
162
- return {
163
- value: value,
164
- unit: unit,
165
- };
166
- }
167
- console.warn("React Spinners: ".concat(size, " is not a valid css value. Defaulting to ").concat(value, "px."));
168
- return {
169
- value: value,
170
- unit: "px",
171
- };
172
- }
173
- /**
174
- * Take value as an input and return valid css value
175
- *
176
- * @param {(number | string)} value
177
- * @return {string} valid css value
178
- */
179
- function cssValue(value) {
180
- var lengthWithunit = parseLengthAndUnit(value);
181
- return "".concat(lengthWithunit.value).concat(lengthWithunit.unit);
182
- }
183
-
184
- var createAnimation = function (loaderName, frames, suffix) {
185
- var animationName = "react-spinners-".concat(loaderName, "-").concat(suffix);
186
- if (typeof window == "undefined" || !window.document) {
187
- return animationName;
188
- }
189
- var styleEl = document.createElement("style");
190
- document.head.appendChild(styleEl);
191
- var styleSheet = styleEl.sheet;
192
- var keyFrames = "\n @keyframes ".concat(animationName, " {\n ").concat(frames, "\n }\n ");
193
- if (styleSheet) {
194
- styleSheet.insertRule(keyFrames, 0);
195
- }
196
- return animationName;
197
- };
198
-
199
- var __assign = (undefined && undefined.__assign) || function () {
200
- __assign = Object.assign || function(t) {
201
- for (var s, i = 1, n = arguments.length; i < n; i++) {
202
- s = arguments[i];
203
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
204
- t[p] = s[p];
205
- }
206
- return t;
207
- };
208
- return __assign.apply(this, arguments);
209
- };
210
- var __rest = (undefined && undefined.__rest) || function (s, e) {
211
- var t = {};
212
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
213
- t[p] = s[p];
214
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
215
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
216
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
217
- t[p[i]] = s[p[i]];
218
- }
219
- return t;
220
- };
221
- var beat = createAnimation("BeatLoader", "50% {transform: scale(0.75);opacity: 0.2} 100% {transform: scale(1);opacity: 1}", "beat");
222
- function BeatLoader(_a) {
223
- var _b = _a.loading, loading = _b === void 0 ? true : _b, _c = _a.color, color = _c === void 0 ? "#000000" : _c, _d = _a.speedMultiplier, speedMultiplier = _d === void 0 ? 1 : _d, _e = _a.cssOverride, cssOverride = _e === void 0 ? {} : _e, _f = _a.size, size = _f === void 0 ? 15 : _f, _g = _a.margin, margin = _g === void 0 ? 2 : _g, additionalprops = __rest(_a, ["loading", "color", "speedMultiplier", "cssOverride", "size", "margin"]);
224
- var wrapper = __assign({ display: "inherit" }, cssOverride);
225
- var style = function (i) {
226
- return {
227
- display: "inline-block",
228
- backgroundColor: color,
229
- width: cssValue(size),
230
- height: cssValue(size),
231
- margin: cssValue(margin),
232
- borderRadius: "100%",
233
- animation: "".concat(beat, " ").concat(0.7 / speedMultiplier, "s ").concat(i % 2 ? "0s" : "".concat(0.35 / speedMultiplier, "s"), " infinite linear"),
234
- animationFillMode: "both",
235
- };
236
- };
237
- if (!loading) {
238
- return null;
239
- }
240
- return (React.createElement("span", __assign({ style: wrapper }, additionalprops),
241
- React.createElement("span", { style: style(1) }),
242
- React.createElement("span", { style: style(2) }),
243
- React.createElement("span", { style: style(3) })));
244
- }
245
-
246
- var searchProducts = function searchProducts(search, limit) {
247
- return {
248
- query: "\n query SearchProducts($search: String!, $limit: Int!) {\n luxity_products_serach_results(search: $search, limit: $limit) {\n brands {\n name\n link\n }\n products {\n name\n link\n }\n luxity_product_ids\n }\n }\n ",
249
- variables: {
250
- search: search,
251
- limit: limit
252
- }
253
- };
254
- };
255
-
256
119
  var Dropdown = function Dropdown(_ref) {
257
120
  var title = _ref.title,
258
121
  imageSrc = _ref.imageSrc,
@@ -410,84 +273,142 @@
410
273
  }, contactNumber)));
411
274
  };
412
275
 
413
- var categories = {
414
- shoes: {
415
- name: 'Shoes',
416
- slug: 'shoes'
417
- },
418
- bags: {
419
- name: 'Bags',
420
- slug: 'bags'
421
- },
422
- clothing: {
423
- name: 'Clothing',
424
- slug: 'apparel'
425
- },
426
- watches: {
427
- name: 'Watches',
428
- slug: 'watches'
429
- },
430
- accessories: {
431
- name: 'Accessories',
432
- slug: 'accessories'
433
- }
434
- };
435
-
436
- var removeCategoryByName = function removeCategoryByName(categories, name) {
437
- var _categories$filter;
438
- return (_categories$filter = categories === null || categories === void 0 ? void 0 : categories.filter(function (category) {
439
- return category.name !== name;
440
- })) !== null && _categories$filter !== void 0 ? _categories$filter : [];
441
- };
442
-
443
276
  var SearchResults = function SearchResults(_ref) {
277
+ var _searchResults$brands, _searchResults$produc, _searchResults$brands2, _searchResults$produc2, _initialSearchData$tr, _initialSearchData$la, _limitBrands, _limitBrands2, _initialSearchData$la2, _searchResults$produc3;
444
278
  var searchValue = _ref.searchValue,
445
279
  searchResults = _ref.searchResults,
446
280
  onViewAll = _ref.onViewAll,
447
281
  searchResultsRef = _ref.searchResultsRef,
448
282
  onSearchSubmit = _ref.onSearchSubmit,
449
- setSearchValue = _ref.setSearchValue;
450
- if (searchValue.trim().length >= 3) {
451
- if (searchResults.brands.length === 0 && searchResults.products.length === 0) {
452
- return null;
453
- }
454
- return /*#__PURE__*/React__default.createElement("div", {
455
- className: "z-50 absolute md:top-14 font-body bg-white w-full lg:w-1/2 flex flex-col md:flex-row md:divide-x divide-black lg:mt-1 shadow-md",
456
- ref: searchResultsRef
457
- }, /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("div", {
458
- className: "w-full lg:w-1/3"
459
- }, /*#__PURE__*/React__default.createElement("p", {
460
- className: "font-bold p-2 px-4"
461
- }, "Brands"), searchResults.brands.map(function (brand) {
462
- return /*#__PURE__*/React__default.createElement("a", {
463
- key: brand.link,
464
- href: brand.link,
465
- className: ""
466
- }, /*#__PURE__*/React__default.createElement("div", {
467
- className: "p-2 px-4 hover:bg-gray-100"
468
- }, brand.name));
283
+ setSearchValue = _ref.setSearchValue,
284
+ initialSearchData = _ref.initialSearchData,
285
+ isSearchFocused = _ref.isSearchFocused,
286
+ setIsSearchFocused = _ref.setIsSearchFocused,
287
+ currency = _ref.currency,
288
+ currencySymbol = _ref.currencySymbol;
289
+ var _useState = React.useState(false),
290
+ _useState2 = _slicedToArray(_useState, 2),
291
+ isMobile = _useState2[0],
292
+ setIsMobile = _useState2[1];
293
+ React.useEffect(function () {
294
+ var checkIfMobile = function checkIfMobile() {
295
+ setIsMobile(window.innerWidth <= 1024);
296
+ };
297
+ checkIfMobile();
298
+ window.addEventListener('resize', checkIfMobile);
299
+ return function () {
300
+ window.removeEventListener('resize', checkIfMobile);
301
+ };
302
+ }, []);
303
+ var shouldShowInitialData = isSearchFocused && (!searchValue || searchValue.trim().length < 3) || (searchValue === null || searchValue === void 0 ? void 0 : searchValue.trim().length) >= 3 && !(searchResults !== null && searchResults !== void 0 && (_searchResults$brands = searchResults.brands) !== null && _searchResults$brands !== void 0 && _searchResults$brands.length) && !(searchResults !== null && searchResults !== void 0 && (_searchResults$produc = searchResults.products) !== null && _searchResults$produc !== void 0 && _searchResults$produc.length);
304
+ var hasResults = (searchResults === null || searchResults === void 0 ? void 0 : (_searchResults$brands2 = searchResults.brands) === null || _searchResults$brands2 === void 0 ? void 0 : _searchResults$brands2.length) > 0 || (searchResults === null || searchResults === void 0 ? void 0 : (_searchResults$produc2 = searchResults.products) === null || _searchResults$produc2 === void 0 ? void 0 : _searchResults$produc2.length) > 0;
305
+ var hasInitialData = (initialSearchData === null || initialSearchData === void 0 ? void 0 : (_initialSearchData$tr = initialSearchData.trending_brands) === null || _initialSearchData$tr === void 0 ? void 0 : _initialSearchData$tr.length) > 0 || (initialSearchData === null || initialSearchData === void 0 ? void 0 : (_initialSearchData$la = initialSearchData.latest_products) === null || _initialSearchData$la === void 0 ? void 0 : _initialSearchData$la.length) > 0;
306
+ if (!hasResults && !hasInitialData) {
307
+ return null;
308
+ }
309
+ if (!isSearchFocused && !hasResults) {
310
+ return null;
311
+ }
312
+ var formatPrice = function formatPrice(price) {
313
+ var formatter = new Intl.NumberFormat(undefined, {
314
+ minimumFractionDigits: 0,
315
+ maximumFractionDigits: 2
316
+ });
317
+ return "".concat(currencySymbol).concat(formatter.format(price));
318
+ };
319
+ var renderProductCard = function renderProductCard(product) {
320
+ var selectedPrice = product.prices ? product.prices.find(function (p) {
321
+ return p.currency === currency;
322
+ }) : {
323
+ price: product.price,
324
+ retail_price: product.est_retail_price
325
+ };
326
+ return /*#__PURE__*/React__default.createElement("a", {
327
+ key: product.link,
328
+ href: product.link,
329
+ className: "product-card"
330
+ }, (product.image_url || product.featured_image) && /*#__PURE__*/React__default.createElement("div", {
331
+ className: "product-card__image-container"
332
+ }, /*#__PURE__*/React__default.createElement("img", {
333
+ src: product.featured_image,
334
+ alt: product.name,
335
+ className: "product-card__image"
469
336
  })), /*#__PURE__*/React__default.createElement("div", {
470
- className: "w-full lg:w-2/3"
471
- }, /*#__PURE__*/React__default.createElement("p", {
472
- className: "font-bold p-2 px-4"
473
- }, "Products"), searchResults.products.map(function (product) {
474
- return /*#__PURE__*/React__default.createElement("a", {
475
- key: product.link,
476
- href: product.link
477
- }, /*#__PURE__*/React__default.createElement("div", {
478
- className: "p-2 px-4 hover:bg-gray-100"
479
- }, product.name));
480
- }), /*#__PURE__*/React__default.createElement("button", {
481
- type: "button",
482
- onClick: function onClick() {
483
- onViewAll();
337
+ className: "product-card__details"
338
+ }, /*#__PURE__*/React__default.createElement("h3", {
339
+ className: "product-card__name"
340
+ }, shouldShowInitialData ? /*#__PURE__*/React__default.createElement("span", null, /*#__PURE__*/React__default.createElement("span", {
341
+ className: "product-card__brand-name"
342
+ }, product.brand.toUpperCase()), ' ', product.name) : product.name), /*#__PURE__*/React__default.createElement("div", {
343
+ className: "product-card__info-row"
344
+ }, /*#__PURE__*/React__default.createElement("div", {
345
+ className: "product-card__price-group"
346
+ }, /*#__PURE__*/React__default.createElement("div", {
347
+ className: "product-card__price"
348
+ }, formatPrice(selectedPrice.price)), selectedPrice.retail_price > 1 && /*#__PURE__*/React__default.createElement("div", {
349
+ className: "product-card__retail-price"
350
+ }, "Est. Retail: ", formatPrice(selectedPrice.retail_price))), /*#__PURE__*/React__default.createElement("div", {
351
+ className: "product-card__condition"
352
+ }, /*#__PURE__*/React__default.createElement("span", {
353
+ className: "product-card__condition-label"
354
+ }, "Condition:"), product.condition))));
355
+ };
356
+ var getBrandLink = function getBrandLink(brand) {
357
+ return "/products/brands/".concat(brand.slug);
358
+ };
359
+ var limitBrands = function limitBrands(brands) {
360
+ if (isMobile && brands && brands.length > 4) {
361
+ return brands.slice(0, 4);
362
+ }
363
+ return brands;
364
+ };
365
+ return /*#__PURE__*/React__default.createElement("div", {
366
+ className: "search-results",
367
+ ref: searchResultsRef
368
+ }, /*#__PURE__*/React__default.createElement("div", {
369
+ className: "search-results__section"
370
+ }, /*#__PURE__*/React__default.createElement("h2", {
371
+ className: "search-results__header"
372
+ }, shouldShowInitialData ? 'TRENDING SEARCHES' : 'BRANDS'), /*#__PURE__*/React__default.createElement("div", {
373
+ className: "search-results__list"
374
+ }, shouldShowInitialData ? (_limitBrands = limitBrands(initialSearchData === null || initialSearchData === void 0 ? void 0 : initialSearchData.trending_brands)) === null || _limitBrands === void 0 ? void 0 : _limitBrands.map(function (brand) {
375
+ return /*#__PURE__*/React__default.createElement("a", {
376
+ key: brand.id,
377
+ href: getBrandLink(brand),
378
+ className: "search-results__item"
379
+ }, brand.name);
380
+ }) : (_limitBrands2 = limitBrands(searchResults === null || searchResults === void 0 ? void 0 : searchResults.brands)) === null || _limitBrands2 === void 0 ? void 0 : _limitBrands2.map(function (brand) {
381
+ return /*#__PURE__*/React__default.createElement("a", {
382
+ key: brand.link,
383
+ href: brand.link,
384
+ className: "search-results__item"
385
+ }, brand.name);
386
+ }))), /*#__PURE__*/React__default.createElement("div", {
387
+ className: "search-results__section"
388
+ }, /*#__PURE__*/React__default.createElement("div", {
389
+ className: "search-results__section-header"
390
+ }, /*#__PURE__*/React__default.createElement("h2", {
391
+ className: "search-results__header"
392
+ }, shouldShowInitialData ? 'POPULAR' : 'TOP MATCHES'), /*#__PURE__*/React__default.createElement("button", {
393
+ type: "button",
394
+ className: "search-results__view-all-link",
395
+ onClick: function onClick() {
396
+ onViewAll();
397
+ }
398
+ }, "View all items")), /*#__PURE__*/React__default.createElement("div", {
399
+ className: "search-results__product-list"
400
+ }, shouldShowInitialData ? initialSearchData === null || initialSearchData === void 0 ? void 0 : (_initialSearchData$la2 = initialSearchData.latest_products) === null || _initialSearchData$la2 === void 0 ? void 0 : _initialSearchData$la2.map(renderProductCard) : searchResults === null || searchResults === void 0 ? void 0 : (_searchResults$produc3 = searchResults.products) === null || _searchResults$produc3 === void 0 ? void 0 : _searchResults$produc3.map(renderProductCard)), /*#__PURE__*/React__default.createElement("button", {
401
+ type: "button",
402
+ className: "search-results__view-all-button",
403
+ onClick: function onClick() {
404
+ onViewAll();
405
+ if (!shouldShowInitialData) {
484
406
  onSearchSubmit(searchValue);
485
407
  setSearchValue('');
486
- },
487
- className: "bottom-0 mt-5 py-3 w-full font-body text-center text-white uppercase bg-black hover:bg-gray-950 border border-black transition-all ease-in-out duration-300 cursor-pointer"
488
- }, "View all"))));
489
- }
490
- return null;
408
+ setIsSearchFocused(false);
409
+ }
410
+ }
411
+ }, "View all items")));
491
412
  };
492
413
 
493
414
  var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
@@ -679,6 +600,106 @@
679
600
  }))));
680
601
  };
681
602
 
603
+ var searchProducts = function searchProducts(search, limit, currencyCode) {
604
+ return {
605
+ query: "\n query SearchProducts($search: String!, $limit: Int!, $currencyCode: String!) {\n luxity_products_serach_results(search: $search, limit: $limit, currency_code: $currencyCode) {\n brands {\n name\n link\n }\n products {\n name\n link\n price\n est_retail_price\n condition\n featured_image\n }\n luxity_product_ids\n }\n }\n ",
606
+ variables: {
607
+ search: search,
608
+ limit: limit,
609
+ currencyCode: currencyCode
610
+ }
611
+ };
612
+ };
613
+
614
+ var useSearch = function useSearch(_ref) {
615
+ var endpoint = _ref.endpoint,
616
+ onProductIdsReceived = _ref.onProductIdsReceived,
617
+ currency = _ref.currency;
618
+ var debounce = React.useCallback(function (func, wait) {
619
+ var timeout;
620
+ return function executedFunction() {
621
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
622
+ args[_key] = arguments[_key];
623
+ }
624
+ var later = function later() {
625
+ clearTimeout(timeout);
626
+ func.apply(void 0, args);
627
+ };
628
+ clearTimeout(timeout);
629
+ timeout = setTimeout(later, wait);
630
+ };
631
+ }, []);
632
+ var fetchInitialSearchData = React.useCallback(function (initialSearchDataUrl, setInitialSearchView) {
633
+ axios.get("".concat(initialSearchDataUrl)).then(function (_ref2) {
634
+ var data = _ref2.data;
635
+ setInitialSearchView({
636
+ trending_brands: data.trending_brands,
637
+ latest_products: data.latest_products
638
+ });
639
+ }).catch(function () {
640
+ setInitialSearchView({
641
+ trending_brands: [],
642
+ latest_products: []
643
+ });
644
+ });
645
+ }, []);
646
+ var performSearch = React.useCallback(function (nextValue, setSearchResults) {
647
+ if (!nextValue || nextValue.trim() === '') {
648
+ setSearchResults({
649
+ brands: [],
650
+ products: [],
651
+ luxity_product_ids: []
652
+ });
653
+ return;
654
+ }
655
+ axios.post(endpoint, searchProducts(nextValue, 3, currency)).then(function (response) {
656
+ var searchResults = response.data.data.luxity_products_serach_results;
657
+ setSearchResults(searchResults);
658
+ if (searchResults && searchResults.luxity_product_ids) {
659
+ onProductIdsReceived(searchResults.luxity_product_ids);
660
+ }
661
+ }).catch(function () {
662
+ setSearchResults({
663
+ brands: [],
664
+ products: [],
665
+ luxity_product_ids: []
666
+ });
667
+ });
668
+ }, [endpoint, currency, onProductIdsReceived]);
669
+ var debouncedSearch = React.useMemo(function () {
670
+ return debounce(function (nextValue, setSearchResults) {
671
+ return performSearch(nextValue, setSearchResults);
672
+ }, 500);
673
+ }, [debounce, performSearch]);
674
+ var createDebouncedSearch = React.useCallback(function (setSearchResults) {
675
+ return function (nextValue) {
676
+ return debouncedSearch(nextValue, setSearchResults);
677
+ };
678
+ }, [debouncedSearch]);
679
+ var createImmediateSearch = React.useCallback(function (setSearchValue, setSearchResults, onSearchSubmit) {
680
+ return function (value) {
681
+ setSearchValue('');
682
+ setSearchResults({
683
+ brands: [],
684
+ products: []
685
+ });
686
+ onSearchSubmit(value);
687
+ };
688
+ }, []);
689
+ return {
690
+ fetchInitialSearchData: fetchInitialSearchData,
691
+ createDebouncedSearch: createDebouncedSearch,
692
+ createImmediateSearch: createImmediateSearch
693
+ };
694
+ };
695
+
696
+ var removeCategoryByName = function removeCategoryByName(categories, name) {
697
+ var _categories$filter;
698
+ return (_categories$filter = categories === null || categories === void 0 ? void 0 : categories.filter(function (category) {
699
+ return category.name.toLowerCase() !== name.toLowerCase();
700
+ })) !== null && _categories$filter !== void 0 ? _categories$filter : [];
701
+ };
702
+
682
703
  var LuxityDesktopHeader = function LuxityDesktopHeader(_ref) {
683
704
  var accountIcon = _ref.accountIcon,
684
705
  cartIcon = _ref.cartIcon,
@@ -686,12 +707,6 @@
686
707
  cartCount = _ref.cartCount,
687
708
  logoSrc = _ref.logoSrc,
688
709
  categoryElements = _ref.categoryElements,
689
- newBrandsImage = _ref.newBrandsImage,
690
- bagsImage = _ref.bagsImage,
691
- shoesImage = _ref.shoesImage,
692
- clothingImage = _ref.clothingImage,
693
- accessoriesImage = _ref.accessoriesImage,
694
- watchesImage = _ref.watchesImage,
695
710
  stores = _ref.stores,
696
711
  contactNumber = _ref.contactNumber,
697
712
  productsUrl = _ref.productsUrl,
@@ -706,21 +721,29 @@
706
721
  ourStoryLink = _ref.ourStoryLink,
707
722
  onLogoClick = _ref.onLogoClick,
708
723
  endpoint = _ref.endpoint,
709
- menuData = _ref.menuData,
724
+ initialSearchData = _ref.initialSearchData,
710
725
  onSearchSubmit = _ref.onSearchSubmit,
711
726
  onProductIdsReceived = _ref.onProductIdsReceived,
712
727
  currency = _ref.currency,
728
+ currencySymbol = _ref.currencySymbol,
713
729
  currencyOptions = _ref.currencyOptions,
714
730
  onCurrencyChange = _ref.onCurrencyChange,
715
731
  isCurrencySelectionDisabled = _ref.isCurrencySelectionDisabled,
716
732
  tooltipContent = _ref.tooltipContent,
717
- earlyAccessIcon = _ref.earlyAccessIcon,
718
- exclusiveIcon = _ref.exclusiveIcon,
733
+ vipIcon = _ref.vipIcon,
719
734
  name = _ref.name,
720
- isEarlyAccess = _ref.isEarlyAccess,
721
- isExclusive = _ref.isExclusive,
735
+ isVip = _ref.isVip,
722
736
  shop = _ref.shop,
723
- app = _ref.app;
737
+ app = _ref.app,
738
+ categoryConfig = _ref.categoryConfig;
739
+ var _useSearch = useSearch({
740
+ endpoint: endpoint,
741
+ onProductIdsReceived: onProductIdsReceived,
742
+ currency: currency
743
+ }),
744
+ fetchInitialSearchData = _useSearch.fetchInitialSearchData,
745
+ createDebouncedSearch = _useSearch.createDebouncedSearch,
746
+ createImmediateSearch = _useSearch.createImmediateSearch;
724
747
  var _useState = React.useState(''),
725
748
  _useState2 = _slicedToArray(_useState, 2),
726
749
  searchValue = _useState2[0],
@@ -729,71 +752,39 @@
729
752
  _useState4 = _slicedToArray(_useState3, 2),
730
753
  loading = _useState4[0],
731
754
  setLoading = _useState4[1];
732
- var _useState5 = React.useState({
733
- latestArrivals: [],
734
- bags: [],
735
- shoes: [],
736
- clothing: [],
737
- accessories: [],
738
- watches: [],
739
- accessoriesCategories: [],
740
- apparelStyles: []
741
- }),
755
+ var _useState5 = React.useState(false),
742
756
  _useState6 = _slicedToArray(_useState5, 2),
743
- dropdownData = _useState6[0],
744
- setDropdownData = _useState6[1];
745
- var _useState7 = React.useState(false),
757
+ isSearchFocused = _useState6[0],
758
+ setIsSearchFocused = _useState6[1];
759
+ var _useState7 = React.useState({
760
+ trending_brands: [],
761
+ latest_products: []
762
+ }),
746
763
  _useState8 = _slicedToArray(_useState7, 2),
747
- hasError = _useState8[0],
748
- setHasError = _useState8[1];
749
- var _useState9 = React.useState(false),
764
+ initialSearchView = _useState8[0],
765
+ setInitialSearchView = _useState8[1];
766
+ var _useState9 = React.useState({}),
750
767
  _useState10 = _slicedToArray(_useState9, 2),
751
- searchLoading = _useState10[0],
752
- setSearchLoading = _useState10[1];
753
- var _useState11 = React.useState({
768
+ dropdownData = _useState10[0],
769
+ setDropdownData = _useState10[1];
770
+ var _useState11 = React.useState(false),
771
+ _useState12 = _slicedToArray(_useState11, 2),
772
+ hasError = _useState12[0],
773
+ setHasError = _useState12[1];
774
+ var _useState13 = React.useState({
754
775
  brands: [],
755
776
  products: []
756
777
  }),
757
- _useState12 = _slicedToArray(_useState11, 2),
758
- searchResults = _useState12[0],
759
- setSearchResults = _useState12[1];
778
+ _useState14 = _slicedToArray(_useState13, 2),
779
+ searchResults = _useState14[0],
780
+ setSearchResults = _useState14[1];
760
781
  var searchResultsRef = React.useRef(null);
761
- var debounce = function debounce(func, wait) {
762
- var timeout;
763
- return function executedFunction() {
764
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
765
- args[_key] = arguments[_key];
766
- }
767
- var later = function later() {
768
- clearTimeout(timeout);
769
- func.apply(void 0, args);
770
- };
771
- clearTimeout(timeout);
772
- timeout = setTimeout(later, wait);
773
- };
774
- };
775
- var debouncedSearch = React.useCallback(debounce(function (nextValue) {
776
- setSearchLoading(true);
777
- axios.post(endpoint, searchProducts(nextValue, 6)).then(function (response) {
778
- setSearchResults(response.data.data.luxity_products_serach_results);
779
- var ids = response.data.data.luxity_products_serach_results.luxity_product_ids;
780
- onProductIdsReceived(ids);
781
- setSearchLoading(false);
782
- }).catch(function () {
783
- setSearchLoading(false);
784
- });
785
- }, 500), [endpoint]);
786
- var immediateSearch = React.useCallback(function (value) {
787
- setSearchValue('');
788
- setSearchResults({
789
- brands: [],
790
- products: []
791
- });
792
- onSearchSubmit(value);
793
- }, [onSearchSubmit]);
782
+ var debouncedSearch = createDebouncedSearch(setSearchResults);
783
+ var immediateSearch = createImmediateSearch(setSearchValue, setSearchResults, onSearchSubmit);
794
784
  var handleChange = function handleChange(event) {
795
785
  var value = event.target.value;
796
786
  setSearchValue(value);
787
+ setIsSearchFocused(true);
797
788
  if (value.trim().length >= 3) {
798
789
  debouncedSearch(value);
799
790
  } else {
@@ -807,6 +798,11 @@
807
798
  var handleClickOutside = function handleClickOutside(event) {
808
799
  if (searchResultsRef.current && !searchResultsRef.current.contains(event.target)) {
809
800
  setSearchValue('');
801
+ setIsSearchFocused(false);
802
+ setSearchResults({
803
+ brands: [],
804
+ products: []
805
+ });
810
806
  }
811
807
  };
812
808
  document.addEventListener('mousedown', handleClickOutside);
@@ -823,37 +819,63 @@
823
819
  } else if (event.key === 'Escape') {
824
820
  setSearchValue('');
825
821
  }
822
+ setIsSearchFocused(false);
826
823
  };
827
- function addCategoryToElements(elements, categoryName) {
828
- return elements.map(function (element) {
829
- return _objectSpread2(_objectSpread2({}, element), {}, {
830
- category: categoryName
831
- });
832
- });
833
- }
834
824
  React.useMemo(function () {
835
825
  setLoading(true);
836
- axios.get("".concat(menuData)).then(function (_ref2) {
826
+ axios.get("".concat(categoryConfig.menuData)).then(function (_ref2) {
837
827
  var data = _ref2.data;
838
828
  setLoading(false);
839
- setDropdownData(function (prev) {
840
- return _objectSpread2(_objectSpread2({}, prev), {}, {
841
- latestArrivals: data.latest_arrivals,
842
- bags: data.bags,
843
- shoes: data.shoes,
844
- apparel: data.apparel,
845
- accessories: data.accessories,
846
- watches: data.watches,
847
- accessoriesCategories: data.accessories_categories,
848
- apparelStyles: data.apparel_styles
849
- });
850
- });
829
+ setDropdownData(data);
851
830
  }).catch(function () {
852
831
  return setHasError(true);
853
832
  });
854
- }, [menuData]);
855
- var getMarginRight = function getMarginRight(showLoyaltyIcon, userName) {
856
- if (showLoyaltyIcon) return '15px';
833
+ }, [categoryConfig.menuData]);
834
+ React.useMemo(function () {
835
+ fetchInitialSearchData(initialSearchData, setInitialSearchView);
836
+ }, [initialSearchData, fetchInitialSearchData]);
837
+ var addCategoryToElements = function addCategoryToElements(elements, categoryName) {
838
+ return elements.map(function (element) {
839
+ return _objectSpread2(_objectSpread2({}, element), {}, {
840
+ category: categoryName
841
+ });
842
+ });
843
+ };
844
+ var renderDropdownLinks = function renderDropdownLinks() {
845
+ return categoryConfig.categories.map(function (category) {
846
+ var title = category.title,
847
+ imageSrc = category.imageSrc,
848
+ categorySlug = category.categorySlug,
849
+ categoryName = category.categoryName,
850
+ elementsKey = category.elementsKey,
851
+ subCategoryElementsKey = category.subCategoryElementsKey,
852
+ styleElementsKey = category.styleElementsKey;
853
+ var categoryElementsProcessed = categoryElements;
854
+ if (subCategoryElementsKey && dropdownData[subCategoryElementsKey]) {
855
+ // show subcategory elements
856
+ categoryElementsProcessed = removeCategoryByName(dropdownData[subCategoryElementsKey], categoryName);
857
+ } else if (styleElementsKey && dropdownData[styleElementsKey]) {
858
+ categoryElementsProcessed = addCategoryToElements(dropdownData[styleElementsKey], categorySlug);
859
+ } else {
860
+ categoryElementsProcessed = addCategoryToElements(categoryElementsProcessed, categorySlug);
861
+ }
862
+ return /*#__PURE__*/React__default.createElement(DropdownLink, {
863
+ key: categorySlug,
864
+ title: title,
865
+ imageSrc: imageSrc,
866
+ categoryElements: categoryElementsProcessed,
867
+ brandElements: dropdownData[elementsKey] || [],
868
+ productsUrl: productsUrl,
869
+ categorySlug: categorySlug,
870
+ categoryTitle: categoryName,
871
+ isLoading: loading,
872
+ hasError: hasError,
873
+ LinkComponent: LinkComponent
874
+ });
875
+ });
876
+ };
877
+ var getMarginRight = function getMarginRight(userIsVip, userName) {
878
+ if (userIsVip) return '15px';
857
879
  if (userName) return '5px';
858
880
  return '18px';
859
881
  };
@@ -887,93 +909,38 @@
887
909
  value: searchValue,
888
910
  onChange: handleChange,
889
911
  onKeyDown: handleKeyDown,
890
- onClick: onSearch
891
- }), searchLoading && /*#__PURE__*/React__default.createElement(BeatLoader, {
892
- color: "#000000",
893
- loading: searchLoading,
894
- size: 5,
895
- "aria-label": "Loading Spinner",
896
- "data-testid": "loader"
912
+ onClick: function onClick() {
913
+ onSearch();
914
+ setIsSearchFocused(true);
915
+ },
916
+ onFocus: function onFocus() {
917
+ return setIsSearchFocused(true);
918
+ }
897
919
  })), /*#__PURE__*/React__default.createElement(SearchResults, {
898
920
  searchValue: searchValue,
899
921
  searchResults: searchResults,
900
922
  onViewAll: function onViewAll() {
901
923
  onSearchSubmit(searchValue);
902
924
  setSearchValue('');
925
+ setSearchResults({
926
+ brands: [],
927
+ products: []
928
+ });
929
+ setIsSearchFocused(false);
903
930
  },
904
931
  searchResultsRef: searchResultsRef,
905
932
  onSearchSubmit: onSearchSubmit,
906
- setSearchValue: setSearchValue
933
+ setSearchValue: setSearchValue,
934
+ initialSearchData: initialSearchView,
935
+ isSearchFocused: isSearchFocused,
936
+ setIsSearchFocused: setIsSearchFocused,
937
+ currency: currency,
938
+ currencySymbol: currencySymbol
907
939
  }), /*#__PURE__*/React__default.createElement("nav", {
908
940
  className: "navbar__nav-links navbar__nav-links--wrap"
909
- }, /*#__PURE__*/React__default.createElement(DropdownLink, {
910
- title: "New",
911
- imageSrc: newBrandsImage,
912
- categoryElements: categoryElements,
913
- brandElements: dropdownData.latestArrivals,
914
- productsUrl: productsUrl,
915
- categorySlug: "brands",
916
- categoryTitle: "Brands",
917
- isLoading: loading,
918
- hasError: hasError,
919
- LinkComponent: LinkComponent
920
- }), /*#__PURE__*/React__default.createElement(DropdownLink, {
921
- title: "Bags",
922
- imageSrc: bagsImage,
923
- categoryElements: addCategoryToElements(categoryElements, categories.bags.slug),
924
- brandElements: dropdownData.bags,
925
- productsUrl: productsUrl,
926
- categorySlug: categories.bags.slug,
927
- categoryTitle: categories.bags.name,
928
- isLoading: loading,
929
- hasError: hasError,
930
- LinkComponent: LinkComponent
931
- }), /*#__PURE__*/React__default.createElement(DropdownLink, {
932
- title: "Shoes",
933
- imageSrc: shoesImage,
934
- categoryElements: addCategoryToElements(categoryElements, categories.shoes.slug),
935
- brandElements: dropdownData.shoes,
936
- productsUrl: productsUrl,
937
- categorySlug: categories.shoes.slug,
938
- categoryTitle: categories.shoes.name,
939
- isLoading: loading,
940
- hasError: hasError,
941
- LinkComponent: LinkComponent
942
- }), /*#__PURE__*/React__default.createElement(DropdownLink, {
943
- title: "Clothing",
944
- imageSrc: clothingImage,
945
- categoryElements: addCategoryToElements(dropdownData.apparelStyles, categories.clothing.slug),
946
- brandElements: dropdownData.apparel,
947
- productsUrl: productsUrl,
948
- categorySlug: categories.clothing.slug,
949
- categoryTitle: categories.clothing.name,
950
- isLoading: loading,
951
- hasError: hasError,
952
- LinkComponent: LinkComponent
953
- }), /*#__PURE__*/React__default.createElement(DropdownLink, {
954
- title: "Accessories",
955
- imageSrc: accessoriesImage,
956
- categoryElements: removeCategoryByName(dropdownData.accessoriesCategories, 'ACCESSORIES'),
957
- brandElements: dropdownData.accessories,
958
- productsUrl: productsUrl,
959
- categorySlug: categories.accessories.slug,
960
- categoryTitle: categories.accessories.name,
961
- isLoading: loading,
962
- hasError: hasError,
963
- LinkComponent: LinkComponent
964
- }), /*#__PURE__*/React__default.createElement(DropdownLink, {
965
- title: "Watches",
966
- imageSrc: watchesImage,
967
- categoryElements: addCategoryToElements(categoryElements, categories.watches.slug),
968
- brandElements: dropdownData.watches,
969
- productsUrl: productsUrl,
970
- categorySlug: categories.watches.slug,
971
- categoryTitle: categories.watches.name,
972
- isLoading: loading,
973
- hasError: hasError,
974
- LinkComponent: LinkComponent
975
- }), /*#__PURE__*/React__default.createElement("li", {
976
- className: "navbar__link"
941
+ }, renderDropdownLinks(), !!stores.length && /*#__PURE__*/React__default.createElement("li", {
942
+ className: "navbar__link",
943
+ key: "Stores"
977
944
  }, /*#__PURE__*/React__default.createElement(LinkComponent, {
978
945
  href: contactUsLink,
979
946
  className: "navbar__link-item navbar__link-item--desktop"
@@ -997,23 +964,17 @@
997
964
  className: "navbar__icon relative flex",
998
965
  onClick: onAccountClick,
999
966
  style: {
1000
- marginRight: getMarginRight(isEarlyAccess || isExclusive, name)
967
+ marginRight: getMarginRight(isVip, name)
1001
968
  }
1002
969
  }, /*#__PURE__*/React__default.createElement("img", {
1003
970
  src: accountIcon,
1004
971
  alt: "account-icon",
1005
972
  width: 20,
1006
973
  height: 20
1007
- }), isEarlyAccess && /*#__PURE__*/React__default.createElement("img", {
1008
- src: earlyAccessIcon,
1009
- alt: "loyalty-icon",
1010
- className: "navbar__loyalty-icon",
1011
- width: 16,
1012
- height: 16
1013
- }), isExclusive && /*#__PURE__*/React__default.createElement("img", {
1014
- src: exclusiveIcon,
1015
- alt: "loyalty-icon",
1016
- className: "navbar__loyalty-icon",
974
+ }), isVip && /*#__PURE__*/React__default.createElement("img", {
975
+ src: vipIcon,
976
+ alt: "vip-icon",
977
+ className: "navbar__vip-icon",
1017
978
  width: 16,
1018
979
  height: 16
1019
980
  })), name && /*#__PURE__*/React__default.createElement("button", {
@@ -1022,7 +983,7 @@
1022
983
  onClick: onAccountClick
1023
984
  }, /*#__PURE__*/React__default.createElement("span", {
1024
985
  className: "text-sm"
1025
- }, name))), /*#__PURE__*/React__default.createElement("button", {
986
+ }, name))), onInterestClick && /*#__PURE__*/React__default.createElement("button", {
1026
987
  type: "button",
1027
988
  className: "".concat(app ? 'navbar__icon--app' : 'navbar__icon'),
1028
989
  onClick: onInterestClick