@sonic-equipment/ui 131.0.0 → 133.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 (89) hide show
  1. package/dist/address/address.d.ts +2 -13
  2. package/dist/buttons/add-to-cart-button/add-to-cart-button.js +1 -1
  3. package/dist/buttons/add-to-cart-button/connected-add-to-cart-button.js +1 -1
  4. package/dist/buttons/button/button.js +2 -1
  5. package/dist/cart-totals/cart-totals.d.ts +2 -1
  6. package/dist/cart-totals/cart-totals.js +2 -2
  7. package/dist/delivery-time/delivery-time.js +6 -5
  8. package/dist/display/info-display/info-display.d.ts +7 -0
  9. package/dist/display/info-display/info-display.js +8 -0
  10. package/dist/display/info-display/info-display.module.css.js +3 -0
  11. package/dist/exports.d.ts +13 -5
  12. package/dist/forms/input/input.d.ts +1 -0
  13. package/dist/forms/input/input.js +5 -3
  14. package/dist/forms/input/input.module.css.js +1 -1
  15. package/dist/forms/switch/switch.d.ts +2 -1
  16. package/dist/forms/switch/switch.js +2 -2
  17. package/dist/forms/text-field/password-reveal-toggle/password-reveal-toggle.d.ts +10 -0
  18. package/dist/forms/text-field/password-reveal-toggle/password-reveal-toggle.js +18 -0
  19. package/dist/forms/text-field/password-reveal-toggle/password-reveal-toggle.module.css.js +3 -0
  20. package/dist/forms/text-field/text-field.d.ts +3 -3
  21. package/dist/forms/text-field/text-field.js +9 -2
  22. package/dist/icons/stroke/stroke-dehashed-icon.js +7 -0
  23. package/dist/icons/stroke/stroke-hashed-icon.js +7 -0
  24. package/dist/index.js +14 -6
  25. package/dist/intl/translation-id.d.ts +1 -1
  26. package/dist/pages/checkout/cart-page/cart-page.js +6 -9
  27. package/dist/pages/checkout/cart-page/components/empty-cart-page.d.ts +1 -0
  28. package/dist/pages/checkout/cart-page/components/empty-cart-page.js +11 -0
  29. package/dist/pages/checkout/components/billing-and-invoice-information.d.ts +7 -0
  30. package/dist/pages/checkout/components/billing-and-invoice-information.js +12 -0
  31. package/dist/pages/checkout/components/billing-and-invoice-information.module.css.js +3 -0
  32. package/dist/pages/checkout/constants.d.ts +8 -0
  33. package/dist/pages/checkout/constants.js +10 -0
  34. package/dist/pages/checkout/layouts/checkout-page-layout/components/checkout-page-section.module.css.js +1 -1
  35. package/dist/pages/checkout/order-confirmation-page/order-confirmation-page.d.ts +4 -0
  36. package/dist/pages/checkout/order-confirmation-page/order-confirmation-page.js +115 -0
  37. package/dist/pages/checkout/order-confirmation-page/order-confirmation-page.module.css.js +3 -0
  38. package/dist/{checkout → pages/checkout/payment-page/components}/adyen-payment.js +5 -5
  39. package/dist/pages/checkout/payment-page/components/adyen-payment.module.css.js +3 -0
  40. package/dist/{checkout → pages/checkout/payment-page/components}/payment.d.ts +4 -2
  41. package/dist/pages/checkout/payment-page/components/payment.js +243 -0
  42. package/dist/pages/checkout/payment-page/components/payment.module.css.js +3 -0
  43. package/dist/pages/checkout/payment-page/payment-page.js +18 -11
  44. package/dist/{checkout → pages/checkout/payment-page/utils}/parse-amount.js +1 -1
  45. package/dist/pages/checkout/shipping-page/components/edit-address.js +8 -4
  46. package/dist/pages/checkout/shipping-page/hooks/use-patch-shipping-details.d.ts +12 -0
  47. package/dist/pages/checkout/shipping-page/hooks/use-patch-shipping-details.js +21 -0
  48. package/dist/pages/checkout/shipping-page/shipping-page.js +45 -59
  49. package/dist/pages/checkout/shipping-page/shipping-page.module.css.js +1 -1
  50. package/dist/pages/components/page/page.d.ts +3 -2
  51. package/dist/pages/components/page/page.js +3 -2
  52. package/dist/pages/components/page-meta-data/page-meta-data.d.ts +3 -4
  53. package/dist/pages/components/page-meta-data/page-meta-data.js +2 -2
  54. package/dist/pages/product/product-details-page/product-details-page.js +2 -10
  55. package/dist/pages/product/product-details-page/product-details.js +10 -4
  56. package/dist/pages/product/product-listing-page/product-listing-page-data-types.d.ts +1 -1
  57. package/dist/pages/product/product-listing-page/product-listing-page.js +2 -10
  58. package/dist/pages/product/product-listing-page/product-listing.js +8 -1
  59. package/dist/pages/product/search-result-page/search-results-page.js +4 -7
  60. package/dist/shared/api/bff/model/bff.model.d.ts +4 -4
  61. package/dist/shared/api/bff/services/bff-service.js +1 -4
  62. package/dist/shared/api/storefront/hooks/cart/use-fetch-cart-by-id.d.ts +8 -0
  63. package/dist/shared/api/storefront/hooks/cart/use-fetch-cart-by-id.js +20 -0
  64. package/dist/shared/api/storefront/hooks/cart/use-fetch-current-cart-count.d.ts +1 -1
  65. package/dist/shared/api/storefront/hooks/cart/use-fetch-current-cart-count.js +3 -3
  66. package/dist/shared/api/storefront/hooks/cart/use-fetch-current-cart.d.ts +2 -5
  67. package/dist/shared/api/storefront/hooks/cart/use-fetch-current-cart.js +3 -16
  68. package/dist/shared/api/storefront/hooks/cart/use-patch-cart.js +11 -8
  69. package/dist/shared/api/storefront/hooks/cart/use-place-order.js +2 -2
  70. package/dist/shared/api/storefront/hooks/customer/use-patch-bill-to-address.d.ts +3 -1
  71. package/dist/shared/api/storefront/hooks/customer/use-patch-bill-to-address.js +3 -1
  72. package/dist/shared/ga/use-data-layer.js +1 -1
  73. package/dist/shared/model/address.d.ts +13 -0
  74. package/dist/shared/providers/react-query-container.d.ts +2 -1
  75. package/dist/shared/providers/react-query-container.js +2 -2
  76. package/dist/shared/utils/date.d.ts +2 -0
  77. package/dist/shared/utils/date.js +11 -1
  78. package/dist/styles.css +331 -261
  79. package/dist/tooltip/tooltip.js +10 -5
  80. package/package.json +4 -5
  81. package/dist/checkout/adyen-payment.module.css.js +0 -3
  82. package/dist/checkout/payment.js +0 -186
  83. package/dist/checkout/payment.module.css.js +0 -3
  84. /package/dist/{checkout → pages/checkout/payment-page/components}/adyen-payment.d.ts +0 -0
  85. /package/dist/{checkout → pages/checkout/payment-page/hooks}/use-get-adyen-redirect-result.d.ts +0 -0
  86. /package/dist/{checkout → pages/checkout/payment-page/hooks}/use-get-adyen-redirect-result.js +0 -0
  87. /package/dist/{checkout → pages/checkout/payment-page/hooks}/use-has-returned-from-adyen.d.ts +0 -0
  88. /package/dist/{checkout → pages/checkout/payment-page/hooks}/use-has-returned-from-adyen.js +0 -0
  89. /package/dist/{checkout → pages/checkout/payment-page/utils}/parse-amount.d.ts +0 -0
