@sonic-equipment/ui 126.0.0 → 128.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.
Files changed (175) hide show
  1. package/dist/address/address.d.ts +6 -1
  2. package/dist/address/address.js +2 -2
  3. package/dist/algolia/filter-section.js +1 -1
  4. package/dist/cards/orderline-card/connected-orderline-card.js +1 -1
  5. package/dist/cards/orderline-card/orderline-card.d.ts +3 -3
  6. package/dist/cards/orderline-card/orderline-card.js +3 -2
  7. package/dist/cards/orderline-card/orderline-card.module.css.js +1 -1
  8. package/dist/cards/product-card/product-card.js +1 -1
  9. package/dist/cart-totals/cart-totals.d.ts +1 -1
  10. package/dist/cart-totals/cart-totals.js +1 -1
  11. package/dist/checkout/adyen-payment.d.ts +3 -5
  12. package/dist/checkout/adyen-payment.js +22 -10
  13. package/dist/checkout/adyen-payment.module.css.js +3 -0
  14. package/dist/checkout/payment-details.d.ts +5 -2
  15. package/dist/checkout/payment-details.js +54 -4
  16. package/dist/checkout/payment.d.ts +8 -3
  17. package/dist/checkout/payment.js +168 -34
  18. package/dist/checkout/payment.module.css.js +3 -0
  19. package/dist/checkout/use-get-adyen-redirect-result.d.ts +1 -0
  20. package/dist/checkout/use-get-adyen-redirect-result.js +13 -0
  21. package/dist/checkout/use-has-returned-from-adyen.d.ts +1 -0
  22. package/dist/checkout/use-has-returned-from-adyen.js +8 -0
  23. package/dist/collapsables/accordion/accordion.d.ts +10 -2
  24. package/dist/collapsables/accordion/accordion.js +20 -1
  25. package/dist/collapsables/accordion/accordion.module.css.js +1 -1
  26. package/dist/exports.d.ts +38 -24
  27. package/dist/forms/checkbox/checkbox.d.ts +2 -1
  28. package/dist/forms/checkbox/checkbox.js +2 -2
  29. package/dist/forms/input/input.js +1 -3
  30. package/dist/forms/label/label.d.ts +1 -1
  31. package/dist/forms/select/select.d.ts +4 -2
  32. package/dist/forms/select/select.js +6 -3
  33. package/dist/forms/select/select.module.css.js +1 -1
  34. package/dist/global-search/search-input/connected-search-input.js +1 -1
  35. package/dist/index.js +41 -27
  36. package/dist/intl/missing-translation-provider.js +9 -2
  37. package/dist/intl/translation-id.d.ts +1 -1
  38. package/dist/loading/loading-overlay.js +1 -1
  39. package/dist/pages/{cart-page → checkout/cart-page}/cart-page.js +20 -20
  40. package/dist/pages/{layouts → checkout/layouts}/checkout-page-layout/checkout-page-layout.js +3 -3
  41. package/dist/pages/checkout/layouts/checkout-page-layout/checkout-page-layout.module.css.js +3 -0
  42. package/dist/pages/checkout/layouts/checkout-page-layout/components/checkout-page-section-content.d.ts +7 -0
  43. package/dist/pages/checkout/layouts/checkout-page-layout/components/checkout-page-section-content.js +9 -0
  44. package/dist/pages/checkout/layouts/checkout-page-layout/components/checkout-page-section-header.d.ts +8 -0
  45. package/dist/pages/checkout/layouts/checkout-page-layout/components/checkout-page-section-header.js +9 -0
  46. package/dist/pages/checkout/layouts/checkout-page-layout/components/checkout-page-section-link.d.ts +4 -0
  47. package/dist/pages/checkout/layouts/checkout-page-layout/components/checkout-page-section-link.js +8 -0
  48. package/dist/pages/checkout/layouts/checkout-page-layout/components/checkout-page-section.d.ts +7 -0
  49. package/dist/pages/checkout/layouts/checkout-page-layout/components/checkout-page-section.js +10 -0
  50. package/dist/pages/checkout/layouts/checkout-page-layout/components/checkout-page-section.module.css.js +3 -0
  51. package/dist/pages/checkout/payment-page/payment-page.d.ts +1 -0
  52. package/dist/pages/checkout/payment-page/payment-page.js +89 -0
  53. package/dist/pages/{shipping-page → checkout/shipping-page}/components/edit-address.d.ts +1 -1
  54. package/dist/pages/{shipping-page → checkout/shipping-page}/components/edit-address.js +13 -13
  55. package/dist/pages/checkout/shipping-page/components/edit-address.module.css.js +3 -0
  56. package/dist/pages/{shipping-page → checkout/shipping-page}/components/readonly-address.d.ts +1 -1
  57. package/dist/pages/checkout/shipping-page/components/readonly-address.js +27 -0
  58. package/dist/pages/checkout/shipping-page/components/readonly-address.module.css.js +3 -0
  59. package/dist/pages/checkout/shipping-page/shipping-page.js +114 -0
  60. package/dist/pages/{page → components/page}/page.d.ts +1 -1
  61. package/dist/pages/{page → components/page}/page.js +3 -5
  62. package/dist/pages/components/page/page.module.css.js +3 -0
  63. package/dist/pages/components/page-container/page-container.module.css.js +3 -0
  64. package/dist/pages/components/page-meta-data/page-meta-data.d.ts +16 -0
  65. package/dist/pages/components/page-meta-data/page-meta-data.js +95 -0
  66. package/dist/pages/error-page/error-page.js +1 -1
  67. package/dist/pages/product/layouts/product-details-page-layout/product-details-page-layout.module.css.js +3 -0
  68. package/dist/pages/{product-details-page → product/product-details-page}/components/product-details-images/product-detail-images.d.ts +1 -1
  69. package/dist/pages/{product-details-page → product/product-details-page}/components/product-details-images/product-detail-images.js +6 -6
  70. package/dist/pages/{product-details-page → product/product-details-page}/components/product-details-images/product-detail-images.module.css.js +1 -1
  71. package/dist/pages/{product-details-page → product/product-details-page}/components/product-details-panel/product-details-panel.js +11 -11
  72. package/dist/pages/product/product-details-page/components/product-details-panel/product-details-panel.module.css.js +3 -0
  73. package/dist/pages/{product-details-page → product/product-details-page}/components/product-details-recently-viewed/product-details-recently-viewed.d.ts +1 -1
  74. package/dist/pages/{product-details-page → product/product-details-page}/components/product-details-recently-viewed/product-details-recently-viewed.js +4 -4
  75. package/dist/pages/product/product-details-page/product-details-page.js +30 -0
  76. package/dist/pages/{product-details-page → product/product-details-page}/product-details.d.ts +1 -1
  77. package/dist/pages/{product-details-page → product/product-details-page}/product-details.js +7 -7
  78. package/dist/pages/{product-listing-page → product/product-listing-page}/no-results/no-results.js +4 -4
  79. package/dist/pages/product/product-listing-page/no-results/no-results.module.css.js +3 -0
  80. package/dist/pages/{product-listing-page → product/product-listing-page}/product-listing-page-category-carousel/product-listing-page-category-carousel.js +3 -3
  81. package/dist/pages/{product-listing-page → product/product-listing-page}/product-listing-page-data-types.d.ts +3 -1
  82. package/dist/pages/product/product-listing-page/product-listing-page.js +37 -0
  83. package/dist/pages/product/product-listing-page/product-listing-page.module.css.js +3 -0
  84. package/dist/pages/{product-listing-page → product/product-listing-page}/product-listing-product-overview/product-listing-product-overview.js +6 -6
  85. package/dist/pages/{product-listing-page → product/product-listing-page}/product-listing.js +16 -16
  86. package/dist/pages/{search-result-page → product/search-result-page}/search-result-product-overview/search-result-product-overview.js +6 -6
  87. package/dist/pages/{search-result-page → product/search-result-page}/search-results-page-category-carousel/search-results-page-category-carousel.js +3 -3
  88. package/dist/pages/{search-result-page → product/search-result-page}/search-results-page.js +22 -17
  89. package/dist/pages/product/search-result-page/search-results-page.module.css.js +3 -0
  90. package/dist/shared/api/bff/model/bff.model.d.ts +14 -0
  91. package/dist/shared/api/bff/services/bff-service.d.ts +1 -1
  92. package/dist/shared/api/bff/services/bff-service.js +1 -0
  93. package/dist/shared/api/shared/hooks/use-awaitable-mutation.d.ts +20 -4
  94. package/dist/shared/api/shared/hooks/use-awaitable-mutation.js +29 -21
  95. package/dist/shared/api/storefront/hooks/authentication/use-patch-session.d.ts +7 -4
  96. package/dist/shared/api/storefront/hooks/authentication/use-patch-session.js +4 -3
  97. package/dist/shared/api/storefront/hooks/cart/use-fetch-current-cart-with-atp.d.ts +2 -1
  98. package/dist/shared/api/storefront/hooks/cart/use-fetch-current-cart-with-atp.js +4 -2
  99. package/dist/shared/api/storefront/hooks/cart/use-fetch-current-cart.d.ts +3 -1
  100. package/dist/shared/api/storefront/hooks/cart/use-fetch-current-cart.js +3 -2
  101. package/dist/shared/api/storefront/hooks/cart/use-patch-cart.d.ts +9 -8
  102. package/dist/shared/api/storefront/hooks/cart/use-patch-cart.js +6 -4
  103. package/dist/shared/api/storefront/hooks/cart/use-place-order.d.ts +10 -4
  104. package/dist/shared/api/storefront/hooks/cart/use-place-order.js +11 -6
  105. package/dist/shared/api/storefront/hooks/customer/use-fetch-fulfillment-methods-by-customer-id.d.ts +4 -0
  106. package/dist/shared/api/storefront/hooks/customer/use-fetch-fulfillment-methods-by-customer-id.js +12 -0
  107. package/dist/shared/api/storefront/hooks/customer/use-fetch-fulfillment-methods-for-current-cart.d.ts +3 -0
  108. package/dist/shared/api/storefront/hooks/customer/use-fetch-fulfillment-methods-for-current-cart.js +12 -0
  109. package/dist/shared/api/storefront/hooks/customer/use-patch-bill-to-address.d.ts +5 -2
  110. package/dist/shared/api/storefront/hooks/customer/use-patch-bill-to-address.js +1 -1
  111. package/dist/shared/api/storefront/hooks/payment/use-invalidate-adyen.d.ts +1 -1
  112. package/dist/shared/api/storefront/hooks/payment/use-invalidate-adyen.js +1 -1
  113. package/dist/shared/api/storefront/model/storefront.model.d.ts +3 -1
  114. package/dist/shared/api/storefront/services/cart-service.d.ts +7 -3
  115. package/dist/shared/api/storefront/services/cart-service.js +11 -8
  116. package/dist/shared/api/storefront/services/customer-service.d.ts +3 -0
  117. package/dist/shared/api/storefront/services/customer-service.js +9 -1
  118. package/dist/shared/api/storefront/services/finance-service.d.ts +13 -0
  119. package/dist/shared/api/storefront/services/finance-service.js +17 -0
  120. package/dist/shared/api/storefront/services/translation-service.js +1 -1
  121. package/dist/shared/hooks/use-css-link.d.ts +3 -0
  122. package/dist/shared/hooks/use-css-link.js +20 -0
  123. package/dist/shared/hooks/use-script.d.ts +15 -0
  124. package/dist/shared/hooks/use-script.js +33 -0
  125. package/dist/shared/providers/react-query-container.js +4 -2
  126. package/dist/shared/routing/route-provider.d.ts +12 -4
  127. package/dist/shared/routing/route-provider.js +14 -10
  128. package/dist/shared/routing/with-routing.js +6 -6
  129. package/dist/shared/utils/string.d.ts +1 -0
  130. package/dist/shared/utils/string.js +6 -1
  131. package/dist/shared/utils/string.test.d.ts +1 -0
  132. package/dist/shared/utils/types.d.ts +3 -0
  133. package/dist/shared/utils/types.js +8 -0
  134. package/dist/styles.css +690 -331
  135. package/dist/tooltip/tooltip.d.ts +2 -2
  136. package/dist/typography/heading/heading.d.ts +4 -2
  137. package/dist/typography/heading/heading.js +3 -2
  138. package/dist/typography/heading/heading.module.css.js +1 -1
  139. package/package.json +1 -1
  140. package/dist/pages/layouts/checkout-page-layout/checkout-page-layout.module.css.js +0 -3
  141. package/dist/pages/layouts/product-details-page-layout/product-details-page-layout.module.css.js +0 -3
  142. package/dist/pages/page/page.module.css.js +0 -3
  143. package/dist/pages/page-container/page-container.module.css.js +0 -3
  144. package/dist/pages/product-details-page/components/product-details-panel/product-details-panel.module.css.js +0 -3
  145. package/dist/pages/product-details-page/product-details-page.js +0 -22
  146. package/dist/pages/product-listing-page/no-results/no-results.module.css.js +0 -3
  147. package/dist/pages/product-listing-page/product-listing-page.js +0 -29
  148. package/dist/pages/product-listing-page/product-listing-page.module.css.js +0 -3
  149. package/dist/pages/search-result-page/search-results-page.module.css.js +0 -3
  150. package/dist/pages/shipping-page/components/edit-address.module.css.js +0 -3
  151. package/dist/pages/shipping-page/components/readonly-address.js +0 -25
  152. package/dist/pages/shipping-page/components/readonly-address.module.css.js +0 -3
  153. package/dist/pages/shipping-page/shipping-page.js +0 -75
  154. package/dist/pages/shipping-page/shipping-page.module.css.js +0 -3
  155. /package/dist/pages/{cart-page → checkout/cart-page}/cart-page.d.ts +0 -0
  156. /package/dist/pages/{layouts → checkout/layouts}/checkout-page-layout/checkout-page-layout.d.ts +0 -0
  157. /package/dist/pages/{shipping-page → checkout/shipping-page}/shipping-page.d.ts +0 -0
  158. /package/dist/pages/{page-container → components/page-container}/page-container.d.ts +0 -0
  159. /package/dist/pages/{page-container → components/page-container}/page-container.js +0 -0
  160. /package/dist/pages/{layouts → product/layouts}/product-details-page-layout/product-details-page-layout.d.ts +0 -0
  161. /package/dist/pages/{layouts → product/layouts}/product-details-page-layout/product-details-page-layout.js +0 -0
  162. /package/dist/pages/{product-details-page → product/product-details-page}/components/product-details-panel/product-details-panel.d.ts +0 -0
  163. /package/dist/pages/{product-details-page → product/product-details-page}/product-details-page.d.ts +0 -0
  164. /package/dist/pages/{product-listing-page → product/product-listing-page}/no-results/no-results.d.ts +0 -0
  165. /package/dist/pages/{product-listing-page → product/product-listing-page}/product-listing-page-category-carousel/product-listing-page-category-carousel.d.ts +0 -0
  166. /package/dist/pages/{product-listing-page → product/product-listing-page}/product-listing-page-provider/product-listing-page-context.d.ts +0 -0
  167. /package/dist/pages/{product-listing-page → product/product-listing-page}/product-listing-page-provider/product-listing-page-context.js +0 -0
  168. /package/dist/pages/{product-listing-page → product/product-listing-page}/product-listing-page-provider/product-listing-page-provider.d.ts +0 -0
  169. /package/dist/pages/{product-listing-page → product/product-listing-page}/product-listing-page-provider/product-listing-page-provider.js +0 -0
  170. /package/dist/pages/{product-listing-page → product/product-listing-page}/product-listing-page.d.ts +0 -0
  171. /package/dist/pages/{product-listing-page → product/product-listing-page}/product-listing-product-overview/product-listing-product-overview.d.ts +0 -0
  172. /package/dist/pages/{product-listing-page → product/product-listing-page}/product-listing.d.ts +0 -0
  173. /package/dist/pages/{search-result-page → product/search-result-page}/search-result-product-overview/search-result-product-overview.d.ts +0 -0
  174. /package/dist/pages/{search-result-page → product/search-result-page}/search-results-page-category-carousel/search-results-page-category-carousel.d.ts +0 -0
  175. /package/dist/pages/{search-result-page → product/search-result-page}/search-results-page.d.ts +0 -0
