@sonic-equipment/ui 124.0.0 → 125.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/address/address.d.ts +9 -0
- package/dist/address/address.js +9 -0
- package/dist/address/address.module.css.js +3 -0
- package/dist/algolia/use-algolia-insights.d.ts +1 -1
- package/dist/breadcrumbs/breadcrumb.js +4 -3
- package/dist/buttons/add-to-cart-button/connected-add-to-cart-button.d.ts +1 -1
- package/dist/buttons/add-to-cart-button/connected-add-to-cart-button.js +2 -2
- package/dist/buttons/button/button.d.ts +2 -1
- package/dist/buttons/button/button.js +2 -2
- package/dist/buttons/button/button.module.css.js +1 -1
- package/dist/checkout/adyen-payment.d.ts +1 -1
- package/dist/checkout/payment-details.d.ts +1 -1
- package/dist/checkout/payment.d.ts +1 -1
- package/dist/checkout/payment.js +1 -1
- package/dist/country-selector/country-select/country-select.d.ts +20 -0
- package/dist/country-selector/country-select/country-select.js +17 -0
- package/dist/country-selector/country-selector-dialog/country-selector-dialog.js +2 -8
- package/dist/exports.d.ts +10 -2
- package/dist/forms/text-field/text-field.d.ts +2 -1
- package/dist/forms/text-field/text-field.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +14 -6
- package/dist/intl/formatted-message.d.ts +1 -2
- package/dist/intl/missing-translation-provider.d.ts +6 -0
- package/dist/intl/missing-translation-provider.js +30 -0
- package/dist/intl/translation-id.d.ts +1 -1
- package/dist/modals/signin/sign-in-dialog.js +1 -1
- package/dist/pages/layouts/checkout-page-layout/checkout-page-layout.d.ts +1 -1
- package/dist/pages/shipping-page/components/edit-address.d.ts +24 -0
- package/dist/pages/shipping-page/components/edit-address.js +54 -0
- package/dist/pages/shipping-page/components/edit-address.module.css.js +3 -0
- package/dist/pages/shipping-page/components/readonly-address.d.ts +10 -0
- package/dist/pages/shipping-page/components/readonly-address.js +25 -0
- package/dist/pages/shipping-page/components/readonly-address.module.css.js +3 -0
- package/dist/pages/shipping-page/shipping-page.d.ts +1 -0
- package/dist/pages/shipping-page/shipping-page.js +75 -0
- package/dist/pages/shipping-page/shipping-page.module.css.js +3 -0
- package/dist/shared/api/shared/hooks/use-awaitable-mutation.d.ts +13 -0
- package/dist/shared/api/shared/hooks/use-awaitable-mutation.js +32 -0
- package/dist/shared/api/storefront/hooks/authentication/use-create-guest-account.d.ts +1 -1
- package/dist/shared/api/storefront/hooks/authentication/use-fetch-session.d.ts +1 -1
- package/dist/shared/api/storefront/hooks/authentication/use-patch-session.d.ts +1 -1
- package/dist/shared/api/storefront/hooks/cart/use-add-product-to-current-cart.d.ts +1 -1
- package/dist/shared/api/storefront/hooks/cart/use-delete-current-cart.d.ts +1 -1
- package/dist/shared/api/storefront/hooks/cart/use-fetch-current-cart-checkout-atp.d.ts +1 -1
- package/dist/shared/api/storefront/hooks/cart/use-fetch-current-cart-lines-with-atp.d.ts +15 -15
- package/dist/shared/api/storefront/hooks/cart/use-fetch-current-cart-lines.d.ts +1 -1
- package/dist/shared/api/storefront/hooks/cart/use-fetch-current-cart-product-atp.d.ts +1 -1
- package/dist/shared/api/storefront/hooks/cart/use-fetch-current-cart-promotions.d.ts +1 -1
- package/dist/shared/api/storefront/hooks/cart/use-fetch-current-cart-with-atp.d.ts +1 -1
- package/dist/shared/api/storefront/hooks/cart/use-fetch-current-cart.d.ts +1 -1
- package/dist/shared/api/storefront/hooks/cart/use-patch-cart-line-by-id.d.ts +6 -0
- package/dist/shared/api/storefront/hooks/cart/{use-update-cart-line-by-id.js → use-patch-cart-line-by-id.js} +4 -4
- package/dist/shared/api/storefront/hooks/cart/use-patch-cart.d.ts +10 -3
- package/dist/shared/api/storefront/hooks/cart/use-patch-cart.js +10 -7
- package/dist/shared/api/storefront/hooks/cart/use-place-order.d.ts +1 -1
- package/dist/shared/api/storefront/hooks/cart/use-save-cart-for-later.d.ts +1 -1
- package/dist/shared/api/storefront/hooks/customer/use-fetch-bill-to-addresses.d.ts +1 -1
- package/dist/shared/api/storefront/hooks/customer/use-fetch-ship-to-addresses.d.ts +1 -1
- package/dist/shared/api/storefront/hooks/customer/use-patch-bill-to-address.d.ts +6 -0
- package/dist/shared/api/storefront/hooks/customer/use-patch-bill-to-address.js +15 -0
- package/dist/shared/api/storefront/hooks/payment/use-create-adyen-session.d.ts +1 -1
- package/dist/shared/api/storefront/hooks/payment/use-fetch-adyen-config.d.ts +1 -1
- package/dist/shared/api/storefront/hooks/translation/use-fetch-translations.js +1 -1
- package/dist/shared/api/storefront/hooks/website/use-fetch-countries-languages.d.ts +2 -2
- package/dist/shared/api/storefront/hooks/website/use-fetch-countries.d.ts +3 -1
- package/dist/shared/api/storefront/hooks/website/use-fetch-countries.js +2 -1
- package/dist/shared/api/storefront/hooks/website/use-fetch-settings.d.ts +1 -1
- package/dist/shared/api/storefront/hooks/website/use-update-locale.d.ts +1 -1
- package/dist/shared/api/storefront/hooks/wishlist/use-fetch-all-wishlists-items.d.ts +1 -1
- package/dist/shared/api/storefront/hooks/wishlist/use-fetch-wishlists.d.ts +1 -1
- package/dist/shared/api/storefront/services/authentication-service.d.ts +1 -1
- package/dist/shared/api/storefront/services/cart-service.d.ts +2 -2
- package/dist/shared/api/storefront/services/cart-service.js +2 -2
- package/dist/shared/api/storefront/services/customer-service.d.ts +2 -2
- package/dist/shared/api/storefront/services/customer-service.js +2 -2
- package/dist/shared/api/storefront/services/payment-service.d.ts +1 -1
- package/dist/shared/api/storefront/services/website-service.d.ts +1 -1
- package/dist/shared/api/storefront/services/wishlist-service.d.ts +1 -1
- package/dist/shared/feature-flags/use-feature-flags.d.ts +3 -0
- package/dist/shared/feature-flags/use-feature-flags.js +3 -0
- package/dist/shared/ga/google-analytics-provider.d.ts +1 -1
- package/dist/shared/ga/google-analytics-provider.js +2 -1
- package/dist/shared/ga/use-data-layer.d.ts +1 -1
- package/dist/shared/providers/cart-provider.d.ts +1 -1
- package/dist/shared/providers/favorite-provider.d.ts +1 -1
- package/dist/shared/utils/string.d.ts +1 -0
- package/dist/shared/utils/string.js +5 -0
- package/dist/styles.css +191 -91
- package/dist/tooltip/tooltip.js +1 -1
- package/dist/tooltip/tooltip.module.css.js +1 -1
- package/package.json +1 -1
- package/dist/shared/api/storefront/hooks/cart/use-update-cart-line-by-id.d.ts +0 -6
- package/dist/shared/api/storefront/hooks/customer/use-update-bill-to-address.d.ts +0 -6
- package/dist/shared/api/storefront/hooks/customer/use-update-bill-to-address.js +0 -17
- /package/dist/shared/api/storefront/model/{shop.model.d.ts → storefront.model.d.ts} +0 -0
- /package/dist/shared/api/storefront/model/{shop.model.js → storefront.model.js} +0 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useState, useMemo } from 'react';
|
|
3
|
+
import { Form } from 'react-aria-components';
|
|
4
|
+
import { CountrySelect } from '../../../country-selector/country-select/country-select.js';
|
|
5
|
+
import { Checkbox } from '../../../forms/checkbox/checkbox.js';
|
|
6
|
+
import { TextField } from '../../../forms/text-field/text-field.js';
|
|
7
|
+
import { FormattedMessage } from '../../../intl/formatted-message.js';
|
|
8
|
+
import { useFormattedMessage } from '../../../intl/use-formatted-message.js';
|
|
9
|
+
import { validatePhone, validateEmail } from '../../../shared/model/address.js';
|
|
10
|
+
import { Tooltip } from '../../../tooltip/tooltip.js';
|
|
11
|
+
import { Heading } from '../../../typography/heading/heading.js';
|
|
12
|
+
import styles from './edit-address.module.css.js';
|
|
13
|
+
|
|
14
|
+
const EDIT_ADDRESS_FORM_ID = 'billToForm';
|
|
15
|
+
function EditAddresses({ countries, isLoading, onSubmit, }) {
|
|
16
|
+
const t = useFormattedMessage();
|
|
17
|
+
const [companyName, setCompanyName] = useState('');
|
|
18
|
+
const [lastName, setLastName] = useState('');
|
|
19
|
+
const lastNameKey = useMemo(() => `lastname-${Boolean(companyName)}`, [companyName]);
|
|
20
|
+
return (jsxs(Fragment, { children: [jsxs("section", { className: styles['form-container'], children: [jsx(Heading, { className: styles['form-header'], size: "xs", tag: "h2", children: jsx(FormattedMessage, { id: "Billing address" }) }), jsxs(Form, { className: styles.form, "data-test-selector": "billToAddressForm", id: EDIT_ADDRESS_FORM_ID, onSubmit: e => {
|
|
21
|
+
e.preventDefault();
|
|
22
|
+
const formData = new FormData(e.currentTarget);
|
|
23
|
+
const countryFormValue = formData.get('country')?.toString();
|
|
24
|
+
const country = countries.find(country => country.id === countryFormValue);
|
|
25
|
+
if (!country)
|
|
26
|
+
throw new Error(`Country not found ${formData.get('country')}`);
|
|
27
|
+
onSubmit({
|
|
28
|
+
address: {
|
|
29
|
+
address1: formData.get('address1')?.toString() || '',
|
|
30
|
+
address2: formData.get('address2')?.toString() || '',
|
|
31
|
+
address3: formData.get('address3')?.toString() || '',
|
|
32
|
+
attention: formData.get('attention')?.toString() || '',
|
|
33
|
+
city: formData.get('address1')?.toString() || '',
|
|
34
|
+
companyName: formData.get('companyName')?.toString() || '',
|
|
35
|
+
country,
|
|
36
|
+
firstName: formData.get('firstName')?.toString() || '',
|
|
37
|
+
lastName: formData.get('address1')?.toString() || '',
|
|
38
|
+
phone: formData.get('phone')?.toString() || '',
|
|
39
|
+
postalCode: formData.get('postalCode')?.toString() || '',
|
|
40
|
+
},
|
|
41
|
+
notes: formData.get('notes')?.toString() || '',
|
|
42
|
+
});
|
|
43
|
+
}, 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 }, lastNameKey), 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, name: "country" }) }), jsx("div", { className: styles['span-2'], children: jsx(TextField, { isRequired: true, isDisabled: isLoading, label: t('Phone'), name: "phone", showLabel: true, validate: value => {
|
|
44
|
+
if (!value)
|
|
45
|
+
return value;
|
|
46
|
+
return (validatePhone(value) || 'Vul een geldig telefoonnummer in');
|
|
47
|
+
} }) }), jsx("div", { className: styles['span-2'], children: jsx(TextField, { isRequired: true, isDisabled: isLoading, label: t('Email'), name: "email", showLabel: true, type: "email", validate: value => {
|
|
48
|
+
if (!value)
|
|
49
|
+
return value;
|
|
50
|
+
return validateEmail(value) || 'Vul een geldig emailadres in';
|
|
51
|
+
} }) }), jsx("div", { className: styles['span-2'], children: jsx(TextField, { isDisabled: isLoading, isMultiline: true, label: t('Add order notes'), name: "notes", rows: 3, showLabel: true }) })] })] }), jsxs("section", { className: styles['form-container'], children: [jsx(Heading, { className: styles['form-header'], size: "xs", tag: "h2", children: jsx(FormattedMessage, { id: "Shipping address" }) }), jsxs("div", { className: styles['use-invoice-checkbox'], children: [jsx(Checkbox, { 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.') })] })] })] }));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { EDIT_ADDRESS_FORM_ID, EditAddresses };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BillToModel, ShipToModel } from '../../../shared/api/storefront/model/storefront.model';
|
|
2
|
+
export declare function ReadOnlyAddresses({ billTo, isLoading, notes, onSubmit, shipTo, }: {
|
|
3
|
+
billTo: BillToModel | undefined | null;
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
notes: string;
|
|
6
|
+
onSubmit: ({ notes }: {
|
|
7
|
+
notes: string;
|
|
8
|
+
}) => void;
|
|
9
|
+
shipTo: ShipToModel | undefined | null;
|
|
10
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { Form } from 'react-aria-components';
|
|
3
|
+
import { Address } from '../../../address/address.js';
|
|
4
|
+
import { Checkbox } from '../../../forms/checkbox/checkbox.js';
|
|
5
|
+
import { TextField } from '../../../forms/text-field/text-field.js';
|
|
6
|
+
import { FormattedMessage } from '../../../intl/formatted-message.js';
|
|
7
|
+
import { useFormattedMessage } from '../../../intl/use-formatted-message.js';
|
|
8
|
+
import { RouteLink } from '../../../shared/routing/route-link.js';
|
|
9
|
+
import { Heading } from '../../../typography/heading/heading.js';
|
|
10
|
+
import { EDIT_ADDRESS_FORM_ID } from './edit-address.js';
|
|
11
|
+
import styles from './readonly-address.module.css.js';
|
|
12
|
+
|
|
13
|
+
const ACCOUNT_ADDRESSES_PATH = '/MyAccount/Addresses';
|
|
14
|
+
function ReadOnlyAddresses({ billTo, isLoading, notes, onSubmit, shipTo, }) {
|
|
15
|
+
const t = useFormattedMessage();
|
|
16
|
+
return (jsxs(Form, { className: styles.form, id: EDIT_ADDRESS_FORM_ID, onSubmit: e => {
|
|
17
|
+
e.preventDefault();
|
|
18
|
+
const formData = new FormData(e.currentTarget);
|
|
19
|
+
onSubmit({
|
|
20
|
+
notes: formData.get('notes')?.toString() || '',
|
|
21
|
+
});
|
|
22
|
+
}, children: [jsxs("section", { className: styles.section, children: [jsx(Heading, { className: styles['section-header'], size: "xs", tag: "h2", children: jsx(FormattedMessage, { id: "Billing address" }) }), jsxs(RouteLink, { className: styles['section-link'], color: "secondary", href: ACCOUNT_ADDRESSES_PATH, isDisabled: isLoading, children: [jsx(FormattedMessage, { id: "Edit billing address" }), " >"] }), jsxs("div", { className: styles['section-content'], children: [billTo && (jsx(Address, { 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("section", { className: styles.section, children: [jsx(Heading, { className: styles['section-header'], size: "xs", tag: "h2", children: jsx(FormattedMessage, { id: "Shipping address" }) }), jsxs(RouteLink, { className: styles['section-link'], color: "secondary", href: ACCOUNT_ADDRESSES_PATH, isDisabled: isLoading, children: [jsx(FormattedMessage, { id: "Edit shipping address" }), " >"] }), jsxs("div", { className: styles['section-content'], children: [jsx(Checkbox, { className: styles['use-invoice-checkbox'], isDisabled: true, isSelected: true, children: jsx(FormattedMessage, { id: "Use billing address" }) }), shipTo && (jsx(Address, { city: shipTo.city, companyName: shipTo.companyName, country: shipTo.country?.name, email: shipTo.email, phone: shipTo.phone, postalCode: shipTo.postalCode }))] })] })] }));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { ReadOnlyAddresses };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var styles = {"section":"readonly-address-module-86tan","section-header":"readonly-address-module-VLsk2","section-content":"readonly-address-module-84Ake","section-link":"readonly-address-module-rxXHA","notes":"readonly-address-module-mhW4y","use-invoice-checkbox":"readonly-address-module-qgm1D"};
|
|
2
|
+
|
|
3
|
+
export { styles as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ShippingPage(): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { Button } from '../../buttons/button/button.js';
|
|
4
|
+
import { CartTotals } from '../../cart-totals/cart-totals.js';
|
|
5
|
+
import { CartTotalsSummary } from '../../cart-totals/cart-totals-summary.js';
|
|
6
|
+
import { FormattedMessage } from '../../intl/formatted-message.js';
|
|
7
|
+
import { useFormattedMessage } from '../../intl/use-formatted-message.js';
|
|
8
|
+
import { useFetchCurrentCart } from '../../shared/api/storefront/hooks/cart/use-fetch-current-cart.js';
|
|
9
|
+
import { usePatchCart } from '../../shared/api/storefront/hooks/cart/use-patch-cart.js';
|
|
10
|
+
import { usePatchBillToAddress } from '../../shared/api/storefront/hooks/customer/use-patch-bill-to-address.js';
|
|
11
|
+
import { useFetchCountries } from '../../shared/api/storefront/hooks/website/use-fetch-countries.js';
|
|
12
|
+
import { useNavigate } from '../../shared/routing/route-provider.js';
|
|
13
|
+
import { ErrorPage } from '../error-page/error-page.js';
|
|
14
|
+
import { CheckoutPageLayout } from '../layouts/checkout-page-layout/checkout-page-layout.js';
|
|
15
|
+
import { LoadingPage } from '../loading-page/loading-page.js';
|
|
16
|
+
import { Page } from '../page/page.js';
|
|
17
|
+
import { EDIT_ADDRESS_FORM_ID, EditAddresses } from './components/edit-address.js';
|
|
18
|
+
import { ReadOnlyAddresses } from './components/readonly-address.js';
|
|
19
|
+
import styles from './shipping-page.module.css.js';
|
|
20
|
+
|
|
21
|
+
const REVIEW_AND_SUBMIT_PATH = '/CheckoutReviewAndSubmit';
|
|
22
|
+
function ShippingPage() {
|
|
23
|
+
const { data: cart, error, isLoading: isLoadingCart } = useFetchCurrentCart();
|
|
24
|
+
const hasCart = Boolean(cart);
|
|
25
|
+
const hasBillTo = Boolean(cart?.billTo);
|
|
26
|
+
const hasEmptyBillTo = Boolean(cart?.billTo?.address1);
|
|
27
|
+
const { data: countries, isLoading: isLoadingCountries } = useFetchCountries({
|
|
28
|
+
enabled: !hasEmptyBillTo,
|
|
29
|
+
});
|
|
30
|
+
const { isLoading: isPatchBillToAddress, mutate: patchBillToAddress } = usePatchBillToAddress();
|
|
31
|
+
const { isLoading: isPatchingCart, mutate: patchCart } = usePatchCart();
|
|
32
|
+
const t = useFormattedMessage();
|
|
33
|
+
const isLoading = isLoadingCart || isLoadingCountries;
|
|
34
|
+
const isPatching = isPatchBillToAddress || isPatchingCart;
|
|
35
|
+
const navigate = useNavigate();
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (hasCart && !hasBillTo)
|
|
38
|
+
navigate('/sign-in?returnUrl=/CheckoutShipping');
|
|
39
|
+
}, [hasCart, hasBillTo, navigate]);
|
|
40
|
+
if (error)
|
|
41
|
+
return jsx(ErrorPage, { error: error });
|
|
42
|
+
if (isLoading)
|
|
43
|
+
return jsx(LoadingPage, {});
|
|
44
|
+
if (!cart || (!hasEmptyBillTo && !countries))
|
|
45
|
+
return null;
|
|
46
|
+
if (!hasBillTo) {
|
|
47
|
+
return (jsx(Page, { breadCrumb: [
|
|
48
|
+
{ href: '/', label: t('Home') },
|
|
49
|
+
{ href: '/CheckoutShipping', label: t('Shipping details') },
|
|
50
|
+
], children: jsx("h1", { children: jsx(FormattedMessage, { id: "Please Sign In" }) }) }));
|
|
51
|
+
}
|
|
52
|
+
return (jsx(Page, { breadCrumb: [
|
|
53
|
+
{ href: '/', label: t('Home') },
|
|
54
|
+
{ href: '/CheckoutShipping', label: t('Shipping details') },
|
|
55
|
+
], title: t('Shipping details'), children: jsx(CheckoutPageLayout, { actions: {
|
|
56
|
+
primary: (jsx(Button, { withArrow: true, "data-test-selector": "checkoutShippingCartTotalContinueButton", form: EDIT_ADDRESS_FORM_ID, isDisabled: isPatching, isLoading: isPatching && jsx(FormattedMessage, { id: "Continue shopping" }), type: "submit", children: jsx(FormattedMessage, { id: "Continue shopping" }) })),
|
|
57
|
+
}, 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 || 0 }), children: jsx("div", { className: styles['main-content'], children: hasEmptyBillTo ? (jsx(ReadOnlyAddresses, { billTo: cart.billTo, isLoading: isPatching, notes: cart.notes, onSubmit: async ({ notes }) => {
|
|
58
|
+
if (!cart.billTo)
|
|
59
|
+
return;
|
|
60
|
+
await patchCart({ cart: { ...cart, notes } });
|
|
61
|
+
navigate(REVIEW_AND_SUBMIT_PATH);
|
|
62
|
+
}, shipTo: cart.shipTo })) : (jsx(EditAddresses, { countries: countries || [], isLoading: isPatching, onSubmit: async ({ address, notes }) => {
|
|
63
|
+
if (!cart.billTo)
|
|
64
|
+
return;
|
|
65
|
+
await Promise.all([
|
|
66
|
+
patchBillToAddress({
|
|
67
|
+
billTo: { ...cart.billTo, ...address },
|
|
68
|
+
}),
|
|
69
|
+
patchCart({ cart: { ...cart, notes } }),
|
|
70
|
+
]);
|
|
71
|
+
navigate(REVIEW_AND_SUBMIT_PATH);
|
|
72
|
+
} })) }) }) }));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { ShippingPage };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
2
|
+
export type InferPromiseResult<T> = T extends (...args: any) => Promise<infer TResult> ? TResult : never;
|
|
3
|
+
interface UseAwaitableMutationArgs<T extends (...args: any) => Promise<TResult>, TResult = InferPromiseResult<T>> {
|
|
4
|
+
mutationFn: T;
|
|
5
|
+
onComplete?: (data: TResult | undefined, error: unknown | undefined, variables: Parameters<T>, queryClient: QueryClient) => void;
|
|
6
|
+
onError?: (error: unknown, variables: Parameters<T>, queryClient: QueryClient) => void;
|
|
7
|
+
onSuccess?: (data: TResult, variables: Parameters<T>, queryClient: QueryClient) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare function useAwaitableMutation<T extends (...args: any) => Promise<TResult>, TResult = InferPromiseResult<T>>({ mutationFn, onComplete, onError, onSuccess, }: UseAwaitableMutationArgs<T, TResult>): {
|
|
10
|
+
isLoading: boolean;
|
|
11
|
+
mutate(...args: Parameters<T>): Promise<TResult>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
3
|
+
|
|
4
|
+
function useAwaitableMutation({ mutationFn, onComplete, onError, onSuccess, }) {
|
|
5
|
+
const queryClient = useQueryClient();
|
|
6
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
7
|
+
return {
|
|
8
|
+
isLoading,
|
|
9
|
+
async mutate(...args) {
|
|
10
|
+
let result;
|
|
11
|
+
let error;
|
|
12
|
+
try {
|
|
13
|
+
setIsLoading(true);
|
|
14
|
+
const _result = await mutationFn(...args);
|
|
15
|
+
result = _result;
|
|
16
|
+
onSuccess?.(_result, args, queryClient);
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
error = err;
|
|
21
|
+
onError?.(error, args, queryClient);
|
|
22
|
+
throw err;
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
setIsLoading(false);
|
|
26
|
+
onComplete?.(result, error, args, queryClient);
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { useAwaitableMutation };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AccountModel } from 'shared/api/storefront/model/
|
|
1
|
+
import { AccountModel } from 'shared/api/storefront/model/storefront.model';
|
|
2
2
|
export declare function useCreateGuestAccount(): import("@tanstack/react-query").UseMutationResult<AccountModel, Error, {
|
|
3
3
|
defaultWarehouseId: string;
|
|
4
4
|
}, unknown>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SessionModel as ShopSessionModel } from '../../model/
|
|
1
|
+
import { SessionModel as ShopSessionModel } from '../../model/storefront.model';
|
|
2
2
|
export declare function useFetchSession({ enabled, }?: {
|
|
3
3
|
enabled?: boolean;
|
|
4
4
|
}): import("@tanstack/react-query").UseQueryResult<ShopSessionModel, Error>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PatchSessionModel, SessionModel } from 'shared/api/storefront/model/
|
|
1
|
+
import { PatchSessionModel, SessionModel } from 'shared/api/storefront/model/storefront.model';
|
|
2
2
|
export declare function usePatchSession(): import("@tanstack/react-query").UseMutationResult<SessionModel, Error, {
|
|
3
3
|
session: PatchSessionModel;
|
|
4
4
|
}, unknown>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { CartLineModel } from '../../model/
|
|
1
|
+
import { CartLineModel } from '../../model/storefront.model';
|
|
2
2
|
import { AddProductToCurrentCartParams } from '../../services/cart-service';
|
|
3
3
|
export declare function useAddProductToCurrentCart(): import("@tanstack/react-query").UseMutationResult<CartLineModel, Error, AddProductToCurrentCartParams, unknown>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { CheckoutAtpEntry } from '../../model/
|
|
1
|
+
import { CheckoutAtpEntry } from '../../model/storefront.model';
|
|
2
2
|
export declare function useFetchCurrentCheckoutAtp(): import("@tanstack/react-query").UseQueryResult<CheckoutAtpEntry[], Error>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare function useFetchCurrentCartLinesWithAtp(): {
|
|
2
|
-
data: import("../../model/
|
|
2
|
+
data: import("../../model/storefront.model").CartLineModel[] | undefined;
|
|
3
3
|
error: Error | null;
|
|
4
4
|
isError: boolean;
|
|
5
5
|
isFetching: boolean;
|
|
@@ -21,11 +21,11 @@ export declare function useFetchCurrentCartLinesWithAtp(): {
|
|
|
21
21
|
isPlaceholderData: boolean;
|
|
22
22
|
isRefetching: boolean;
|
|
23
23
|
isStale: boolean;
|
|
24
|
-
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<import("../../model/
|
|
24
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<import("../../model/storefront.model").CartModel, Error>>;
|
|
25
25
|
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
26
|
-
promise: Promise<import("../../model/
|
|
26
|
+
promise: Promise<import("../../model/storefront.model").CartModel>;
|
|
27
27
|
} | {
|
|
28
|
-
data: import("../../model/
|
|
28
|
+
data: import("../../model/storefront.model").CartLineModel[] | undefined;
|
|
29
29
|
error: Error | null;
|
|
30
30
|
isError: boolean;
|
|
31
31
|
isFetching: boolean;
|
|
@@ -47,11 +47,11 @@ export declare function useFetchCurrentCartLinesWithAtp(): {
|
|
|
47
47
|
isPlaceholderData: boolean;
|
|
48
48
|
isRefetching: boolean;
|
|
49
49
|
isStale: boolean;
|
|
50
|
-
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<import("../../model/
|
|
50
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<import("../../model/storefront.model").CartModel, Error>>;
|
|
51
51
|
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
52
|
-
promise: Promise<import("../../model/
|
|
52
|
+
promise: Promise<import("../../model/storefront.model").CartModel>;
|
|
53
53
|
} | {
|
|
54
|
-
data: import("../../model/
|
|
54
|
+
data: import("../../model/storefront.model").CartLineModel[] | undefined;
|
|
55
55
|
error: Error | null;
|
|
56
56
|
isError: boolean;
|
|
57
57
|
isFetching: boolean;
|
|
@@ -73,11 +73,11 @@ export declare function useFetchCurrentCartLinesWithAtp(): {
|
|
|
73
73
|
isPlaceholderData: boolean;
|
|
74
74
|
isRefetching: boolean;
|
|
75
75
|
isStale: boolean;
|
|
76
|
-
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<import("../../model/
|
|
76
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<import("../../model/storefront.model").CartModel, Error>>;
|
|
77
77
|
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
78
|
-
promise: Promise<import("../../model/
|
|
78
|
+
promise: Promise<import("../../model/storefront.model").CartModel>;
|
|
79
79
|
} | {
|
|
80
|
-
data: import("../../model/
|
|
80
|
+
data: import("../../model/storefront.model").CartLineModel[] | undefined;
|
|
81
81
|
error: Error | null;
|
|
82
82
|
isError: boolean;
|
|
83
83
|
isFetching: boolean;
|
|
@@ -99,11 +99,11 @@ export declare function useFetchCurrentCartLinesWithAtp(): {
|
|
|
99
99
|
isPlaceholderData: boolean;
|
|
100
100
|
isRefetching: boolean;
|
|
101
101
|
isStale: boolean;
|
|
102
|
-
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<import("../../model/
|
|
102
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<import("../../model/storefront.model").CartModel, Error>>;
|
|
103
103
|
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
104
|
-
promise: Promise<import("../../model/
|
|
104
|
+
promise: Promise<import("../../model/storefront.model").CartModel>;
|
|
105
105
|
} | {
|
|
106
|
-
data: import("../../model/
|
|
106
|
+
data: import("../../model/storefront.model").CartLineModel[] | undefined;
|
|
107
107
|
error: Error | null;
|
|
108
108
|
isError: boolean;
|
|
109
109
|
isFetching: boolean;
|
|
@@ -125,7 +125,7 @@ export declare function useFetchCurrentCartLinesWithAtp(): {
|
|
|
125
125
|
isPlaceholderData: boolean;
|
|
126
126
|
isRefetching: boolean;
|
|
127
127
|
isStale: boolean;
|
|
128
|
-
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<import("../../model/
|
|
128
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<import("../../model/storefront.model").CartModel, Error>>;
|
|
129
129
|
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
130
|
-
promise: Promise<import("../../model/
|
|
130
|
+
promise: Promise<import("../../model/storefront.model").CartModel>;
|
|
131
131
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function useFetchCurrentCartLines(): import("@tanstack/react-query").UseQueryResult<import("../../model/
|
|
1
|
+
export declare function useFetchCurrentCartLines(): import("@tanstack/react-query").UseQueryResult<import("../../model/storefront.model").CartLineModel[], Error>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ProductAtp } from '../../model/
|
|
1
|
+
import { ProductAtp } from '../../model/storefront.model';
|
|
2
2
|
export declare function useFetchCurrentCartProductAtp(): import("@tanstack/react-query").UseQueryResult<ProductAtp[], Error>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function useFetchCurrentCartPromotions(): import("@tanstack/react-query").UseQueryResult<import("../../model/
|
|
1
|
+
export declare function useFetchCurrentCartPromotions(): import("@tanstack/react-query").UseQueryResult<import("../../model/storefront.model").PromotionModel[], Error>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CartModel } from '../../model/
|
|
1
|
+
import { CartModel } from '../../model/storefront.model';
|
|
2
2
|
export declare function useFetchCurrentCart<T = CartModel>({ select, }?: {
|
|
3
3
|
select?: (data: CartModel) => T;
|
|
4
4
|
}): import("@tanstack/react-query").UseQueryResult<T, Error>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CartLineModel } from '../../model/storefront.model';
|
|
2
|
+
export interface PatchCartLineParams {
|
|
3
|
+
cartLine: CartLineModel;
|
|
4
|
+
cartLineId: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function usePatchCartLineById(): import("@tanstack/react-query").UseMutationResult<void, Error, PatchCartLineParams, unknown>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { useQueryClient, useMutation } from '@tanstack/react-query';
|
|
2
|
-
import {
|
|
2
|
+
import { patchCartLineById } from '../../services/cart-service.js';
|
|
3
3
|
|
|
4
|
-
function
|
|
4
|
+
function usePatchCartLineById() {
|
|
5
5
|
const queryClient = useQueryClient();
|
|
6
6
|
return useMutation({
|
|
7
7
|
mutationFn: async ({ cartLine: _cartLine, cartLineId }) => {
|
|
8
|
-
await
|
|
8
|
+
await patchCartLineById({ cartLine: _cartLine, cartLineId });
|
|
9
9
|
// Invalidate the related current cart query cache
|
|
10
10
|
queryClient.invalidateQueries({ queryKey: ['carts', 'current'] });
|
|
11
11
|
},
|
|
@@ -15,4 +15,4 @@ function useUpdateCartLineById() {
|
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export {
|
|
18
|
+
export { usePatchCartLineById };
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
export declare function usePatchCart():
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export declare function usePatchCart(): {
|
|
2
|
+
isLoading: boolean;
|
|
3
|
+
mutate(args_0: {
|
|
4
|
+
cart: Partial<Omit<import("../../model/storefront.model").CartModel, "billTo"> & {
|
|
5
|
+
billTo?: import("../../model/storefront.model").BillToModel | {
|
|
6
|
+
id: string;
|
|
7
|
+
} | null;
|
|
8
|
+
}>;
|
|
9
|
+
}): Promise<import("../../model/storefront.model").CartModel>;
|
|
10
|
+
};
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useAwaitableMutation } from '../../../shared/hooks/use-awaitable-mutation.js';
|
|
2
2
|
import { patchCart } from '../../services/cart-service.js';
|
|
3
3
|
|
|
4
4
|
function usePatchCart() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
return useAwaitableMutation({
|
|
6
|
+
mutationFn: patchCart,
|
|
7
|
+
onError: (_, [{ cart }], queryClient) => {
|
|
8
|
+
queryClient.invalidateQueries({ queryKey: ['carts', cart.id] });
|
|
9
|
+
},
|
|
10
|
+
onSuccess: (updatedCart, [{ cart }], queryClient) => {
|
|
11
|
+
queryClient.setQueriesData({ queryKey: ['carts', updatedCart.id] }, { ...updatedCart, cartLines: cart.cartLines });
|
|
12
|
+
},
|
|
13
|
+
});
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
export { usePatchCart };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function useFetchBillToAddresses(): import("@tanstack/react-query").UseQueryResult<import("../../model/
|
|
1
|
+
export declare function useFetchBillToAddresses(): import("@tanstack/react-query").UseQueryResult<import("../../model/storefront.model").BillToModel[] | null, Error>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare function useFetchShipToAddresses({ shipToId }: {
|
|
2
2
|
shipToId: string;
|
|
3
|
-
}): import("@tanstack/react-query").UseQueryResult<import("../../model/
|
|
3
|
+
}): import("@tanstack/react-query").UseQueryResult<import("../../model/storefront.model").ShipToModel[] | null, Error>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { patchBillToAddress } from '../../services/customer-service.js';
|
|
2
|
+
import { useAwaitableMutation } from '../../../shared/hooks/use-awaitable-mutation.js';
|
|
3
|
+
|
|
4
|
+
function usePatchBillToAddress() {
|
|
5
|
+
return useAwaitableMutation({
|
|
6
|
+
mutationFn: patchBillToAddress,
|
|
7
|
+
onComplete(_result, _error, _args, queryClient) {
|
|
8
|
+
queryClient.invalidateQueries({ queryKey: ['customer'] });
|
|
9
|
+
queryClient.invalidateQueries({ queryKey: ['carts'] });
|
|
10
|
+
queryClient.invalidateQueries({ queryKey: ['session'] });
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { usePatchBillToAddress };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { PaymentAuthenticationModel } from 'shared/api/storefront/model/
|
|
1
|
+
import { PaymentAuthenticationModel } from 'shared/api/storefront/model/storefront.model';
|
|
2
2
|
import { CreateAdyenSessionParameters } from 'shared/api/storefront/services/payment-service';
|
|
3
3
|
export declare function useCreateAdyenSession(): import("@tanstack/react-query").UseMutationResult<PaymentAuthenticationModel, Error, CreateAdyenSessionParameters, unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function useFetchAdyenConfig(): import("@tanstack/react-query").UseQueryResult<import("../../model/
|
|
1
|
+
export declare function useFetchAdyenConfig(): import("@tanstack/react-query").UseQueryResult<import("../../model/storefront.model").AdyenSettings, Error>;
|
|
@@ -7,7 +7,7 @@ function useFetchTranslations(languagCode, { enabled = true } = { enabled: true
|
|
|
7
7
|
enabled,
|
|
8
8
|
gcTime: 1 * TIME.DAY,
|
|
9
9
|
queryFn: () => fetchTranslations(languagCode),
|
|
10
|
-
queryKey: ['translations'],
|
|
10
|
+
queryKey: ['translations', languagCode],
|
|
11
11
|
staleTime: 1 * TIME.DAY,
|
|
12
12
|
});
|
|
13
13
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare function useFetchCountriesLanguages({ enabled, }?: {
|
|
2
2
|
enabled?: boolean;
|
|
3
3
|
}): import("@tanstack/react-query").UseQueryResult<{
|
|
4
|
-
countries: import("../../model/
|
|
5
|
-
languages: import("../../model/
|
|
4
|
+
countries: import("../../model/storefront.model").CountryModel[];
|
|
5
|
+
languages: import("../../model/storefront.model").LanguageModel[];
|
|
6
6
|
}, Error>;
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
export declare function useFetchCountries(
|
|
1
|
+
export declare function useFetchCountries({ enabled }?: {
|
|
2
|
+
enabled: boolean;
|
|
3
|
+
}): import("@tanstack/react-query").UseQueryResult<import("../../model/storefront.model").CountryModel[], Error>;
|
|
@@ -2,8 +2,9 @@ import { useQuery } from '@tanstack/react-query';
|
|
|
2
2
|
import { TIME } from '../../../../utils/time.js';
|
|
3
3
|
import { fetchCountries } from '../../services/website-service.js';
|
|
4
4
|
|
|
5
|
-
function useFetchCountries() {
|
|
5
|
+
function useFetchCountries({ enabled = true } = { enabled: true }) {
|
|
6
6
|
return useQuery({
|
|
7
|
+
enabled,
|
|
7
8
|
gcTime: 24 * TIME.HOUR,
|
|
8
9
|
queryFn: fetchCountries,
|
|
9
10
|
queryKey: ['countries'],
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SettingsCollectionModel } from '../../model/
|
|
1
|
+
import { SettingsCollectionModel } from '../../model/storefront.model';
|
|
2
2
|
export declare function useFetchSettings({ enabled, }?: {
|
|
3
3
|
enabled?: boolean;
|
|
4
4
|
}): import("@tanstack/react-query").UseQueryResult<SettingsCollectionModel, Error>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SessionModel } from '../../model/
|
|
1
|
+
import { SessionModel } from '../../model/storefront.model';
|
|
2
2
|
export declare function useUpdateLocale(): import("@tanstack/react-query").UseMutationResult<SessionModel, Error, {
|
|
3
3
|
countryId: string;
|
|
4
4
|
languageId: string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { WishListCollectionModel as ShopWishListCollectionModel } from '../../model/
|
|
1
|
+
import { WishListCollectionModel as ShopWishListCollectionModel } from '../../model/storefront.model';
|
|
2
2
|
export declare function useFetchWishLists(): import("@tanstack/react-query").UseQueryResult<ShopWishListCollectionModel, Error>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AccountModel, PatchSessionModel, SessionModel, SessionModel as ShopSessionModel } from '../model/
|
|
1
|
+
import { AccountModel, PatchSessionModel, SessionModel, SessionModel as ShopSessionModel } from '../model/storefront.model';
|
|
2
2
|
export declare function fetchSession(): Promise<ShopSessionModel>;
|
|
3
3
|
export declare function patchSession({ session, }: {
|
|
4
4
|
session: PatchSessionModel;
|