@sonic-equipment/ui 260.0.5 → 260.0.7

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.
@@ -23,7 +23,10 @@ function OrderLineList({ children, onRemoveAll }) {
23
23
  // eslint-disable-next-line @eslint-react/no-children-map
24
24
  Children.map(children, (child, index) => (
25
25
  // eslint-disable-next-line @eslint-react/no-array-index-key
26
- jsx("li", { className: styles.item, children: child }, index))) })] }), onRemoveAll && (jsx(ConfirmationDialog, { isOpen: isOpen, onCancel: close, onConfirm: onRemoveAll, title: t('Are you sure you want to remove all items from your cart?') }))] }));
26
+ jsx("li", { className: styles.item, children: child }, index))) })] }), onRemoveAll && (jsx(ConfirmationDialog, { isOpen: isOpen, onCancel: close, onConfirm: () => {
27
+ close();
28
+ onRemoveAll();
29
+ }, title: t('Are you sure you want to remove all items from your cart?') }))] }));
27
30
  }
28
31
 
29
32
  export { OrderLineList };
@@ -15,4 +15,4 @@ export interface ModalProps {
15
15
  onOpenChange?: (isOpen: boolean) => void;
16
16
  shouldCloseOnInteractOutside?: boolean;
17
17
  }
18
- export declare function Modal({ children, className, hasCloseButton, isDismissable, isFullScreen, isKeyboardDismissDisabled, isOpen, onOpenChange, shouldCloseOnInteractOutside, }: ModalProps): import("react/jsx-runtime").JSX.Element | undefined;
18
+ export declare function Modal({ children, className, hasCloseButton, isDismissable, isFullScreen, isKeyboardDismissDisabled, isOpen, onOpenChange, shouldCloseOnInteractOutside, }: ModalProps): import("react/jsx-runtime").JSX.Element;
@@ -7,28 +7,9 @@ import { useFormattedMessage } from '../../intl/use-formatted-message.js';
7
7
  import resetStyles from '../../shared/reset.module.css.js';
8
8
  import styles from './modal.module.css.js';
9
9
 