@@ -1,48 +1,152 @@
1
- import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
2
- import { useRef, useEffect, useCallback } from 'react';
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import { useRef, useState, useMemo, useEffect, useCallback } from 'react';
3
3
  import { Form } from 'react-aria-components';
4
- import qs from 'query-string';
5
- import { Button } from '../buttons/button/button.js';
4
+ import { Address } from '../address/address.js';
5
+ import { Accordion } from '../collapsables/accordion/accordion.js';
6
+ import { AccordionItem } from '../collapsables/accordion/accordion-item.js';
7
+ import { Checkbox } from '../forms/checkbox/checkbox.js';
8
+ import { Label } from '../forms/label/label.js';
9
+ import { Select } from '../forms/select/select.js';
10
+ import { TextField } from '../forms/text-field/text-field.js';
11
+ import { FormattedMessage } from '../intl/formatted-message.js';
12
+ import { useFormattedMessage } from '../intl/use-formatted-message.js';
13
+ import { useFetchSession } from '../shared/api/storefront/hooks/authentication/use-fetch-session.js';
14
+ import { usePatchSession } from '../shared/api/storefront/hooks/authentication/use-patch-session.js';
15
+ import { useFetchCurrentCart } from '../shared/api/storefront/hooks/cart/use-fetch-current-cart.js';
6
16
  import { usePatchCart } from '../shared/api/storefront/hooks/cart/use-patch-cart.js';
