@sonic-equipment/ui 200.0.0 → 201.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 (62) hide show
  1. package/dist/algolia/algolia-multi-select-filter-section.js +1 -1
  2. package/dist/country-select/hooks/use-countries.d.ts +2 -2
  3. package/dist/country-select/hooks/use-countries.js +1 -1
  4. package/dist/exports.d.ts +8 -2
  5. package/dist/forms/elements/checkbox/checkbox.d.ts +1 -0
  6. package/dist/forms/elements/checkbox/checkbox.js +1 -1
  7. package/dist/forms/elements/checkbox/checkbox.module.css.js +1 -1
  8. package/dist/forms/partials/address-form/address-form.d.ts +11 -0
  9. package/dist/forms/partials/address-form/address-form.js +36 -0
  10. package/dist/forms/partials/address-form/address-form.module.css.js +3 -0
  11. package/dist/index.js +9 -3
  12. package/dist/intl/translation-id.d.ts +1 -1
  13. package/dist/pages/account/components/sign-in-form/sign-in-form.d.ts +2 -1
  14. package/dist/pages/account/components/sign-in-form/sign-in-form.js +8 -6
  15. package/dist/pages/account/sign-in-page/sign-in-page.js +2 -2
  16. package/dist/pages/checkout/shipping-page/components/edit-checkout-bill-to-address-form.js +2 -2
  17. package/dist/pages/checkout/shipping-page/hooks/use-patch-shipping-details.js +1 -1
  18. package/dist/pages/my-sonic/actions/create-ship-to-address/connected-create-ship-to-address-form.d.ts +4 -0
  19. package/dist/pages/my-sonic/actions/create-ship-to-address/connected-create-ship-to-address-form.js +90 -0
  20. package/dist/pages/my-sonic/actions/create-ship-to-address/create-ship-to-address.module.css.js +3 -0
  21. package/dist/pages/my-sonic/actions/edit-bill-to-address/connected-edit-bill-to-address-form.d.ts +4 -0
  22. package/dist/pages/my-sonic/actions/edit-bill-to-address/connected-edit-bill-to-address-form.js +95 -0
  23. package/dist/pages/my-sonic/actions/edit-bill-to-address/edit-bill-to-address.module.css.js +3 -0
  24. package/dist/pages/my-sonic/actions/edit-ship-to-address/connected-edit-ship-to-address-form.d.ts +5 -0
  25. package/dist/pages/my-sonic/actions/edit-ship-to-address/connected-edit-ship-to-address-form.js +127 -0
  26. package/dist/pages/my-sonic/actions/edit-ship-to-address/edit-ship-to-address.module.css.js +3 -0
  27. package/dist/pages/my-sonic/widgets/components/address-data-card.d.ts +2 -2
  28. package/dist/pages/my-sonic/widgets/components/address-data-card.js +2 -6
  29. package/dist/pages/my-sonic/widgets/connected-bill-to-address-widget.d.ts +3 -1
  30. package/dist/pages/my-sonic/widgets/connected-bill-to-address-widget.js +13 -4
  31. package/dist/pages/my-sonic/widgets/connected-ship-to-address-widget.d.ts +4 -1
  32. package/dist/pages/my-sonic/widgets/connected-ship-to-address-widget.js +18 -4
  33. package/dist/shared/api/storefront/hooks/customer/use-fetch-bill-to-address.d.ts +4 -0
  34. package/dist/shared/api/storefront/hooks/customer/use-fetch-bill-to-address.js +11 -0
  35. package/dist/shared/api/storefront/hooks/customer/use-fetch-current-bill-to-address.d.ts +3 -1
  36. package/dist/shared/api/storefront/hooks/customer/use-fetch-current-bill-to-address.js +3 -7
  37. package/dist/shared/api/storefront/hooks/customer/use-fetch-current-ship-to-address.d.ts +3 -1
  38. package/dist/shared/api/storefront/hooks/customer/use-fetch-current-ship-to-address.js +6 -12
  39. package/dist/shared/api/storefront/hooks/customer/use-fetch-ship-to-address.d.ts +5 -0
  40. package/dist/shared/api/storefront/hooks/customer/use-fetch-ship-to-address.js +18 -0
  41. package/dist/shared/api/storefront/hooks/customer/use-patch-ship-to-address.d.ts +13 -0
  42. package/dist/shared/api/storefront/hooks/customer/use-patch-ship-to-address.js +17 -0
  43. package/dist/shared/api/storefront/hooks/customer/use-post-ship-to-address.d.ts +17 -0
  44. package/dist/shared/api/storefront/hooks/customer/use-post-ship-to-address.js +17 -0
  45. package/dist/shared/api/storefront/hooks/payment/use-invalidate-adyen.d.ts +1 -1
  46. package/dist/shared/api/storefront/hooks/payment/use-invalidate-adyen.js +1 -1
  47. package/dist/shared/api/storefront/hooks/product/use-mark-product-as-viewed.js +3 -1
  48. package/dist/shared/api/storefront/hooks/wishlist/use-add-wishlist-item-to-current-wishlist.js +2 -2
  49. package/dist/shared/api/storefront/hooks/wishlist/use-delete-wishlist-item-from-wishlist.js +2 -2
  50. package/dist/shared/api/storefront/model/storefront.model.d.ts +12 -0
  51. package/dist/shared/api/storefront/services/account-service.js +5 -0
  52. package/dist/shared/api/storefront/services/customer-service.d.ts +24 -3
  53. package/dist/shared/api/storefront/services/customer-service.js +39 -5
  54. package/dist/shared/hooks/use-cookiebot.js +9 -5
  55. package/dist/shared/routing/types.d.ts +2 -0
  56. package/dist/styles.css +93 -7
  57. package/package.json +1 -1
  58. package/dist/forms/partials/edit-address-form/edit-address-form.d.ts +0 -9
  59. package/dist/forms/partials/edit-address-form/edit-address-form.js +0 -36
  60. package/dist/forms/partials/edit-address-form/edit-address-form.module.css.js +0 -3
  61. package/dist/pages/my-sonic/actions/edit-bill-to-address/edit-bill-to-address.d.ts +0 -1
  62. package/dist/pages/my-sonic/actions/edit-bill-to-address/edit-bill-to-address.js +0 -8
