@sonic-equipment/ui 127.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.
- package/dist/cart-totals/cart-totals.js +1 -1
- package/dist/global-search/search-input/connected-search-input.js +1 -1
- package/dist/intl/translation-id.d.ts +1 -1
- package/dist/loading/loading-overlay.js +1 -1
- package/dist/pages/checkout/payment-page/payment-page.js +7 -5
- package/dist/pages/checkout/shipping-page/components/readonly-address.js +2 -2
- package/dist/pages/checkout/shipping-page/shipping-page.js +53 -20
- package/dist/shared/api/shared/hooks/use-awaitable-mutation.d.ts +3 -0
- package/dist/shared/api/shared/hooks/use-awaitable-mutation.js +7 -0
- package/dist/shared/api/storefront/hooks/authentication/use-patch-session.d.ts +3 -0
- package/dist/shared/api/storefront/hooks/cart/use-patch-cart.d.ts +3 -0
- package/dist/shared/api/storefront/hooks/cart/use-place-order.d.ts +3 -0
- package/dist/shared/api/storefront/hooks/customer/use-patch-bill-to-address.d.ts +3 -0
- package/dist/shared/routing/route-provider.d.ts +5 -1
- package/dist/shared/routing/route-provider.js +6 -2
- package/dist/shared/routing/with-routing.js +1 -1
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@ import { Heading } from '../typography/heading/heading.js';
|
|
|
4
4
|
import styles from './cart-totals.module.css.js';
|
|
5
5
|
|
|
6
6
|
function CartTotals({ fulfillmentMethod, orderNumber, shippingCost, subtotal, tax, total, vatPercentage, }) {
|
|
7
|
-
return (jsxs("div", { className: styles['cart-totals'], children: [orderNumber && (jsxs("section", { className: styles.section, children: [jsx(Heading, { className: styles['section-header'], size: "xxxs", tag: "h3", children: jsx(FormattedMessage, { id: "Order number" }) }), jsx("div", { children: jsx("div", { className: styles.line, children: jsx("p", { className: styles.label, "data-test-selector": "orderConfirmation_orderNumber", children: orderNumber }) }) })] })), fulfillmentMethod && (jsxs("section", { className: styles.section, children: [jsx(Heading, { className: styles['section-header'], size: "xxxs", tag: "h3", children: jsx(FormattedMessage, { id: "Fulfillment method" }) }), jsx("div", { children: jsx("div", { className: styles.line, children: jsx("p", { className: styles.label, children: fulfillmentMethod }) }) })] })), jsxs("section", { className: styles.section, children: [jsx(Heading, { className: styles['section-header'], size: "xxxs", tag: "h3", children: jsx(FormattedMessage, { id: "Cost overview" }) }), jsxs("div", { children: [jsxs("div", { className: styles.line, children: [jsxs("p", { className: styles.label, children: [jsx(FormattedMessage, { id: "Subtotal" }), ' ', jsx(FormattedMessage, { id: "Excl. VAT" })] }), jsx("p", { className: styles.value, "data-test-selector": "cartTotal_subTotal", children: subtotal })] }), jsxs("div", { className: styles.line, children: [jsx("p", { className: styles.label, children: jsx(FormattedMessage, { id: "Shipping and handling" }) }), jsx("p", { className: styles.value, children: shippingCost })] }), jsxs("div", { className: styles.line, children: [jsxs("p", { className: styles.label, children: [jsx(FormattedMessage, { id: "VAT" }), ' ', vatPercentage ? `${vatPercentage}%` : ''] }), jsx("p", { className: styles.value, children: tax })] })] })] }), jsx("section", { className: styles.totals, children: jsxs("div", { className: styles.line, children: [jsx("p", { className: styles.label, children: jsx(FormattedMessage, { id: "Total" }) }), jsx("p", { className: styles.value, "data-test-selector": "cartTotal_orderGrandTotalDisplay", children: total })] }) })] }));
|
|
7
|
+
return (jsxs("div", { className: styles['cart-totals'], children: [orderNumber && (jsxs("section", { className: styles.section, children: [jsx(Heading, { className: styles['section-header'], size: "xxxs", tag: "h3", children: jsx(FormattedMessage, { id: "Order number" }) }), jsx("div", { children: jsx("div", { className: styles.line, children: jsx("p", { className: styles.label, "data-test-selector": "orderConfirmation_orderNumber", children: orderNumber }) }) })] })), fulfillmentMethod && (jsxs("section", { className: styles.section, children: [jsx(Heading, { className: styles['section-header'], size: "xxxs", tag: "h3", children: jsx(FormattedMessage, { id: "Fulfillment method" }) }), jsx("div", { children: jsx("div", { className: styles.line, children: jsx("p", { className: styles.label, "data-test-selector": "fulfullmentMethod", children: fulfillmentMethod }) }) })] })), jsxs("section", { className: styles.section, children: [jsx(Heading, { className: styles['section-header'], size: "xxxs", tag: "h3", children: jsx(FormattedMessage, { id: "Cost overview" }) }), jsxs("div", { children: [jsxs("div", { className: styles.line, children: [jsxs("p", { className: styles.label, children: [jsx(FormattedMessage, { id: "Subtotal" }), ' ', jsx(FormattedMessage, { id: "Excl. VAT" })] }), jsx("p", { className: styles.value, "data-test-selector": "cartTotal_subTotal", children: subtotal })] }), jsxs("div", { className: styles.line, children: [jsx("p", { className: styles.label, children: jsx(FormattedMessage, { id: "Shipping and handling" }) }), jsx("p", { className: styles.value, "data-test-selector": "shippingCost", children: shippingCost })] }), jsxs("div", { className: styles.line, children: [jsxs("p", { className: styles.label, children: [jsx(FormattedMessage, { id: "VAT" }), ' ', vatPercentage ? `${vatPercentage}%` : ''] }), jsx("p", { className: styles.value, "data-test-selector": "vatAmount", children: tax })] })] })] }), jsx("section", { className: styles.totals, children: jsxs("div", { className: styles.line, children: [jsx("p", { className: styles.label, children: jsx(FormattedMessage, { id: "Total" }) }), jsx("p", { className: styles.value, "data-test-selector": "cartTotal_orderGrandTotalDisplay", children: total })] }) })] }));
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export { CartTotals };
|
|
@@ -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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type TranslationId = "'{0}' in all products" | "Try 'Search' and try to find the product you're looking for" | "Unfortnately, We found no articles for your search '{0}'" | ' to your account to manage your lists.' | 'Add order notes' | 'Add to list' | 'Address' | 'Amount: {0}' | 'An error occurred while processing your payment. Please try again.' | 'An unexpected error occured' | 'Are you looking for information about our service? Please visit our customer support page' | 'Are you sure you want to remove all items from your cart?' | 'Are you sure you want to remove this item from your cart?' | 'article' | 'articles' | 'As soon as possible' | 'Attention' | 'Billing address' | 'Billing and shipping address' | 'Cancel' | 'Cart' | 'Changing your address is currently not possible. Please contact customer support to change your address.' | 'Chosen filters' | 'City' | 'Clear filters' | 'Clear' | 'Click the button below to continue shopping.' | 'Company name' | 'Continue shopping' | 'Continue' | 'Cost overview' | 'Country' | 'create account' | 'Create new list' | 'Delivery expected in {0} {1}' | 'Double check your spelling' | 'Downloads' | 'Easily add your favorite products' | 'Edit billing address' | 'Edit shipping address' | 'Email' | 'Excl. VAT' | 'Explore by categories' | 'Exploring our products by category' | 'facet.categories' | 'facet.height' | 'facet.weight' | 'Features' | 'First name' | 'Fulfillment method' | 'Hide filters' | 'Home' | 'Incl. VAT' | 'Includes' | 'Industry' | 'Language' | 'Last name' | 'List name already exists' | 'New list name' | 'of' | 'Order number' | 'Order' | 'Pay' | 'Payment method' | 'Payment' | 'pc' | 'Phone' | 'Pick up' | 'Please Sign In' | 'PO Number' | 'Popular searches' | 'Postal Code' | 'Print' | 'Processing' | 'Product Features' | 'Product' | 'Products' | 'Quick access' | 'Recent searches' | 'Recently viewed' | 'Remove all' | 'Review and payment' | 'Save order' | 'Save' | 'Saved cart for later.' | 'Search' | 'Searching again using more general terms' | 'See all results' | 'Select a desired delivery date' | 'Select a list' | 'Selecting As Soon As Possible will enable us to send the products to you as they become available.' | 'Share your favorite list with others' | 'Ship' | 'Shipping address' | 'Shipping and handling' | 'Shipping details' | 'Shop more efficiently and quicker with a favorites list' | 'Show all' | 'Show filters' | 'Show less' | 'Show' | 'sign in' | 'Sorry, there are no products found' | 'Sorry, we could not find matches for' | 'Sort by' | 'sort.newest' | 'sort.price_asc' | 'sort.price_desc' | 'sort.relevance' | 'Specifications' | 'Submit' | 'Subtotal' | 'Suggestions' | 'tag.limited' | 'tag.new' | 'The product has been added to your cart.' | 'The product has been removed from your cart.' | 'The product has been updated in your cart.' | 'There are no products in your shopping cart.' | 'Total amount is' | 'Total' | 'Total' | 'Try another search' | 'Try another search' | 'Unable to add the product to your cart.' | 'Unable to add the product to your cart.' | 'Unable to empty your cart.' | 'Unable to empty your cart.' | 'Unable to remove the product from your cart.' | 'Unable to remove the product from your cart.' | 'Unable to save cart for later.' | 'Unable to save cart for later.' | 'Unable to update the product in your cart.' | 'Unable to update the product in your cart.' | 'Use billing address' | 'Use fewer keywords' | 'Validating' | 'validation.badInput' | 'validation.customError' | 'validation.invalid' | 'validation.patternMismatch' | 'validation.rangeOverflow' | 'validation.rangeUnderflow' | 'validation.stepMismatch' | 'validation.tooLong' | 'validation.tooShort' | 'validation.typeMismatch' | 'validation.valid' | 'validation.valueMissing' | 'VAT Number' | 'VAT' | 'Welcome to Sonic Equipment. Please choose your country and language below.' | 'What are you searching for?' | 'You could try checking the spelling of your search query' | 'You could try exploring our products by category' | 'You could try' | 'You must ' | 'Your cart has been emptied.' | 'Your favorites are available on multiple devices' | 'Your shopping cart is still empty';
|
|
1
|
+
export type TranslationId = "'{0}' in all products" | "Try 'Search' and try to find the product you're looking for" | "Unfortnately, We found no articles for your search '{0}'" | ' to your account to manage your lists.' | 'Add order notes' | 'Add to list' | 'Address' | 'Amount: {0}' | 'An error occurred while processing your payment. Please try again.' | 'An unexpected error occured' | 'Are you looking for information about our service? Please visit our customer support page' | 'Are you sure you want to remove all items from your cart?' | 'Are you sure you want to remove this item from your cart?' | 'article' | 'articles' | 'As soon as possible' | 'Attention' | 'Billing address' | 'Billing and shipping address' | 'Cancel' | 'Cart' | 'Changing your address is currently not possible. Please contact customer support to change your address.' | 'Chosen filters' | 'City' | 'Clear filters' | 'Clear' | 'Click the button below to continue shopping.' | 'Company name' | 'Continue shopping' | 'Continue' | 'Cost overview' | 'Country' | 'create account' | 'Create new list' | 'Delivery expected in {0} {1}' | 'Double check your spelling' | 'Downloads' | 'Easily add your favorite products' | 'Edit billing address' | 'Edit shipping address' | 'Email' | 'Excl. VAT' | 'Explore by categories' | 'Exploring our products by category' | 'facet.categories' | 'facet.height' | 'facet.weight' | 'Features' | 'First name' | 'Fulfillment method' | 'Hide filters' | 'Home' | 'Incl. VAT' | 'Includes' | 'Industry' | 'Language' | 'Last name' | 'List name already exists' | 'New list name' | 'of' | 'Order number' | 'Order' | 'Pay' | 'Payment method' | 'Payment' | 'pc' | 'Phone' | 'Pick up' | 'Please Sign In' | 'PO Number' | 'Popular searches' | 'Postal Code' | 'Print' | 'Processing' | 'Product Features' | 'Product' | 'Products' | 'Quick access' | 'Recent searches' | 'Recently viewed' | 'Remove all' | 'Review and payment' | 'Save order' | 'Save' | 'Saved cart for later.' | 'Search' | 'Searching again using more general terms' | 'See all results' | 'Select a desired delivery date' | 'Select a list' | 'Selecting As Soon As Possible will enable us to send the products to you as they become available.' | 'Share your favorite list with others' | 'Ship' | 'Shipping address' | 'Shipping and handling' | 'Shipping details' | 'Shop more efficiently and quicker with a favorites list' | 'Show all' | 'Show filters' | 'Show less' | 'Show' | 'sign in' | 'Sorry, there are no products found' | 'Sorry, we could not find matches for' | 'Sort by' | 'sort.newest' | 'sort.price_asc' | 'sort.price_desc' | 'sort.relevance' | 'Specifications' | 'Submit' | 'Subtotal' | 'Suggestions' | 'tag.limited' | 'tag.new' | 'The product has been added to your cart.' | 'The product has been removed from your cart.' | 'The product has been updated in your cart.' | 'There are no products in your shopping cart.' | 'Total amount is' | 'Total' | 'Total' | 'Try another search' | 'Try another search' | 'Unable to add the product to your cart.' | 'Unable to add the product to your cart.' | 'Unable to empty your cart.' | 'Unable to empty your cart.' | 'Unable to remove the product from your cart.' | 'Unable to remove the product from your cart.' | 'Unable to save cart for later.' | 'Unable to save cart for later.' | 'Unable to update the product in your cart.' | 'Unable to update the product in your cart.' | 'Updating address' | 'Use billing address' | 'Use fewer keywords' | 'Validating' | 'validation.badInput' | 'validation.customError' | 'validation.invalid' | 'validation.patternMismatch' | 'validation.rangeOverflow' | 'validation.rangeUnderflow' | 'validation.stepMismatch' | 'validation.tooLong' | 'validation.tooShort' | 'validation.typeMismatch' | 'validation.valid' | 'validation.valueMissing' | 'VAT Number' | 'VAT' | 'Welcome to Sonic Equipment. Please choose your country and language below.' | 'What are you searching for?' | 'You could try checking the spelling of your search query' | 'You could try exploring our products by category' | 'You could try' | 'You must ' | 'Your cart has been emptied.' | 'Your favorites are available on multiple devices' | 'Your shopping cart is still empty';
|
|
@@ -3,7 +3,7 @@ import { ProgressCircle } from './progress-circle.js';
|
|
|
3
3
|
import styles from './loading-overlay.module.css.js';
|
|
4
4
|
|
|
5
5
|
function LoadingOverlay() {
|
|
6
|
-
return (jsx("div", { className: styles['loading-overlay'], children: jsx(ProgressCircle, {}) }));
|
|
6
|
+
return (jsx("div", { className: styles['loading-overlay'], children: jsx(ProgressCircle, { variant: "gray" }) }));
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export { LoadingOverlay };
|
|
@@ -35,25 +35,27 @@ function PaymentPage() {
|
|
|
35
35
|
const t = useFormattedMessage();
|
|
36
36
|
const [isProcessing, setIsProcessing] = useState(false);
|
|
37
37
|
const [isValidating, setIsValidating] = useState(false);
|
|
38
|
-
const navigate = useNavigate();
|
|
38
|
+
const { isNavigating, navigate } = useNavigate();
|
|
39
39
|
const onPaymentComplete = useCallback(() => navigate('/CheckoutConfirmation'), [navigate]);
|
|
40
40
|
useEffect(() => {
|
|
41
|
+
if (isNavigating)
|
|
42
|
+
return;
|
|
41
43
|
if (isAuthenticated === undefined)
|
|
42
44
|
return;
|
|
43
45
|
if (!isAuthenticated)
|
|
44
|
-
return navigate('/
|
|
46
|
+
return navigate('/signin?returnUrl=/CheckoutShipping');
|
|
45
47
|
if (hasNo(cart))
|
|
46
48
|
return;
|
|
47
49
|
if (hasNo(cart.cartLines) || cart.cartLines.length === 0)
|
|
48
50
|
return navigate('/cart');
|
|
49
51
|
if (hasNo(cart.billTo))
|
|
50
|
-
return navigate('/
|
|
52
|
+
return navigate('/signin?returnUrl=/CheckoutShipping');
|
|
51
53
|
if (hasNo(cart.billTo.address1))
|
|
52
54
|
return navigate('/CheckoutShipping');
|
|
53
|
-
}, [cart, navigate, isAuthenticated]);
|
|
55
|
+
}, [cart, navigate, isAuthenticated, isNavigating]);
|
|
54
56
|
if (error)
|
|
55
57
|
return jsx(ErrorPage, { error: error });
|
|
56
|
-
if (isLoading)
|
|
58
|
+
if (isLoading || isNavigating)
|
|
57
59
|
return jsx(LoadingPage, {});
|
|
58
60
|
if (!isAuthenticated ||
|
|
59
61
|
hasNo(atp) ||
|
|
@@ -15,13 +15,13 @@ import styles from './readonly-address.module.css.js';
|
|
|
15
15
|
const ACCOUNT_ADDRESSES_PATH = '/MyAccount/Addresses';
|
|
16
16
|
function ReadOnlyAddresses({ billTo, isLoading, notes, onSubmit, shipTo, }) {
|
|
17
17
|
const t = useFormattedMessage();
|
|
18
|
-
return (jsxs(Form, { id: EDIT_ADDRESS_FORM_ID, onSubmit: e => {
|
|
18
|
+
return (jsxs(Form, { "data-test-selector": "billToAddressForm", id: EDIT_ADDRESS_FORM_ID, onSubmit: e => {
|
|
19
19
|
e.preventDefault();
|
|
20
20
|
const formData = new FormData(e.currentTarget);
|
|
21
21
|
onSubmit({
|
|
22
22
|
notes: formData.get('notes')?.toString() || '',
|
|
23
23
|
});
|
|
24
|
-
}, children: [jsxs(CheckoutPageSection, { title: jsx(FormattedMessage, { id: "Billing address" }), children: [jsx(CheckoutPageSectionLink, { children: jsxs(RouteLink, { color: "secondary", href: ACCOUNT_ADDRESSES_PATH, isDisabled: isLoading, children: [jsx(FormattedMessage, { id: "Edit billing address" }), " >"] }) }), jsxs(CheckoutPageSectionContent, { children: [billTo && (jsx(Address, { address1: billTo.address1, address2: billTo.address2, address3: billTo.address3, city: billTo.city, companyName: billTo.companyName, country: billTo.country?.name, email: billTo.email, phone: billTo.phone, postalCode: billTo.postalCode })), jsx("div", { className: styles.notes, children: jsx(TextField, { defaultValue: notes, isDisabled: isLoading, isMultiline: true, label: t('Add order notes'), name: "notes", rows: 3, showLabel: true }) })] })] }), jsxs(CheckoutPageSection, { title: jsx(FormattedMessage, { id: "Shipping address" }), children: [jsx(CheckoutPageSectionLink, { children: jsxs(RouteLink, { color: "secondary", href: ACCOUNT_ADDRESSES_PATH, isDisabled: isLoading, children: [jsx(FormattedMessage, { id: "Edit shipping address" }), " >"] }) }), jsxs(CheckoutPageSectionContent, { children: [jsx(Checkbox, { className: styles['use-invoice-checkbox'], isDisabled: true, isSelected: true, children: jsx(FormattedMessage, { id: "Use billing address" }) }), shipTo && (jsx(Address, { address1: shipTo.address1, address2: shipTo.address2, address3: shipTo.address3, city: shipTo.city, companyName: shipTo.companyName, country: shipTo.country?.name, email: shipTo.email, phone: shipTo.phone, postalCode: shipTo.postalCode }))] })] })] }));
|
|
24
|
+
}, children: [jsxs(CheckoutPageSection, { title: jsx(FormattedMessage, { id: "Billing address" }), children: [jsx(CheckoutPageSectionLink, { children: jsxs(RouteLink, { color: "secondary", href: ACCOUNT_ADDRESSES_PATH, isDisabled: isLoading, children: [jsx(FormattedMessage, { id: "Edit billing address" }), " >"] }) }), jsxs(CheckoutPageSectionContent, { children: [billTo && (jsx(Address, { address1: billTo.address1, address2: billTo.address2, address3: billTo.address3, city: billTo.city, companyName: billTo.companyName, country: billTo.country?.name, email: billTo.email, firstName: billTo.firstName, lastName: billTo.lastName, phone: billTo.phone, postalCode: billTo.postalCode })), jsx("div", { className: styles.notes, children: jsx(TextField, { defaultValue: notes, isDisabled: isLoading, isMultiline: true, label: t('Add order notes'), name: "notes", rows: 3, showLabel: true }) })] })] }), jsxs(CheckoutPageSection, { title: jsx(FormattedMessage, { id: "Shipping address" }), children: [jsx(CheckoutPageSectionLink, { children: jsxs(RouteLink, { color: "secondary", href: ACCOUNT_ADDRESSES_PATH, isDisabled: isLoading, children: [jsx(FormattedMessage, { id: "Edit shipping address" }), " >"] }) }), jsxs(CheckoutPageSectionContent, { children: [jsx(Checkbox, { className: styles['use-invoice-checkbox'], isDisabled: true, isSelected: true, children: jsx(FormattedMessage, { id: "Use billing address" }) }), shipTo && (jsx(Address, { address1: shipTo.address1, address2: shipTo.address2, address3: shipTo.address3, city: shipTo.city, companyName: shipTo.companyName, country: shipTo.country?.name, email: shipTo.email, firstName: shipTo.firstName, lastName: shipTo.lastName, phone: shipTo.phone, postalCode: shipTo.postalCode }))] })] })] }));
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export { ReadOnlyAddresses };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { useEffect } from 'react';
|
|
2
|
+
import { useMemo, useEffect, useCallback } from 'react';
|
|
3
3
|
import { Button } from '../../../buttons/button/button.js';
|
|
4
4
|
import { CartTotals } from '../../../cart-totals/cart-totals.js';
|
|
5
5
|
import { CartTotalsSummary } from '../../../cart-totals/cart-totals-summary.js';
|
|
@@ -11,7 +11,7 @@ import { usePatchCart } from '../../../shared/api/storefront/hooks/cart/use-patc
|
|
|
11
11
|
import { usePatchBillToAddress } from '../../../shared/api/storefront/hooks/customer/use-patch-bill-to-address.js';
|
|
12
12
|
import { useFetchCountries } from '../../../shared/api/storefront/hooks/website/use-fetch-countries.js';
|
|
13
13
|
import { useNavigate } from '../../../shared/routing/route-provider.js';
|
|
14
|
-
import { hasNo
|
|
14
|
+
import { hasNo } from '../../../shared/utils/types.js';
|
|
15
15
|
import { Page } from '../../components/page/page.js';
|
|
16
16
|
import { ErrorPage } from '../../error-page/error-page.js';
|
|
17
17
|
import { LoadingPage } from '../../loading-page/loading-page.js';
|
|
@@ -20,33 +20,67 @@ import { EDIT_ADDRESS_FORM_ID, EditAddresses } from './components/edit-address.j
|
|
|
20
20
|
import { ReadOnlyAddresses } from './components/readonly-address.js';
|
|
21
21
|
|
|
22
22
|
const REVIEW_AND_SUBMIT_PATH = '/CheckoutReviewAndSubmit';
|
|
23
|
+
function usePatchCartAndBillingAddress() {
|
|
24
|
+
const { isError: isPatchingBillToAddressError, isLoading: isPatchBillToAddress, isSuccess: isPatchingBillToAddressSuccess, mutate: patchBillToAddress, } = usePatchBillToAddress();
|
|
25
|
+
const { isError: isPatchCartError, isLoading: isPatchingCart, isSuccess: isPatchCartSuccess, mutate: patchCart, } = usePatchCart();
|
|
26
|
+
const mutate = useCallback(async ({ billTo, cart, notes, }) => {
|
|
27
|
+
await Promise.all([
|
|
28
|
+
billTo &&
|
|
29
|
+
patchBillToAddress({
|
|
30
|
+
billTo,
|
|
31
|
+
}),
|
|
32
|
+
patchCart({ cart: { ...cart, notes } }),
|
|
33
|
+
].filter(Boolean));
|
|
34
|
+
}, [patchBillToAddress, patchCart]);
|
|
35
|
+
return {
|
|
36
|
+
isError: isPatchingBillToAddressError || isPatchCartError,
|
|
37
|
+
isPatching: isPatchBillToAddress || isPatchingCart,
|
|
38
|
+
isSuccess: isPatchingBillToAddressSuccess || isPatchCartSuccess,
|
|
39
|
+
mutate,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
23
42
|
function ShippingPage() {
|
|
24
43
|
const isAuthenticated = useIsAuthenticated();
|
|
25
44
|
const { data: cart, error, isLoading: isLoadingCart } = useFetchCurrentCart();
|
|
26
45
|
const { data: countries, isLoading: isLoadingCountries } = useFetchCountries({
|
|
27
46
|
enabled: hasNo(cart?.billTo?.address1),
|
|
28
47
|
});
|
|
29
|
-
const {
|
|
30
|
-
const { isLoading: isPatchingCart, mutate: patchCart } = usePatchCart();
|
|
31
|
-
const t = useFormattedMessage();
|
|
48
|
+
const { isError, isPatching, isSuccess, mutate: patchCartAndBillingAddress, } = usePatchCartAndBillingAddress();
|
|
32
49
|
const isLoading = isLoadingCart || isLoadingCountries;
|
|
33
|
-
const
|
|
34
|
-
const navigate = useNavigate();
|
|
50
|
+
const t = useFormattedMessage();
|
|
51
|
+
const { isNavigating, navigate } = useNavigate();
|
|
52
|
+
const hasBillToAddress = useMemo(() => {
|
|
53
|
+
return Boolean(cart?.billTo?.address1);
|
|
54
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
55
|
+
}, [Boolean(cart)]);
|
|
35
56
|
useEffect(() => {
|
|
57
|
+
if (isNavigating)
|
|
58
|
+
return;
|
|
36
59
|
if (isAuthenticated === undefined)
|
|
37
60
|
return;
|
|
38
61
|
if (!isAuthenticated)
|
|
39
|
-
return navigate('/
|
|
62
|
+
return navigate('/signin?returnUrl=/CheckoutShipping');
|
|
40
63
|
if (hasNo(cart))
|
|
41
64
|
return;
|
|
42
65
|
if (hasNo(cart.cartLines) || cart.cartLines.length === 0)
|
|
43
66
|
return navigate('/cart');
|
|
44
67
|
if (hasNo(cart.billTo))
|
|
45
|
-
return navigate('/
|
|
46
|
-
}, [cart, navigate, isAuthenticated]);
|
|
68
|
+
return navigate('/signin?returnUrl=/CheckoutShipping');
|
|
69
|
+
}, [cart, navigate, isAuthenticated, isNavigating]);
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (isPatching)
|
|
72
|
+
return;
|
|
73
|
+
if (!isSuccess)
|
|
74
|
+
return;
|
|
75
|
+
if (isNavigating)
|
|
76
|
+
return;
|
|
77
|
+
if (isError)
|
|
78
|
+
return location?.reload();
|
|
79
|
+
navigate(REVIEW_AND_SUBMIT_PATH);
|
|
80
|
+
}, [isSuccess, navigate, isNavigating, isPatching, isError]);
|
|
47
81
|
if (error)
|
|
48
82
|
return jsx(ErrorPage, { error: error });
|
|
49
|
-
if (isLoading)
|
|
83
|
+
if (isLoading || isNavigating || isError)
|
|
50
84
|
return jsx(LoadingPage, {});
|
|
51
85
|
if (!isAuthenticated ||
|
|
52
86
|
hasNo(cart) ||
|
|
@@ -59,21 +93,20 @@ function ShippingPage() {
|
|
|
59
93
|
{ href: '/', label: t('Home') },
|
|
60
94
|
{ href: '/CheckoutShipping', label: t('Shipping details') },
|
|
61
95
|
], title: t('Shipping details'), children: jsx(CheckoutPageLayout, { actions: {
|
|
62
|
-
primary: (jsx(Button, { withArrow: true, "data-test-selector": "checkoutShippingCartTotalContinueButton", form: EDIT_ADDRESS_FORM_ID, isDisabled: isPatching, isLoading: isPatching && jsx(FormattedMessage, { id: "
|
|
63
|
-
}, mobileSummary: jsx(CartTotalsSummary, { totalAmount: cart.orderGrandTotalDisplay }), overview: jsx(CartTotals, { shippingCost: cart.shippingAndHandlingDisplay, subtotal: cart.orderSubTotalDisplay, tax: cart.totalTaxDisplay, total: cart.orderGrandTotalDisplay, vatPercentage: cart.cartLines[0]?.pricing?.vatRate }), children:
|
|
96
|
+
primary: (jsx(Button, { withArrow: true, "data-test-selector": "checkoutShippingCartTotalContinueButton", form: EDIT_ADDRESS_FORM_ID, isDisabled: isPatching, isLoading: isPatching && jsx(FormattedMessage, { id: "Updating address" }), type: "submit", children: jsx(FormattedMessage, { id: "Continue shopping" }) })),
|
|
97
|
+
}, mobileSummary: jsx(CartTotalsSummary, { totalAmount: cart.orderGrandTotalDisplay }), overview: jsx(CartTotals, { shippingCost: cart.shippingAndHandlingDisplay, subtotal: cart.orderSubTotalDisplay, tax: cart.totalTaxDisplay, total: cart.orderGrandTotalDisplay, vatPercentage: cart.cartLines[0]?.pricing?.vatRate }), children: hasBillToAddress ? (jsx(ReadOnlyAddresses, { billTo: cart.billTo, isLoading: isPatching, notes: cart.notes, onSubmit: async ({ notes }) => {
|
|
64
98
|
if (!cart.billTo)
|
|
65
99
|
return;
|
|
66
|
-
await
|
|
100
|
+
await patchCartAndBillingAddress({ cart, notes });
|
|
67
101
|
navigate(REVIEW_AND_SUBMIT_PATH);
|
|
68
102
|
}, shipTo: cart.shipTo })) : (jsx(EditAddresses, { countries: countries || [], isLoading: isPatching, onSubmit: async ({ address, notes }) => {
|
|
69
103
|
if (!cart.billTo)
|
|
70
104
|
return;
|
|
71
|
-
await
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
]);
|
|
105
|
+
await patchCartAndBillingAddress({
|
|
106
|
+
billTo: { ...cart.billTo, ...address },
|
|
107
|
+
cart,
|
|
108
|
+
notes,
|
|
109
|
+
});
|
|
77
110
|
navigate(REVIEW_AND_SUBMIT_PATH);
|
|
78
111
|
} })) }) }));
|
|
79
112
|
}
|
|
@@ -20,7 +20,10 @@ interface UseAwaitableMutationArgs<T extends (...args: any) => Promise<TResult>,
|
|
|
20
20
|
}) => void;
|
|
21
21
|
}
|
|
22
22
|
export declare function useAwaitableMutation<T extends (...args: any) => Promise<TResult>, TResult = InferPromiseResult<T>>({ mutationFn, onComplete, onError, onSuccess, }: UseAwaitableMutationArgs<T, TResult>): {
|
|
23
|
+
error: unknown;
|
|
24
|
+
isError: boolean;
|
|
23
25
|
isLoading: boolean;
|
|
26
|
+
isSuccess: boolean;
|
|
24
27
|
mutate: (...args: Parameters<T>) => Promise<TResult>;
|
|
25
28
|
};
|
|
26
29
|
export {};
|
|
@@ -4,6 +4,8 @@ import { useQueryClient } from '@tanstack/react-query';
|
|
|
4
4
|
function useAwaitableMutation({ mutationFn, onComplete, onError, onSuccess, }) {
|
|
5
5
|
const queryClient = useQueryClient();
|
|
6
6
|
const [isLoading, setIsLoading] = useState(false);
|
|
7
|
+
const [isSuccess, setIsSuccess] = useState(false);
|
|
8
|
+
const [error, setError] = useState();
|
|
7
9
|
const mutate = useCallback(async (...args) => {
|
|
8
10
|
let result;
|
|
9
11
|
let error;
|
|
@@ -11,11 +13,13 @@ function useAwaitableMutation({ mutationFn, onComplete, onError, onSuccess, }) {
|
|
|
11
13
|
setIsLoading(true);
|
|
12
14
|
const _result = await mutationFn(...args);
|
|
13
15
|
result = _result;
|
|
16
|
+
setIsSuccess(true);
|
|
14
17
|
onSuccess?.({ args, data: _result, queryClient });
|
|
15
18
|
return result;
|
|
16
19
|
}
|
|
17
20
|
catch (err) {
|
|
18
21
|
error = err;
|
|
22
|
+
setError(error);
|
|
19
23
|
onError?.({ args, error, queryClient });
|
|
20
24
|
throw err;
|
|
21
25
|
}
|
|
@@ -25,7 +29,10 @@ function useAwaitableMutation({ mutationFn, onComplete, onError, onSuccess, }) {
|
|
|
25
29
|
}
|
|
26
30
|
}, [mutationFn, onComplete, onError, onSuccess, queryClient]);
|
|
27
31
|
return {
|
|
32
|
+
error,
|
|
33
|
+
isError: Boolean(error),
|
|
28
34
|
isLoading,
|
|
35
|
+
isSuccess,
|
|
29
36
|
mutate,
|
|
30
37
|
};
|
|
31
38
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export declare function usePatchCart({ skipInvalidation, }?: {
|
|
2
2
|
skipInvalidation?: boolean;
|
|
3
3
|
}): {
|
|
4
|
+
error: unknown;
|
|
5
|
+
isError: boolean;
|
|
4
6
|
isLoading: boolean;
|
|
7
|
+
isSuccess: boolean;
|
|
5
8
|
mutate: (args_0: {
|
|
6
9
|
cart: import("../../model/storefront.model").PatchCartModel;
|
|
7
10
|
}) => Promise<import("../../model/storefront.model").CartModel>;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export declare function usePatchBillToAddress(): {
|
|
2
|
+
error: unknown;
|
|
3
|
+
isError: boolean;
|
|
2
4
|
isLoading: boolean;
|
|
5
|
+
isSuccess: boolean;
|
|
3
6
|
mutate: (args_0: {
|
|
4
7
|
billTo: import("../../model/storefront.model").BillToModel;
|
|
5
8
|
}) => Promise<import("../../model/storefront.model").BillToModel>;
|
|
@@ -4,6 +4,10 @@ export interface NavigateOptions {
|
|
|
4
4
|
replace?: boolean;
|
|
5
5
|
}
|
|
6
6
|
export type NavigateFn = (href: string, options?: NavigateOptions) => void;
|
|
7
|
+
export interface UseNavigateReturnType {
|
|
8
|
+
isNavigating: boolean;
|
|
9
|
+
navigate: NavigateFn;
|
|
10
|
+
}
|
|
7
11
|
export interface RouteContext {
|
|
8
12
|
basePath?: string;
|
|
9
13
|
navigate: NavigateFn;
|
|
@@ -15,5 +19,5 @@ export interface RouteProviderProps {
|
|
|
15
19
|
}
|
|
16
20
|
export declare function RouteProvider({ basePath, children, navigate, }: RouteProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
17
21
|
export declare function useOnNavigate(callback?: NavigateFn): NavigateFn;
|
|
18
|
-
export declare function useNavigate():
|
|
22
|
+
export declare function useNavigate(): UseNavigateReturnType;
|
|
19
23
|
export declare function useBasePath(): string | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
3
|
-
import { useEffect, useCallback } from 'react';
|
|
3
|
+
import { useEffect, useCallback, useRef } from 'react';
|
|
4
4
|
import { useGlobalState } from '../providers/global-state-provider.js';
|
|
5
5
|
|
|
6
6
|
function RouteProvider({ basePath, children, navigate, }) {
|
|
@@ -22,20 +22,24 @@ function useOnNavigate(callback) {
|
|
|
22
22
|
}, []);
|
|
23
23
|
}
|
|
24
24
|
function useNavigate() {
|
|
25
|
+
const isNavigatingRef = useRef(false);
|
|
25
26
|
const [state] = useGlobalState('routing');
|
|
26
27
|
const trigger = useOnNavigate();
|
|
27
28
|
if (!state) {
|
|
28
29
|
throw new Error('RouteProvider not found');
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
+
const navigate = useCallback((href, options) => {
|
|
31
32
|
trigger(href, options);
|
|
32
33
|
if (href.toLowerCase().startsWith('http')) {
|
|
33
34
|
if (typeof window === 'undefined')
|
|
34
35
|
return;
|
|
36
|
+
isNavigatingRef.current = true;
|
|
35
37
|
return (window.location.href = href);
|
|
36
38
|
}
|
|
39
|
+
isNavigatingRef.current = true;
|
|
37
40
|
return state.navigate(href, options);
|
|
38
41
|
}, [state, trigger]);
|
|
42
|
+
return { isNavigating: isNavigatingRef.current, navigate };
|
|
39
43
|
}
|
|
40
44
|
function useBasePath() {
|
|
41
45
|
const [state] = useGlobalState('routing');
|
|
@@ -3,7 +3,7 @@ import { useNavigate, useBasePath } from './route-provider.js';
|
|
|
3
3
|
|
|
4
4
|
function withRouting(component) {
|
|
5
5
|
const Component = ({ href, onClick, route, ...rest }) => {
|
|
6
|
-
const navigate = useNavigate();
|
|
6
|
+
const { navigate } = useNavigate();
|
|
7
7
|
const basePath = useBasePath();
|
|
8
8
|
if (basePath &&
|
|
9
9
|
href &&
|