7
17
  import { usePlaceOrder } from '../shared/api/storefront/hooks/cart/use-place-order.js';
18
+ import { useInvalidateAdyen } from '../shared/api/storefront/hooks/payment/use-invalidate-adyen.js';
19
+ import { validateVATNumber } from '../shared/api/storefront/services/finance-service.js';
20
+ import { useDebouncedCallback } from '../shared/hooks/use-debounced-callback.js';
8
21
  import { currencySymbolToISO } from '../shared/model/currency.js';
22
+ import { Tooltip } from '../tooltip/tooltip.js';
9
23
  import { AdyenPayment } from './adyen-payment.js';
10
- import { PaymentDetails } from './payment-details.js';
24
+ import { useHasReturnedFromAdyen } from './use-has-returned-from-adyen.js';
25
+ import styles from './payment.module.css.js';
11
26
 
12
- function Payment({ cart: _cart, onError, onPaymentComplete, }) {
13
- const { mutate: patchCart } = usePatchCart();
14
- const placeOrder = usePlaceOrder();
27
+ function Payment({ atp, cart: _cart, form, fulfillmentMethods, onError: _onError, onPaymentComplete, onProcessing, onValidating, }) {
28
+ const { data: session } = useFetchSession();
29
+ const { isLoading: isPatchingCart, mutate: patchCart } = usePatchCart();
30
+ const { isLoading: isPatchingSession, mutate: patchSession } = usePatchSession();
31
+ const { isLoading: isPlacingCart, mutate: placeOrder } = usePlaceOrder();
32
+ const { refetch: refetchCart } = useFetchCurrentCart();
15
33
  const dropinRef = useRef(null);
34
+ const [paymentError, setPaymentError] = useState();
35
+ const invalidateAdyen = useInvalidateAdyen();
36
+ const [isValidatingVAT, setIsValidatingVAT] = useState(false);
37
+ const t = useFormattedMessage();
16
38
  const cartRef = useRef(_cart);
17
39
  const cart = cartRef.current;
18
- const { redirectResult } =
19
- // eslint-disable-next-line ssr-friendly/no-dom-globals-in-react-fc
20
- typeof window === 'undefined' ? {} : qs.parse(window.location.search || '');
21
- const allowSubmit = !redirectResult;
40
+ const hasAtp = atp.length > 0 && atp[0]?.date !== null;
41
+ const [asSoonAsPossible, setAsSoonAsPossible] = useState(!hasAtp);
42
+ const [deliveryDate, setDeliveryDate] = useState(cart.requestedDeliveryDateDisplay?.toString() || '');
43
+ const hasReturnedFromAdyen = useHasReturnedFromAdyen();
22
44
  const countryCode = _cart.billTo?.country?.abbreviation;
45
+ const isProcessing = useMemo(() => hasReturnedFromAdyen || isPlacingCart, [isPlacingCart, hasReturnedFromAdyen]);
23
46
  useEffect(() => {
24
47
  cartRef.current = _cart;
25
48
  }, [_cart]);
26
- async function onSubmit() {
49
+ useEffect(() => {
50
+ onValidating(isValidatingVAT || isPatchingSession);
51
+ }, [isPatchingSession, isValidatingVAT, onValidating]);
52
+ useEffect(() => {
53
+ onProcessing(isPatchingCart);
54
+ }, [isPatchingCart, onProcessing]);
55
+ useEffect(() => {
56
+ onProcessing(isProcessing);
57
+ }, [isProcessing, onProcessing]);
58
+ const [validationErrors, setValidationErrors] = useState({});
59
+ const atpSelectOptions = atp.reduce((acc, atp) => ({
60
+ ...acc,
61
+ [atp.date || '']: atp.displayDate,
62
+ }), {});
63
+ const fulfillmentMethodOptions = fulfillmentMethods.reduce((acc, method) => ({
64
+ ...acc,
65
+ [method]: t(`fulfillmentMethod.${method}`),
66
+ }), {});
67
+ const paymentMethodOptions = cart.paymentOptions?.paymentMethods?.reduce((acc, method) => {
68
+ acc[method.name] = t(`paymentMethod.${method.description}`);
69
+ return acc;
70
+ }, {});
71
+ const debouncedValidator = useDebouncedCallback(async (value) => {
72
+ if (!value)
73
+ return setValidationErrors({});
74
+ if (value.length < 8) {
75
+ return setValidationErrors({
76
+ ...validationErrors,
77
+ vatNumber: t('validation.tooShort'),
78
+ });
79
+ }
80
+ try {
81
+ setIsValidatingVAT(true);
82
+ const response = await validateVATNumber({ vatNumber: value });
83
+ if (response.isValid) {
84
+ setValidationErrors(prev => {
85
+ delete prev.vatNumber;
86
+ return prev;
87
+ });
88
+ }
89
+ else {
90
+ setValidationErrors({
91
+ ...validationErrors,
92
+ vatNumber: t('validation.invalid'),
93
+ });
94
+ }
95
+ }
96
+ catch {
97
+ setValidationErrors({
98
+ ...validationErrors,
99
+ vatNumber: t('validation.invalid'),
100
+ });
101
+ }
102
+ finally {
103
+ setIsValidatingVAT(false);
104
+ }
105
+ }, 500);
106
+ async function onSubmit(e) {
107
+ const formData = new FormData(e.currentTarget);
27
108
  const cart = cartRef.current;
28
- dropinRef.current?.showValidation();
29
- if (!cart.customerVatNumber)
109
+ setValidationErrors(prev => prev); // NOTE: This makes sure the form is revalidated on submit
110
+ if (Object.keys(validationErrors).length > 0)
111
+ return;
112
+ if (!dropinRef.current) {
113
+ console.warn('Adyen Dropin not ready');
114
+ return;
115
+ }
116
+ dropinRef.current.showValidation();
117
+ if (!dropinRef.current.isValid)
30
118
  return;
31
- if (dropinRef.current) {
32
- if (!dropinRef.current.isValid)
33
- return;
34
- await patchCart({ cart });
119
+ try {
120
+ // TODO: try catch handle failed patch, display error on top of form
121
+ await patchCart({
122
+ cart: {
123
+ ...cart,
124
+ customerVatNumber: formData.get('vatNumber')?.toString(),
125
+ fulfillmentMethod: formData.get('fulfillmentMethod')?.toString(),
126
+ poNumber: formData.get('poNumber')?.toString(),
127
+ properties: {
128
+ ...cart.properties,
129
+ industry: formData.get('industry')?.toString() || '',
130
+ },
131
+ requestedDeliveryDate: formData.get('deliveryDate')?.toString(),
132
+ },
133
+ });
35
134
  dropinRef.current.submit();
36
135
  }
136
+ catch (error) {
137
+ console.error(error);
138
+ setPaymentError(error);
139
+ }
37
140
  }
38
141
  const onComplete = useCallback(async (result) => {
39
142
  const cart = cartRef.current;
143
+ // TODO: try catch handle error, display error on top
40
144
  await placeOrder({
41
145
  cart: {
42
146
  ...cart,
43
147
  paymentMethod: null,
44
148
  paymentOptions: {
45
- ...cart.paymentOptions,
149
+ ...cart.paymentOptions, // Hack needed to make B2B happy
46
150
  adyenPspReference: result.pspReference,
47
151
  isAdyenDropIn: true,
48
152
  },
@@ -50,20 +154,50 @@ function Payment({ cart: _cart, onError, onPaymentComplete, }) {
50
154
  });
51
155
  return onPaymentComplete();
52
156
  }, [onPaymentComplete, placeOrder]);
53
- return (jsxs(Fragment, { children: [jsx("h2", { children: "Payment" }), jsxs(Form, { onSubmit: e => {
54
- e.preventDefault();
55
- onSubmit();
56
- }, children: [!redirectResult && (jsx(PaymentDetails, { cart: cart, onCartChanged: cart => {
57
- cartRef.current = cart;
58
- } })), cart.paymentMethod?.name === 'PBI' && 'Pay by invoice', cart.paymentMethod?.name !== 'PBI' &&
59
- cart.paymentOptions &&
60
- cart.billTo?.id &&
61
- countryCode && (jsx(AdyenPayment, { amount: cart.orderGrandTotal, billToId: cart.billTo.id, cartId: cart.trackId, countryCode: countryCode, currencyCode: currencySymbolToISO[cart.currencySymbol], dropinRef: dropinRef, environment: "test", locale: "nl-NL", onComplete: onComplete, onError: onError, orderAmount: cart.orderGrandTotal, redirectResult: !redirectResult || Array.isArray(redirectResult)
62
- ? undefined
63
- : redirectResult, returnUrl: typeof window === 'undefined'
64
- ? ''
65
- : // eslint-disable-next-line ssr-friendly/no-dom-globals-in-react-fc
66
- `${window.location.pathname}${window.location.search ? `?${window.location.search}` : ''}` })), jsx(Button, { isDisabled: !allowSubmit, type: "submit", children: "Pay" })] })] }));
157
+ const onError = useCallback((error, result) => {
158
+ invalidateAdyen();
159
+ // invalidateCurrentCart()
160
+ setPaymentError(error);
161
+ console.error(error);
162
+ _onError?.(error, result);
163
+ }, [_onError, invalidateAdyen]);
164
+ return (jsxs(Form, { className: styles['payment-form'], id: form, onSubmit: e => {
165
+ e.preventDefault();
166
+ onSubmit(e);
167
+ }, validationErrors: validationErrors, children: [jsxs("div", { className: styles['delivery-date'], children: [jsx(Select, { showLabel: true, "data-test-selector": "delivery-date", isDisabled: hasReturnedFromAdyen || asSoonAsPossible, isRequired: !asSoonAsPossible, label: t('Select a desired delivery date'), name: "deliveryDate", onChange: setDeliveryDate, options: atpSelectOptions, selectedOption: deliveryDate, variant: "solid" }, String(asSoonAsPossible)), jsxs("div", { className: styles['asap-checkbox'], children: [jsx(Checkbox, { "data-test-selector": "asapCheckbox", isDisabled: hasReturnedFromAdyen || !hasAtp, isSelected: asSoonAsPossible, onChange: checked => {
168
+ setAsSoonAsPossible(checked);
169
+ if (checked)
170
+ setDeliveryDate('');
171
+ }, children: jsx(FormattedMessage, { id: "As soon as possible" }) }), jsx(Tooltip, { text: t('Selecting As Soon As Possible will enable us to send the products to you as they become available.') })] })] }), jsx(Select, { isRequired: true, showLabel: true, defaultSelectedOption: cart.fulfillmentMethod, isDisabled: hasReturnedFromAdyen || fulfillmentMethods.length <= 1, label: t('Fulfillment method'), name: "fulfillmentMethod", onChange: async (value) => {
172
+ await patchSession({
173
+ session: {
174
+ ...session,
175
+ fulfillmentMethod: value,
176
+ },
177
+ });
178
+ await refetchCart();
179
+ }, options: fulfillmentMethodOptions, variant: "solid" }), jsx(Select, { isRequired: true, defaultSelectedOption: cart.properties.industry, isDisabled: hasReturnedFromAdyen, label: t('Industry'), name: "industry", options: {
180
+ /* eslint-disable sort-keys-fix/sort-keys-fix */
181
+ PP: 'Private User',
182
+ AU: 'Automotive',
183
+ MC: 'Motorcycle',
184
+ BC: 'Bicycle',
185
+ TR: 'Truck',
186
+ AG: 'Agricultural',
187
+ AV: 'Aviation',
188
+ MA: 'Maritime',
189
+ OT: 'Other',
190
+ /* eslint-enable sort-keys-fix/sort-keys-fix */
191
+ }, variant: "solid" }), jsx(TextField, { showLabel: true, defaultValue: cart.customerVatNumber, isDisabled: hasReturnedFromAdyen || isProcessing, label: t('VAT Number'), name: "vatNumber", onInput: e => debouncedValidator(e.target.value), validate: () => validationErrors.vatNumber ?? true }), jsx(TextField, { showLabel: true, defaultValue: cart.poNumber, isDisabled: hasReturnedFromAdyen || isProcessing, label: t('PO Number'), name: "poNumber" }), paymentMethodOptions && (jsx(Select, { defaultSelectedOption: cart.paymentOptions?.paymentMethods?.[0]?.name || 'ADY', isDisabled: (hasReturnedFromAdyen ||
192
+ (cart.paymentOptions?.paymentMethods &&
193
+ cart.paymentOptions.paymentMethods.length <= 1)) ??
194
+ true, label: t('Payment method'), name: "paymentMethod", options: paymentMethodOptions, variant: "solid" })), cart.paymentMethod?.name !== 'PBI' &&
195
+ cart.paymentOptions &&
196
+ cart.billTo?.id &&
197
+ countryCode && (jsx(AdyenPayment, { amount: cart.orderGrandTotal, cartId: cart.trackId, countryCode: countryCode, currencyCode: currencySymbolToISO[cart.currencySymbol], customerId: cart.billTo.id, dropinRef: dropinRef, environment: "test", onComplete: onComplete, onError: onError, orderAmount: cart.orderGrandTotal, returnUrl: typeof window === 'undefined'
198
+ ? ''
199
+ : // eslint-disable-next-line ssr-friendly/no-dom-globals-in-react-fc
200
+ `https://sonicequipment.commerce.insitesandbox.com${window.location.pathname}${window.location.search ? `${window.location.search}` : ''}` })), Boolean(paymentError) && (jsx("div", { className: styles['error-message'], children: jsx(FormattedMessage, { id: "An error occurred while processing your payment. Please try again." }) })), jsxs("div", { className: styles['invoice-and-shipping'], children: [jsx(Label, { children: jsx(FormattedMessage, { id: "Billing and shipping address" }) }), jsx(Accordion, { variant: "select", children: jsx(AccordionItem, { id: "invoice-and-shipping", title: "Factuur- en verzendinformatie", children: jsxs("div", { className: styles['content'], children: [jsx("section", { className: styles.section, children: jsxs("div", { children: [jsx("p", { className: styles.label, children: jsx(FormattedMessage, { id: "Billing address" }) }), jsx(Address, { address1: cart.billTo?.address1, address2: cart.billTo?.address2, address3: cart.billTo?.address3, city: cart.billTo?.city, companyName: cart.billTo?.companyName, country: cart.billTo?.country?.name, email: cart.billTo?.email, phone: cart.billTo?.phone, postalCode: cart.billTo?.postalCode })] }) }), jsx("section", { className: styles.section, children: jsxs("div", { children: [jsx("p", { className: styles.label, children: jsx(FormattedMessage, { id: "Shipping address" }) }), jsx(Address, { address1: cart.shipTo?.address1, address2: cart.shipTo?.address2, address3: cart.shipTo?.address3, city: cart.shipTo?.city, companyName: cart.shipTo?.companyName, country: cart.shipTo?.country?.name, email: cart.shipTo?.email, phone: cart.shipTo?.phone, postalCode: cart.shipTo?.postalCode })] }) })] }) }) })] })] }));
67
201
  }
68
202
 
69
203
  export { Payment };
@@ -0,0 +1,3 @@
1
+ var styles = {"error-message":"payment-module-cF0-P","payment-form":"payment-module-XsBSV","delivery-date":"payment-module-yoZKM","asap-checkbox":"payment-module-iKZK1","invoice-and-shipping":"payment-module-RHQBy","content":"payment-module-3hHuC","section":"payment-module-Vdgdo","label":"payment-module-Hpq8j"};
2
+
3
+ export { styles as default };
@@ -0,0 +1 @@
1
+ export declare function useGetAdyenRedirectResult(): string | undefined;
@@ -0,0 +1,13 @@
1
+ import { useRef } from 'react';
2
+ import qs from 'query-string';
3
+
4
+ function useGetAdyenRedirectResult() {
5
+ const redirectResult = useRef((typeof window === 'undefined'
6
+ ? { redirectResult: undefined }
7
+ : qs.parse(window.location.search || '')).redirectResult);
8
+ return typeof redirectResult.current === 'string'
9
+ ? redirectResult.current
10
+ : undefined;
11
+ }
12
+
13
+ export { useGetAdyenRedirectResult };
@@ -0,0 +1 @@
1
+ export declare function useHasReturnedFromAdyen(): boolean;
@@ -0,0 +1,8 @@
1
+ import { useGetAdyenRedirectResult } from './use-get-adyen-redirect-result.js';
2
+
3
+ function useHasReturnedFromAdyen() {
4
+ const redirectResult = useGetAdyenRedirectResult();
5
+ return Boolean(redirectResult);
6
+ }
7
+
8
+ export { useHasReturnedFromAdyen };
@@ -1,12 +1,20 @@
1
1
  import { ReactElement } from 'react';
2
2
  import { AccordionItemProps, BorderType } from './accordion-item';
3
3
  interface AccordionProps {
4
- borderType?: BorderType | BorderType[];
5
4
  children?: ReactElement<AccordionItemProps> | ReactElement<AccordionItemProps>[] | false | undefined | null | (false | undefined | null | ReactElement<AccordionItemProps>)[];
5
+ variant?: 'standard' | 'select';
6
+ }
7
+ interface AccordionStandardProps extends AccordionProps {
8
+ borderType?: BorderType | BorderType[];
6
9
  color?: 'white' | 'black';
7
10
  hasLineSeparator?: boolean;
8
11
  indented?: boolean;
9
12
  size?: 'md' | 'lg';
13
+ variant?: 'standard';
14
+ }
15
+ interface AccordionDropDownProps extends AccordionProps {
16
+ variant: 'select';
10
17
  }
11
- export declare function Accordion({ borderType, children, color, hasLineSeparator, indented, size, }: AccordionProps): import("react/jsx-runtime").JSX.Element;
18
+ type Props = AccordionStandardProps | AccordionDropDownProps;
19
+ export declare function Accordion({ variant, ...rest }: Props): import("react/jsx-runtime").JSX.Element;
12
20
  export {};
@@ -3,7 +3,18 @@ import { Children, cloneElement } from 'react';
3
3
  import clsx from 'clsx';
4
4
  import styles from './accordion.module.css.js';
5
5
 
6
- function Accordion({ borderType = 'bottom', children, color = 'black', hasLineSeparator = true, indented, size = 'md', }) {
6
+ function Accordion({ variant = 'standard', ...rest }) {
7
+ /* eslint-disable @typescript-eslint/no-unnecessary-condition */
8
+ if (variant === 'standard') {
9
+ return jsx(StandardAccordion, { variant: variant, ...rest });
10
+ }
11
+ if (variant === 'select') {
12
+ return jsx(DropDownAccordion, { variant: variant, ...rest });
13
+ }
14
+ throw new Error(`Invalid variant ${variant}`);
15
+ /* eslint-enable @typescript-eslint/no-unnecessary-condition */
16
+ }
17
+ function StandardAccordion({ borderType = 'bottom', children, color = 'black', hasLineSeparator = true, indented, size = 'md', }) {
7
18
  return (jsx("div", { className: clsx({ [styles.indented]: indented }, styles.accordion, styles[color], styles[size], hasLineSeparator && styles['with-seperators']), children: Boolean(children) &&
8
19
  Children.map(children, child => {
9
20
  if (!child)
@@ -11,5 +22,13 @@ function Accordion({ borderType = 'bottom', children, color = 'black', hasLineSe
11
22
  return cloneElement(child, { borderType, size });
12
23
  }) }));
13
24
  }
25
+ function DropDownAccordion({ children, variant }) {
26
+ return (jsx("div", { className: clsx(styles.accordion, styles[variant]), children: Boolean(children) &&
27
+ Children.map(children, child => {
28
+ if (!child)
29
+ return null;
30
+ return cloneElement(child);
31
+ }) }));
32
+ }
14
33
 
15
34
  export { Accordion };
@@ -1,3 +1,3 @@
1
- var styles = {"accordion":"accordion-module-9WvAH","indented":"accordion-module-6CcEH","white":"accordion-module-CaVdG","accordion-item":"accordion-module-lf9d-","lg":"accordion-module-0qnae","with-seperators":"accordion-module-yOLrW","button":"accordion-module--Rwpb","icon":"accordion-module-Y50uq","focus":"accordion-module-M4BZs","allow-toggle":"accordion-module-QEO2d","panel":"accordion-module-KZjMo","content":"accordion-module-ejMH3","border-type-bottom":"accordion-module-oTdZK","border-type-top":"accordion-module-0mrLq","border-type-middle":"accordion-module-aAr-R","is-open":"accordion-module-W0F1z","border-type-middle-accentuated":"accordion-module-OB98a"};
1
+ var styles = {"accordion":"accordion-module-9WvAH","indented":"accordion-module-6CcEH","white":"accordion-module-CaVdG","accordion-item":"accordion-module-lf9d-","lg":"accordion-module-0qnae","with-seperators":"accordion-module-yOLrW","button":"accordion-module--Rwpb","icon":"accordion-module-Y50uq","focus":"accordion-module-M4BZs","allow-toggle":"accordion-module-QEO2d","panel":"accordion-module-KZjMo","content":"accordion-module-ejMH3","border-type-bottom":"accordion-module-oTdZK","border-type-top":"accordion-module-0mrLq","border-type-middle":"accordion-module-aAr-R","is-open":"accordion-module-W0F1z","border-type-middle-accentuated":"accordion-module-OB98a","select":"accordion-module-SAbiG"};
2
2
 
3
3
  export { styles as default };
package/dist/exports.d.ts CHANGED
@@ -60,6 +60,8 @@ export * from './checkout/adyen-payment';
60
60
  export * from './checkout/parse-amount';
61
61
  export * from './checkout/payment';
62
62
  export * from './checkout/payment-details';
63
+ export * from './checkout/use-get-adyen-redirect-result';
64
+ export * from './checkout/use-has-returned-from-adyen';
63
65
  export * from './collapsables/accordion/accordion';
64
66
  export * from './collapsables/accordion/accordion-item';
65
67
  export * from './collapsables/show-all/show-all';
@@ -140,32 +142,38 @@ export * from './notifications/announcements/announcement';
140
142
  export * from './notifications/announcements/announcement-provider';
141
143
  export * from './notifications/announcements/connected-announcement';
142
144
  export * from './observers/intersection-observer';
143
- export * from './pages/cart-page/cart-page';
145
+ export * from './pages/checkout/cart-page/cart-page';
146
+ export * from './pages/checkout/layouts/checkout-page-layout/checkout-page-layout';
147
+ export * from './pages/checkout/layouts/checkout-page-layout/components/checkout-page-section';
148
+ export * from './pages/checkout/layouts/checkout-page-layout/components/checkout-page-section-content';
149
+ export * from './pages/checkout/layouts/checkout-page-layout/components/checkout-page-section-header';
150
+ export * from './pages/checkout/layouts/checkout-page-layout/components/checkout-page-section-link';
151
+ export * from './pages/checkout/payment-page/payment-page';
152
+ export * from './pages/checkout/shipping-page/components/edit-address';
153
+ export * from './pages/checkout/shipping-page/components/readonly-address';
154
+ export * from './pages/checkout/shipping-page/shipping-page';
155
+ export * from './pages/components/page-container/page-container';
156
+ export * from './pages/components/page-meta-data/page-meta-data';
157
+ export * from './pages/components/page/page';
144
158
  export * from './pages/error-page/error-page';
145
- export * from './pages/layouts/checkout-page-layout/checkout-page-layout';
146
- export * from './pages/layouts/product-details-page-layout/product-details-page-layout';
147
159
  export * from './pages/loading-page/loading-page';
148
- export * from './pages/page-container/page-container';
149
- export * from './pages/page/page';
150
- export * from './pages/product-details-page/components/product-details-images/product-detail-images';
151
- export * from './pages/product-details-page/components/product-details-panel/product-details-panel';
152
- export * from './pages/product-details-page/components/product-details-recently-viewed/product-details-recently-viewed';
153
- export * from './pages/product-details-page/product-details';
154
- export * from './pages/product-details-page/product-details-page';
155
- export * from './pages/product-listing-page/no-results/no-results';
156
- export * from './pages/product-listing-page/product-listing';
157
- export * from './pages/product-listing-page/product-listing-page';
158
- export * from './pages/product-listing-page/product-listing-page-category-carousel/product-listing-page-category-carousel';
159
- export * from './pages/product-listing-page/product-listing-page-data-types';
160
- export * from './pages/product-listing-page/product-listing-page-provider/product-listing-page-context';
161
- export * from './pages/product-listing-page/product-listing-page-provider/product-listing-page-provider';
162
- export * from './pages/product-listing-page/product-listing-product-overview/product-listing-product-overview';
163
- export * from './pages/search-result-page/search-result-product-overview/search-result-product-overview';
164
- export * from './pages/search-result-page/search-results-page';
165
- export * from './pages/search-result-page/search-results-page-category-carousel/search-results-page-category-carousel';
166
- export * from './pages/shipping-page/components/edit-address';
167
- export * from './pages/shipping-page/components/readonly-address';
168
- export * from './pages/shipping-page/shipping-page';
160
+ export * from './pages/product/layouts/product-details-page-layout/product-details-page-layout';
161
+ export * from './pages/product/product-details-page/components/product-details-images/product-detail-images';
162
+ export * from './pages/product/product-details-page/components/product-details-panel/product-details-panel';
163
+ export * from './pages/product/product-details-page/components/product-details-recently-viewed/product-details-recently-viewed';
164
+ export * from './pages/product/product-details-page/product-details';
165
+ export * from './pages/product/product-details-page/product-details-page';
166
+ export * from './pages/product/product-listing-page/no-results/no-results';
167
+ export * from './pages/product/product-listing-page/product-listing';
168
+ export * from './pages/product/product-listing-page/product-listing-page';
169
+ export * from './pages/product/product-listing-page/product-listing-page-category-carousel/product-listing-page-category-carousel';
170
+ export * from './pages/product/product-listing-page/product-listing-page-data-types';
171
+ export * from './pages/product/product-listing-page/product-listing-page-provider/product-listing-page-context';
172
+ export * from './pages/product/product-listing-page/product-listing-page-provider/product-listing-page-provider';
173
+ export * from './pages/product/product-listing-page/product-listing-product-overview/product-listing-product-overview';
174
+ export * from './pages/product/search-result-page/search-result-product-overview/search-result-product-overview';
175
+ export * from './pages/product/search-result-page/search-results-page';
176
+ export * from './pages/product/search-result-page/search-results-page-category-carousel/search-results-page-category-carousel';
169
177
  export * from './promos/promo-banner/promo-banner';
170
178
  export * from './promos/promo-banners/promo-banners';
171
179
  export * from './promos/promo-card/promo-card';
@@ -198,6 +206,8 @@ export * from './shared/api/storefront/hooks/cart/use-patch-cart-line-by-id';
198
206
  export * from './shared/api/storefront/hooks/cart/use-place-order';
199
207
  export * from './shared/api/storefront/hooks/cart/use-save-cart-for-later';
200
208
  export * from './shared/api/storefront/hooks/customer/use-fetch-bill-to-addresses';
209
+ export * from './shared/api/storefront/hooks/customer/use-fetch-fulfillment-methods-by-customer-id';
210
+ export * from './shared/api/storefront/hooks/customer/use-fetch-fulfillment-methods-for-current-cart';
201
211
  export * from './shared/api/storefront/hooks/customer/use-fetch-ship-to-addresses';
202
212
  export * from './shared/api/storefront/hooks/customer/use-patch-bill-to-address';
203
213
  export * from './shared/api/storefront/hooks/payment/use-create-adyen-session';
@@ -218,6 +228,7 @@ export * from './shared/api/storefront/hooks/wishlist/use-fetch-wishlists';
218
228
  export * from './shared/api/storefront/services/authentication-service';
219
229
  export * from './shared/api/storefront/services/cart-service';
220
230
  export * from './shared/api/storefront/services/customer-service';
231
+ export * from './shared/api/storefront/services/finance-service';
221
232
  export * from './shared/api/storefront/services/payment-service';
222
233
  export * from './shared/api/storefront/services/translation-service';
223
234
  export * from './shared/api/storefront/services/website-service';
@@ -230,12 +241,14 @@ export * from './shared/ga/types';
230
241
  export * from './shared/ga/use-data-layer';
231
242
  export * from './shared/hooks/use-breakpoint';
232
243
  export * from './shared/hooks/use-cookie';
244
+ export * from './shared/hooks/use-css-link';
233
245
  export * from './shared/hooks/use-debounced-callback';
234
246
  export * from './shared/hooks/use-disclosure';
235
247
  export * from './shared/hooks/use-enable-mobile-zoom';
236
248
  export * from './shared/hooks/use-intersection-observer';
237
249
  export * from './shared/hooks/use-is-breakpoint';
238
250
  export * from './shared/hooks/use-resize-observer';
251
+ export * from './shared/hooks/use-script';
239
252
  export * from './shared/hooks/use-scroll-lock';
240
253
  export * from './shared/hooks/use-scroll-to';
241
254
  export * from './shared/hooks/use-session-storage';
@@ -268,6 +281,7 @@ export * from './shared/utils/price';
268
281
  export * from './shared/utils/random';
269
282
  export * from './shared/utils/string';
270
283
  export * from './shared/utils/time';
284
+ export * from './shared/utils/types';
271
285
  export * from './shared/utils/uuid';
272
286
  export * from './shared/utils/wait';
273
287
  export * from './sidebar/sidebar';
@@ -3,9 +3,10 @@ export interface CheckboxProps {
3
3
  _pseudo?: 'none' | 'focus' | 'hover' | 'active';
4
4
  children: ReactNode;
5
5
  className?: string;
6
+ 'data-test-selector'?: string;
6
7
  isDisabled?: boolean;
7
8
  isSelected?: boolean;
8
9
  onChange?: (isSelected: boolean) => void;
9
10
  value?: string;
10
11
  }
11
- export declare function Checkbox({ _pseudo, children, className, isDisabled, isSelected, onChange, value, }: CheckboxProps): import("react/jsx-runtime").JSX.Element;
12
+ export declare function Checkbox({ _pseudo, children, className, 'data-test-selector': dataTestSelector, isDisabled, isSelected, onChange, value, }: CheckboxProps): import("react/jsx-runtime").JSX.Element;
@@ -4,8 +4,8 @@ import { Checkbox as Checkbox$1 } from 'react-aria-components';
4
4
  import clsx from 'clsx';
5
5
  import styles from './checkbox.module.css.js';
6
6
 
7
- function Checkbox({ _pseudo = 'none', children, className, isDisabled, isSelected, onChange, value, }) {
8
- return (jsxs(Checkbox$1, { className: clsx(className, styles.checkbox, styles[_pseudo]), isDisabled: isDisabled, isSelected: isSelected, onChange: onChange, value: value, children: [jsx("div", { className: styles.box, children: jsx("svg", { "aria-hidden": "true", className: styles.checkmark, viewBox: "0 0 18 18", children: jsx("polyline", { points: "1 9 7 14 15 4" }) }) }), children] }));
7
+ function Checkbox({ _pseudo = 'none', children, className, 'data-test-selector': dataTestSelector, isDisabled, isSelected, onChange, value, }) {
8
+ return (jsxs(Checkbox$1, { className: clsx(className, styles.checkbox, styles[_pseudo]), "data-test-selector": dataTestSelector, isDisabled: isDisabled, isSelected: isSelected, onChange: onChange, value: value, children: [jsx("div", { className: styles.box, children: jsx("svg", { "aria-hidden": "true", className: styles.checkmark, viewBox: "0 0 18 18", children: jsx("polyline", { points: "1 9 7 14 15 4" }) }) }), children] }));
9
9
  }
10
10
 
11
11
  export { Checkbox };
@@ -1,7 +1,6 @@
1
1
  "use client";
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
3
  import { forwardRef, useState } from 'react';
4
- import { usePress } from 'react-aria';
5
4
  import { useContextProps, InputContext, Input as Input$1 } from 'react-aria-components';
6
5
  import clsx from 'clsx';
7
6
  import styles from './input.module.css.js';
@@ -19,8 +18,7 @@ const Input = forwardRef(({ _pseudo = 'none', autoGrow, label, size = 'lg', ...i
19
18
  const handleChange = (event) => isControlled
20
19
  ? onChange?.(event)
21
20
  : setUncontrolledValue(event.target.value);
22
- const { pressProps } = usePress({});
23
- return (jsx("div", { className: clsx(styles['input-container'], styles[size], styles[_pseudo]), children: jsxs("div", { className: clsx({ [styles['growing-input']]: autoGrow }), children: [jsx(Input$1, { "aria-label": label, size: autoGrow ? 1 : undefined, ...props, ...pressProps, ref: ref, onChange: handleChange, onClick: e => {
21
+ return (jsx("div", { className: clsx(styles['input-container'], styles[size], styles[_pseudo]), children: jsxs("div", { className: clsx({ [styles['growing-input']]: autoGrow }), children: [jsx(Input$1, { "aria-label": label, size: autoGrow ? 1 : undefined, ...props, ref: ref, onChange: handleChange, onClick: e => {
24
22
  e.preventDefault();
25
23
  e.stopPropagation();
26
24
  e.target.focus();
@@ -1,5 +1,5 @@
1
1
  interface LabelProps {
2
- children: string;
2
+ children: string | React.ReactNode;
3
3
  isRequired?: boolean;
4
4
  }
5
5
  export declare function Label({ children, isRequired }: LabelProps): import("react/jsx-runtime").JSX.Element | null;
@@ -1,11 +1,13 @@
1
1
  export interface SelectProps<T> {
2
2
  'data-test-selector'?: string;
3
3
  defaultSelectedOption?: keyof T;
4
+ icon?: React.ReactNode;
4
5
  isDisabled?: boolean;
6
+ isLoading?: boolean;
5
7
  isRequired?: boolean;
6
8
  label: string;
7
9
  name?: string;
8
- onChange: (value: keyof T) => void;
10
+ onChange?: (value: keyof T) => void;
9
11
  options: T;
10
12
  placeholder?: string;
11
13
  selectedOption?: keyof T;
@@ -14,4 +16,4 @@ export interface SelectProps<T> {
14
16
  size?: 'sm' | 'md';
15
17
  variant?: 'outline' | 'solid';
16
18
  }
17
- export declare function Select<T extends Record<string, string>>({ 'data-test-selector': dataTestSelector, defaultSelectedOption, isDisabled, isRequired, label, name, onChange, options, placeholder, selectedOption, showLabel, showPlaceholder, size, variant, }: SelectProps<T>): import("react/jsx-runtime").JSX.Element;
19
+ export declare function Select<T extends Record<string, string>>({ 'data-test-selector': dataTestSelector, defaultSelectedOption, icon, isDisabled, isLoading, isRequired, label, name, onChange, options, placeholder, selectedOption, showLabel, showPlaceholder, size, variant, }: SelectProps<T>): import("react/jsx-runtime").JSX.Element;
@@ -5,11 +5,12 @@ import { Select as Select$1, Button, SelectValue, Popover, ListBox, Section, Hea
5
5
  import clsx from 'clsx';
6
6
  import { GlyphsChevronsSlimDownIcon } from '../../icons/glyph/glyphs-chevrons-slim-down-icon.js';
7
7
  import { StrokeCheckmarkIcon } from '../../icons/stroke/stroke-checkmark-icon.js';
8
+ import { ProgressCircle } from '../../loading/progress-circle.js';
8
9
  import { FieldError } from '../field-error/field-error.js';
9
10
  import { Label } from '../label/label.js';
10
11
  import styles from './select.module.css.js';
11
12
 
12
- function Select({ 'data-test-selector': dataTestSelector, defaultSelectedOption, isDisabled = false, isRequired = false, label, name, onChange, options, placeholder, selectedOption, showLabel = true, showPlaceholder = true, size = 'md', variant = 'outline', }) {
13
+ function Select({ 'data-test-selector': dataTestSelector, defaultSelectedOption, icon = (jsx(GlyphsChevronsSlimDownIcon, { "aria-hidden": "true", className: styles.chevron })), isDisabled = false, isLoading, isRequired = false, label, name, onChange, options, placeholder, selectedOption, showLabel = true, showPlaceholder = true, size = 'md', variant = 'outline', }) {
13
14
  const selectRef = useRef(null);
14
15
  useEffect(() => {
15
16
  const updateWidth = () => {
@@ -24,9 +25,11 @@ function Select({ 'data-test-selector': dataTestSelector, defaultSelectedOption,
24
25
  window.addEventListener('resize', updateWidth);
25
26
  return () => window?.removeEventListener('resize', updateWidth);
26
27
  }, []);
27
- return (jsxs(Select$1, { ref: selectRef, "aria-label": label, className: clsx(styles.select, styles[size], styles[variant]), "data-test-selector": dataTestSelector, defaultSelectedKey: defaultSelectedOption === undefined
28
+ return (jsxs(Select$1, { ref: selectRef, "aria-label": label, className: clsx(styles.select, styles[size], styles[variant], {
29
+ [styles['loading']]: isLoading,
30
+ }), "data-test-selector": dataTestSelector, defaultSelectedKey: defaultSelectedOption === undefined
28
31
  ? undefined
29
- : String(defaultSelectedOption), isDisabled: isDisabled, isRequired: isRequired, name: name, onSelectionChange: selected => onChange(selected), placeholder: placeholder || label, selectedKey: selectedOption === undefined ? undefined : String(selectedOption), children: [showLabel && jsx(Label, { isRequired: isRequired, children: label }), jsxs(Button, { className: styles.button, children: [jsx(SelectValue, { "data-test-selector": "value" }), jsx(GlyphsChevronsSlimDownIcon, { "aria-hidden": "true", className: styles.chevron })] }), jsx(FieldError, {}), jsx(Popover, { ref: ref =>
32
+ : String(defaultSelectedOption), isDisabled: isDisabled, isRequired: isRequired, name: name, onSelectionChange: selected => onChange?.(selected), placeholder: placeholder || label, selectedKey: selectedOption === undefined ? undefined : String(selectedOption), children: [showLabel && jsx(Label, { isRequired: isRequired, children: label }), jsxs(Button, { className: styles.button, children: [jsx(SelectValue, { "data-test-selector": "value" }), jsx("div", { className: styles['icon-wrapper'], children: isLoading ? jsx(ProgressCircle, { variant: "gray" }) : icon })] }), jsx(FieldError, {}), jsx(Popover, { ref: ref =>
30
33
  // Workaround for react/react-aria #1513
31
34
  ref?.addEventListener('touchend', e => e.preventDefault()), className: clsx(styles.popover, styles[variant]), placement: "bottom left", children: jsx(ListBox, { className: styles.listbox, "data-test-selector": dataTestSelector ? `${dataTestSelector}_options` : undefined, children: jsxs(Section, { children: [showPlaceholder && (jsx(Header, { className: styles.header, children: placeholder || label })), Object.entries(options).map(([key, value]) => (jsxs(ListBoxItem, { "aria-label": value, className: styles.item, id: key, textValue: value, children: [selectedOption === key && (jsx("span", { slot: "description", children: jsx(StrokeCheckmarkIcon, { className: styles.check }) })), jsx("span", { slot: "label", children: value })] }, key)))] }) }) })] }));
32
35
  }
@@ -1,3 +1,3 @@
1
- var styles = {"select":"select-module-ui-Wc","sm":"select-module-44a1l","md":"select-module-QUm-8","button":"select-module-aMQIQ","chevron":"select-module-00uRU","focus":"select-module-XMc0P","solid":"select-module-IRd4F","popover":"select-module-z8cWq","listbox":"select-module-S21ba","header":"select-module-4Bm2j","item":"select-module-LgEJO","check":"select-module-lQFw3"};
1
+ var styles = {"select":"select-module-ui-Wc","sm":"select-module-44a1l","md":"select-module-QUm-8","button":"select-module-aMQIQ","icon-wrapper":"select-module-3scUm","focus":"select-module-XMc0P","solid":"select-module-IRd4F","loading":"select-module-nKUxG","popover":"select-module-z8cWq","listbox":"select-module-S21ba","header":"select-module-4Bm2j","item":"select-module-LgEJO","check":"select-module-lQFw3"};
2
2
 
3
3
  export { styles as default };
@@ -10,7 +10,7 @@ function ConnectedSearchInput() {
10
10
  const { autocomplete, formRef, inputRef } = useAlgoliaSearch();
11
11
  const { close } = useGlobalSearchDisclosure();
12
12
  const t = useFormattedMessage();
13
- const navigate = useNavigate();
13
+ const { navigate } = useNavigate();
14
14
  return (jsx(SearchInput, { autocomplete: autocomplete, formRef: formRef, inputRef: inputRef, onCancel: close, onSubmit: () => {
15
15
  if (!inputRef.current?.value)
16
16
  return;