@@ -0,0 +1,10 @@
1
+ const CHECKOUT_PATHS = {
2
+ CART: '/cart',
3
+ CHECKOUT_SHIPPING: '/CheckoutShipping',
4
+ CHECKOUT_SHIPPING_VIA_SIGNIN: '/signin?returnUrl=/CheckoutShipping',
5
+ HOME: '/',
6
+ ORDER_CONFIRMATION: '/OrderConfirmation',
7
+ REVIEW_AND_SUBMIT: '/CheckoutReviewAndSubmit',
8
+ };
9
+
10
+ export { CHECKOUT_PATHS };
@@ -1,3 +1,3 @@
1
- var styles = {"section":"checkout-page-section-module-zyovs","has-border":"checkout-page-section-module-pe5iL","section-header":"checkout-page-section-module-lcEdH","section-content":"checkout-page-section-module-ZkhMj","stretch":"checkout-page-section-module-24DRv","section-link":"checkout-page-section-module-l508k"};
1
+ var styles = {"section":"checkout-page-section-module-zyovs","has-border":"checkout-page-section-module-pe5iL","section-header":"checkout-page-section-module-lcEdH","section-link":"checkout-page-section-module-l508k","section-content":"checkout-page-section-module-ZkhMj","stretch":"checkout-page-section-module-24DRv"};
2
2
 
3
3
  export { styles as default };