10
- const getDocument = () => typeof window === 'undefined' ? undefined : window.document;
11
10
  function Modal({ children, className, hasCloseButton, isDismissable, isFullScreen, isKeyboardDismissDisabled, isOpen, onOpenChange, shouldCloseOnInteractOutside = true, }) {
12
11
  const t = useFormattedMessage();
13
- const document = getDocument();
14
- if (!document)
15
- return;
16
- return (jsx(ModalOverlay, { ref: ref => {
17
- ref?.addEventListener('click', e => {
18
- if ((!e.target || ref.contains(e.target)) &&
19
- ref !== e.target)
20
- return;
21
- e.preventDefault();
22
- e.stopPropagation();
23
- });
24
- ref?.addEventListener('touchend', e => {
25
- if ((!e.target || ref.contains(e.target)) &&
26
- ref !== e.target)
27
- return;
28
- e.preventDefault();
29
- e.stopPropagation();
30
- });
31
- }, className: clsx(styles['modal-overlay'], resetStyles.reset, typeof className === 'string' ? className : className?.overlay), isDismissable: isDismissable, isKeyboardDismissDisabled: isKeyboardDismissDisabled, isOpen: isOpen, onOpenChange: onOpenChange, shouldCloseOnInteractOutside: () => shouldCloseOnInteractOutside, UNSTABLE_portalContainer: document.body, children: jsxs(Modal$1, { className: clsx(styles.modal, {
12
+ return (jsx(ModalOverlay, { className: clsx(styles['modal-overlay'], resetStyles.reset, typeof className === 'string' ? className : className?.overlay), isDismissable: isDismissable, isKeyboardDismissDisabled: isKeyboardDismissDisabled, isOpen: isOpen, onOpenChange: onOpenChange, shouldCloseOnInteractOutside: () => shouldCloseOnInteractOutside, children: jsxs(Modal$1, { className: clsx(styles.modal, {
32
13
  [styles['is-full-screen']]: isFullScreen,
33
14
  }, typeof className === 'string' ? undefined : className?.modal), children: [hasCloseButton && (jsx(IconButton, { className: styles.close, icon: "Close", isDisabled: !isDismissable, label: t('Close'), onClick: () => onOpenChange?.(false), theme: "secondary" })), jsx("div", { className: clsx(styles.content, typeof className === 'string' ? className : className?.content), children: children })] }) }));
34
15
  }
@@ -52,7 +52,10 @@ function SignInPage({ returnUrl } = {}) {
52
52
  setIsSuccess(true);
53
53
  navigate(returnUrl || paths.HOME, { reload: true });
54
54
  };
55
- const allowGuestSignIn = returnUrl?.toLowerCase() === paths.CHECKOUT_SHIPPING.toLowerCase();
55
+ const decodedReturnUrl = returnUrl
56
+ ? decodeURIComponent(returnUrl).toLowerCase()
57
+ : undefined;
58
+ const allowGuestSignIn = !!decodedReturnUrl?.includes(paths.CHECKOUT_SHIPPING.toLowerCase());
56
59
  const createAccountPath = `${paths.ACCOUNT_CREATE}${returnUrl ? `?returnUrl=${encodeURIComponent(returnUrl)}` : ''}`;
57
60
  const onSignIn = ({ data }) => {
58
61
  resetSignIn();
@@ -11,8 +11,6 @@ import { CheckoutPageLayout } from '../layouts/checkout-page-layout/checkout-pag
11
11
  import { Page } from '../../components/page/page.js';
12
12
  import { ErrorPage } from '../../error-page/error-page.js';
13
13
  import { LoadingPage } from '../../loading-page/loading-page.js';
14
- import { useSaveCartForLater } from '../../../shared/api/bff/hooks/cart/use-save-cart-for-later.js';
15
- import { useIsAuthenticated } from '../../../shared/api/storefront/hooks/authentication/use-is-authenticated.js';
16
14
  import { useDeleteCartLineById } from '../../../shared/api/storefront/hooks/cart/use-delete-cart-line-by-id.js';
17
15
  import { useDeleteCurrentCart } from '../../../shared/api/storefront/hooks/cart/use-delete-current-cart.js';
18
16
  import { useFetchCurrentCartLinesWithAtp } from '../../../shared/api/storefront/hooks/cart/use-fetch-current-cart-lines-with-atp.js';
@@ -27,22 +25,22 @@ function CartContent({ cartLines }) {
27
25
  const paths = usePaths();
28
26
  const { addToast } = useToast();
29
27
  const { data: currentCart } = useFetchCurrentCartWithAtp();
30
- const saveCartForLater = useSaveCartForLater({
31
- onError: () => {
32
- addToast({
33
- body: jsx(FormattedMessage, { id: "Unable to save cart for later." }),
34
- isUserDismissable: false,
35
- messageType: 'danger',
36
- });
37
- },
38
- onSuccess: () => {
39
- addToast({
40
- body: jsx(FormattedMessage, { id: "Saved cart for later." }),
41
- isUserDismissable: false,
42
- messageType: 'success',
43
- });
44
- },
45
- });
28
+ // const saveCartForLater = useSaveCartForLater({
29
+ // onError: () => {
30
+ // addToast({
31
+ // body: <FormattedMessage id="Unable to save cart for later." />,
32
+ // isUserDismissable: false,
33
+ // messageType: 'danger',
34
+ // })
35
+ // },
36
+ // onSuccess: () => {
37
+ // addToast({
38
+ // body: <FormattedMessage id="Saved cart for later." />,
39
+ // isUserDismissable: false,
40
+ // messageType: 'success',
41
+ // })
42
+ // },
43
+ // })
46
44
  const deleteCurrentCart = useDeleteCurrentCart({
47
45
  onError: () => {
48
46
  addToast({
@@ -75,7 +73,7 @@ function CartContent({ cartLines }) {
75
73
  });
76
74
  },
77
75
  });
78
- const isAuthenticated = useIsAuthenticated();
76
+ // const isAuthenticated = useIsAuthenticated()
79
77
  if (!currentCart)
80
78
  return null;
81
79
  const currencyCode = getCurrencyCodeBySymbol(currentCart.currencySymbol);
@@ -83,9 +81,25 @@ function CartContent({ cartLines }) {
83
81
  throw new Error(`Currency code not found for symbol ${currentCart.currencySymbol}`);
84
82
  return (jsx(CheckoutPageLayout, { actions: {
85
83
  primary: (jsx(Button, { withArrow: true, "data-test-selector": "checkoutShippingCartTotalContinueButton", href: paths.CHECKOUT_SHIPPING, children: jsx(FormattedMessage, { id: "Start checkout" }) })),
86
- secondary: isAuthenticated ? (jsx(Button, { color: "secondary", "data-test-selector": "saveCartForLaterButton", onClick: () => {
87
- saveCartForLater.mutate({ cart: currentCart });
88
- }, variant: "outline", children: jsx(FormattedMessage, { id: "Save order" }) })) : (jsx(Button, { color: "secondary", "data-test-selector": "saveCartForLaterButton", href: paths.SIGN_IN, variant: "outline", children: jsx(FormattedMessage, { id: "Save order" }) })),
84
+ // secondary: isAuthenticated ? (
85
+ // <Button
86
+ // color="secondary"
87
+ // data-test-selector="saveCartForLaterButton"
88
+ // onClick={() => {
89
+ // saveCartForLater.mutate({ cart: currentCart })
90
+ // }}
91
+ // variant="outline">
92
+ // <FormattedMessage id="Save order" />
93
+ // </Button>
94
+ // ) : (
95
+ // <Button
96
+ // color="secondary"
97
+ // data-test-selector="saveCartForLaterButton"
98
+ // href={paths.SIGN_IN}
99
+ // variant="outline">
100
+ // <FormattedMessage id="Save order" />
101
+ // </Button>
102
+ // ),
89
103
  }, mobileSummary: jsx(CartTotalsSummary, { currencyCode: currencyCode, totalAmount: currentCart.orderGrandTotal }), overview: jsx(CartTotals, { currencyCode: currencyCode, shippingCost: currentCart.shippingAndHandling, subtotal: currentCart.orderSubTotal, tax: currentCart.totalTax, total: currentCart.orderGrandTotal, vatPercentage: cartLines[0]?.pricing?.vatRate || 0 }), children: jsx(OrderLineList, { onRemoveAll: () => deleteCurrentCart.mutate(), children: cartLines.map(cartLine => (jsx(ConnectedOrderLineCard, { deliveryDate: cartLine.atp?.date ?? null, href: cartLine.productUri, image: {
90
104
  fit: 'contain',
91
105
  image: {
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsxs, jsx } from 'react/jsx-runtime';
3
- import { useRef, useState, useEffect, useCallback } from 'react';
3
+ import { useRef, useState, useEffect, useMemo, useCallback } from 'react';
4
4
  import { Form } from 'react-aria-components';
5
5
  import { useAlgoliaInsights } from '../../../../algolia/use-algolia-insights.js';
6
6
  import { Accordion } from '../../../../collapsables/accordion/accordion.js';
@@ -57,16 +57,29 @@ function Payment({ atp, cart: _cart, form, isProcessing, onError: _onError, onPa
57
57
  cartRef.current = _cart;
58
58
  }, [_cart]);
59
59
  const [validationErrors, setValidationErrors] = useState({});
60
- const atpSelectOptions = atp
60
+ const atpSelectOptions = useMemo(() => atp
61
61
  .filter(atp => Boolean(atp.date))
62
62
  .reduce((acc, atp) => ({
63
63
  ...acc,
64
64
  [atp.date || '']: atp.displayDate,
65
- }), {});
66
- const paymentMethodOptions = cart.paymentOptions?.paymentMethods?.reduce((acc, method) => {
65
+ }), {}), [atp]);
66
+ const paymentMethodOptions = useMemo(() => cart.paymentOptions?.paymentMethods?.reduce((acc, method) => {
67
67
  acc[method.name] = t(`paymentMethod.${method.description}`);
68
68
  return acc;
69
- }, {});
69
+ }, {}), [cart.paymentOptions?.paymentMethods, t]);
70
+ const industryOptions = useMemo(() => ({
71
+ /* eslint-disable sort-keys-fix/sort-keys-fix */
72
+ PP: t('industry.PP'),
73
+ AU: t('industry.AU'),
74
+ MC: t('industry.MC'),
75
+ BC: t('industry.BC'),
76
+ TR: t('industry.TR'),
77
+ AG: t('industry.AG'),
78
+ AV: t('industry.AV'),
79
+ MA: t('industry.MA'),
80
+ OT: t('industry.OT'),
81
+ /* eslint-enable sort-keys-fix/sort-keys-fix */
82
+ }), [t]);
70
83
  const onPlaceOrderCompleted = useCallback(({ cart, payment_type }) => {
71
84
  dataLayer.push(createEcommerceEvent({
72
85
  cart,
@@ -231,19 +244,7 @@ function Payment({ atp, cart: _cart, form, isProcessing, onError: _onError, onPa
231
244
  setAsSoonAsPossible(checked);
232
245
  if (checked)
233
246
  setDeliveryDate('');
234
- }, children: t('As soon as possible') }), jsx(InfoIconTooltip, { size: "sm", 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, showLabel: true, "data-test-selector": "industrySelect", defaultSelectedOption: cart.properties.industry, isDisabled: isDisabled, label: t('Industry'), name: "industry", options: {
235
- /* eslint-disable sort-keys-fix/sort-keys-fix */
236
- PP: t('industry.PP'),
237
- AU: t('industry.AU'),
238
- MC: t('industry.MC'),
239
- BC: t('industry.BC'),
240
- TR: t('industry.TR'),
241
- AG: t('industry.AG'),
242
- AV: t('industry.AV'),
243
- MA: t('industry.MA'),
244
- OT: t('industry.OT'),
245
- /* eslint-enable sort-keys-fix/sort-keys-fix */
246
- }, placeholder: t('Select an industry'), variant: "solid" }), jsx(TextField, { showLabel: true, defaultValue: cart.customerVatNumber, isDisabled: isDisabled, label: t('VAT Number'), minLength: 8, name: "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: isProductionEnvironment ? 'live' : 'test', isDisabled: isDisabled, onComplete: onComplete, onError: onError, orderAmount: cart.orderGrandTotal, returnUrl:
247
+ }, children: t('As soon as possible') }), jsx(InfoIconTooltip, { size: "sm", 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, showLabel: true, "data-test-selector": "industrySelect", defaultSelectedOption: cart.properties.industry || 'AU', isDisabled: isDisabled, label: t('Industry'), name: "industry", options: industryOptions, placeholder: t('Select an industry'), variant: "solid" }), jsx(TextField, { showLabel: true, defaultValue: cart.customerVatNumber, isDisabled: isDisabled, label: t('VAT Number'), minLength: 8, name: "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: isProductionEnvironment ? 'live' : 'test', isDisabled: isDisabled, onComplete: onComplete, onError: onError, orderAmount: cart.orderGrandTotal, returnUrl:
247
248
  /* eslint-disable ssr-friendly/no-dom-globals-in-react-fc */
248
249
  typeof window === 'undefined'
249
250
  ? ''
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonic-equipment/ui",
3
- "version": "260.0.5",
3
+ "version": "260.0.7",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "engines": {