@sonic-equipment/ui 0.0.115 → 0.0.117

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.
@@ -1,14 +1,18 @@
1
+ import { CartLineModel } from '../shared/api/storefront/model/shop.model';
1
2
  import { AlgoliaInsightsProviderGlobalState } from './use-algolia-insights-provider-global-state';
2
3
  export interface UseAlgoliaEventResult {
3
4
  context: Readonly<AlgoliaInsightsProviderGlobalState>;
4
- sendAddToCartFromProductListPageEvent({ objectId, }: {
5
+ sendAddToCartFromProductListPageEvent({ cartLine, objectId, }: {
6
+ cartLine: CartLineModel;
5
7
  objectId: string;
6
8
  }): void;
7
- sendAddToCartFromSearchEvent({ objectId, queryId, }: {
9
+ sendAddToCartFromSearchEvent({ cartLine, objectId, queryId, }: {
10
+ cartLine: CartLineModel;
8
11
  objectId: string;
9
12
  queryId: string;
10
13
  }): void;
11
- sendAddToCartFromSearchResultPageEvent({ objectId, }: {
14
+ sendAddToCartFromSearchResultPageEvent({ cartLine, objectId, }: {
15
+ cartLine: CartLineModel;
12
16
  objectId: string;
13
17
  }): void;
14
18
  sendAddToWishListFromProductListPageEvent({ objectId, position, }: {
@@ -1,5 +1,9 @@
1
+ import { CartLineModel } from '../../shared/api/storefront/model/shop.model';
2
+ export type AddToCartHandler = ({ cartLine, }: {
3
+ cartLine: CartLineModel;
4
+ }) => void;
1
5
  interface Props {
2
- onAddToCart?: () => void;
6
+ onAddToCart?: AddToCartHandler;
3
7
  productId: string;
4
8
  }
5
9
  export declare const ConnectedAddToCartButton: ({ onAddToCart, productId }: Props) => import("react/jsx-runtime").JSX.Element;
@@ -1,6 +1,7 @@
1
+ import { AddToCartHandler } from '../../buttons/add-to-cart-button/connected-add-to-cart-button';
1
2
  import { ProductCardProps } from './product-card';
2
3
  export interface ConnectedProductCartProps extends Omit<ProductCardProps, 'addToCartButton' | 'favoriteButton'> {
3
- onAddToCart?: VoidFunction;
4
+ onAddToCart?: AddToCartHandler;
4
5
  onFavorited?: VoidFunction;
5
6
  onFavoriting?: VoidFunction;
6
7
  }
package/dist/index.js CHANGED
@@ -3399,49 +3399,105 @@ function AlgoliaSortBy() {
3399
3399
  return (jsx(Select, { label: t('Sort by'), onChange: value => refine(String(value)), options: options, selectedOption: currentRefinement, showLabel: false, size: "sm" }));
3400
3400
  }
3401
3401
 
3402
+ const currencySymbolToISO = {
3403
+ $: 'USD', // US Dollar
3404
+ 'Bs.': 'VES', // Venezuelan Bolívar Soberano
3405
+ Ft: 'HUF', // Hungarian Forint
3406
+ Kč: 'CZK', // Czech Koruna
3407
+ R: 'ZAR', // South African Rand
3408
+ kr: 'SEK', // Swedish Krona (and others like DKK, NOK depending on context)
3409
+ lei: 'RON', // Romanian Leu
3410
+ zł: 'PLN', // Polish Zloty
3411
+ '£': 'GBP', // British Pound
3412
+ '¥': 'JPY', // Japanese Yen
3413
+ '฿': 'THB', // Thai Baht
3414
+ '₡': 'CRC', // Costa Rican Colón
3415
+ '₦': 'NGN', // Nigerian Naira
3416
+ '₩': 'KRW', // South Korean Won
3417
+ '₪': 'ILS', // Israeli Shekel
3418
+ '₫': 'VND', // Vietnamese Dong
3419
+ '€': 'EUR', // Euro
3420
+ '₮': 'MNT', // Mongolian Tögrög
3421
+ '₱': 'PHP', // Philippine Peso
3422
+ '₲': 'PYG', // Paraguayan Guarani
3423
+ '₴': 'UAH', // Ukrainian Hryvnia
3424
+ '₵': 'GHS', // Ghanaian Cedi
3425
+ '₹': 'INR', // Indian Rupee
3426
+ '₺': 'TRY', // Turkish Lira
3427
+ '₽': 'RUB', // Russian Ruble
3428
+ };
3429
+
3430
+ function getCurrencyFromPriceString(priceString) {
3431
+ const currencySymbol = priceString?.replace(/\d|\.|,|-| /g, '');
3432
+ return currencySymbol ? currencySymbolToISO[currencySymbol] : undefined;
3433
+ }
3402
3434
  function useAlgoliaInsights() {
3403
3435
  const context = useContext(AlgoliaInsightsProviderContext);
3404
3436
  const [, setGlobalState] = useAlgoliaInsightsGlobalState();
3405
3437
  return {
3406
3438
  context,
3407
- sendAddToCartFromProductListPageEvent({ objectId }) {
3439
+ sendAddToCartFromProductListPageEvent({ cartLine, objectId }) {
3408
3440
  if (!context.index)
3409
3441
  return console.warn('Unable to send clickedObjectIDsAfterSearch event, no index', context);
3410
3442
  if (!context.queryId)
3411
3443
  return console.warn('Unable to send clickedObjectIDsAfterSearch event, no queryId', context);
3412
3444
  aa('addedToCartObjectIDsAfterSearch', {
3445
+ currency: getCurrencyFromPriceString(cartLine.pricing?.actualPriceDisplay),
3413
3446
  eventName: 'PLP: AddToCart ClickedAfterSearch',
3414
3447
  index: context.index,
3448
+ objectData: [
3449
+ {
3450
+ price: cartLine.pricing?.actualPrice || undefined,
3451
+ quantity: cartLine.qtyOrdered || undefined,
3452
+ queryID: context.queryId,
3453
+ },
3454
+ ],
3415
3455
  objectIDs: [].concat(objectId),
3416
3456
  queryID: context.queryId,
3417
3457
  userToken,
3418
3458
  });
3419
3459
  },
3420
- sendAddToCartFromSearchEvent({ objectId, queryId }) {
3460
+ sendAddToCartFromSearchEvent({ cartLine, objectId, queryId }) {
3421
3461
  if (!context.index)
3422
3462
  return console.warn('Unable to send clickedObjectIDsAfterSearch event, no index', context);
3423
3463
  aa('addedToCartObjectIDsAfterSearch', {
3464
+ currency: getCurrencyFromPriceString(cartLine.pricing?.actualPriceDisplay),
3424
3465
  eventName: 'SRP: AddToCart ClickedAfterSearch',
3425
3466
  index: context.index,
3467
+ objectData: [
3468
+ {
3469
+ price: cartLine.pricing?.actualPrice || undefined,
3470
+ quantity: cartLine.qtyOrdered || undefined,
3471
+ queryID: context.queryId,
3472
+ },
3473
+ ],
3426
3474
  objectIDs: [].concat(objectId),
3427
3475
  queryID: queryId,
3428
3476
  userToken,
3429
3477
  });
3430
3478
  },
3431
- sendAddToCartFromSearchResultPageEvent({ objectId, }) {
3479
+ sendAddToCartFromSearchResultPageEvent({ cartLine, objectId }) {
3432
3480
  if (!context.index)
3433
3481
  return console.warn('Unable to send clickedObjectIDsAfterSearch event, no index', context);
3434
3482
  if (!context.queryId)
3435
3483
  return console.warn('Unable to send clickedObjectIDsAfterSearch event, no queryId', context);
3436
3484
  aa('addedToCartObjectIDsAfterSearch', {
3485
+ currency: getCurrencyFromPriceString(cartLine.pricing?.actualPriceDisplay),
3437
3486
  eventName: 'SRP: AddToCart ClickedAfterSearch',
3438
3487
  index: context.index,
3488
+ objectData: [
3489
+ {
3490
+ price: cartLine.pricing?.actualPrice || undefined,
3491
+ quantity: cartLine.qtyOrdered || undefined,
3492
+ queryID: context.queryId,
3493
+ },
3494
+ ],
3439
3495
  objectIDs: [].concat(objectId),
3440
3496
  queryID: context.queryId,
3441
3497
  userToken,
3442
3498
  });
3443
3499
  },
3444
- sendAddToWishListFromProductListPageEvent({ objectId, position, }) {
3500
+ sendAddToWishListFromProductListPageEvent({ objectId, position }) {
3445
3501
  if (!context.index)
3446
3502
  return console.warn('Unable to send clickedObjectIDsAfterSearch event, no index', context);
3447
3503
  if (!context.queryId)
@@ -3455,7 +3511,7 @@ function useAlgoliaInsights() {
3455
3511
  userToken,
3456
3512
  });
3457
3513
  },
3458
- sendAddToWishListFromSearchEvent({ objectId, position, queryId, }) {
3514
+ sendAddToWishListFromSearchEvent({ objectId, position, queryId }) {
3459
3515
  if (!context.index)
3460
3516
  return console.warn('Unable to send clickedObjectIDsAfterSearch event, no index', context);
3461
3517
  aa('clickedObjectIDsAfterSearch', {
@@ -3519,7 +3575,7 @@ function useAlgoliaInsights() {
3519
3575
  queryId,
3520
3576
  });
3521
3577
  },
3522
- sendProductClickFromSearchResultPageEvent({ objectId, position, }) {
3578
+ sendProductClickFromSearchResultPageEvent({ objectId, position }) {
3523
3579
  if (!objectId)
3524
3580
  return console.warn('Unable to send clickedObjectIDsAfterSearch event, no index', context);
3525
3581
  if (!context.index)
@@ -3541,30 +3597,6 @@ function useAlgoliaInsights() {
3541
3597
  },
3542
3598
  };
3543
3599
  }
3544
- /*
3545
- init: Parameters<typeof init>;
3546
- getVersion: Parameters<typeof getVersion>;
3547
- addAlgoliaAgent: Parameters<typeof addAlgoliaAgent>;
3548
- setUserToken: Parameters<typeof setUserToken>;
3549
- getUserToken: Parameters<typeof getUserToken>;
3550
- onUserTokenChange: Parameters<typeof onUserTokenChange>;
3551
- setAuthenticatedUserToken: Parameters<typeof setAuthenticatedUserToken>;
3552
- getAuthenticatedUserToken: Parameters<typeof getAuthenticatedUserToken>;
3553
- onAuthenticatedUserTokenChange: Parameters<typeof onAuthenticatedUserTokenChange>;
3554
- clickedObjectIDsAfterSearch: Parameters<typeof clickedObjectIDsAfterSearch>;
3555
- clickedObjectIDs: Parameters<typeof clickedObjectIDs>;
3556
- clickedFilters: Parameters<typeof clickedFilters>;
3557
- convertedObjectIDsAfterSearch: Parameters<typeof convertedObjectIDsAfterSearch>;
3558
- convertedObjectIDs: Parameters<typeof convertedObjectIDs>;
3559
- convertedFilters: Parameters<typeof convertedFilters>;
3560
- viewedObjectIDs: Parameters<typeof viewedObjectIDs>;
3561
- viewedFilters: Parameters<typeof viewedFilters>;
3562
- purchasedObjectIDs: Parameters<typeof purchasedObjectIDs>;
3563
- purchasedObjectIDsAfterSearch: Parameters<typeof purchasedObjectIDsAfterSearch>;
3564
- addedToCartObjectIDs: Parameters<typeof addedToCartObjectIDs>;
3565
- addedToCartObjectIDsAfterSearch: Parameters<typeof addedToCartObjectIDsAfterSearch>;
3566
- sendEvents: Parameters<ReturnType<typeof makeSendEvents>>;
3567
- */
3568
3600
 
3569
3601
  function useAlgoliaSearch() {
3570
3602
  const globalSearch = useContext(GlobalSearchContext);
@@ -4152,7 +4184,7 @@ const ConnectedAddToCartButton = ({ onAddToCart, productId }) => {
4152
4184
  });
4153
4185
  },
4154
4186
  onSuccess: cartLine => {
4155
- onAddToCart?.();
4187
+ onAddToCart?.({ cartLine });
4156
4188
  onCartLineAdded?.(cartLine);
4157
4189
  addToast({
4158
4190
  body: (jsx(FormattedMessage, { id: "The product has been added to your cart." })),
@@ -11008,13 +11040,6 @@ function useFetchCountriesWithLanguages({ enabled = true, } = { enabled: true })
11008
11040
  });
11009
11041
  }
11010
11042
 
11011
- function useUpdateLocale() {
11012
- return useMutation({
11013
- mutationFn: updateLocale,
11014
- throwOnError: true,
11015
- });
11016
- }
11017
-
11018
11043
  function useCookie(name, options) {
11019
11044
  const cookieValue = Cookies.get()[name];
11020
11045
  const [stateValue, setStateValue] = useState(cookieValue);
@@ -11063,7 +11088,6 @@ const cookieOptions = {
11063
11088
  };
11064
11089
  function useCountriesLanguages({ defaultCountryCode, defaultLanguageCode, }) {
11065
11090
  const [sessionCountries, setSessionCountries] = useSessionStorage('countries-v1');
11066
- const { mutate: updateLocale } = useUpdateLocale();
11067
11091
  const [currentCountryId] = useCookie('CurrentCountryId', cookieOptions);
11068
11092
  const [currentLanguageId] = useCookie('CurrentLanguageId', cookieOptions);
11069
11093
  const [contextLanguageCode] = useCookie('SetContextLanguageCode', cookieOptions);
@@ -11078,7 +11102,7 @@ function useCountriesLanguages({ defaultCountryCode, defaultLanguageCode, }) {
11078
11102
  // eslint-disable-next-line react-hooks/exhaustive-deps
11079
11103
  }, [apiCountries]);
11080
11104
  async function updateCountryLanguage({ country, language, }) {
11081
- updateLocale({ countryId: country.id, languageId: language.id });
11105
+ await updateLocale({ countryId: country.id, languageId: language.id });
11082
11106
  }
11083
11107
  if (error)
11084
11108
  throw error;
@@ -11419,8 +11443,9 @@ function ProductHitCard$2({ autocomplete, hit, index, source, }) {
11419
11443
  fit: 'contain',
11420
11444
  image: hit.image,
11421
11445
  title: hit.name,
11422
- }, onAddToCart: () => hit.queryId &&
11446
+ }, onAddToCart: ({ cartLine }) => hit.queryId &&
11423
11447
  sendAddToCartFromSearchEvent({
11448
+ cartLine,
11424
11449
  objectId: hit.objectId,
11425
11450
  queryId: hit.queryId,
11426
11451
  }), onClick: () => {
@@ -12171,7 +12196,8 @@ function ProductHitCard$1({ hit }) {
12171
12196
  fit: 'contain',
12172
12197
  image: hit.image,
12173
12198
  title: hit.name,
12174
- }, onAddToCart: () => sendAddToCartFromProductListPageEvent({
12199
+ }, onAddToCart: ({ cartLine }) => sendAddToCartFromProductListPageEvent({
12200
+ cartLine,
12175
12201
  objectId: hit.objectId,
12176
12202
  }), onClick: () => sendProductClickFromProductListPageEvent({
12177
12203
  objectId: hit.objectId,
@@ -12235,7 +12261,8 @@ function ProductHitCard({ hit }) {
12235
12261
  fit: 'contain',
12236
12262
  image: hit.image,
12237
12263
  title: hit.name,
12238
- }, onAddToCart: () => sendAddToCartFromSearchResultPageEvent({
12264
+ }, onAddToCart: ({ cartLine }) => sendAddToCartFromSearchResultPageEvent({
12265
+ cartLine,
12239
12266
  objectId: hit.objectId,
12240
12267
  }), onClick: () => {
12241
12268
  sendProductClickFromSearchResultPageEvent({
@@ -12474,6 +12501,13 @@ function useFetchSettings({ enabled = true, } = {}) {
12474
12501
  });
12475
12502
  }
12476
12503
 
12504
+ function useUpdateLocale() {
12505
+ return useMutation({
12506
+ mutationFn: updateLocale,
12507
+ throwOnError: true,
12508
+ });
12509
+ }
12510
+
12477
12511
  function useAddWishListItemToWishList() {
12478
12512
  const queryClient = useQueryClient();
12479
12513
  return useMutation({
@@ -0,0 +1,27 @@
1
+ export declare const currencySymbolToISO: {
2
+ readonly $: "USD";
3
+ readonly 'Bs.': "VES";
4
+ readonly Ft: "HUF";
5
+ readonly Kč: "CZK";
6
+ readonly R: "ZAR";
7
+ readonly kr: "SEK";
8
+ readonly lei: "RON";
9
+ readonly zł: "PLN";
10
+ readonly '\u00A3': "GBP";
11
+ readonly '\u00A5': "JPY";
12
+ readonly '\u0E3F': "THB";
13
+ readonly '\u20A1': "CRC";
14
+ readonly '\u20A6': "NGN";
15
+ readonly '\u20A9': "KRW";
16
+ readonly '\u20AA': "ILS";
17
+ readonly '\u20AB': "VND";
18
+ readonly '\u20AC': "EUR";
19
+ readonly '\u20AE': "MNT";
20
+ readonly '\u20B1': "PHP";
21
+ readonly '\u20B2': "PYG";
22
+ readonly '\u20B4': "UAH";
23
+ readonly '\u20B5': "GHS";
24
+ readonly '\u20B9': "INR";
25
+ readonly '\u20BA': "TRY";
26
+ readonly '\u20BD': "RUB";
27
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonic-equipment/ui",
3
- "version": "0.0.115",
3
+ "version": "0.0.117",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "engines": {