@@ -0,0 +1,4 @@
1
+ export interface OrderConfirmationPageProps {
2
+ cartId: string;
3
+ }
4
+ export declare function OrderConfirmationPage({ cartId }: OrderConfirmationPageProps): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,115 @@
1
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
+ import { useEffect } from 'react';
3
+ import { PrintButton } from '../../../buttons/print-button/print-button.js';
4
+ import { OrderLineCard } from '../../../cards/orderline-card/orderline-card.js';
5
+ import { CartTotals } from '../../../cart-totals/cart-totals.js';
6
+ import { InfoDisplay } from '../../../display/info-display/info-display.js';
7
+ import { FormattedMessage } from '../../../intl/formatted-message.js';
8
+ import { useCultureCode } from '../../../intl/use-culture-code.js';
9
+ import { useFormattedMessage } from '../../../intl/use-formatted-message.js';
10
+ import { OrderLineList } from '../../../lists/orderline-list/orderline-list.js';
11
+ import { LoadingPage } from '../../loading-page/loading-page.js';
12
+ import { useIsAuthenticated } from '../../../shared/api/storefront/hooks/authentication/use-is-authenticated.js';
13
+ import { useFetchCartById } from '../../../shared/api/storefront/hooks/cart/use-fetch-cart-by-id.js';
14
+ import { useSaveCartForLater } from '../../../shared/api/storefront/hooks/cart/use-save-cart-for-later.js';
15
+ import { RouteButton } from '../../../shared/routing/route-button.js';
16
+ import { useNavigate } from '../../../shared/routing/route-provider.js';
17
+ import { formatDateToLocaleString } from '../../../shared/utils/date.js';
18
+ import { hasNo } from '../../../shared/utils/types.js';
19
+ import { useToast } from '../../../toast/use-toast.js';
20
+ import { Page } from '../../components/page/page.js';
21
+ import { ErrorPage } from '../../error-page/error-page.js';
22
+ import { BillingAndInvoiceInformation } from '../components/billing-and-invoice-information.js';
23
+ import { CHECKOUT_PATHS } from '../constants.js';
24
+ import { CheckoutPageLayout } from '../layouts/checkout-page-layout/checkout-page-layout.js';
25
+ import { CheckoutPageSection } from '../layouts/checkout-page-layout/components/checkout-page-section.js';
26
+ import { CheckoutPageSectionContent } from '../layouts/checkout-page-layout/components/checkout-page-section-content.js';
27
+ import styles from './order-confirmation-page.module.css.js';
28
+
29
+ function OrderConfirmationPage({ cartId }) {
30
+ const isAuthenticated = useIsAuthenticated();
31
+ const t = useFormattedMessage();
32
+ const cultureCode = useCultureCode();
33
+ const { addToast } = useToast();
34
+ const { isNavigating, navigate } = useNavigate();
35
+ const { data: cart, error, isLoading: cartIsLoading, } = useFetchCartById({
36
+ id: cartId,
37
+ });
38
+ useEffect(() => {
39
+ if (!cart)
40
+ return;
41
+ if (isAuthenticated === undefined)
42
+ return;
43
+ if (!isAuthenticated)
44
+ return navigate(CHECKOUT_PATHS.CART);
45
+ if (cart.status === 'Cart')
46
+ navigate(CHECKOUT_PATHS.CART);
47
+ }, [cart, navigate, isAuthenticated]);
48
+ const saveCartForLater = useSaveCartForLater({
49
+ onError: () => {
50
+ addToast({
51
+ body: jsx(FormattedMessage, { id: "Unable to save cart for later." }),
52
+ isUserDismissable: false,
53
+ messageType: 'danger',
54
+ });
55
+ },
56
+ onSuccess: () => {
57
+ addToast({
58
+ body: jsx(FormattedMessage, { id: "Saved cart for later." }),
59
+ isUserDismissable: false,
60
+ messageType: 'success',
61
+ });
62
+ },
63
+ });
64
+ if (error)
65
+ return jsx(ErrorPage, { error: error });
66
+ if (cartIsLoading || isNavigating)
67
+ return jsx(LoadingPage, {});
68
+ if (!isAuthenticated ||
69
+ hasNo(cart) ||
70
+ hasNo(cart.cartLines) ||
71
+ cart.cartLines.length === 0) {
72
+ return null;
73
+ }
74
+ return (jsx(Page, { breadCrumb: [{ href: CHECKOUT_PATHS.HOME, label: t('Home') }], title: t('Order confirmation'), children: jsx(CheckoutPageLayout, { actions: {
75
+ primary: (jsx(RouteButton, { withArrow: true, "data-test-selector": "checkoutShippingCartTotalContinueButton", href: "/", children: jsx(FormattedMessage, { id: "Continue shopping" }) })),
76
+ secondary: (jsxs(Fragment, { children: [cart.canSaveOrder && (jsx(RouteButton, { color: "secondary", onClick: () => {
77
+ saveCartForLater.mutate({ cart });
78
+ }, variant: "outline", children: jsx(FormattedMessage, { id: "Save order" }) })), jsx(PrintButton, {})] })),
79
+ }, overview: jsx(CartTotals, { fulfillmentMethod: t(`fulfillmentmethod.${cart.fulfillmentMethod}`), orderNumber: cart.orderNumber, shippingCost: cart.shippingAndHandlingDisplay, subtotal: cart.orderSubTotalDisplay, tax: cart.totalTaxDisplay, total: cart.orderGrandTotalDisplay, vatPercentage: cart.cartLines[0]?.pricing?.vatRate }), children: jsxs("div", { children: [jsx(CheckoutPageSection, { hasBorder: false, title: t('General'), children: jsx(CheckoutPageSectionContent, { children: jsxs("div", { className: styles['general-order-info'], children: [cart.orderDate && (jsx(InfoDisplay, { id: "order-date", label: t('Order date'), value: formatDateToLocaleString(new Date(cart.orderDate), cultureCode) })), cart.requestedDeliveryDate && (jsx(InfoDisplay, { id: "requested-delivery-date", label: t('Requested delivery date'), value: formatDateToLocaleString(new Date(cart.requestedDeliveryDate), cultureCode) })), cart.poNumber && (jsx(InfoDisplay, { id: "po-number", label: t('PO Number'), value: cart.poNumber }))] }) }) }), jsx(CheckoutPageSection, { hasBorder: false, title: t('Billing and shipping information'), children: jsx(CheckoutPageSectionContent, { children: jsx(BillingAndInvoiceInformation, { billToAddress: {
80
+ address1: cart.billTo?.address1,
81
+ address2: cart.billTo?.address2,
82
+ address3: cart.billTo?.address3,
83
+ city: cart.billTo?.city,
84
+ companyName: cart.billTo?.companyName,
85
+ country: cart.billTo?.country?.name,
86
+ email: cart.billTo?.email,
87
+ phone: cart.billTo?.phone,
88
+ postalCode: cart.billTo?.postalCode,
89
+ }, shipToAddress: {
90
+ address1: cart.shipTo?.address1,
91
+ address2: cart.shipTo?.address2,
92
+ address3: cart.shipTo?.address3,
93
+ city: cart.shipTo?.city,
94
+ companyName: cart.shipTo?.companyName,
95
+ country: cart.shipTo?.country?.name,
96
+ email: cart.shipTo?.email,
97
+ phone: cart.shipTo?.phone,
98
+ postalCode: cart.shipTo?.postalCode,
99
+ } }) }) }), jsx(CheckoutPageSection, { hasBorder: false, title: t('Order'), children: jsx(CheckoutPageSectionContent, { stretch: true, children: jsx(OrderLineList, { children: cart.cartLines.map(cartLine => (jsx(OrderLineCard, { deliveryDate: cartLine.atp?.date, href: cartLine.productUri, image: {
100
+ fit: 'contain',
101
+ image: {
102
+ '1': cartLine.smallImagePath,
103
+ '2': cartLine.smallImagePath,
104
+ '3': cartLine.smallImagePath,
105
+ altText: cartLine.altText,
106
+ },
107
+ title: cartLine.altText,
108
+ }, isReadonly: true, price: {
109
+ originalTotalPrice: cartLine.pricing?.extendedUnitNetPrice || 0,
110
+ pricePerUnit: cartLine.pricing?.unitNetPrice || 0,
111
+ totalPrice: cartLine.pricing?.extendedUnitNetPrice || 0,
112
+ }, productId: cartLine.productId || '', quantity: cartLine.qtyOrdered || 1, sku: cartLine.erpNumber || '', tags: [], title: cartLine.productName }, cartLine.id))) }) }) })] }) }) }));
113
+ }
114
+
115
+ export { OrderConfirmationPage };
@@ -0,0 +1,3 @@
1
+ var styles = {"general-order-info":"order-confirmation-page-module-UvVzH"};
2
+
3
+ export { styles as default };
@@ -3,11 +3,11 @@ import { useRef, useEffect } from 'react';
3
3
  import AdyenCheckout from '@adyen/adyen-web';
4
4
  import clsx from 'clsx';
5
5
  import qs from 'query-string';
