@sonic-equipment/ui 163.0.0 → 164.0.0

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.
@@ -11,7 +11,7 @@ import styles from './orderline-card.module.css.js';
11
11
 
12
12
  function OrderLineCard(props) {
13
13
  const { deliveryDate, href, image, isReadonly, price, productId, sku, tags, title, } = props;
14
- return (jsxs("article", { "aria-labelledby": `title-${productId}`, className: clsx(styles['orderline-card'], isReadonly && styles.readonly), "data-disabled": isReadonly ? true : undefined, "data-product-id": sku, "data-test-selector": "orderLineListItem", id: productId, children: [isReadonly ? (jsx("div", { className: styles.title, "data-test-selector": "orderLineCardTitle", id: `title-${productId}`, children: title })) : (jsx(RouteLink, { className: styles.title, "data-test-selector": "orderLineCardTitle", href: href, id: `title-${productId}`, children: title })), tags && tags.length > 0 && (jsx("div", { className: styles.tags, children: tags.map(tag => (jsx(Tag, { children: jsx(FormattedMessage, { fallbackValue: tag, id: `tag.${tag.toLowerCase()}` }) }, tag))) })), jsx(ProductSku, { className: styles.sku, sku: sku }), jsx(Price, { className: styles.price, currencyCode: price.currencyCode, "data-test-selector": "orderLineCardPrice", originalPrice: price.originalTotalPrice, price: price.totalPrice, pricePerUnit: price.pricePerUnit, variant: "sonic" }), jsx("div", { className: styles['image-container'], role: "presentation", children: jsx(Image, { "data-test-selector": "orderLineCardImage", ...image, fit: "contain" }) }), isReadonly ? (jsx("p", { className: styles.amount, children: jsx(FormattedMessage, { id: "Amount: {0}", replacementValues: { '0': props.quantity.toString() } }) })) : (jsx("div", { className: styles['add-to-cart-button'], children: props.addToCartButton })), deliveryDate && (jsx(DeliveryTime, { className: styles.delivery, deliveryDate: deliveryDate })), !isReadonly && (jsx("div", { className: styles.remove, "data-test-selector": "orderLineCardRemove", children: props.removeButton }))] }));
14
+ return (jsxs("article", { "aria-labelledby": `title-${productId}`, className: clsx(styles['orderline-card'], isReadonly && styles.readonly), "data-disabled": isReadonly ? true : undefined, "data-product-id": sku, "data-test-selector": "orderLineListItem", id: productId, children: [isReadonly ? (jsx("div", { className: styles.title, "data-test-selector": "orderLineCardTitle", id: `title-${productId}`, children: title })) : (jsx(RouteLink, { className: styles.title, "data-test-selector": "orderLineCardTitle", href: href, id: `title-${productId}`, children: title })), tags && tags.length > 0 && (jsx("div", { className: styles.tags, children: tags.map(tag => (jsx(Tag, { children: jsx(FormattedMessage, { fallbackValue: tag, id: `tag.${tag.toLowerCase()}` }) }, tag))) })), jsx(ProductSku, { className: styles.sku, sku: sku }), jsx(Price, { className: styles.price, currencyCode: price.currencyCode, "data-test-selector": "orderLineCardPrice", originalPrice: price.originalTotalPrice, price: price.totalPrice, pricePerUnit: price.pricePerUnit, variant: "sonic" }), jsx("div", { className: styles['image-container'], role: "presentation", children: jsx(Image, { "data-test-selector": "orderLineCardImage", ...image, fit: "contain" }) }), isReadonly ? (jsx("p", { className: styles.amount, children: jsx(FormattedMessage, { id: "Amount: {0}", replacementValues: { '0': props.quantity.toString() } }) })) : (jsx("div", { className: styles['add-to-cart-button'], children: props.addToCartButton })), jsx(DeliveryTime, { className: styles.delivery, deliveryDate: deliveryDate }), !isReadonly && (jsx("div", { className: styles.remove, "data-test-selector": "orderLineCardRemove", children: props.removeButton }))] }));
15
15
  }
16
16
 
17
17
  export { OrderLineCard };
@@ -20,7 +20,7 @@ function CountrySelect({ countries, countryNameInLanguageOfCountry = false, 'dat
20
20
  }), {}),
21
21
  // eslint-disable-next-line react-hooks/exhaustive-deps
22
22
  [countries]);
23
- return (jsx(SelectField, { "data-key": selectedCountry?.id, "data-test-selector": dataTestSelector, defaultSelectedOption: defaultSelectedCountry?.id, isDisabled: isDisabled, isLoading: isLoading, isRequired: isRequired, label: t('Country'), name: name, onChange: value => onCountryChange?.(countries.find(country => country.id === value)), options: countryOptions, selectedOption: selectedCountry?.id, showLabel: showLabel, showPlaceholder: false, variant: "solid" }));
23
+ return (jsx(SelectField, { "data-key": selectedCountry?.id, "data-test-selector": dataTestSelector, defaultSelectedOption: defaultSelectedCountry?.id, isDisabled: isDisabled, isLoading: isLoading, isRequired: isRequired, label: t('Country'), name: name, onChange: value => onCountryChange?.(countries.find(country => country.id === value)), options: countryOptions, placeholder: t('Select a country'), selectedOption: selectedCountry?.id, showLabel: showLabel, variant: "solid" }));
24
24
  }
25
25
 
26
26
  export { CountrySelect };
@@ -1,6 +1,7 @@
1
1
  "use client";
2
2
  import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
3
3
  import { useMemo, useEffect } from 'react';
4
+ import { logger } from '../logging/logger.js';
4
5
  import { useDisclosure } from '../shared/hooks/use-disclosure.js';
5
6
  import { CountrySelectorDialog } from './country-selector-dialog/country-selector-dialog.js';
6
7
  import { CountrySelectorTrigger } from './country-selector-trigger/country-selector-trigger.js';
@@ -8,18 +9,35 @@ import { useCountriesLanguages } from './use-countries-languages.js';
8
9
 