@@ -0,0 +1,127 @@
1
+ "use client";
2
+ import { jsx, jsxs } from 'react/jsx-runtime';
3
+ import { useMemo } from 'react';
4
+ import { Button } from '../../../../buttons/button/button.js';
5
+ import { useCountries } from '../../../../country-select/hooks/use-countries.js';
6
+ import { Checkbox } from '../../../../forms/elements/checkbox/checkbox.js';
7
+ import { Form } from '../../../../forms/layout/form/form.js';
8
+ import { AddressForm } from '../../../../forms/partials/address-form/address-form.js';
9
+ import { FormattedMessage } from '../../../../intl/formatted-message.js';
10
+ import { Message } from '../../../../message/message.js';
11
+ import { usePatchCurrentAccount } from '../../../../shared/api/storefront/hooks/account/use-patch-current-account.js';
12
+ import { usePatchSession } from '../../../../shared/api/storefront/hooks/authentication/use-patch-session.js';
13
+ import { useFetchShipToAddress } from '../../../../shared/api/storefront/hooks/customer/use-fetch-ship-to-address.js';
14
+ import { usePatchShipToAddress } from '../../../../shared/api/storefront/hooks/customer/use-patch-ship-to-address.js';
15
+ import { NotFoundRequestError } from '../../../../shared/fetch/request.js';
16
+ import { useNavigate } from '../../../../shared/routing/use-navigate.js';
17
+ import { Heading } from '../../../../typography/heading/heading.js';
18
+ import { ErrorPage } from '../../../error-page/error-page.js';
19
+ import { LoadingPage } from '../../../loading-page/loading-page.js';
20
+ import formStyles from '../../../../forms/partials/address-form/address-form.module.css.js';
21
+ import styles from './edit-ship-to-address.module.css.js';
22
+
23
+ function ConnectedEditShipToAddressForm({ billToId, returnUrl, shipToId, }) {
24
+ const { navigate } = useNavigate();
25
+ const { countries, currentCountry, error: errorCountries, isFetching: isLoadingCountries, } = useCountries();
26
+ const { data: shipToAddress, error: errorShipToAddress, isLoading: isLoadingShipToAddress, } = useFetchShipToAddress({ billToId, includeValidation: true, shipToId });
27
+ const { isLoading: isPatchingShipToAddress, isSuccess, mutate: patchShipToAddress, } = usePatchShipToAddress();
28
+ const { isLoading: isPatchingSession, mutate: patchSession } = usePatchSession();
29
+ const { isLoading: isPatchingCurrentAccount, mutate: patchCurrentAccount } = usePatchCurrentAccount();
30
+ const isPatching = isPatchingShipToAddress || isPatchingSession || isPatchingCurrentAccount;
31
+ const isReadonly = useMemo(() => {
32
+ if (shipToAddress?.validation?.address1?.isDisabled)
33
+ return true;
34
+ if (shipToAddress?.validation?.address2?.isDisabled)
35
+ return true;
36
+ if (shipToAddress?.validation?.address3?.isDisabled)
37
+ return true;
38
+ if (shipToAddress?.validation?.address4?.isDisabled)
39
+ return true;
40
+ if (shipToAddress?.validation?.attention?.isDisabled)
41
+ return true;
42
+ if (shipToAddress?.validation?.city?.isDisabled)
43
+ return true;
44
+ if (shipToAddress?.validation?.companyName?.isDisabled)
45
+ return true;
46
+ if (shipToAddress?.validation?.country?.isDisabled)
47
+ return true;
48
+ if (shipToAddress?.validation?.email?.isDisabled)
49
+ return true;
50
+ if (shipToAddress?.validation?.fax?.isDisabled)
51
+ return true;
52
+ if (shipToAddress?.validation?.firstName?.isDisabled)
53
+ return true;
54
+ if (shipToAddress?.validation?.lastName?.isDisabled)
55
+ return true;
56
+ if (shipToAddress?.validation?.phone?.isDisabled)
57
+ return true;
58
+ if (shipToAddress?.validation?.postalCode?.isDisabled)
59
+ return true;
60
+ if (shipToAddress?.validation?.state?.isDisabled)
61
+ return true;
62
+ return false;
63
+ }, [shipToAddress]);
64
+ if (isLoadingShipToAddress || isLoadingCountries)
65
+ return jsx(LoadingPage, {});
66
+ if (errorShipToAddress && errorShipToAddress instanceof NotFoundRequestError)
67
+ return (jsx(Heading, { size: "l", children: jsx(FormattedMessage, { id: "Address not found" }) }));
68
+ if (errorShipToAddress)
69
+ return jsx(ErrorPage, { error: errorShipToAddress });
70
+ if (errorCountries)
71
+ return jsx(ErrorPage, { error: errorCountries });
72
+ if (!shipToAddress || !countries) {
73
+ return (jsx(ErrorPage, { error: new Error('No ship to address or countries data available.') }));
74
+ }
75
+ return (jsxs(Form, { className: formStyles.form, "data-test-selector": "shipToAddressForm", onSubmit: async ({ formData }) => {
76
+ const countryFormValue = formData.get('countrySelect')?.toString();
77
+ const country = countries.find(country => country.id === countryFormValue);
78
+ if (!country)
79
+ throw new Error(`Country not found ${formData.get('country')}`);
80
+ const isDefault = formData.get('setAsDefault')?.toString() === 'TRUE' || false;
81
+ const patchedShipToAddress = await patchShipToAddress({
82
+ billToId,
83
+ shipTo: {
84
+ ...shipToAddress,
85
+ address1: formData.get('address1')?.toString() || '',
86
+ address2: formData.get('address2')?.toString() || '',
87
+ address3: formData.get('address3')?.toString() || '',
88
+ attention: formData.get('attention')?.toString() || '',
89
+ city: formData.get('city')?.toString() || '',
90
+ companyName: formData.get('companyName')?.toString() || '',
91
+ country,
92
+ email: formData.get('email')?.toString() || '',
93
+ firstName: formData.get('firstName')?.toString() || '',
94
+ isDefault,
95
+ lastName: formData.get('lastName')?.toString() || '',
96
+ phone: formData.get('phone')?.toString() || '',
97
+ postalCode: formData.get('postalCode')?.toString() || '',
98
+ },
99
+ });
100
+ if (!shipToAddress.isDefault && isDefault) {
101
+ await patchSession({
102
+ session: {
103
+ customerWasUpdated: true,
104
+ shipTo: { id: patchedShipToAddress.id, isDefault: true },
105
+ },
106
+ });
107
+ await patchCurrentAccount({
108
+ account: {
109
+ defaultCustomerId: patchedShipToAddress.id,
110
+ defaultFulfillmentMethod: 'Ship',
111
+ setDefaultCustomer: true,
112
+ },
113
+ });
114
+ }
115
+ if (shipToAddress.isDefault && !isDefault) {
116
+ await patchCurrentAccount({
117
+ account: {
118
+ defaultCustomerId: null,
119
+ defaultFulfillmentMethod: 'Ship',
120
+ setDefaultCustomer: true,
121
+ },
122
+ });
123
+ }
124
+ }, children: [jsx(AddressForm, { address: shipToAddress, countries: countries, currentCountry: currentCountry, isLoading: isPatching, isReadonly: isReadonly || isPatching }), shipToAddress.id !== 'current' && (jsx(Checkbox, { defaultSelected: shipToAddress.isDefault, isDisabled: isReadonly || isPatching, name: "setAsDefault", value: "TRUE", children: jsx(FormattedMessage, { id: "Make this the default ship to address" }) })), isSuccess && !isPatching && (jsx("div", { className: styles.info, children: jsx(Message, { type: "info", children: jsx(FormattedMessage, { id: "Saved" }) }) })), jsxs("div", { className: styles.actions, children: [returnUrl && (jsx(Button, { color: "secondary", isDisabled: isPatching, onClick: () => navigate(returnUrl), variant: "outline", children: jsx(FormattedMessage, { id: "Back" }) })), !isReadonly && (jsx(Button, { isLoading: isPatching ? jsx(FormattedMessage, { id: "Saving" }) : undefined, type: "submit", children: jsx(FormattedMessage, { id: "Save" }) }))] })] }));
125
+ }
126
+
127
+ export { ConnectedEditShipToAddressForm };
@@ -0,0 +1,3 @@
1
+ var styles = {"actions":"edit-ship-to-address-module-aDVqM","info":"edit-ship-to-address-module-9FsP4"};
2
+
3
+ export { styles as default };
@@ -1,5 +1,6 @@
1
1
  import { DataCardProps } from '../../../../cards/data-card/data-card';