6
- import { useCultureCode } from '../intl/use-culture-code.js';
7
- import { useCreateAdyenSession } from '../shared/api/storefront/hooks/payment/use-create-adyen-session.js';
8
- import { useFetchAdyenConfig } from '../shared/api/storefront/hooks/payment/use-fetch-adyen-config.js';
9
- import { getAdyenPaymentDetails, postAdyenPayment } from '../shared/api/storefront/services/cart-service.js';
10
- import { parseAmount } from './parse-amount.js';
6
+ import { useCultureCode } from '../../../../intl/use-culture-code.js';
7
+ import { useCreateAdyenSession } from '../../../../shared/api/storefront/hooks/payment/use-create-adyen-session.js';
8
+ import { useFetchAdyenConfig } from '../../../../shared/api/storefront/hooks/payment/use-fetch-adyen-config.js';
9
+ import { getAdyenPaymentDetails, postAdyenPayment } from '../../../../shared/api/storefront/services/cart-service.js';
10
+ import { parseAmount } from '../utils/parse-amount.js';
11
11
  import styles from './adyen-payment.module.css.js';
12
12
 
13
13
  function AdyenPayment({ amount, cartId, countryCode, currencyCode, customerId, dropinRef, environment, onComplete, onError, orderAmount, returnUrl, }) {
@@ -0,0 +1,3 @@
1
+ var styles = {"loading":"adyen-payment-module-rV-qW"};
2
+
3
+ export { styles as default };
@@ -1,10 +1,12 @@
1
- import { AdyenPaymentModel, CartModel, CheckoutAtpEntry } from '../shared/api/storefront/model/storefront.model';
1
+ import { AdyenPaymentModel, CartModel, CheckoutAtpEntry } from '../../../../shared/api/storefront/model/storefront.model';
2
2
  export declare function Payment({ atp, cart: _cart, form, onError: _onError, onPaymentComplete, onProcessing, onValidating, }: {
3
3
  atp: CheckoutAtpEntry[];
4
4
  cart: CartModel;
5
5
  form: string;
6
6
  onError?: (error: unknown, result: AdyenPaymentModel | null) => void;
7
- onPaymentComplete: () => void;
7
+ onPaymentComplete: ({ cartId }: {
8
+ cartId: string;
9
+ }) => void;
8
10
  onProcessing: (processing: boolean) => void;
9
11
  onValidating: (validating: boolean) => void;
10
12
  }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,243 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import { useRef, useState, useMemo, useEffect, useCallback } from 'react';
3
+ import { Form } from 'react-aria-components';
4
+ import { Accordion } from '../../../../collapsables/accordion/accordion.js';
5
+ import { AccordionItem } from '../../../../collapsables/accordion/accordion-item.js';
6
+ import { config } from '../../../../config.js';
7
+ import { InfoDisplay } from '../../../../display/info-display/info-display.js';
8
+ import { Checkbox } from '../../../../forms/checkbox/checkbox.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 { usePatchSession } from '../../../../shared/api/storefront/hooks/authentication/use-patch-session.js';
14
+ import { usePatchCart } from '../../../../shared/api/storefront/hooks/cart/use-patch-cart.js';
15
+ import { usePlaceOrder } from '../../../../shared/api/storefront/hooks/cart/use-place-order.js';
16
+ import { useInvalidateAdyen } from '../../../../shared/api/storefront/hooks/payment/use-invalidate-adyen.js';
17
+ import { validateVATNumber } from '../../../../shared/api/storefront/services/finance-service.js';
18
+ import { useDebouncedCallback } from '../../../../shared/hooks/use-debounced-callback.js';
19
+ import { currencySymbolToISO } from '../../../../shared/model/currency.js';
20
+ import { Tooltip } from '../../../../tooltip/tooltip.js';
21
+ import { BillingAndInvoiceInformation } from '../../components/billing-and-invoice-information.js';
22
+ import { useHasReturnedFromAdyen } from '../hooks/use-has-returned-from-adyen.js';
23
+ import { AdyenPayment } from './adyen-payment.js';
24
+ import styles from './payment.module.css.js';
25
+
26
+ function Payment({ atp, cart: _cart, form, onError: _onError, onPaymentComplete, onProcessing, onValidating, }) {
27
+ const { isLoading: isPatchingCart, mutate: patchCart } = usePatchCart();
28
+ const { isLoading: isPatchingSession } = usePatchSession();
29
+ const { isLoading: isPlacingCart, mutate: placeOrder } = usePlaceOrder();
30
+ const dropinRef = useRef(null);
31
+ const [paymentError, setPaymentError] = useState();
32
+ const [apiError, setAPIError] = useState();
33
+ const invalidateAdyen = useInvalidateAdyen();
34
+ const [isValidatingVAT, setIsValidatingVAT] = useState(false);
35
+ const t = useFormattedMessage();
36
+ const cartRef = useRef(_cart);
37
+ const cart = cartRef.current;
38
+ const hasAtp = atp.length > 1;
39
+ const [asSoonAsPossible, setAsSoonAsPossible] = useState(!hasAtp);
40
+ const [deliveryDate, setDeliveryDate] = useState(cart.requestedDeliveryDateDisplay?.toString() || '');
41
+ const [selectedPaymentMethod, setSelectedPaymentMethod] = useState(cart.paymentOptions?.paymentMethods?.[0]?.name || 'ADY');
42
+ const countryCode = _cart.billTo?.country?.abbreviation;
43
+ const isAdyenPayment = selectedPaymentMethod === 'ADY' &&
44
+ cart.paymentOptions &&
45
+ cart.billTo?.id &&
46
+ countryCode;
47
+ const hasReturnedFromAdyen = useHasReturnedFromAdyen();
48
+ const isProcessing = useMemo(() => hasReturnedFromAdyen || isPlacingCart, [isPlacingCart, hasReturnedFromAdyen]);
49
+ useEffect(() => {
50
+ cartRef.current = _cart;
51
+ }, [_cart]);
52
+ useEffect(() => {
53
+ onValidating(isValidatingVAT || isPatchingSession);
54
+ }, [isPatchingSession, isValidatingVAT, onValidating]);
55
+ useEffect(() => {
56
+ onProcessing(isPatchingCart);
57
+ }, [isPatchingCart, onProcessing]);
58
+ useEffect(() => {
59
+ onProcessing(isProcessing);
60
+ }, [isProcessing, onProcessing]);
61
+ const [validationErrors, setValidationErrors] = useState({});
62
+ const atpSelectOptions = atp
63
+ .filter(atp => Boolean(atp.date))
64
+ .reduce((acc, atp) => ({
65
+ ...acc,
66
+ [atp.date || '']: atp.displayDate,
67
+ }), {});
68
+ const paymentMethodOptions = cart.paymentOptions?.paymentMethods?.reduce((acc, method) => {
69
+ acc[method.name] = t(`paymentMethod.${method.description}`);
70
+ return acc;
71
+ }, {});
72
+ const debouncedValidator = useDebouncedCallback(async (value) => {
73
+ if (!value)
74
+ return setValidationErrors({});
75
+ if (value.length < 8) {
76
+ return setValidationErrors({
77
+ ...validationErrors,
78
+ vatNumber: t('validation.tooShort'),
79
+ });
80
+ }
81
+ try {
82
+ setIsValidatingVAT(true);
83
+ const response = await validateVATNumber({ vatNumber: value });
84
+ if (response.isValid) {
85
+ setValidationErrors(prev => {
86
+ delete prev.vatNumber;
87
+ return prev;
88
+ });
89
+ }
90
+ else {
91
+ setValidationErrors({
92
+ ...validationErrors,
93
+ vatNumber: t('validation.invalid'),
94
+ });
95
+ }
96
+ }
97
+ catch {
98
+ setValidationErrors({
99
+ ...validationErrors,
100
+ vatNumber: t('validation.invalid'),
101
+ });
102
+ }
103
+ finally {
104
+ setIsValidatingVAT(false);
105
+ }
106
+ }, 500);
107
+ async function onSubmit(e) {
108
+ const formData = new FormData(e.currentTarget);
109
+ const cart = cartRef.current;
110
+ setValidationErrors(prev => prev); // NOTE: This makes sure the form is revalidated on submit
111
+ if (Object.keys(validationErrors).length > 0)
112
+ return;
113
+ if (isAdyenPayment) {
114
+ /* Adyen Payment */
115
+ if (!dropinRef.current) {
116
+ console.warn('Adyen Dropin not ready');
117
+ return;
118
+ }
119
+ dropinRef.current.showValidation();
120
+ if (!dropinRef.current.isValid)
121
+ return;
122
+ const updatedCart = {
123
+ ...cart,
124
+ customerVatNumber: formData.get('vatNumber')?.toString(),
125
+ poNumber: formData.get('poNumber')?.toString(),
126
+ properties: {
127
+ ...cart.properties,
128
+ industry: formData.get('industry')?.toString() || '',
129
+ },
130
+ requestedDeliveryDate: formData.get('deliveryDate')?.toString(),
131
+ };
132
+ try {
133
+ cartRef.current = await patchCart({
134
+ cart: updatedCart,
135
+ });
136
+ }
137
+ catch (error) {
138
+ console.error(error);
139
+ setAPIError(error);
140
+ }
141
+ try {
142
+ dropinRef.current.submit();
143
+ }
144
+ catch (error) {
145
+ console.error(error);
146
+ setPaymentError(error);
147
+ }
148
+ }
149
+ else {
150
+ /* Pay by Invoice */
151
+ const cart = cartRef.current;
152
+ try {
153
+ await placeOrder({ cart });
154
+ return onPaymentComplete({ cartId: cart.trackId });
155
+ }
156
+ catch (error) {
157
+ console.error(error);
158
+ setPaymentError(error);
159
+ }
160
+ }
161
+ }
162
+ const onComplete = useCallback(
163
+ /* Adyen payment continuation after submit */
164
+ async (result) => {
165
+ const cart = cartRef.current;
166
+ try {
167
+ await placeOrder({
168
+ cart: {
169
+ ...cart,
170
+ paymentMethod: null,
171
+ paymentOptions: {
172
+ ...cart.paymentOptions, // Hack needed to make B2B happy
173
+ adyenPspReference: result.pspReference,
174
+ isAdyenDropIn: true,
175
+ },
176
+ },
177
+ });
178
+ return onPaymentComplete({ cartId: cart.trackId });
179
+ }
180
+ catch (error) {
181
+ console.error(error);
182
+ // TODO: Errors from the placeOrder call are not displayed
183
+ setAPIError(error);
184
+ }
185
+ }, [onPaymentComplete, placeOrder]);
186
+ const onError = useCallback((error, result) => {
187
+ invalidateAdyen();
188
+ // invalidateCurrentCart()
189
+ setPaymentError(error);
190
+ console.error(error);
191
+ _onError?.(error, result);
192
+ }, [_onError, invalidateAdyen]);
193
+ return (jsxs(Form, { className: styles['payment-form'], "data-test-selector": "paymentForm", id: form, onSubmit: e => {
194
+ e.preventDefault();
195
+ onSubmit(e);
196
+ }, validationErrors: validationErrors, children: [Boolean(apiError) && (jsx("div", { className: styles['error-message'], children: jsx(FormattedMessage, { id: "An unexpected error occured" }) })), hasAtp && (jsxs("div", { className: styles['delivery-date'], children: [jsx(Select, { showLabel: true, "data-test-selector": "deliveryDateSelect", 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 => {
197
+ setAsSoonAsPossible(checked);
198
+ if (checked)
199
+ setDeliveryDate('');
200
+ }, 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, "data-test-selector": "industrySelect", defaultSelectedOption: cart.properties.industry, isDisabled: hasReturnedFromAdyen, label: t('Industry'), name: "industry", options: {
201
+ /* eslint-disable sort-keys-fix/sort-keys-fix */
202
+ PP: 'Private User',
203
+ AU: 'Automotive',
204
+ MC: 'Motorcycle',
205
+ BC: 'Bicycle',
206
+ TR: 'Truck',
207
+ AG: 'Agricultural',
208
+ AV: 'Aviation',
209
+ MA: 'Maritime',
210
+ OT: 'Other',
211
+ /* eslint-enable sort-keys-fix/sort-keys-fix */
212
+ }, 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, 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: (hasReturnedFromAdyen ||
213
+ (cart.paymentOptions?.paymentMethods &&
214
+ cart.paymentOptions.paymentMethods.length <= 1)) ??
215
+ true, 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: currencySymbolToISO[cart.currencySymbol], customerId: cart.billTo.id, dropinRef: dropinRef,
216
+ // TODO: Use the correct Adyen environment before going live
217
+ environment: "test", onComplete: onComplete, onError: onError, orderAmount: cart.orderGrandTotal, returnUrl: typeof window === 'undefined'
218
+ ? ''
219
+ : /* eslint-disable ssr-friendly/no-dom-globals-in-react-fc */
220
+ `${config.SHOP_API_URL}${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." }) })), jsx(InfoDisplay, { id: "shipping-and-invoice-information", label: t('Billing and shipping address'), value: jsx(Accordion, { variant: "select", children: jsx(AccordionItem, { id: "invoice-and-shipping", title: "Factuur- en verzendinformatie", children: jsx(BillingAndInvoiceInformation, { billToAddress: {
221
+ address1: cart.billTo?.address1,
222
+ address2: cart.billTo?.address2,
223
+ address3: cart.billTo?.address3,
224
+ city: cart.billTo?.city,
225
+ companyName: cart.billTo?.companyName,
226
+ country: cart.billTo?.country?.name,
227
+ email: cart.billTo?.email,
228
+ phone: cart.billTo?.phone,
229
+ postalCode: cart.billTo?.postalCode,
230
+ }, shipToAddress: {
231
+ address1: cart.shipTo?.address1,
232
+ address2: cart.shipTo?.address2,
233
+ address3: cart.shipTo?.address3,
234
+ city: cart.shipTo?.city,
235
+ companyName: cart.shipTo?.companyName,
236
+ country: cart.shipTo?.country?.name,
237
+ email: cart.shipTo?.email,
238
+ phone: cart.shipTo?.phone,
239
+ postalCode: cart.shipTo?.postalCode,
240
+ } }) }) }) })] }));
241
+ }
242
+
243
+ export { Payment };
@@ -0,0 +1,3 @@
1
+ var styles = {"error-message":"payment-module-ZvObJ","payment-form":"payment-module-i4R0m","delivery-date":"payment-module-gtAqD","asap-checkbox":"payment-module-fP31W"};
2
+
3
+ export { styles as default };
@@ -4,8 +4,6 @@ import { Button } from '../../../buttons/button/button.js';
4
4
  import { OrderLineCard } from '../../../cards/orderline-card/orderline-card.js';
5
5
  import { CartTotals } from '../../../cart-totals/cart-totals.js';
6
6
  import { CartTotalsSummary } from '../../../cart-totals/cart-totals-summary.js';
7
- import { Payment } from '../../../checkout/payment.js';
8
- import { useHasReturnedFromAdyen } from '../../../checkout/use-has-returned-from-adyen.js';
9
7
  import { FormattedMessage } from '../../../intl/formatted-message.js';
10
8
  import { useFormattedMessage } from '../../../intl/use-formatted-message.js';
11
9
  import { OrderLineList } from '../../../lists/orderline-list/orderline-list.js';
@@ -17,9 +15,12 @@ import { hasNo } from '../../../shared/utils/types.js';
17
15
  import { Page } from '../../components/page/page.js';
18
16
  import { ErrorPage } from '../../error-page/error-page.js';
19
17
  import { LoadingPage } from '../../loading-page/loading-page.js';
18
+ import { CHECKOUT_PATHS } from '../constants.js';
20
19
  import { CheckoutPageLayout } from '../layouts/checkout-page-layout/checkout-page-layout.js';
21
20
  import { CheckoutPageSection } from '../layouts/checkout-page-layout/components/checkout-page-section.js';
22
21
  import { CheckoutPageSectionContent } from '../layouts/checkout-page-layout/components/checkout-page-section-content.js';
22
+ import { Payment } from './components/payment.js';
23
+ import { useHasReturnedFromAdyen } from './hooks/use-has-returned-from-adyen.js';
23
24
 
24
25
  const PAYMENT_FORM_ID = 'paymentForm';
25
26
  function PaymentPage() {
@@ -29,28 +30,30 @@ function PaymentPage() {
29
30
  forceRecalculation: !hasReturnedFromAdyen,
30
31
  });
31
32
  const { data: atp, isLoading: isAtpLoading } = useFetchCurrentCheckoutAtp();
32
- const hasAtp = atp && atp.length > 0 && atp[0]?.date !== null;
33
+ const hasAtp = atp && atp.length > 1;
33
34
  const isLoading = isLoadingCart || isAtpLoading;
34
35
  const t = useFormattedMessage();
35
36
  const [isProcessing, setIsProcessing] = useState(false);
36
37
  const [isValidating, setIsValidating] = useState(false);
37
38
  const { isNavigating, navigate } = useNavigate();
38
- const onPaymentComplete = useCallback(() => navigate('/CheckoutConfirmation'), [navigate]);
39
+ const onPaymentComplete = useCallback(({ cartId }) => {
40
+ navigate(`${CHECKOUT_PATHS.ORDER_CONFIRMATION}?cartId=${cartId}`);
41
+ }, [navigate]);
39
42
  useEffect(() => {
40
43
  if (isNavigating)
41
44
  return;
42
45
  if (isAuthenticated === undefined)
43
46
  return;
44
47
  if (!isAuthenticated)
45
- return navigate('/signin?returnUrl=/CheckoutShipping');
48
+ return navigate(CHECKOUT_PATHS.CHECKOUT_SHIPPING_VIA_SIGNIN);
46
49
  if (hasNo(cart))
47
50
  return;
48
51
  if (hasNo(cart.cartLines) || cart.cartLines.length === 0)
49
- return navigate('/cart');
52
+ return navigate(CHECKOUT_PATHS.CART);
50
53
  if (hasNo(cart.billTo))
51
- return navigate('/signin?returnUrl=/CheckoutShipping');
54
+ return navigate(CHECKOUT_PATHS.CHECKOUT_SHIPPING_VIA_SIGNIN);
52
55
  if (hasNo(cart.billTo.address1))
53
- return navigate('/CheckoutShipping');
56
+ return navigate(CHECKOUT_PATHS.CHECKOUT_SHIPPING);
54
57
  }, [cart, navigate, isAuthenticated, isNavigating]);
55
58
  if (error)
56
59
  return jsx(ErrorPage, { error: error });
@@ -64,11 +67,15 @@ function PaymentPage() {
64
67
  hasNo(cart.billTo?.address1))
65
68
  return null;
66
69
  return (jsx(Page, { breadCrumb: [
67
- { href: '/', label: t('Home') },
68
- { href: '/CheckoutReviewAndSubmit', label: t('Review and payment') },
70
+ { href: CHECKOUT_PATHS.HOME, label: t('Home') },
71
+ {
72
+ href: CHECKOUT_PATHS.REVIEW_AND_SUBMIT,
73
+ label: t('Review and payment'),
74
+ },
69
75
  ], title: t('Review and payment'), children: jsxs(CheckoutPageLayout, { actions: {
70
76
  primary: (jsx(Button, { withArrow: true, "data-test-selector": "checkoutShippingCartTotalContinueButton", form: PAYMENT_FORM_ID, isDisabled: isProcessing, isLoading: isProcessing ? (jsx(FormattedMessage, { id: "Processing" })) : isValidating ? (jsx(FormattedMessage, { id: "Validating" })) : (false), type: "submit", children: jsx(FormattedMessage, { id: "Pay" }) })),
71
- }, mobileSummary: jsx(CartTotalsSummary, { totalAmount: cart.orderGrandTotalDisplay }), overview: jsx(CartTotals, { deliveryDate: hasAtp ? undefined : cart.requestedDeliveryDate, fulfillmentMethod: cart.fulfillmentMethod, shippingCost: cart.shippingAndHandlingDisplay, subtotal: cart.orderSubTotalDisplay, tax: cart.totalTaxDisplay, total: cart.orderGrandTotalDisplay, vatPercentage: cart.cartLines[0]?.pricing?.vatRate || 0 }), children: [jsx(CheckoutPageSection, { hasBorder: false, title: jsx(FormattedMessage, { id: "Payment" }), children: jsx(CheckoutPageSectionContent, { children: jsx(Payment, { atp: atp, cart: cart, form: PAYMENT_FORM_ID, onPaymentComplete: onPaymentComplete, onProcessing: setIsProcessing, onValidating: setIsValidating }) }) }), jsx(CheckoutPageSection, { hasBorder: false, title: jsx(FormattedMessage, { id: "Order" }), children: jsx(CheckoutPageSectionContent, { stretch: true, children: jsx(OrderLineList, { children: cart.cartLines.map(cartLine => (jsx(OrderLineCard, { deliveryDate: cartLine.atp?.date, href: cartLine.productUri, image: {
77
+ }, mobileSummary: jsx(CartTotalsSummary, { totalAmount: cart.orderGrandTotalDisplay }), overview: jsx(CartTotals, { deliveryDate: hasAtp ? undefined : cart.requestedDeliveryDate, fulfillmentMethod: cart.fulfillmentMethod, isPayByInvoice: (cart.paymentOptions?.paymentMethods?.length || 1) <= 1 &&
78
+ cart.paymentMethod?.name === 'PBI', shippingCost: cart.shippingAndHandlingDisplay, subtotal: cart.orderSubTotalDisplay, tax: cart.totalTaxDisplay, total: cart.orderGrandTotalDisplay, vatPercentage: cart.cartLines[0]?.pricing?.vatRate || 0 }), children: [jsx(CheckoutPageSection, { hasBorder: false, title: jsx(FormattedMessage, { id: "Payment" }), children: jsx(CheckoutPageSectionContent, { children: jsx(Payment, { atp: atp, cart: cart, form: PAYMENT_FORM_ID, onPaymentComplete: onPaymentComplete, onProcessing: setIsProcessing, onValidating: setIsValidating }) }) }), jsx(CheckoutPageSection, { hasBorder: false, title: jsx(FormattedMessage, { id: "Order" }), children: jsx(CheckoutPageSectionContent, { stretch: true, children: jsx(OrderLineList, { children: cart.cartLines.map(cartLine => (jsx(OrderLineCard, { deliveryDate: cartLine.atp?.date, href: cartLine.productUri, image: {
72
79
  fit: 'contain',
73
80
  image: {
74
81
  '1': cartLine.smallImagePath,
@@ -1,4 +1,4 @@
1
- import { getCurrencyByCountryCode } from '../shared/utils/price.js';
1
+ import { getCurrencyByCountryCode } from '../../../../shared/utils/price.js';
2
2
 
3
3
  function parseAmount(amount, countryCode) {
4
4
  return {
@@ -6,6 +6,7 @@ import { Checkbox } from '../../../../forms/checkbox/checkbox.js';
6
6
  import { TextField } from '../../../../forms/text-field/text-field.js';
7
7
  import { FormattedMessage } from '../../../../intl/formatted-message.js';
8
8
  import { useFormattedMessage } from '../../../../intl/use-formatted-message.js';
9
+ import { useFetchCurrentCart } from '../../../../shared/api/storefront/hooks/cart/use-fetch-current-cart.js';
9
10
  import { validatePhone, validateEmail } from '../../../../shared/model/address.js';
10
11
  import { Tooltip } from '../../../../tooltip/tooltip.js';
11
12
  import { CheckoutPageSection } from '../../layouts/checkout-page-layout/components/checkout-page-section.js';
@@ -18,10 +19,11 @@ function EditAddresses({ countries, isLoading, isPickup, onSubmit, }) {
18
19
  const t = useFormattedMessage();
19
20
  const [companyName, setCompanyName] = useState('');
20
21
  const [lastName, setLastName] = useState('');
22
+ const { data: cart } = useFetchCurrentCart();
21
23
  return (jsxs(Fragment, { children: [jsx(CheckoutPageSection, { title: jsx(FormattedMessage, { id: "Billing address" }), children: jsx(CheckoutPageSectionContent, { children: jsxs(Form, { className: styles.form, "data-test-selector": "billToAddressForm", id: EDIT_ADDRESS_FORM_ID, onSubmit: e => {
22
24
  e.preventDefault();
23
25
  const formData = new FormData(e.currentTarget);
24
- const countryFormValue = formData.get('country')?.toString();
26
+ const countryFormValue = formData.get('countrySelect')?.toString();
25
27
  const country = countries.find(country => country.id === countryFormValue);
26
28
  if (!country)
27
29
  throw new Error(`Country not found ${formData.get('country')}`);
@@ -44,11 +46,13 @@ function EditAddresses({ countries, isLoading, isPickup, onSubmit, }) {
44
46
  }, children: [jsx(TextField, { isDisabled: isLoading, label: t('First name'), name: "firstName", showLabel: true }), jsx(TextField, { isDisabled: isLoading, isRequired: !companyName, label: t('Last name'), minLength: 3, name: "lastName", onChange: setLastName, showLabel: true, value: lastName }, `lastname-${Boolean(companyName)}`), jsx(TextField, { isDisabled: isLoading, label: t('Company name'), name: "companyName", onChange: setCompanyName, showLabel: true, value: companyName }), jsx(TextField, { isDisabled: isLoading, label: t('Attention'), name: "attention", showLabel: true }), jsx("div", { className: styles['span-2'], children: jsx(TextField, { isRequired: true, isDisabled: isLoading, label: `${t('Address')} 1`, maxLength: 30, minLength: 3, name: "address1", showLabel: true }) }), jsx("div", { className: styles['span-2'], children: jsx(TextField, { isDisabled: isLoading, label: `${t('Address')} 2`, maxLength: 30, minLength: 3, name: "address2", showLabel: true }) }), jsx("div", { className: styles['span-2'], children: jsx(TextField, { isDisabled: isLoading, label: `${t('Address')} 3`, maxLength: 30, minLength: 3, name: "address3", showLabel: true }) }), jsx(TextField, { isRequired: true, isDisabled: isLoading, label: t('Postal Code'), maxLength: 10, minLength: 4, name: "postalCode", showLabel: true }), jsx(TextField, { isRequired: true, isDisabled: isLoading, label: t('City'), maxLength: 30, minLength: 3, name: "city", showLabel: true }), jsx("div", { className: styles['span-2'], children: jsx(CountrySelect, { isRequired: true, countries: countries, "data-test-selector": "countrySelect", name: "countrySelect" }) }), jsx("div", { className: styles['span-2'], children: jsx(TextField, { isRequired: true, isDisabled: isLoading, label: t('Phone'), name: "phone", showLabel: true, validate: value => {
45
47
  if (!value)
46
48
  return value;
47
- return (validatePhone(value) || 'Vul een geldig telefoonnummer in');
48
- } }) }), jsx("div", { className: styles['span-2'], children: jsx(TextField, { isRequired: true, isDisabled: isLoading, label: t('Email'), name: "email", showLabel: true, type: "email", validate: value => {
49
+ return (validatePhone(value) ||
50
+ t('Please enter a valid phone number'));
51
+ } }) }), jsx("div", { className: styles['span-2'], children: jsx(TextField, { isRequired: true, defaultValue: cart?.billTo?.email || '', isDisabled: isLoading, label: t('Email'), name: "email", showLabel: true, type: "email", validate: value => {
49
52
  if (!value)
50
53
  return value;
51
- return validateEmail(value) || 'Vul een geldig emailadres in';
54
+ return (validateEmail(value) ||
55
+ t('Please enter a valid e-mail address'));
52
56
  } }) }), jsx("div", { className: styles['span-2'], children: jsx(TextField, { isDisabled: isLoading, isMultiline: true, label: t('Add order notes'), name: "notes", rows: 3, showLabel: true }) })] }) }) }), jsx(CheckoutPageSection, { title: jsx(FormattedMessage, { id: isPickup ? 'Pickup address' : 'Shipping address' }), children: jsx(CheckoutPageSectionContent, { children: jsx(Fragment, { children: isPickup ? (jsx(SonicAddress, {})) : (jsxs("div", { className: styles['use-invoice-checkbox'], children: [jsx(Checkbox, { "data-test-selector": "checkboxUseBillingAddress", isDisabled: true, isSelected: true, children: jsx(FormattedMessage, { id: "Use billing address" }) }), jsx(Tooltip, { text: t('Changing your address is currently not possible. Please contact customer support to change your address.') })] })) }) }) })] }));
53
57
  }
54
58
 
@@ -0,0 +1,12 @@
1
+ import { BillToModel, CartModel } from '../../../../shared/api/storefront/model/storefront.model';
2
+ export declare function usePatchShippingDetails(): {
3
+ error: unknown;
4
+ isError: boolean;
5
+ isLoading: boolean;
6
+ isSuccess: boolean;
7
+ mutate: (args_0: {
8
+ billTo?: BillToModel;
9
+ cart: CartModel;
10
+ notes: string | undefined;
11
+ }) => Promise<void>;
12
+ };
@@ -0,0 +1,21 @@
1
+ import { useAwaitableMutation } from '../../../../shared/api/shared/hooks/use-awaitable-mutation.js';
2
+ import { patchCart } from '../../../../shared/api/storefront/services/cart-service.js';
3
+ import { patchBillToAddress } from '../../../../shared/api/storefront/services/customer-service.js';
4
+
5
+ function usePatchShippingDetails() {
6
+ return useAwaitableMutation({
7
+ mutationFn: async ({ billTo, cart, notes, }) => {
8
+ await Promise.all([
9
+ billTo && patchBillToAddress({ billTo }),
10
+ patchCart({ cart: { ...cart, notes } }),
11
+ ].filter(Boolean));
12
+ },
13
+ onSuccess: ({ queryClient }) => {
14
+ queryClient.removeQueries({ queryKey: ['customer'] });
15
+ queryClient.removeQueries({ queryKey: ['carts'] });
16
+ queryClient.removeQueries({ queryKey: ['session'] });
17
+ },
18
+ });
19
+ }
20
+
21
+ export { usePatchShippingDetails };