9
10
  function ConnectedCountrySelector({ defaultCountryCode, defaultLanguageCode, onChange, showCountry = true, }) {
10
11
  const { close, isOpen, open, setIsOpen } = useDisclosure(false);
11
- const { countries, defaultCountry, defaultLanguage, isFetching, selectedCountry, selectedLanguage, updateCountryLanguage, } = useCountriesLanguages({
12
+ const { countries, defaultCountry, defaultLanguage, error, isFetching, selectedCountry, selectedLanguage, updateCountryLanguage, } = useCountriesLanguages({
12
13
  defaultCountryCode,
13
14
  defaultLanguageCode,
14
15
  });
15
16
  const isCountryLanguageSelected = useMemo(() => selectedCountry !== undefined && selectedLanguage !== undefined, [selectedCountry, selectedLanguage]);
16
17
  const isDismissable = isCountryLanguageSelected;
17
18
  useEffect(() => {
19
+ if (!isFetching) {
20
+ if (selectedCountry === undefined && selectedLanguage === undefined) {
21
+ logger.info('Opening country selector dialog because no country or language is selected');
22
+ }
23
+ else if (selectedCountry === undefined) {
24
+ logger.info('Opening country selector dialog because no country is selected');
25
+ }
26
+ else if (selectedLanguage === undefined) {
27
+ logger.info('Opening country selector dialog because no language is selected');
28
+ }
29
+ }
30
+ if (isOpen)
31
+ return;
18
32
  setIsOpen(!isFetching && !isCountryLanguageSelected);
19
33
  // eslint-disable-next-line react-hooks/exhaustive-deps
20
- }, [isFetching, isCountryLanguageSelected]);
34
+ }, [isFetching, isCountryLanguageSelected, isOpen]);
21
35
  if (isFetching)
22
36
  return null;
37
+ if (error !== undefined) {
38
+ logger.error('Error fetching countries and languages:', error);
39
+ return null;
40
+ }
23
41
  return (jsxs(Fragment, { children: [jsx(CountrySelectorTrigger, { onClick: open, selectedCountry: selectedCountry, selectedLanguage: selectedLanguage, showCountry: showCountry }), jsx(CountrySelectorDialog, { countries: countries, isDismissable: isDismissable, isOpen: isOpen, onOpenChange: open => {
24
42
  if (!isDismissable)
25
43
  return;
@@ -32,7 +32,7 @@ function CountrySelectorDialog({ countries, isDismissable, isOpen, onOpenChange,
32
32
  onSubmit({ country: currentCountry, language: currentLanguage });
33
33
  e.preventDefault();
34
34
  e.stopPropagation();
35
- }, shouldCloseOnInteractOutside: isDismissable, title: "Country Selector", children: jsxs("div", { className: styles.content, children: [jsx("svg", { className: styles.logo, height: "32", viewBox: "0 0 134 32", width: "134", xmlns: "http://www.w3.org/2000/svg", children: jsxs("g", { fill: "none", fillRule: "evenodd", children: [jsx("path", { d: "M15.83 11.533c2.42 0 4.382 1.977 4.382 4.415 0 8.794-7.1 15.95-15.83 15.95C1.963 31.897 0 29.92 0 27.481c0-2.354 1.83-4.278 4.134-4.408l.249-.007c3.797 0 6.905-3.036 7.058-6.826l.006-.293c0-2.438 1.963-4.415 4.383-4.415zM15.83 0c2.42 0 4.383 1.977 4.383 4.415 0 2.355-1.83 4.279-4.134 4.409l-.249.007c-3.8 0-6.906 3.035-7.059 6.824l-.006.293c0 2.438-1.962 4.415-4.382 4.415S0 18.386 0 15.948C0 7.154 7.101 0 15.83 0zm8.208 16.022c0 8.794 7.101 15.95 15.83 15.95s15.83-7.156 15.83-15.95S48.597.074 39.868.074s-15.83 7.154-15.83 15.948zm8.765 0c0-3.924 3.169-7.118 7.065-7.118 3.895 0 7.065 3.194 7.065 7.118 0 3.926-3.17 7.119-7.065 7.119-3.896 0-7.065-3.193-7.065-7.12zm76.888-11.276c-6.173 6.217-6.173 16.335-.002 22.553 6.173 6.217 16.215 6.217 22.388 0a4.44 4.44 0 0 0 .001-6.244 4.359 4.359 0 0 0-6.003-.184l-.194.184a7.04 7.04 0 0 1-9.994 0c-2.753-2.775-2.753-7.29.002-10.065a7.036 7.036 0 0 1 9.751-.233l.24.231a4.36 4.36 0 0 0 6.198 0 4.44 4.44 0 0 0-.001-6.245c-6.173-6.217-16.215-6.216-22.386.003zm-17.162-.174v22.863c0 2.439 1.961 4.416 4.381 4.416 2.422 0 4.384-1.977 4.384-4.416V4.572c0-2.439-1.962-4.416-4.384-4.416-2.42 0-4.38 1.977-4.38 4.416zM64.1.1c-2.42 0-4.383 1.977-4.383 4.415v23.07c0 2.438 1.962 4.415 4.382 4.415s4.383-1.977 4.383-4.415V8.93h3.933c3.895 0 7.065 3.192 7.065 7.118v11.537c0 2.438 1.962 4.415 4.382 4.415s4.383-1.977 4.383-4.415V16.048C88.244 7.254 81.143.1 72.414.1h-8.316z", fill: "#000" }), jsx("path", { d: "M47.036 16.022c0 3.99-3.209 7.222-7.168 7.222-3.96 0-7.169-3.233-7.169-7.222 0-3.989 3.21-7.222 7.169-7.222 3.96 0 7.168 3.233 7.168 7.222", fill: "#E30613" })] }) }), jsx("p", { className: styles.intro, children: jsx(FormattedMessage, { id: "Welcome to Sonic Equipment. Please choose your country and language below." }) }), jsxs("div", { className: styles.selects, children: [showCountry && (jsx(CountrySelect, { countries: countries, countryNameInLanguageOfCountry: true, "data-test-selector": "clSelector_country", onCountryChange: onCountryChange, selectedCountry: currentCountry })), jsx(Select, { "data-test-selector": "clSelector_language", label: t('Language'), onChange: value => setCurrentLanguage(currentCountry.languages.find(language => language.id === value) || currentLanguage), options: languageOptions, selectedOption: currentLanguage.id, showPlaceholder: false, variant: "solid" })] })] }) }));
35
+ }, shouldCloseOnInteractOutside: isDismissable, title: "Country Selector", children: jsxs("div", { className: styles.content, children: [jsx("svg", { className: styles.logo, height: "32", viewBox: "0 0 134 32", width: "134", xmlns: "http://www.w3.org/2000/svg", children: jsxs("g", { fill: "none", fillRule: "evenodd", children: [jsx("path", { d: "M15.83 11.533c2.42 0 4.382 1.977 4.382 4.415 0 8.794-7.1 15.95-15.83 15.95C1.963 31.897 0 29.92 0 27.481c0-2.354 1.83-4.278 4.134-4.408l.249-.007c3.797 0 6.905-3.036 7.058-6.826l.006-.293c0-2.438 1.963-4.415 4.383-4.415zM15.83 0c2.42 0 4.383 1.977 4.383 4.415 0 2.355-1.83 4.279-4.134 4.409l-.249.007c-3.8 0-6.906 3.035-7.059 6.824l-.006.293c0 2.438-1.962 4.415-4.382 4.415S0 18.386 0 15.948C0 7.154 7.101 0 15.83 0zm8.208 16.022c0 8.794 7.101 15.95 15.83 15.95s15.83-7.156 15.83-15.95S48.597.074 39.868.074s-15.83 7.154-15.83 15.948zm8.765 0c0-3.924 3.169-7.118 7.065-7.118 3.895 0 7.065 3.194 7.065 7.118 0 3.926-3.17 7.119-7.065 7.119-3.896 0-7.065-3.193-7.065-7.12zm76.888-11.276c-6.173 6.217-6.173 16.335-.002 22.553 6.173 6.217 16.215 6.217 22.388 0a4.44 4.44 0 0 0 .001-6.244 4.359 4.359 0 0 0-6.003-.184l-.194.184a7.04 7.04 0 0 1-9.994 0c-2.753-2.775-2.753-7.29.002-10.065a7.036 7.036 0 0 1 9.751-.233l.24.231a4.36 4.36 0 0 0 6.198 0 4.44 4.44 0 0 0-.001-6.245c-6.173-6.217-16.215-6.216-22.386.003zm-17.162-.174v22.863c0 2.439 1.961 4.416 4.381 4.416 2.422 0 4.384-1.977 4.384-4.416V4.572c0-2.439-1.962-4.416-4.384-4.416-2.42 0-4.38 1.977-4.38 4.416zM64.1.1c-2.42 0-4.383 1.977-4.383 4.415v23.07c0 2.438 1.962 4.415 4.382 4.415s4.383-1.977 4.383-4.415V8.93h3.933c3.895 0 7.065 3.192 7.065 7.118v11.537c0 2.438 1.962 4.415 4.382 4.415s4.383-1.977 4.383-4.415V16.048C88.244 7.254 81.143.1 72.414.1h-8.316z", fill: "#000" }), jsx("path", { d: "M47.036 16.022c0 3.99-3.209 7.222-7.168 7.222-3.96 0-7.169-3.233-7.169-7.222 0-3.989 3.21-7.222 7.169-7.222 3.96 0 7.168 3.233 7.168 7.222", fill: "#E30613" })] }) }), jsx("p", { className: styles.intro, children: jsx(FormattedMessage, { id: "Welcome to Sonic Equipment. Please choose your country and language below." }) }), jsxs("div", { className: styles.selects, children: [showCountry && (jsx(CountrySelect, { isRequired: true, countries: countries, countryNameInLanguageOfCountry: true, "data-test-selector": "clSelector_country", onCountryChange: onCountryChange, selectedCountry: currentCountry })), jsx(Select, { isRequired: true, "data-test-selector": "clSelector_language", label: t('Language'), onChange: value => setCurrentLanguage(currentCountry.languages.find(language => language.id === value) || currentLanguage), options: languageOptions, placeholder: t('Select a language'), selectedOption: currentLanguage.id, showPlaceholder: false, variant: "solid" })] })] }) }));
36
36
  }
37
37
 
38
38
  export { CountrySelectorDialog };
@@ -4,10 +4,24 @@ interface UseCountriesLanguagesArgs {
4
4
  defaultCountryCode: CountryCode;
5
5
  defaultLanguageCode: LanguageCode;
6
6
  }
7
+ interface UseCountriesLanguagesReturnTypeError {
8
+ countries: undefined;
9
+ defaultCountry: undefined;
10
+ defaultLanguage: undefined;
11
+ error: object | Error | string;
12
+ isFetching: false;
13
+ selectedCountry: undefined;
14
+ selectedLanguage: undefined;
15
+ updateCountryLanguage(args: {
16
+ country: Country;
17
+ language: Language;
18
+ }): Promise<void>;
19
+ }
7
20
  interface UseCountriesLanguagesReturnTypeFetching {
8
21
  countries: undefined;
9
22
  defaultCountry: undefined;
10
23
  defaultLanguage: undefined;
24
+ error: undefined;
11
25
  isFetching: true;
12
26
  selectedCountry: undefined;
13
27
  selectedLanguage: undefined;
@@ -20,6 +34,7 @@ interface UseCountriesLanguagesReturnTypeSelected {
20
34
  countries: Country[];
21
35
  defaultCountry: Country;
22
36
  defaultLanguage: Language;
37
+ error: undefined;
23
38
  isFetching: false;
24
39
  selectedCountry: Country;
25
40
  selectedLanguage: Language;
@@ -32,6 +47,7 @@ interface UseCountriesLanguagesReturnType {
32
47
  countries: Country[];
33
48
  defaultCountry: Country;
34
49
  defaultLanguage: Language;
50
+ error: undefined;
35
51
  isFetching: false;
36
52
  selectedCountry: Country | undefined;
37
53
  selectedLanguage: Language | undefined;
@@ -40,5 +56,5 @@ interface UseCountriesLanguagesReturnType {
40
56
  language: Language;
41
57
  }): Promise<void>;
42
58
  }
43
- export declare function useCountriesLanguages({ defaultCountryCode, defaultLanguageCode, }: UseCountriesLanguagesArgs): UseCountriesLanguagesReturnType | UseCountriesLanguagesReturnTypeFetching | UseCountriesLanguagesReturnTypeSelected;
59
+ export declare function useCountriesLanguages({ defaultCountryCode, defaultLanguageCode, }: UseCountriesLanguagesArgs): UseCountriesLanguagesReturnType | UseCountriesLanguagesReturnTypeError | UseCountriesLanguagesReturnTypeFetching | UseCountriesLanguagesReturnTypeSelected;
44
60
  export {};
@@ -1,6 +1,7 @@
1
1
  "use client";
2
2
  import { useEffect } from 'react';
3
3
  import { config } from '../config.js';
4
+ import { logger } from '../logging/logger.js';
4
5
  import { useFetchCountriesWithLanguages } from '../shared/api/storefront/hooks/website/use-fetch-countries-with-languages.js';
5
6
  import { updateLocale } from '../shared/api/storefront/services/website-service.js';
6
7
  import { useCookie } from '../shared/hooks/use-cookie.js';
@@ -17,8 +18,8 @@ const cookieOptions = {
17
18
  function useCountriesLanguages({ defaultCountryCode, defaultLanguageCode, }) {
18
19
  const [sessionCountries, setSessionCountries] = useSessionStorage('countries-v1');
19
20
  const [currentCountryId] = useCookie('CurrentCountryId', cookieOptions);
21
+ // const [currentLanguageId] = ['be71b608-4876-420a-b1f5-adfe0093a72a'] // useCookie('CurrentLanguageId', cookieOptions)
20
22
  const [currentLanguageId] = useCookie('CurrentLanguageId', cookieOptions);
21
- const [contextLanguageCode] = useCookie('SetContextLanguageCode', cookieOptions);
22
23
  const hasSessionCountries = Boolean(sessionCountries?.length);
23
24
  const { data: apiCountries, error, isFetching, } = useFetchCountriesWithLanguages({
24
25
  enabled: !hasSessionCountries,
@@ -32,44 +33,72 @@ function useCountriesLanguages({ defaultCountryCode, defaultLanguageCode, }) {
32
33
  // eslint-disable-next-line react-hooks/exhaustive-deps
33
34
  }, [apiCountries]);
34
35
  async function updateCountryLanguage({ country, language, }) {
35
- await updateLocale({ countryId: country.id, languageId: language.id });
36
+ await updateLocale({
37
+ countryId: country.id,
38
+ languageId: language.id,
39
+ });
36
40
  }
37
- if (error)
38
- throw error;
39
- if (isFetching) {
41
+ useEffect(() => {
42
+ logger.info('CountryID from cookie', currentCountryId, countries?.find(country => country.id === currentCountryId)?.name ||
43
+ 'Unknown');
44
+ }, [countries, currentCountryId]);
45
+ useEffect(() => {
46
+ logger.info('LanguageID from cookie', currentLanguageId, countries
47
+ ?.find(country => country.id === currentCountryId)
48
+ ?.languages.find(language => language.id === currentLanguageId)
49
+ ?.description || 'Unknown');
50
+ }, [countries, currentCountryId, currentLanguageId]);
51
+ try {
52
+ if (error)
53
+ throw error;
54
+ if (isFetching) {
55
+ return {
56
+ countries: undefined,
57
+ defaultCountry: undefined,
58
+ defaultLanguage: undefined,
59
+ error: undefined,
60
+ isFetching,
61
+ selectedCountry: undefined,
62
+ selectedLanguage: undefined,
63
+ updateCountryLanguage,
64
+ };
65
+ }
66
+ if (!countries || countries.length === 0)
67
+ throw new Error('No countries found');
68
+ const defaultCountry = countries.find(country => country.abbreviation.toUpperCase() ===
69
+ defaultCountryCode.toUpperCase()) || countries[0];
70
+ if (!defaultCountry)
71
+ throw new Error(`Unable to find the default country ${defaultCountryCode}`);
72
+ const defaultLanguage = defaultCountry.languages.find(language => language.languageCode.toUpperCase() ===
73
+ defaultLanguageCode.toUpperCase()) || defaultCountry.languages[0];
74
+ if (!defaultLanguage)
75
+ throw new Error(`Unable to find the default language ${defaultLanguageCode} for country ${defaultCountry.name}`);
76
+ const selectedCountry = countries.find(country => country.id === currentCountryId);
77
+ const selectedLanguage = selectedCountry &&
78
+ selectedCountry.languages.find(language => language.id === currentLanguageId);
79
+ return {
80
+ countries,
81
+ defaultCountry,
82
+ defaultLanguage,
83
+ error: undefined,
84
+ isFetching,
85
+ selectedCountry,
86
+ selectedLanguage,
87
+ updateCountryLanguage,
88
+ };
89
+ }
90
+ catch (error) {
40
91
  return {
41
92
  countries: undefined,
42
93
  defaultCountry: undefined,
43
94
  defaultLanguage: undefined,
44
- isFetching,
95
+ error: error,
96
+ isFetching: false,
45
97
  selectedCountry: undefined,
46
98
  selectedLanguage: undefined,
47
99
  updateCountryLanguage,
48
100
  };
49
101
  }
50
- if (!countries || countries.length === 0)
51
- throw new Error('No countries found');
52
- const defaultCountry = countries.find(country => country.abbreviation.toUpperCase() === defaultCountryCode.toUpperCase()) || countries[0];
53
- if (!defaultCountry)
54
- throw new Error(`Unable to find the default country ${defaultCountryCode}`);
55
- const defaultLanguage = defaultCountry.languages.find(language => language.languageCode.toUpperCase() ===
56
- defaultLanguageCode.toUpperCase()) || defaultCountry.languages[0];
57
- if (!defaultLanguage)
58
- throw new Error(`Unable to find the default language ${defaultLanguageCode} for country ${defaultCountry.name}`);
59
- const selectedCountry = countries.find(country => country.id === currentCountryId);
60
- const selectedLanguage = selectedCountry &&
61
- (selectedCountry.languages.find(language => language.id === currentLanguageId) ||
62
- selectedCountry.languages.find(language => language.languageCode.toUpperCase() ===
63
- contextLanguageCode?.toUpperCase()));
64
- return {
65
- countries,
66
- defaultCountry,
67
- defaultLanguage,
68
- isFetching,
69
- selectedCountry,
70
- selectedLanguage,
71
- updateCountryLanguage,
72
- };
73
102
  }
74
103
 
75
104
  export { useCountriesLanguages };
@@ -1,5 +1,5 @@
1
1
  export interface DeliveryTimeProps {
2
2
  className?: string;
3
- deliveryDate: Date;
3
+ deliveryDate?: Date;
4
4
  }
5
5
  export declare function DeliveryTime({ className, deliveryDate }: DeliveryTimeProps): import("react/jsx-runtime").JSX.Element;
@@ -1,19 +1,31 @@
1
1
  "use client";
2
- import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import { jsx, jsxs } from 'react/jsx-runtime';
3
3
  import clsx from 'clsx';
4
4
  import { FormattedMessage } from '../intl/formatted-message.js';
5
- import { useFormattedMessage } from '../intl/use-formatted-message.js';
6
- import { getDateUnitObject } from '../shared/utils/date.js';
7
5
  import { InfoIconTooltip } from '../info-icon-tooltip/info-icon-tooltip.js';
6
+ import { useFormattedMessage } from '../intl/use-formatted-message.js';
7
+ import { useIntl } from '../intl/use-intl.js';
8
+ import { formatDateToLocaleString } from '../shared/utils/date.js';
8
9
  import styles from './delivery-time.module.css.js';
9
10
 
10
11
  function DeliveryTime({ className, deliveryDate }) {
12
+ const { cultureCode } = useIntl();
11
13
  const t = useFormattedMessage();
12
- const { number, unit } = getDateUnitObject(deliveryDate);
13
- return (jsxs("div", { className: clsx(styles['delivery-time'], className), children: [jsx("p", { "data-test-selector": "deliveryTime", children: jsx(FormattedMessage, { id: "Delivery expected in {0} {1}", replacementValues: {
14
- '0': number.toString(),
15
- '1': t.pluralize('unit', unit, number),
16
- } }) }), jsx(InfoIconTooltip, { variant: "stroke", children: jsx(FormattedMessage, { id: "The expected delivery is an indication based on the product availability and the shipping location." }) })] }));
14
+ if (!deliveryDate) {
15
+ return (jsx("div", { className: clsx(styles['delivery-time'], className), children: jsx("p", {
16
+ // eslint-disable-next-line @eslint-react/dom/no-dangerously-set-innerhtml
17
+ dangerouslySetInnerHTML: {
18
+ __html: t('Availability unknown, please contact customer support for lead time or alternatives.'),
19
+ }, "data-test-selector": "deliveryTime_unknown" }) }));
20
+ }
21
+ const localeDate = formatDateToLocaleString(deliveryDate, cultureCode, {
22
+ day: 'numeric',
23
+ month: 'short',
24
+ year: 'numeric',
25
+ });
26
+ return (jsxs("div", { className: clsx(styles['delivery-time'], className), children: [jsx("p", { "data-test-selector": "deliveryTime", children: jsx(FormattedMessage, { id: "Delivery expected on {0}", replacementValues: {
27
+ '0': localeDate,
28
+ } }) }), jsx(InfoIconTooltip, { className: styles['info'], variant: "stroke", children: jsx(FormattedMessage, { id: "The expected delivery is an indication based on the product availability and the shipping location." }) })] }));
17
29
  }
18
30
 
19
31
  export { DeliveryTime };
@@ -1,3 +1,3 @@
1
- var styles = {"delivery-time":"delivery-time-module-fEWEl"};
1
+ var styles = {"delivery-time":"delivery-time-module-fEWEl","info":"delivery-time-module-Ta7xm"};
2
2
 
3
3
  export { styles as default };
package/dist/index.js CHANGED
@@ -338,7 +338,7 @@ export { useOnNavigate } from './shared/routing/use-on-navigate.js';
338
338
  export { withRouting } from './shared/routing/with-routing.js';
339
339
  export { ensureArray } from './shared/utils/array.js';
340
340
  export { breakpoints, getCurrentBreakpoints } from './shared/utils/breakpoints.js';
341
- export { convertDateUnitToPluralOrSingle, formatDateToLocaleString, getDateUnitObject } from './shared/utils/date.js';
341
+ export { formatDateToLocaleString } from './shared/utils/date.js';
342
342
  export { trackPropertyChange } from './shared/utils/debug.js';
343
343
  export { environment, environments } from './shared/utils/environment.js';
344
344
  export { EventEmitter } from './shared/utils/event-emitter.js';
@@ -1 +1 @@
1
- export type TranslationId = "'{0}' in all products" | "Try 'Search' and try to find the product you're looking for" | "Unfortnately, We found no articles for your search '{0}'" | ' to your account to manage your lists.' | 'Access denied.' | 'Your email and password were not recognized.' | 'Add order notes' | 'Add to list' | 'Address' | 'Amount: {0}' | 'An error occurred while processing your payment. Please try again.' | 'An unexpected error occured' | 'An unexpected error occured. Please try again.' | 'Are you looking for information about our service? Please visit our customer support page' | 'Are you sure you want to remove all items from your cart?' | 'Are you sure you want to remove this item from your cart?' | 'article' | 'articles' | 'As soon as possible' | 'Attention' | 'Billing address' | 'Billing and shipping address' | 'Billing and shipping information' | 'Cancel' | 'Cart' | 'Changing your address is currently not possible. Please contact customer support to change your address.' | 'Chosen filters' | 'City' | 'Clear filters' | 'Clear' | 'Click the button below to continue shopping.' | 'Close' | 'Company name' | 'Conceal value' | 'Confirm password' | 'Continue shopping' | 'Continue to sign in' | 'Continue' | 'Cost overview' | 'Country' | 'create account' | 'Create new list' | 'Currency Change' | 'Current page' | 'Delivery date' | 'Delivery expected in {0} {1}' | 'Double check your spelling' | 'Downloads' | 'Easily add your favorite products' | 'Edit billing address' | 'Edit shipping address' | 'Email' | 'Enter your email address and we will send you an email that will allow you to recover your password.' | 'Excl. VAT' | 'Explore by categories' | 'Exploring our products by category' | 'facet.categories' | 'facet.height' | 'facet.weight' | 'Features' | 'First name' | 'Forgot password?' | 'Fulfillment method' | 'General' | 'Hide filters' | 'Home' | 'If an account matches the email address you entered, instructions on how to recover the password will be sent to that email address shortly. If you do not receive this email, please contact Customer Support.' | 'Incl. VAT' | 'Includes' | 'Industry' | 'Information' | 'Language' | 'Last name' | 'List name already exists' | 'More than {0} articles' | 'New list name' | 'New user?' | 'of' | 'Or continue as guest' | 'Order number' | 'Order' | 'Order confirmation' | 'Order date' | 'Order number' | 'Order' | 'Pay by invoice' | 'Pay' | 'Payment method' | 'Payment' | 'Password' | 'Passwords do not match' | 'Password does not meet requirements' | 'pc' | 'Phone' | 'Pick up' | 'Pickup address' | 'Please enter a valid email address' | 'Please enter a valid phone number' | 'please go back to your cart.' | 'Please Sign In' | 'PO Number' | 'Popular searches' | 'Postal Code' | 'Print' | 'Private account' | 'Processing' | 'Product Features' | 'Product' | 'Products' | 'Quantity' | 'Quick access' | 'Recent searches' | 'Recently viewed' | 'Requested delivery date' | 'Remember me' | 'Remove all' | 'Requested delivery date' | 'Submenu' | 'Submitting…' | 'Submit email address' | 'Recover your password' | 'Reveal value' | 'Review and payment' | 'Save order' | 'Save' | 'Saved cart for later.' | 'Search' | 'Searching again using more general terms' | 'See all results' | 'Select a desired delivery date' | 'Selecting this country will result in your cart to be converted to the currency {0}' | 'Select a list' | 'Select an industry' | 'Selecting As Soon As Possible will enable us to send the products to you as they become available.' | 'Share your favorite list with others' | 'Ship' | 'Shipping address' | 'Shipping and handling' | 'Shipping details' | 'Shop more efficiently and quicker with a favorites list' | 'Show all' | 'Show filters' | 'Show less' | 'Show' | 'sign in' | 'Sign me up for newsletters and product updates' | 'Signing in…' | 'Sonic address' | 'Sonic Equipment' | 'Sorry, there are no products found' | 'Sorry, we could not find matches for' | 'Sort by' | 'sort.newest' | 'sort.price_asc' | 'sort.price_desc' | 'sort.relevance' | 'Specifications' | 'Submit' | 'Subtotal' | 'Suggestions' | 'tag.limited' | 'tag.new' | 'The email address you entered is already associated with an existing account. Please sign in to this account or contact Customer Support.' | 'The expected delivery is an indication based on the product availability and the shipping location.' | 'The product has been added to your cart.' | 'The product has been removed from your cart.' | 'The product has been updated in your cart.' | 'There are no products in your shopping cart.' | 'Toggle navigation menu' | 'Total amount is' | 'Total' | 'Try another search' | 'Unable to add the product to your cart.' | 'Unable to empty your cart.' | 'Unable to remove the product from your cart.' | 'Unable to save cart for later.' | 'Unable to update the product in your cart.' | 'Unknown' | 'Updating address' | 'Use billing address' | 'Use fewer keywords' | 'Validating' | 'validation.badInput' | 'validation.customError' | 'validation.invalid' | 'validation.patternMismatch' | 'validation.rangeOverflow' | 'validation.rangeUnderflow' | 'validation.stepMismatch' | 'validation.tooLong' | 'validation.tooShort' | 'validation.typeMismatch' | 'validation.valid' | 'validation.valueMissing' | 'VAT Number' | 'VAT' | 'Welcome to Sonic Equipment. Please choose your country and language below.' | 'What are you searching for?' | 'You selected a country where we invoice in a different currency. This will result in your cart being converted to the new currency. If you would like to review your order, ' | 'If you want to proceed, click the continue button. If you want to change your country, close this message and select a different country.' | 'You could try checking the spelling of your search query' | 'You could try exploring our products by category' | 'You could try' | 'You must ' | 'Your cart has been emptied.' | 'Your favorites are available on multiple devices' | 'Your shopping cart is still empty' | 'Your new Sonic Equipment account was succesfully created. You should receive an email soon with further instructions on how to activate this account. If you do not receive this email, please contact Customer Support.' | 'You have reached the end of the results, but there may be more articles available. Adjust your filters or search to discover more!';
1
+ export type TranslationId = "'{0}' in all products" | "Try 'Search' and try to find the product you're looking for" | "Unfortnately, We found no articles for your search '{0}'" | ' to your account to manage your lists.' | 'Access denied.' | 'Add order notes' | 'Add to list' | 'Address' | 'Amount: {0}' | 'An error occurred while processing your payment. Please try again.' | 'An unexpected error occured' | 'An unexpected error occured. Please try again.' | 'Are you looking for information about our service? Please visit our customer support page' | 'Are you sure you want to remove all items from your cart?' | 'Are you sure you want to remove this item from your cart?' | 'article' | 'articles' | 'As soon as possible' | 'Attention' | 'Availability unknown, please contact customer support for lead time or alternatives.' | 'Billing address' | 'Billing and shipping address' | 'Billing and shipping information' | 'Cancel' | 'Cart' | 'Changing your address is currently not possible. Please contact customer support to change your address.' | 'Chosen filters' | 'City' | 'Clear filters' | 'Clear' | 'Click the button below to continue shopping.' | 'Close' | 'Company name' | 'Conceal value' | 'Confirm password' | 'Continue shopping' | 'Continue to sign in' | 'Continue' | 'Cost overview' | 'Country' | 'create account' | 'Create new list' | 'Currency Change' | 'Current page' | 'Delivery date' | 'Delivery expected on {0}' | 'Double check your spelling' | 'Downloads' | 'Easily add your favorite products' | 'Edit billing address' | 'Edit shipping address' | 'Email' | 'Enter your email address and we will send you an email that will allow you to recover your password.' | 'Excl. VAT' | 'Explore by categories' | 'Exploring our products by category' | 'facet.categories' | 'facet.height' | 'facet.weight' | 'Features' | 'First name' | 'Forgot password?' | 'Fulfillment method' | 'General' | 'Hide filters' | 'Home' | 'If an account matches the email address you entered, instructions on how to recover the password will be sent to that email address shortly. If you do not receive this email, please contact Customer Support.' | 'If you want to proceed, click the continue button. If you want to change your country, close this message and select a different country.' | 'Incl. VAT' | 'Includes' | 'Industry' | 'industry.PP' | 'industry.AU' | 'industry.MC' | 'industry.BC' | 'industry.TR' | 'industry.AG' | 'industry.AV' | 'industry.MA' | 'industry.OT' | 'Information' | 'Language' | 'Last name' | 'List name already exists' | 'More than {0} articles' | 'New list name' | 'New user?' | 'of' | 'Or continue as guest' | 'Order confirmation' | 'Order date' | 'Order number' | 'Order number' | 'Order' | 'Order' | 'Password does not meet requirements' | 'Password' | 'Passwords do not match' | 'Pay by invoice' | 'Pay' | 'Payment method' | 'Payment' | 'pc' | 'Phone' | 'Pick up' | 'Pickup address' | 'Please enter a valid email address' | 'Please enter a valid phone number' | 'please go back to your cart.' | 'Please Sign In' | 'PO Number' | 'Popular searches' | 'Postal Code' | 'Print' | 'Private account' | 'Processing' | 'Product Features' | 'Product' | 'Products' | 'Quantity' | 'Quick access' | 'Recent searches' | 'Recently viewed' | 'Recover your password' | 'Remember me' | 'Remove all' | 'Requested delivery date' | 'Requested delivery date' | 'Reveal value' | 'Review and payment' | 'Save order' | 'Save' | 'Saved cart for later.' | 'Search' | 'Searching again using more general terms' | 'See all results' | 'Select a country' | 'Select a desired delivery date' | 'Select a language' | 'Select a list' | 'Select an industry' | 'Selecting As Soon As Possible will enable us to send the products to you as they become available.' | 'Selecting this country will result in your cart to be converted to the currency {0}' | 'Share your favorite list with others' | 'Ship' | 'Shipping address' | 'Shipping and handling' | 'Shipping details' | 'Shop more efficiently and quicker with a favorites list' | 'Show all' | 'Show filters' | 'Show less' | 'Show' | 'sign in' | 'Sign me up for newsletters and product updates' | 'Signing in…' | 'Sonic address' | 'Sonic Equipment' | 'Sorry, there are no products found' | 'Sorry, we could not find matches for' | 'Sort by' | 'sort.newest' | 'sort.price_asc' | 'sort.price_desc' | 'sort.relevance' | 'Specifications' | 'Submenu' | 'Submit email address' | 'Submit' | 'Submitting…' | 'Subtotal' | 'Suggestions' | 'tag.limited' | 'tag.new' | 'The email address you entered is already associated with an existing account. Please sign in to this account or contact Customer Support.' | 'The expected delivery is an indication based on the product availability and the shipping location.' | 'The product has been added to your cart.' | 'The product has been removed from your cart.' | 'The product has been updated in your cart.' | 'There are no products in your shopping cart.' | 'Toggle navigation menu' | 'Total amount is' | 'Total' | 'Try another search' | 'Unable to add the product to your cart.' | 'Unable to empty your cart.' | 'Unable to remove the product from your cart.' | 'Unable to save cart for later.' | 'Unable to update the product in your cart.' | 'Unknown' | 'Updating address' | 'Use billing address' | 'Use fewer keywords' | 'Validating' | 'validation.badInput' | 'validation.customError' | 'validation.invalid' | 'validation.patternMismatch' | 'validation.rangeOverflow' | 'validation.rangeUnderflow' | 'validation.stepMismatch' | 'validation.tooLong' | 'validation.tooShort' | 'validation.typeMismatch' | 'validation.valid' | 'validation.valueMissing' | 'VAT Number' | 'VAT' | 'Welcome to Sonic Equipment. Please choose your country and language below.' | 'What are you searching for?' | 'You could try checking the spelling of your search query' | 'You could try exploring our products by category' | 'You could try' | 'You have reached the end of the results, but there may be more articles available. Adjust your filters or search to discover more!' | 'You must ' | 'You selected a country where we invoice in a different currency. This will result in your cart being converted to the new currency. If you would like to review your order, ' | 'Your cart has been emptied.' | 'Your email and password were not recognized.' | 'Your favorites are available on multiple devices' | 'Your new Sonic Equipment account was succesfully created. You should receive an email soon with further instructions on how to activate this account. If you do not receive this email, please contact Customer Support.' | 'Your shopping cart is still empty';
@@ -306,15 +306,15 @@ function Payment({ atp, cart: _cart, form, isProcessing, onError: _onError, onPa
306
306
  setDeliveryDate('');
307
307
  }, children: t('As soon as possible') }), jsx(InfoIconTooltip, { variant: "stroke", children: t('Selecting As Soon As Possible will enable us to send the products to you as they become available.') })] })] })), jsx(Select, { isRequired: true, "data-test-selector": "industrySelect", defaultSelectedOption: cart.properties.industry, isDisabled: isDisabled, label: t('Industry'), name: "industry", options: {
308
308
  /* eslint-disable sort-keys-fix/sort-keys-fix */
309
- PP: 'Private User',
310
- AU: 'Automotive',
311
- MC: 'Motorcycle',
312
- BC: 'Bicycle',
313
- TR: 'Truck',
314
- AG: 'Agricultural',
315
- AV: 'Aviation',
316
- MA: 'Maritime',
317
- OT: 'Other',
309
+ PP: t('industry.PP'),
310
+ AU: t('industry.AU'),
311
+ MC: t('industry.MC'),
312
+ BC: t('industry.BC'),
313
+ TR: t('industry.TR'),
314
+ AG: t('industry.AG'),
315
+ AV: t('industry.AV'),
316
+ MA: t('industry.MA'),
317
+ OT: t('industry.OT'),
318
318
  /* eslint-enable sort-keys-fix/sort-keys-fix */
319
319
  }, placeholder: t('Select an industry'), variant: "solid" }), jsx(TextField, { showLabel: true, isDisabled: isDisabled, label: t('VAT Number'), name: "customerVatNumber", onBlur: e => validateVAT(e.target.value), onChange: setCustomerVatNumber, validate: () => validationErrors.customerVatNumber ?? true, value: customerVatNumber }, `vat${Boolean(validationErrors.customerVatNumber)}`), jsx(TextField, { showLabel: true, defaultValue: cart.poNumber, isDisabled: isDisabled, isRequired: cart.requiresPoNumber, label: t('PO Number'), name: "poNumber" }), paymentMethodOptions && Object.keys(paymentMethodOptions).length > 1 && (jsx(Select, { "data-test-selector": "paymentMethodSelect", defaultSelectedOption: cart.paymentOptions?.paymentMethods?.[0]?.name || 'ADY', isDisabled: isDisabled, label: t('Payment method'), name: "paymentMethod", onChange: setSelectedPaymentMethod, options: paymentMethodOptions, selectedOption: selectedPaymentMethod, variant: "solid" })), isAdyenPayment && cart.billTo && (jsx(AdyenPayment, { amount: cart.orderGrandTotal, cartId: cart.trackId, countryCode: countryCode, currencyCode: currencyCode, customerId: cart.billTo.id, dropinRef: dropinRef, environment: environment === 'production' ? 'live' : 'test', isDisabled: isDisabled, onComplete: onComplete, onError: onError, orderAmount: cart.orderGrandTotal, returnUrl:
320
320
  /* eslint-disable ssr-friendly/no-dom-globals-in-react-fc */
@@ -1,13 +1,2 @@
1
1
  import { CultureCode } from '../../intl/types';
2
- export type DateUnit = 'day' | 'week' | 'month';
3
- export type DateUnitObject = {
4
- number: number;
5
- unit: DateUnit;
6
- };
7
- export type DateThreshold = {
8
- dateUnitObject: DateUnitObject;
9
- numberOfDays: number;
10
- };
11
- export declare function getDateUnitObject(date: Date): DateUnitObject;
12
- export declare function convertDateUnitToPluralOrSingle(unit: DateUnit, number: number): 'day' | 'days' | 'week' | 'weeks' | 'month' | 'months';
13
- export declare function formatDateToLocaleString(date?: Date, cultureCode?: CultureCode): string;
2
+ export declare function formatDateToLocaleString(date?: Date, cultureCode?: CultureCode, options?: Intl.DateTimeFormatOptions): string;
@@ -1,68 +1,12 @@
1
- import { TIME } from './time.js';
2
-
3
- function getDaysDifference(date, now) {
4
- const diffTime = date.getTime() - now.getTime();
5
- return diffTime / TIME.DAY;
6
- }
7
- const dateThresholds = [
8
- {
9
- dateUnitObject: { number: 1, unit: 'week' },
10
- numberOfDays: 4,
11
- },
12
- {
13
- dateUnitObject: { number: 2, unit: 'week' },
14
- numberOfDays: 11,
15
- },
16
- {
17
- dateUnitObject: { number: 3, unit: 'week' },
18
- numberOfDays: 18,
19
- },
20
- {
21
- dateUnitObject: { number: 4, unit: 'week' },
22
- numberOfDays: 27,
23
- },
24
- {
25
- dateUnitObject: { number: 2, unit: 'month' },
26
- numberOfDays: 60,
27
- },
28
- {
29
- dateUnitObject: { number: 3, unit: 'month' },
30
- numberOfDays: 90,
31
- },
32
- ];
33
- function getDateUnitObject(date) {
34
- const fallbackDateUnitObject = { number: 6, unit: 'month' };
35
- const days = getDaysDifference(date, new Date());
36
- if (days <= -1)
37
- return fallbackDateUnitObject;
38
- for (const threshold of dateThresholds) {
39
- if (days <= threshold.numberOfDays) {
40
- return threshold.dateUnitObject;
41
- }
42
- }
43
- return fallbackDateUnitObject;
44
- }
45
- function convertDateUnitToPluralOrSingle(unit, number) {
46
- if (number === 1)
47
- return unit;
48
- switch (unit) {
49
- case 'day':
50
- return 'days';
51
- case 'week':
52
- return 'weeks';
53
- case 'month':
54
- return 'months';
55
- }
56
- }
57
- function formatDateToLocaleString(date, cultureCode) {
1
+ function formatDateToLocaleString(date, cultureCode, options = {
2
+ day: 'numeric',
3
+ month: 'long',
4
+ weekday: 'long',
5
+ year: 'numeric',
6
+ }) {
58
7
  if (!date || !cultureCode)
59
8
  return '';
60
- return date.toLocaleDateString(cultureCode, {
61
- day: 'numeric',
62
- month: 'long',
63
- weekday: 'long',
64
- year: 'numeric',
65
- });
9
+ return date.toLocaleDateString(cultureCode, options);
66
10
  }
67
11
 
68
- export { convertDateUnitToPluralOrSingle, formatDateToLocaleString, getDateUnitObject };
12
+ export { formatDateToLocaleString };
package/dist/styles.css CHANGED
@@ -259,6 +259,9 @@
259
259
  100% no-repeat exclude,
260
260
  linear-gradient(0deg, #000, #000);
261
261
  }
262
+ :root {
263
+ scrollbar-gutter: stable;
264
+ }
262
265
 
263
266
  .address-info-display-module-CbRth {
264
267
  font: inherit;
@@ -2658,15 +2661,24 @@
2658
2661
  display: flex;
2659
2662
  align-items: center;
2660
2663
  color: var(--color-status-available);
2664
+ font-size: var(--font-size-14);
2661
2665
  gap: var(--space-4);
2662
2666
  grid-column: span 2;
2663
- line-height: 1.5;
2667
+ line-height: 1.25;
2664
2668
  }
2665
2669
 
2666
2670
  .delivery-time-module-fEWEl p {
2667
2671
  margin: 0;
2668
2672
  }
2669
2673
 
2674
+ .delivery-time-module-fEWEl p a {
2675
+ color: inherit;
2676
+ }
2677
+
2678
+ .delivery-time-module-fEWEl .delivery-time-module-Ta7xm {
2679
+ margin-block-start: -0.1em;
2680
+ }
2681
+
2670
2682
  /* Singular prices */
2671
2683
  .price-module-Qyyas {
2672
2684
  display: inline-grid;
@@ -2991,7 +3003,7 @@
2991
3003
  'image . sku price'
2992
3004
  'image . . price'
2993
3005
  'image . amount price'
2994
- 'image . info price';
3006
+ 'image . info info';
2995
3007
  grid-template-columns:
2996
3008
  143px var(--space-8)
2997
3009
  1fr auto
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonic-equipment/ui",
3
- "version": "163.0.0",
3
+ "version": "164.0.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -1 +0,0 @@
1
- export {};