2
2
  export interface AddressDataCardProps {
3
+ actions?: DataCardProps['actions'];
3
4
  data: {
4
5
  address1: string | undefined;
5
6
  address2: string | undefined;
@@ -16,8 +17,7 @@ export interface AddressDataCardProps {
16
17
  };
17
18
  'data-test-selector'?: string;
18
19
  isLoading?: DataCardProps['isLoading'];
19
- onEdit?: VoidFunction;
20
20
  showError?: DataCardProps['showError'];
21
21
  title?: DataCardProps['title'];
22
22
  }
23
- export declare function AddressDataCard({ data: { address1, address2, address3, address4, attention, city, country, email, firstName, lastName, phone, postalCode, }, 'data-test-selector': dataTestSelector, isLoading, onEdit, showError, title, }: AddressDataCardProps): import("react/jsx-runtime").JSX.Element;
23
+ export declare function AddressDataCard({ actions, data: { address1, address2, address3, address4, attention, city, country, email, firstName, lastName, phone, postalCode, }, 'data-test-selector': dataTestSelector, isLoading, showError, title, }: AddressDataCardProps): import("react/jsx-runtime").JSX.Element;
@@ -1,10 +1,8 @@
1
1
  "use client";
2
2
  import { jsx } from 'react/jsx-runtime';
3
- import { Button } from '../../../../buttons/button/button.js';
4
3
  import { DataCard } from '../../../../cards/data-card/data-card.js';
5
- import { FormattedMessage } from '../../../../intl/formatted-message.js';
6
4
 
7
- function AddressDataCard({ data: { address1, address2, address3, address4, attention, city, country, email, firstName, lastName, phone, postalCode, }, 'data-test-selector': dataTestSelector, isLoading = false, onEdit, showError = false, title, }) {
5
+ function AddressDataCard({ actions, data: { address1, address2, address3, address4, attention, city, country, email, firstName, lastName, phone, postalCode, }, 'data-test-selector': dataTestSelector, isLoading = false, showError = false, title, }) {
8
6
  const data = [
9
7
  { key: 'first-name', label: 'First name', value: firstName },
10
8
  { key: 'last-name', label: 'Last name', value: lastName },
@@ -39,9 +37,7 @@ function AddressDataCard({ data: { address1, address2, address3, address4, atten
39
37
  { key: 'email', label: 'Email', value: email },
40
38
  { key: 'phone', label: 'Phone', value: phone },
41
39
  ];
42
- return (jsx(DataCard, { actions: [
43
- jsx(Button, { isDisabled: true, color: "secondary", onClick: onEdit, size: "sm", variant: "outline", children: jsx(FormattedMessage, { id: "Edit" }) }, "edit"),
44
- ], data: data, "data-test-selector": dataTestSelector, isLoading: isLoading, showError: showError, title: title }));
40
+ return (jsx(DataCard, { actions: actions, data: data, "data-test-selector": dataTestSelector, isLoading: isLoading, showError: showError, title: title }));
45
41
  }
46
42
 
47
43
  export { AddressDataCard };
@@ -1 +1,3 @@
1
- export declare function ConnectedBillToAddressWidget(): import("react/jsx-runtime").JSX.Element;
1
+ export declare function ConnectedBillToAddressWidget({ billToId, }?: {
2
+ billToId?: string;
3
+ }): import("react/jsx-runtime").JSX.Element;
@@ -1,11 +1,20 @@
1
1
  "use client";
2
2
  import { jsx } from 'react/jsx-runtime';
3
- import { useFetchCurrentBillToAddress } from '../../../shared/api/storefront/hooks/customer/use-fetch-current-bill-to-address.js';
3
+ import { Button } from '../../../buttons/button/button.js';
4
+ import { FormattedMessage } from '../../../intl/formatted-message.js';
5
+ import { useFetchBillToAddress } from '../../../shared/api/storefront/hooks/customer/use-fetch-bill-to-address.js';
6
+ import { useLocation } from '../../../shared/routing/use-location.js';
7
+ import { usePaths } from '../../../shared/routing/use-paths.js';
4
8
  import { AddressDataCard } from './components/address-data-card.js';
5
9
 
6
- function ConnectedBillToAddressWidget() {
7
- const { data: billToAddress, error, isLoading, } = useFetchCurrentBillToAddress();
8
- return (jsx(AddressDataCard, { data: {
10
+ function ConnectedBillToAddressWidget({ billToId = 'current', } = {}) {
11
+ const paths = usePaths();
12
+ const { href } = useLocation();
13
+ const editAddressUrl = `${paths.ACCOUNT_EDIT_BILL_TO_ADDRESS}/${billToId}?returnUrl=${encodeURIComponent(href)}`;
14
+ const { data: billToAddress, error, isLoading, } = useFetchBillToAddress({ billToId });
15
+ return (jsx(AddressDataCard, { actions: [
16
+ jsx(Button, { color: "secondary", href: editAddressUrl, size: "sm", variant: "outline", children: jsx(FormattedMessage, { id: "Edit" }) }, "edit"),
17
+ ], data: {
9
18
  address1: billToAddress?.address1,
10
19
  address2: billToAddress?.address2,
11
20
  address3: billToAddress?.address3,
@@ -1 +1,4 @@
1
- export declare function ConnectedShipToAddressWidget(): import("react/jsx-runtime").JSX.Element;
1
+ export declare function ConnectedShipToAddressWidget({ billToId, shipToId, }?: {
2
+ billToId?: string;
3
+ shipToId?: string;
4
+ }): import("react/jsx-runtime").JSX.Element;
@@ -1,11 +1,25 @@
1
1
  "use client";
2
2
  import { jsx } from 'react/jsx-runtime';
3
- import { useFetchCurrentShipToAddress } from '../../../shared/api/storefront/hooks/customer/use-fetch-current-ship-to-address.js';
3
+ import { Button } from '../../../buttons/button/button.js';
4
+ import { FormattedMessage } from '../../../intl/formatted-message.js';
5
+ import { useFetchShipToAddress } from '../../../shared/api/storefront/hooks/customer/use-fetch-ship-to-address.js';
6
+ import { useLocation } from '../../../shared/routing/use-location.js';
7
+ import { usePaths } from '../../../shared/routing/use-paths.js';
4
8
  import { AddressDataCard } from './components/address-data-card.js';
5
9
 
6
- function ConnectedShipToAddressWidget() {
7
- const { data: shipToAddress, error, isLoading, } = useFetchCurrentShipToAddress();
8
- return (jsx(AddressDataCard, { data: {
10
+ function ConnectedShipToAddressWidget({ billToId = 'current', shipToId = 'current', } = {}) {
11
+ const paths = usePaths();
12
+ const { href } = useLocation();
13
+ const editAddressUrl = `${paths.ACCOUNT_EDIT_BILL_TO_ADDRESS}/${billToId}${paths.ACCOUNT_EDIT_SHIP_TO_ADDRESS}/${shipToId}?returnUrl=${encodeURIComponent(href)}`;
14
+ const createAddressUrl = `${paths.ACCOUNT_EDIT_BILL_TO_ADDRESS}/${billToId}${paths.ACCOUNT_EDIT_SHIP_TO_ADDRESS}/new?returnUrl=${encodeURIComponent(href)}`;
15
+ const { data: shipToAddress, error, isLoading, } = useFetchShipToAddress({
16
+ billToId,
17
+ shipToId,
18
+ });
19
+ return (jsx(AddressDataCard, { actions: [
20
+ jsx(Button, { color: "secondary", href: editAddressUrl, size: "sm", variant: "outline", children: jsx(FormattedMessage, { id: "Edit" }) }, "edit"),
21
+ jsx(Button, { color: "secondary", href: createAddressUrl, size: "sm", variant: "outline", children: jsx(FormattedMessage, { id: "Create" }) }, "create"),
22
+ ], data: {
9
23
  address1: shipToAddress?.address1,
10
24
  address2: shipToAddress?.address2,
11
25
  address3: shipToAddress?.address3,
@@ -0,0 +1,4 @@
1
+ export declare function useFetchBillToAddress({ billToId, includeValidation, }: {
2
+ billToId: string;
3
+ includeValidation?: boolean;
4
+ }): import("@tanstack/react-query").UseQueryResult<import("../../model/storefront.model").BillToModel, Error>;
@@ -0,0 +1,11 @@
1
+ import { useQuery } from '@tanstack/react-query';
2
+ import { fetchBillToAddress } from '../../services/customer-service.js';
3
+
4
+ function useFetchBillToAddress({ billToId, includeValidation = false, }) {
5
+ return useQuery({
6
+ queryFn: () => fetchBillToAddress({ billToId, includeValidation }),
7
+ queryKey: ['customer', 'bill-to-address', billToId, includeValidation],
8
+ });
9
+ }
10
+
11
+ export { useFetchBillToAddress };
@@ -1 +1,3 @@
1
- export declare function useFetchCurrentBillToAddress(): import("@tanstack/react-query").UseQueryResult<import("../../model/storefront.model").BillToModel, Error>;
1
+ export declare function useFetchCurrentBillToAddress({ includeValidation, }?: {
2
+ includeValidation?: boolean;
3
+ }): import("@tanstack/react-query").UseQueryResult<import("../../model/storefront.model").BillToModel, Error>;
@@ -1,11 +1,7 @@
1
- import { useQuery } from '@tanstack/react-query';
2
- import { fetchCurrentBillToAddress } from '../../services/customer-service.js';
1
+ import { useFetchBillToAddress } from './use-fetch-bill-to-address.js';
3
2
 
4
- function useFetchCurrentBillToAddress() {
5
- return useQuery({
6
- queryFn: fetchCurrentBillToAddress,
7
- queryKey: ['customer', 'bill-to-address', 'current'],
8
- });
3
+ function useFetchCurrentBillToAddress({ includeValidation = false, } = {}) {
4
+ return useFetchBillToAddress({ billToId: 'current', includeValidation });
9
5
  }
10
6
 
11
7
  export { useFetchCurrentBillToAddress };
@@ -1 +1,3 @@
1
- export declare function useFetchCurrentShipToAddress(): import("@tanstack/react-query").UseQueryResult<import("../../model/storefront.model").ShipToModel, Error>;
1
+ export declare function useFetchCurrentShipToAddress({ includeValidation, }?: {
2
+ includeValidation?: boolean;
3
+ }): import("@tanstack/react-query").UseQueryResult<import("../../model/storefront.model").ShipToModel, Error>;
@@ -1,16 +1,10 @@
1
- import { useQuery } from '@tanstack/react-query';
2
- import { fetchCurrentShipToAddress } from '../../services/customer-service.js';
1
+ import { useFetchShipToAddress } from './use-fetch-ship-to-address.js';
3
2
 
4
- function useFetchCurrentShipToAddress() {
5
- return useQuery({
6
- queryFn: fetchCurrentShipToAddress,
7
- queryKey: [
8
- 'customer',
9
- 'bill-to-address',
10
- 'current',
11
- 'ship-to-address',
12
- 'current',
13
- ],
3
+ function useFetchCurrentShipToAddress({ includeValidation = false, } = {}) {
4
+ return useFetchShipToAddress({
5
+ billToId: 'current',
6
+ includeValidation,
7
+ shipToId: 'current',
14
8
  });
15
9
  }
16
10
 
@@ -0,0 +1,5 @@
1
+ export declare function useFetchShipToAddress({ billToId, includeValidation, shipToId, }: {
2
+ billToId: string;
3
+ includeValidation?: boolean;
4
+ shipToId: string;
5
+ }): import("@tanstack/react-query").UseQueryResult<import("../../model/storefront.model").ShipToModel, Error>;
@@ -0,0 +1,18 @@
1
+ import { useQuery } from '@tanstack/react-query';
2
+ import { fetchShipToAddress } from '../../services/customer-service.js';
3
+
4
+ function useFetchShipToAddress({ billToId, includeValidation = false, shipToId, }) {
5
+ return useQuery({
6
+ queryFn: () => fetchShipToAddress({ billToId, includeValidation, shipToId }),
7
+ queryKey: [
8
+ 'customer',
9
+ 'bill-to-address',
10
+ billToId,
11
+ 'ship-to-address',
12
+ shipToId,
13
+ includeValidation,
14
+ ],
15
+ });
16
+ }
17
+
18
+ export { useFetchShipToAddress };
@@ -0,0 +1,13 @@
1
+ export declare function usePatchShipToAddress({ skipInvalidation, }?: {
2
+ skipInvalidation?: boolean;
3
+ }): {
4
+ error: unknown;
5
+ isError: boolean;
6
+ isLoading: boolean;
7
+ isSuccess: boolean;
8
+ mutate: (args_0: {
9
+ billToId: string;
10
+ shipTo: import("../../model/storefront.model").PatchShipToModel;
11
+ }) => Promise<import("../../model/storefront.model").ShipToModel>;
12
+ reset: () => void;
13
+ };
@@ -0,0 +1,17 @@
1
+ import { patchShipToAddress } from '../../services/customer-service.js';
2
+ import { useAwaitableMutation } from '../../../shared/hooks/use-awaitable-mutation.js';
3
+
4
+ function usePatchShipToAddress({ skipInvalidation = false, } = {}) {
5
+ return useAwaitableMutation({
6
+ mutationFn: patchShipToAddress,
7
+ onComplete({ queryClient }) {
8
+ if (skipInvalidation)
9
+ return;
10
+ queryClient.invalidateQueries({ queryKey: ['customer'] });
11
+ queryClient.invalidateQueries({ queryKey: ['carts'] });
12
+ queryClient.invalidateQueries({ queryKey: ['session'] });
13
+ },
14
+ });
15
+ }
16
+
17
+ export { usePatchShipToAddress };
@@ -0,0 +1,17 @@
1
+ export declare function usePostShipToAddress({ skipInvalidation, }?: {
2
+ skipInvalidation?: boolean;
3
+ }): {
4
+ error: unknown;
5
+ isError: boolean;
6
+ isLoading: boolean;
7
+ isSuccess: boolean;
8
+ mutate: (args_0: {
9
+ billToId: string;
10
+ shipTo: Partial<Omit<import("../../model/storefront.model").ShipToModel, "country"> & {
11
+ country?: import("../../model/storefront.model").CountryModel | {
12
+ id: string;
13
+ } | null;
14
+ }>;
15
+ }) => Promise<import("../../model/storefront.model").ShipToModel>;
16
+ reset: () => void;
17
+ };
@@ -0,0 +1,17 @@
1
+ import { postShipToAddress } from '../../services/customer-service.js';
2
+ import { useAwaitableMutation } from '../../../shared/hooks/use-awaitable-mutation.js';
3
+
4
+ function usePostShipToAddress({ skipInvalidation = false, } = {}) {
5
+ return useAwaitableMutation({
6
+ mutationFn: postShipToAddress,
7
+ onComplete({ queryClient }) {
8
+ if (skipInvalidation)
9
+ return;
10
+ queryClient.invalidateQueries({ queryKey: ['customer'] });
11
+ queryClient.invalidateQueries({ queryKey: ['carts'] });
12
+ queryClient.invalidateQueries({ queryKey: ['session'] });
13
+ },
14
+ });
15
+ }
16
+
17
+ export { usePostShipToAddress };
@@ -1 +1 @@
1
- export declare function useInvalidateAdyen(): () => void;
1
+ export declare function useInvalidateAdyen(): () => Promise<void>;
@@ -3,7 +3,7 @@ import { useQueryClient } from '@tanstack/react-query';
3
3
 
4
4
  function useInvalidateAdyen() {
5
5
  const queryClient = useQueryClient();
6
- return useCallback(() => queryClient.removeQueries({ queryKey: ['adyen'] }), [queryClient]);
6
+ return useCallback(() => queryClient.invalidateQueries({ queryKey: ['adyen'] }), [queryClient]);
7
7
  }
8
8
 
9
9
  export { useInvalidateAdyen };
@@ -8,7 +8,9 @@ function useMarkProductAsRecentlyViewed({ productId, }) {
8
8
  gcTime: 0,
9
9
  queryFn: () => {
10
10
  markProductAsRecentlyViewed({ productId: productId });
11
- queryClient.removeQueries({ queryKey: ['products', 'recently-viewed'] });
11
+ queryClient.invalidateQueries({
12
+ queryKey: ['products', 'recently-viewed'],
13
+ });
12
14
  },
13
15
  queryKey: ['mark-product-as-recently-viewed', productId],
14
16
  staleTime: 0,
@@ -25,8 +25,8 @@ function useAddWishListItemToCurrentWishList() {
25
25
  ]);
26
26
  },
27
27
  onError() {
28
- queryClient.removeQueries({ queryKey: ['wishlists'] });
29
- queryClient.removeQueries({ queryKey: ['wishlistlines'] });
28
+ queryClient.invalidateQueries({ queryKey: ['wishlists'] });
29
+ queryClient.invalidateQueries({ queryKey: ['wishlistlines'] });
30
30
  },
31
31
  });
32
32
  }
@@ -12,8 +12,8 @@ function useDeleteWishListItemFromWishList() {
12
12
  }
13
13
  },
14
14
  onError() {
15
- queryClient.removeQueries({ queryKey: ['wishlists'] });
16
- queryClient.removeQueries({ queryKey: ['wishlistlines'] });
15
+ queryClient.invalidateQueries({ queryKey: ['wishlists'] });
16
+ queryClient.invalidateQueries({ queryKey: ['wishlistlines'] });
17
17
  },
18
18
  });
19
19
  }
@@ -984,6 +984,18 @@ export type PatchBillToModel = Partial<Omit<BillToModel, 'country'> & {
984
984
  }> & {
985
985
  id: string;
986
986
  };
987
+ export type PostShipToModel = Partial<Omit<ShipToModel, 'country'> & {
988
+ country?: CountryModel | {
989
+ id: string;
990
+ } | null;
991
+ }>;
992
+ export type PatchShipToModel = Partial<Omit<ShipToModel, 'country'> & {
993
+ country?: CountryModel | {
994
+ id: string;
995
+ } | null;
996
+ }> & {
997
+ id: string;
998
+ };
987
999
  export type PatchCartModel = Partial<Omit<CartModel, 'billTo'> & {
988
1000
  billTo?: PatchBillToModel | {
989
1001
  id: string;
@@ -80,5 +80,10 @@ async function patchCurrentAccount({ account, }) {
80
80
  throw error;
81
81
  }
82
82
  }
83
+ /*
84
+ "setDefaultCustomer": true,
85
+ "defaultCustomerId": "f73fd87f-bf14-4454-afaf-b328007d3c86",
86
+ "defaultFulfillmentMethod": "Ship",
87
+ */
83
88
 
84
89
  export { ExistingAccountError, createAccount, createGuestAccount, fetchCurrentAccount, patchCurrentAccount };
@@ -1,6 +1,19 @@
1
- import { BillToCollectionModel, BillToModel, PatchBillToModel, ShipToCollectionModel, ShipToModel } from 'shared/api/storefront/model/storefront.model';
2
- export declare function fetchCurrentBillToAddress(): Promise<BillToModel>;
3
- export declare function fetchCurrentShipToAddress(): Promise<ShipToModel>;
1
+ import { BillToCollectionModel, BillToModel, PatchBillToModel, PatchShipToModel, PostShipToModel, ShipToCollectionModel, ShipToModel } from 'shared/api/storefront/model/storefront.model';
2
+ export declare function fetchCurrentBillToAddress({ includeValidation, }?: {
3
+ includeValidation?: boolean;
4
+ }): Promise<BillToModel>;
5
+ export declare function fetchBillToAddress({ billToId, includeValidation, }: {
6
+ billToId: string;
7
+ includeValidation?: boolean;
8
+ }): Promise<BillToModel>;
9
+ export declare function fetchCurrentShipToAddress({ includeValidation, }?: {
10
+ includeValidation?: boolean;
11
+ }): Promise<ShipToModel>;
12
+ export declare function fetchShipToAddress({ billToId, includeValidation, shipToId, }: {
13
+ billToId: string;
14
+ includeValidation?: boolean;
15
+ shipToId: string;
16
+ }): Promise<ShipToModel>;
4
17
  export interface FetchBillToAddressesParams {
5
18
  filter?: string;
6
19
  pageSize?: number;
@@ -12,6 +25,14 @@ export declare function fetchShipToAddresses({ shipToId }: {
12
25
  export declare function patchBillToAddress({ billTo, }: {
13
26
  billTo: PatchBillToModel;
14
27
  }): Promise<BillToModel>;
28
+ export declare function patchShipToAddress({ billToId, shipTo, }: {
29
+ billToId: string;
30
+ shipTo: PatchShipToModel;
31
+ }): Promise<ShipToModel>;
32
+ export declare function postShipToAddress({ billToId, shipTo, }: {
33
+ billToId: string;
34
+ shipTo: PostShipToModel;
35
+ }): Promise<ShipToModel>;
15
36
  export declare function fetchFulfillmentMethods({ customerId, }: {
16
37
  customerId: string;
17
38
  }): Promise<string[]>;
@@ -1,17 +1,27 @@
1
1
  import { config } from '../../../../config.js';
2
2
  import { request } from '../../../fetch/request.js';
3
3
 
4
- async function fetchCurrentBillToAddress() {
4
+ async function fetchCurrentBillToAddress({ includeValidation = false, } = {}) {
5
+ return fetchBillToAddress({ billToId: 'current', includeValidation });
6
+ }
7
+ async function fetchBillToAddress({ billToId, includeValidation = false, }) {
5
8
  const { body } = await request({
6
9
  credentials: 'include',
7
- url: `${config.SHOP_API_URL}/api/v1/billtos/current`,
10
+ url: `${config.SHOP_API_URL}/api/v1/billtos/${billToId}${includeValidation ? '?expand=validation' : ''}`,
8
11
  });
9
12
  return body;
10
13
  }
11
- async function fetchCurrentShipToAddress() {
14
+ async function fetchCurrentShipToAddress({ includeValidation = false, } = {}) {
15
+ return fetchShipToAddress({
16
+ billToId: 'current',
17
+ includeValidation,
18
+ shipToId: 'current',
19
+ });
20
+ }
21
+ async function fetchShipToAddress({ billToId, includeValidation = false, shipToId, }) {
12
22
  const { body } = await request({
13
23
  credentials: 'include',
14
- url: `${config.SHOP_API_URL}/api/v1/billtos/current/shiptos/current`,
24
+ url: `${config.SHOP_API_URL}/api/v1/billtos/${billToId}/shiptos/${shipToId}${includeValidation ? '?expand=validation' : ''}`,
15
25
  });
16
26
  return body;
17
27
  }
@@ -41,6 +51,30 @@ async function patchBillToAddress({ billTo, }) {
41
51
  });
42
52
  return updatedBillTo;
43
53
  }
54
+ async function patchShipToAddress({ billToId, shipTo, }) {
55
+ const { body: updatedShipTo } = await request({
56
+ body: shipTo,
57
+ credentials: 'include',
58
+ headers: {
59
+ 'Content-Type': 'application/json',
60
+ },
61
+ method: 'PATCH',
62
+ url: `${config.SHOP_API_URL}/api/v1/billtos/${billToId}/shiptos/${shipTo.id}`,
63
+ });
64
+ return updatedShipTo;
65
+ }
66
+ async function postShipToAddress({ billToId, shipTo, }) {
67
+ const { body: createdShipTo } = await request({
68
+ body: shipTo,
69
+ credentials: 'include',
70
+ headers: {
71
+ 'Content-Type': 'application/json',
72
+ },
73
+ method: 'POST',
74
+ url: `${config.SHOP_API_URL}/api/v1/billtos/${billToId}/shiptos`,
75
+ });
76
+ return createdShipTo;
77
+ }
44
78
  async function fetchFulfillmentMethods({ customerId, }) {
45
79
  const { body: updatedBillTo } = await request({
46
80
  credentials: 'include',
@@ -50,4 +84,4 @@ async function fetchFulfillmentMethods({ customerId, }) {
50
84
  return updatedBillTo;
51
85
  }
52
86
 
53
- export { fetchBillToAddresses, fetchCurrentBillToAddress, fetchCurrentShipToAddress, fetchFulfillmentMethods, fetchShipToAddresses, patchBillToAddress };
87
+ export { fetchBillToAddress, fetchBillToAddresses, fetchCurrentBillToAddress, fetchCurrentShipToAddress, fetchFulfillmentMethods, fetchShipToAddress, fetchShipToAddresses, patchBillToAddress, patchShipToAddress, postShipToAddress };
@@ -3,19 +3,23 @@ import { useState, useEffect } from 'react';
3
3
 
4
4
  // https://www.cookiebot.com/en/developer/
5
5
  function useCookiebot() {
6
- const [hasResponse, setHasResponse] = useState(Boolean(window?.Cookiebot?.hasResponse));
6
+ const [hasResponse, setHasResponse] = useState(Boolean(typeof window === 'undefined' ? undefined : window.Cookiebot?.hasResponse));
7
7
  const [isDialogOpen, setIsDialogOpen] = useState(false);
8
8
  const handleDialogDisplay = () => {
9
9
  setIsDialogOpen(true);
10
10
  };
11
11
  const handleAcceptDecline = () => {
12
- setHasResponse(Boolean(window?.Cookiebot?.hasResponse));
12
+ setHasResponse(Boolean(typeof window === 'undefined'
13
+ ? undefined
14
+ : window.Cookiebot?.hasResponse));
13
15
  setIsDialogOpen(false);
14
16
  };
15
17
  useEffect(() => {
16
- window?.addEventListener('CookiebotOnDialogDisplay', handleDialogDisplay);
17
- window?.addEventListener('CookiebotOnAccept', handleAcceptDecline);
18
- window?.addEventListener('CookiebotOnDecline', handleAcceptDecline);
18
+ if (typeof window === 'undefined')
19
+ return;
20
+ window.addEventListener('CookiebotOnDialogDisplay', handleDialogDisplay);
21
+ window.addEventListener('CookiebotOnAccept', handleAcceptDecline);
22
+ window.addEventListener('CookiebotOnDecline', handleAcceptDecline);
19
23
  return () => {
20
24
  window?.removeEventListener('CookiebotOnDialogDisplay', handleDialogDisplay);
21
25
  window?.removeEventListener('CookiebotOnAccept', handleAcceptDecline);