@sonic-equipment/ui 184.0.0 → 186.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-info-display/address-info-display.d.ts +2 -2
- package/dist/address-info-display/address-info-display.js +1 -1
- package/dist/algolia/algolia-multi-select-filter-section.js +1 -1
- package/dist/algolia/algolia-sort-by.js +1 -1
- package/dist/buttons/add-to-cart-button/add-to-cart-button.js +1 -1
- package/dist/cards/data-card/data-card.js +37 -20
- package/dist/cards/data-card/data-card.module.css.js +1 -1
- package/dist/country-select/country-select.js +1 -1
- package/dist/country-select/hooks/use-countries.js +1 -0
- package/dist/country-selector/country-selector-dialog/country-selector-dialog.js +2 -6
- package/dist/exports.d.ts +43 -23
- package/dist/filters/pagination/pagination.js +1 -1
- package/dist/forms/elements/checkbox/checkbox.module.css.js +3 -0
- package/dist/forms/{field-error → elements/field-error}/field-error.js +1 -1
- package/dist/forms/elements/field-error/field-error.module.css.js +3 -0
- package/dist/forms/elements/input/input.module.css.js +3 -0
- package/dist/forms/elements/label/label.module.css.js +3 -0
- package/dist/forms/{select → elements/select}/select.d.ts +2 -1
- package/dist/forms/{select → elements/select}/select.js +5 -5
- package/dist/forms/elements/select/select.module.css.js +3 -0
- package/dist/forms/elements/switch/switch.module.css.js +3 -0
- package/dist/forms/elements/textarea/textarea.module.css.js +3 -0
- package/dist/forms/{checkbox-field → fields/checkbox-field}/checkbox-field.d.ts +2 -2
- package/dist/forms/{checkbox-field → fields/checkbox-field}/checkbox-field.js +4 -4
- package/dist/forms/fields/checkbox-field/checkbox-field.module.css.js +3 -0
- package/dist/forms/{number-field → fields/number-field}/number-field.d.ts +1 -1
- package/dist/forms/{number-field → fields/number-field}/number-field.js +8 -8
- package/dist/forms/fields/number-field/number-field.module.css.js +3 -0
- package/dist/forms/{search-field → fields/search-field}/search-field.js +3 -3
- package/dist/forms/{select-field → fields/select-field}/select-field.d.ts +1 -1
- package/dist/forms/{select-field → fields/select-field}/select-field.js +7 -7
- package/dist/forms/fields/select-field/select-field.module.css.js +3 -0
- package/dist/forms/{switch-field → fields/switch-field}/switch-field.d.ts +2 -2
- package/dist/forms/{switch-field → fields/switch-field}/switch-field.js +4 -4
- package/dist/forms/fields/switch-field/switch-field.module.css.js +3 -0
- package/dist/forms/{text-field → fields/text-field}/password-reveal-toggle/password-reveal-toggle.js +3 -3
- package/dist/forms/{text-field → fields/text-field}/password-reveal-toggle/password-reveal-toggle.module.css.js +1 -1
- package/dist/forms/{text-field → fields/text-field}/text-field.d.ts +1 -1
- package/dist/forms/{text-field → fields/text-field}/text-field.js +6 -6
- package/dist/forms/fields/text-field/text-field.module.css.js +3 -0
- package/dist/forms/layout/form/form-field-layout.module.css.js +3 -0
- package/dist/forms/layout/form/form-segment-group.module.css.js +3 -0
- package/dist/forms/layout/form/form-segment.module.css.js +3 -0
- package/dist/forms/layout/form/form.d.ts +20 -0
- package/dist/forms/{form → layout/form}/form.js +4 -4
- package/dist/forms/layout/form/form.module.css.js +3 -0
- package/dist/forms/partials/edit-address-form/edit-address-form.d.ts +8 -0
- package/dist/forms/partials/edit-address-form/edit-address-form.js +35 -0
- package/dist/forms/partials/edit-address-form/edit-address-form.module.css.js +3 -0
- package/dist/forms/partials/password-validation/password-validation.d.ts +4 -0
- package/dist/forms/partials/password-validation/password-validation.js +32 -0
- package/dist/index.js +44 -24
- package/dist/intl/formatted-message.js +5 -1
- package/dist/intl/translation-id.d.ts +1 -1
- package/dist/intl/types.d.ts +6 -1
- package/dist/intl/use-formatted-message.js +2 -1
- package/dist/lists/menu-list/menu-list.d.ts +2 -1
- package/dist/lists/menu-list/menu-list.js +2 -2
- package/dist/lists/widget-grid/widget-grid.d.ts +5 -0
- package/dist/lists/widget-grid/widget-grid.js +9 -0
- package/dist/lists/widget-grid/widget-grid.module.css.js +3 -0
- package/dist/lists/widget-grid/widget.d.ts +6 -0
- package/dist/lists/widget-grid/widget.js +10 -0
- package/dist/modals/dialog/dialog.d.ts +5 -5
- package/dist/modals/dialog/dialog.js +18 -18
- package/dist/modals/dialog/dialog.module.css.js +1 -1
- package/dist/modals/favorite/add-to-favorite-dialog.js +2 -2
- package/dist/modals/recover-password/recover-password-dialog.js +2 -4
- package/dist/pages/account/components/create-account-form/create-account-form.js +8 -23
- package/dist/pages/account/components/sign-in-form/sign-in-form.js +6 -6
- package/dist/pages/account/create-account-page/create-account-page.js +4 -5
- package/dist/pages/account/layouts/sign-in-page-layout/sign-in-page-layout.js +1 -1
- package/dist/pages/account/sign-in-page/sign-in-page.js +2 -3
- package/dist/pages/checkout/components/billing-and-invoice-information.d.ts +3 -3
- package/dist/pages/checkout/components/billing-and-invoice-information.js +1 -1
- package/dist/pages/checkout/order-confirmation-page/order-confirmation-page-content.js +26 -20
- package/dist/pages/checkout/payment-page/components/payment.js +29 -23
- package/dist/pages/checkout/shipping-page/components/{edit-address-form.d.ts → edit-checkout-bill-to-address-form.d.ts} +3 -17
- package/dist/pages/checkout/shipping-page/components/edit-checkout-bill-to-address-form.js +49 -0
- package/dist/pages/checkout/shipping-page/components/edit-checkout-bill-to-address-form.module.css.js +3 -0
- package/dist/pages/checkout/shipping-page/components/readonly-address.js +7 -5
- package/dist/pages/checkout/shipping-page/hooks/use-patch-shipping-details.d.ts +1 -0
- package/dist/pages/checkout/shipping-page/shipping-page-content.js +2 -2
- package/dist/pages/checkout/shipping-page/shipping-page.js +2 -2
- package/dist/pages/components/page-container/page-container.js +1 -1
- package/dist/pages/my-sonic/actions/change-customer/change-customer-dialog.d.ts +4 -3
- package/dist/pages/my-sonic/actions/change-customer/change-customer-dialog.js +10 -4
- package/dist/pages/my-sonic/actions/change-customer/change-customer.d.ts +5 -2
- package/dist/pages/my-sonic/actions/change-customer/change-customer.js +17 -8
- package/dist/pages/my-sonic/actions/change-customer/change-customer.module.css.js +1 -1
- package/dist/pages/my-sonic/actions/change-customer/connected-change-customer-dialog.d.ts +7 -2
- package/dist/pages/my-sonic/actions/change-customer/connected-change-customer-dialog.js +9 -6
- package/dist/pages/my-sonic/actions/change-password/change-password-dialog.d.ts +10 -0
- package/dist/pages/my-sonic/actions/change-password/change-password-dialog.js +24 -0
- package/dist/pages/my-sonic/actions/change-password/change-password.d.ts +7 -0
- package/dist/pages/my-sonic/actions/change-password/change-password.js +35 -0
- package/dist/pages/my-sonic/actions/change-password/change-password.module.css.js +3 -0
- package/dist/pages/my-sonic/actions/change-password/connected-change-password-dialog.d.ts +5 -0
- package/dist/pages/my-sonic/actions/change-password/connected-change-password-dialog.js +39 -0
- package/dist/pages/my-sonic/actions/edit-bill-to-address/edit-bill-to-address.d.ts +1 -0
- package/dist/pages/my-sonic/actions/edit-bill-to-address/edit-bill-to-address.js +8 -0
- package/dist/pages/my-sonic/actions/edit-user-info/connected-edit-user-info-dialog.d.ts +5 -0
- package/dist/pages/my-sonic/actions/edit-user-info/connected-edit-user-info-dialog.js +56 -0
- package/dist/pages/my-sonic/actions/edit-user-info/edit-user-info-dialog.d.ts +10 -0
- package/dist/pages/my-sonic/actions/edit-user-info/edit-user-info-dialog.js +15 -0
- package/dist/pages/my-sonic/actions/edit-user-info/edit-user-info.d.ts +11 -0
- package/dist/pages/my-sonic/actions/edit-user-info/edit-user-info.js +29 -0
- package/dist/pages/my-sonic/actions/edit-user-info/edit-user-info.module.css.js +3 -0
- package/dist/pages/my-sonic/layouts/my-sonic-layout/my-sonic-layout-aside.d.ts +4 -0
- package/dist/pages/my-sonic/layouts/my-sonic-layout/my-sonic-layout-aside.js +9 -0
- package/dist/pages/my-sonic/layouts/my-sonic-layout/my-sonic-layout-main.d.ts +4 -0
- package/dist/pages/my-sonic/layouts/my-sonic-layout/my-sonic-layout-main.js +9 -0
- package/dist/pages/my-sonic/layouts/my-sonic-layout/my-sonic-layout-page.d.ts +5 -0
- package/dist/pages/my-sonic/layouts/my-sonic-layout/my-sonic-layout-page.js +10 -0
- package/dist/pages/my-sonic/layouts/my-sonic-layout/my-sonic-layout-pre-aside.d.ts +4 -0
- package/dist/pages/my-sonic/layouts/my-sonic-layout/my-sonic-layout-pre-aside.js +9 -0
- package/dist/pages/my-sonic/layouts/my-sonic-layout/my-sonic-layout-title.d.ts +4 -0
- package/dist/pages/my-sonic/layouts/my-sonic-layout/my-sonic-layout-title.js +10 -0
- package/dist/pages/my-sonic/layouts/my-sonic-layout/my-sonic-layout.d.ts +5 -0
- package/dist/pages/my-sonic/layouts/my-sonic-layout/my-sonic-layout.js +10 -0
- package/dist/pages/my-sonic/layouts/my-sonic-layout/my-sonic-layout.module.css.js +3 -0
- package/dist/pages/my-sonic/navigation/connected-my-sonic-navigation.js +3 -4
- package/dist/pages/my-sonic/navigation/connected-my-sonic-navigation.module.css.js +3 -0
- package/dist/pages/my-sonic/navigation/my-sonic-desktop-navigation.d.ts +2 -1
- package/dist/pages/my-sonic/navigation/my-sonic-desktop-navigation.js +2 -2
- package/dist/pages/my-sonic/navigation/my-sonic-mobile-navigation.d.ts +2 -1
- package/dist/pages/my-sonic/navigation/my-sonic-mobile-navigation.js +3 -3
- package/dist/pages/my-sonic/widgets/connected-customer-information-widget.js +3 -3
- package/dist/pages/my-sonic/widgets/connected-user-account-widget.js +16 -5
- package/dist/shared/api/shared/hooks/use-awaitable-mutation.d.ts +1 -0
- package/dist/shared/api/shared/hooks/use-awaitable-mutation.js +6 -0
- package/dist/shared/api/storefront/hooks/{authentication → account}/use-create-account.d.ts +1 -1
- package/dist/shared/api/storefront/hooks/{authentication → account}/use-create-account.js +3 -1
- package/dist/shared/api/storefront/hooks/{authentication → account}/use-create-guest-account.js +3 -1
- package/dist/shared/api/storefront/hooks/account/use-fetch-current-account.d.ts +3 -0
- package/dist/shared/api/storefront/hooks/account/use-fetch-current-account.js +13 -0
- package/dist/shared/api/storefront/hooks/account/use-patch-current-account.d.ts +11 -0
- package/dist/shared/api/storefront/hooks/account/use-patch-current-account.js +20 -0
- package/dist/shared/api/storefront/hooks/authentication/use-patch-session.d.ts +1 -0
- package/dist/shared/api/storefront/hooks/authentication/use-patch-session.js +1 -1
- package/dist/shared/api/storefront/hooks/cart/use-patch-cart.d.ts +1 -0
- package/dist/shared/api/storefront/hooks/cart/use-place-order.d.ts +1 -0
- package/dist/shared/api/storefront/hooks/customer/use-patch-bill-to-address.d.ts +1 -0
- package/dist/shared/api/storefront/services/account-service.d.ts +31 -0
- package/dist/shared/api/storefront/services/account-service.js +84 -0
- package/dist/shared/api/storefront/services/authentication-service.d.ts +7 -26
- package/dist/shared/api/storefront/services/authentication-service.js +38 -65
- package/dist/shared/data/countries-languages.data.js +4 -0
- package/dist/shared/model/address.d.ts +27 -12
- package/dist/shared/model/countries-languages.d.ts +1 -0
- package/dist/shared/utils/price.d.ts +1 -1
- package/dist/styles.css +751 -627
- package/package.json +1 -1
- package/dist/forms/checkbox/checkbox.module.css.js +0 -3
- package/dist/forms/checkbox-field/checkbox-field.module.css.js +0 -3
- package/dist/forms/field-error/field-error.module.css.js +0 -3
- package/dist/forms/form/form-field-layout.module.css.js +0 -3
- package/dist/forms/form/form-segment-group.module.css.js +0 -3
- package/dist/forms/form/form-segment.module.css.js +0 -3
- package/dist/forms/form/form.d.ts +0 -16
- package/dist/forms/form/form.module.css.js +0 -3
- package/dist/forms/input/input.module.css.js +0 -3
- package/dist/forms/label/label.module.css.js +0 -3
- package/dist/forms/number-field/number-field.module.css.js +0 -3
- package/dist/forms/select/select.module.css.js +0 -3
- package/dist/forms/select-field/select-field.module.css.js +0 -3
- package/dist/forms/switch/switch.module.css.js +0 -3
- package/dist/forms/switch-field/switch-field.module.css.js +0 -3
- package/dist/forms/text-field/text-field.module.css.js +0 -3
- package/dist/forms/textarea/textarea.module.css.js +0 -3
- package/dist/pages/checkout/shipping-page/components/edit-address-form.js +0 -68
- package/dist/pages/checkout/shipping-page/components/edit-address-form.module.css.js +0 -3
- /package/dist/forms/{checkbox → elements/checkbox}/checkbox.d.ts +0 -0
- /package/dist/forms/{checkbox → elements/checkbox}/checkbox.js +0 -0
- /package/dist/forms/{color-checkbox → elements/color-checkbox}/color-checkbox.d.ts +0 -0
- /package/dist/forms/{color-checkbox → elements/color-checkbox}/color-checkbox.js +0 -0
- /package/dist/forms/{field-error → elements/field-error}/field-error.d.ts +0 -0
- /package/dist/forms/{input → elements/input}/input.d.ts +0 -0
- /package/dist/forms/{input → elements/input}/input.js +0 -0
- /package/dist/forms/{label → elements/label}/label.d.ts +0 -0
- /package/dist/forms/{label → elements/label}/label.js +0 -0
- /package/dist/forms/{switch → elements/switch}/switch.d.ts +0 -0
- /package/dist/forms/{switch → elements/switch}/switch.js +0 -0
- /package/dist/forms/{textarea → elements/textarea}/textarea.d.ts +0 -0
- /package/dist/forms/{textarea → elements/textarea}/textarea.js +0 -0
- /package/dist/forms/{password-field → fields/password-field}/password-field.d.ts +0 -0
- /package/dist/forms/{password-field → fields/password-field}/password-field.js +0 -0
- /package/dist/forms/{search-field → fields/search-field}/search-field.d.ts +0 -0
- /package/dist/forms/{text-field → fields/text-field}/password-reveal-toggle/password-reveal-toggle.d.ts +0 -0
- /package/dist/forms/{form → layout/form}/form-field-layout.d.ts +0 -0
- /package/dist/forms/{form → layout/form}/form-field-layout.js +0 -0
- /package/dist/forms/{form → layout/form}/form-segment-group.d.ts +0 -0
- /package/dist/forms/{form → layout/form}/form-segment-group.js +0 -0
- /package/dist/forms/{form → layout/form}/form-segment.d.ts +0 -0
- /package/dist/forms/{form → layout/form}/form-segment.js +0 -0
- /package/dist/shared/api/storefront/hooks/{authentication → account}/use-create-guest-account.d.ts +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export declare function MySonicMobileNavigation({ currentPath, onLogout, }: {
|
|
1
|
+
export declare function MySonicMobileNavigation({ className, currentPath, onLogout, }: {
|
|
2
|
+
className?: string;
|
|
2
3
|
currentPath?: string;
|
|
3
4
|
onLogout: () => void;
|
|
4
5
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
|
-
import { Select } from '../../../forms/select/select.js';
|
|
3
|
+
import { Select } from '../../../forms/elements/select/select.js';
|
|
4
4
|
import { useFormattedMessage } from '../../../intl/use-formatted-message.js';
|
|
5
5
|
import { useNavigate } from '../../../shared/routing/use-navigate.js';
|
|
6
6
|
import { mySonicNavigationItems } from './my-sonic-navigation-items.js';
|
|
7
7
|
|
|
8
|
-
function MySonicMobileNavigation({ currentPath, onLogout, }) {
|
|
8
|
+
function MySonicMobileNavigation({ className, currentPath, onLogout, }) {
|
|
9
9
|
const { navigate } = useNavigate();
|
|
10
10
|
const t = useFormattedMessage();
|
|
11
|
-
return (jsx(Select, { label: t('Navigate to...'), onChange: option => {
|
|
11
|
+
return (jsx(Select, { className: className, label: t('Navigate to...'), onChange: option => {
|
|
12
12
|
if (option === 'logout')
|
|
13
13
|
return onLogout();
|
|
14
14
|
return navigate(option);
|
|
@@ -12,7 +12,7 @@ function ConnectedCustomerInformationWidget() {
|
|
|
12
12
|
const [isOpenChangeCustomerDialog, setIsOpenChangeCustomerDialog] = useState(false);
|
|
13
13
|
const { data: billToAddress, error: fetchBillToAddressError, isLoading: isLoadingFetchCurrentBillToAddress, } = useFetchCurrentBillToAddress();
|
|
14
14
|
const { data: billToAddresses, error: fetchBillToAddressesError, isLoading: isLoadingFetchBillToAddresses, } = useFetchBillToAddresses();
|
|
15
|
-
const
|
|
15
|
+
const hasMoreThanOneBillToAddress = Boolean((billToAddresses?.pagination?.totalItemCount || 0) > 1);
|
|
16
16
|
const data = billToAddress
|
|
17
17
|
? [
|
|
18
18
|
{
|
|
@@ -45,11 +45,11 @@ function ConnectedCustomerInformationWidget() {
|
|
|
45
45
|
function onChangeCustomer() {
|
|
46
46
|
setIsOpenChangeCustomerDialog(true);
|
|
47
47
|
}
|
|
48
|
-
return (jsxs(Fragment, { children: [jsx(DataCard, { actions:
|
|
48
|
+
return (jsxs(Fragment, { children: [jsx(DataCard, { actions: hasMoreThanOneBillToAddress
|
|
49
49
|
? [
|
|
50
50
|
jsx(Button, { color: "secondary", onClick: onChangeCustomer, size: "sm", variant: "outline", children: jsx(FormattedMessage, { id: "Select other customer" }) }, "edit"),
|
|
51
51
|
]
|
|
52
|
-
: undefined, data: data, "data-test-selector": "customer-information-widget", isLoading: isLoadingFetchCurrentBillToAddress || isLoadingFetchBillToAddresses, showError: fetchBillToAddressError || fetchBillToAddressesError, title: "Selected customer" }),
|
|
52
|
+
: undefined, data: data, "data-test-selector": "customer-information-widget", isLoading: isLoadingFetchCurrentBillToAddress || isLoadingFetchBillToAddresses, showError: fetchBillToAddressError || fetchBillToAddressesError, title: "Selected customer" }), hasMoreThanOneBillToAddress && (jsx(ConnectedChangeCustomerDialog, { allowSetDefault: true, isOpen: isOpenChangeCustomerDialog, onClose: () => setIsOpenChangeCustomerDialog(false), onCustomerSelected: () => {
|
|
53
53
|
window?.location.reload();
|
|
54
54
|
} }, billToAddress?.id))] }));
|
|
55
55
|
}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useState } from 'react';
|
|
3
4
|
import { Button } from '../../../buttons/button/button.js';
|
|
4
5
|
import { DataCard } from '../../../cards/data-card/data-card.js';
|
|
5
6
|
import { FormattedMessage } from '../../../intl/formatted-message.js';
|
|
6
7
|
import { useFetchSession } from '../../../shared/api/storefront/hooks/authentication/use-fetch-session.js';
|
|
8
|
+
import { ConnectedChangePasswordDialog } from '../actions/change-password/connected-change-password-dialog.js';
|
|
9
|
+
import { ConnectedEditUserInfoDialog } from '../actions/edit-user-info/connected-edit-user-info-dialog.js';
|
|
7
10
|
|
|
8
11
|
function ConnectedUserAccountWidget() {
|
|
12
|
+
const [isOpenEditUserInfoDialog, setIsOpenEditUserInfoDialog] = useState(false);
|
|
13
|
+
const [isOpenChangePasswordDialog, setIsOpenChangePasswordDialog] = useState(false);
|
|
9
14
|
const { data: session, error, isLoading } = useFetchSession();
|
|
10
15
|
const data = session
|
|
11
16
|
? [
|
|
@@ -24,10 +29,16 @@ function ConnectedUserAccountWidget() {
|
|
|
24
29
|
},
|
|
25
30
|
]
|
|
26
31
|
: [];
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
function onEditUserInfo() {
|
|
33
|
+
setIsOpenEditUserInfoDialog(true);
|
|
34
|
+
}
|
|
35
|
+
function onChangePassword() {
|
|
36
|
+
setIsOpenChangePasswordDialog(true);
|
|
37
|
+
}
|
|
38
|
+
return (jsxs(Fragment, { children: [jsx(DataCard, { actions: [
|
|
39
|
+
jsx(Button, { color: "secondary", onClick: onEditUserInfo, size: "sm", variant: "outline", children: jsx(FormattedMessage, { id: "Edit" }) }, "edit"),
|
|
40
|
+
jsx(Button, { color: "secondary", onClick: onChangePassword, size: "sm", variant: "outline", children: jsx(FormattedMessage, { id: "Change password" }) }, "change-pasword"),
|
|
41
|
+
], data: data, "data-test-selector": "user-account-widget", isLoading: isLoading, showError: error, title: "Sonic account" }), isOpenEditUserInfoDialog && (jsx(ConnectedEditUserInfoDialog, { isOpen: isOpenEditUserInfoDialog, onClose: () => setIsOpenEditUserInfoDialog(false) })), isOpenChangePasswordDialog && (jsx(ConnectedChangePasswordDialog, { isOpen: isOpenChangePasswordDialog, onClose: () => setIsOpenChangePasswordDialog(false) }))] }));
|
|
31
42
|
}
|
|
32
43
|
|
|
33
44
|
export { ConnectedUserAccountWidget };
|
|
@@ -7,6 +7,11 @@ function useAwaitableMutation({ mutationFn, onComplete, onError, onSuccess, }) {
|
|
|
7
7
|
const [isLoading, setIsLoading] = useState(false);
|
|
8
8
|
const [isSuccess, setIsSuccess] = useState(false);
|
|
9
9
|
const [error, setError] = useState();
|
|
10
|
+
const reset = useCallback(() => {
|
|
11
|
+
setIsLoading(false);
|
|
12
|
+
setIsSuccess(false);
|
|
13
|
+
setError(undefined);
|
|
14
|
+
}, []);
|
|
10
15
|
const mutate = useCallback(async (...args) => {
|
|
11
16
|
let result;
|
|
12
17
|
let error;
|
|
@@ -35,6 +40,7 @@ function useAwaitableMutation({ mutationFn, onComplete, onError, onSuccess, }) {
|
|
|
35
40
|
isLoading,
|
|
36
41
|
isSuccess,
|
|
37
42
|
mutate,
|
|
43
|
+
reset,
|
|
38
44
|
};
|
|
39
45
|
}
|
|
40
46
|
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { AccountModel } from 'shared/api/storefront/model/storefront.model';
|
|
2
|
-
import { CreateAccountRequestBody } from 'shared/api/storefront/services/
|
|
2
|
+
import { CreateAccountRequestBody } from 'shared/api/storefront/services/account-service';
|
|
3
3
|
export declare function useCreateAccount(): import("@tanstack/react-query").UseMutationResult<AccountModel, Error, CreateAccountRequestBody, unknown>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { useQueryClient, useMutation } from '@tanstack/react-query';
|
|
2
|
-
import { createAccount
|
|
3
|
+
import { createAccount } from '../../services/account-service.js';
|
|
4
|
+
import { createSession } from '../../services/authentication-service.js';
|
|
3
5
|
|
|
4
6
|
function useCreateAccount() {
|
|
5
7
|
const queryClient = useQueryClient();
|
package/dist/shared/api/storefront/hooks/{authentication → account}/use-create-guest-account.js
RENAMED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { useQueryClient, useMutation } from '@tanstack/react-query';
|
|
2
|
-
import {
|
|
3
|
+
import { createGuestAccount } from '../../services/account-service.js';
|
|
4
|
+
import { fetchSession, createSession } from '../../services/authentication-service.js';
|
|
3
5
|
|
|
4
6
|
function useCreateGuestAccount() {
|
|
5
7
|
const queryClient = useQueryClient();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useQuery } from '@tanstack/react-query';
|
|
3
|
+
import { fetchCurrentAccount } from '../../services/account-service.js';
|
|
4
|
+
|
|
5
|
+
function useFetchCurrentAccount({ isEnabled = true, } = {}) {
|
|
6
|
+
return useQuery({
|
|
7
|
+
enabled: isEnabled,
|
|
8
|
+
queryFn: fetchCurrentAccount,
|
|
9
|
+
queryKey: ['account', 'current'],
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { useFetchCurrentAccount };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AccountModel } from '../../model/storefront.model';
|
|
2
|
+
export declare function usePatchCurrentAccount(): {
|
|
3
|
+
error: unknown;
|
|
4
|
+
isError: boolean;
|
|
5
|
+
isLoading: boolean;
|
|
6
|
+
isSuccess: boolean;
|
|
7
|
+
mutate: (args_0: {
|
|
8
|
+
account: Partial<AccountModel>;
|
|
9
|
+
}) => Promise<AccountModel>;
|
|
10
|
+
reset: () => void;
|
|
11
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
3
|
+
import { useAwaitableMutation } from '../../../shared/hooks/use-awaitable-mutation.js';
|
|
4
|
+
import { patchCurrentAccount } from '../../services/account-service.js';
|
|
5
|
+
|
|
6
|
+
function usePatchCurrentAccount() {
|
|
7
|
+
const queryClient = useQueryClient();
|
|
8
|
+
return useAwaitableMutation({
|
|
9
|
+
mutationFn: async ({ account }) => {
|
|
10
|
+
const updatedAccount = await patchCurrentAccount({ account });
|
|
11
|
+
/* Completely clear out the client side cache.
|
|
12
|
+
* By patching the account also the session and
|
|
13
|
+
* cart are potentially invalid/changed */
|
|
14
|
+
queryClient.clear();
|
|
15
|
+
return updatedAccount;
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { usePatchCurrentAccount };
|
|
@@ -7,7 +7,7 @@ function usePatchSession() {
|
|
|
7
7
|
return useAwaitableMutation({
|
|
8
8
|
mutationFn: async ({ session }) => {
|
|
9
9
|
const updatedSession = await patchSession({ session });
|
|
10
|
-
queryClient.
|
|
10
|
+
queryClient.clear();
|
|
11
11
|
return updatedSession;
|
|
12
12
|
},
|
|
13
13
|
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { RequestError } from '../../../fetch/request';
|
|
2
|
+
import { AccountModel } from '../model/storefront.model';
|
|
3
|
+
export declare function fetchCurrentAccount(): Promise<AccountModel>;
|
|
4
|
+
export declare class ExistingAccountError extends RequestError {
|
|
5
|
+
constructor(error: Error);
|
|
6
|
+
}
|
|
7
|
+
export interface CreateAccountRequestBase {
|
|
8
|
+
email: string;
|
|
9
|
+
firstName?: string;
|
|
10
|
+
isSubscribed: boolean;
|
|
11
|
+
lastName: string;
|
|
12
|
+
password: string;
|
|
13
|
+
}
|
|
14
|
+
export interface CreatePrivateAccountRequestBody extends CreateAccountRequestBase {
|
|
15
|
+
companyName?: string | undefined;
|
|
16
|
+
countryCode: string;
|
|
17
|
+
isPrivateAccount: true;
|
|
18
|
+
}
|
|
19
|
+
export interface CreateBusinessAccountRequestBody extends CreateAccountRequestBase {
|
|
20
|
+
companyName: string;
|
|
21
|
+
countryCode: string;
|
|
22
|
+
isPrivateAccount: false;
|
|
23
|
+
}
|
|
24
|
+
export type CreateAccountRequestBody = CreatePrivateAccountRequestBody | CreateBusinessAccountRequestBody;
|
|
25
|
+
export declare function createAccount({ companyName, countryCode, email, firstName, isPrivateAccount, isSubscribed, lastName, password, }: CreateAccountRequestBody): Promise<AccountModel>;
|
|
26
|
+
export declare function createGuestAccount({ defaultWarehouseId, }: {
|
|
27
|
+
defaultWarehouseId: string;
|
|
28
|
+
}): Promise<AccountModel>;
|
|
29
|
+
export declare function patchCurrentAccount({ account, }: {
|
|
30
|
+
account: Partial<AccountModel>;
|
|
31
|
+
}): Promise<AccountModel>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { config } from '../../../../config.js';
|
|
2
|
+
import { request, RequestError, isRequestError } from '../../../fetch/request.js';
|
|
3
|
+
|
|
4
|
+
async function fetchCurrentAccount() {
|
|
5
|
+
const { body } = await request({
|
|
6
|
+
url: `${config.SHOP_API_URL}/api/v1/accounts/current`,
|
|
7
|
+
});
|
|
8
|
+
return body;
|
|
9
|
+
}
|
|
10
|
+
class ExistingAccountError extends RequestError {
|
|
11
|
+
constructor(error) {
|
|
12
|
+
super(error);
|
|
13
|
+
this.name = 'ExistingAccountError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
async function createAccount({ companyName, countryCode, email, firstName, isPrivateAccount, isSubscribed, lastName, password, }) {
|
|
17
|
+
try {
|
|
18
|
+
const { body } = await request({
|
|
19
|
+
body: {
|
|
20
|
+
email,
|
|
21
|
+
firstName,
|
|
22
|
+
isSubscribed,
|
|
23
|
+
lastName,
|
|
24
|
+
password,
|
|
25
|
+
properties: {
|
|
26
|
+
PrivateAccount: isPrivateAccount,
|
|
27
|
+
companyName,
|
|
28
|
+
countryCode,
|
|
29
|
+
},
|
|
30
|
+
userName: '',
|
|
31
|
+
},
|
|
32
|
+
headers: {
|
|
33
|
+
'Content-Type': 'application/json',
|
|
34
|
+
},
|
|
35
|
+
method: 'POST',
|
|
36
|
+
url: `${config.SHOP_API_URL}/api/v1/accounts`,
|
|
37
|
+
});
|
|
38
|
+
return body;
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (isRequestError(error) &&
|
|
42
|
+
error.status === 400 &&
|
|
43
|
+
error.body?.message === 'Email Address already exists')
|
|
44
|
+
throw new ExistingAccountError(error);
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async function createGuestAccount({ defaultWarehouseId, }) {
|
|
49
|
+
const { body } = await request({
|
|
50
|
+
body: {
|
|
51
|
+
defaultFulfillmentMethod: 'Ship',
|
|
52
|
+
defaultWarehouseId,
|
|
53
|
+
isGuest: true,
|
|
54
|
+
},
|
|
55
|
+
headers: {
|
|
56
|
+
'Content-Type': 'application/json',
|
|
57
|
+
},
|
|
58
|
+
method: 'POST',
|
|
59
|
+
url: `${config.SHOP_API_URL}/api/v1/accounts`,
|
|
60
|
+
});
|
|
61
|
+
return body;
|
|
62
|
+
}
|
|
63
|
+
async function patchCurrentAccount({ account, }) {
|
|
64
|
+
try {
|
|
65
|
+
const { body } = await request({
|
|
66
|
+
body: account,
|
|
67
|
+
headers: {
|
|
68
|
+
'Content-Type': 'application/json',
|
|
69
|
+
},
|
|
70
|
+
method: 'PATCH',
|
|
71
|
+
url: `${config.SHOP_API_URL}/api/v1/accounts/current`,
|
|
72
|
+
});
|
|
73
|
+
return body;
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
if (isRequestError(error) &&
|
|
77
|
+
error.status === 400 &&
|
|
78
|
+
error.body?.message === 'Email Address already exists')
|
|
79
|
+
throw new ExistingAccountError(error);
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export { ExistingAccountError, createAccount, createGuestAccount, fetchCurrentAccount, patchCurrentAccount };
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { RequestError } from '../../../fetch/request';
|
|
2
|
-
import {
|
|
2
|
+
import { PatchSessionModel, SessionModel } from '../model/storefront.model';
|
|
3
3
|
export declare function fetchSession(): Promise<SessionModel>;
|
|
4
|
+
export declare class InvalidPasswordError extends Error {
|
|
5
|
+
constructor(error: RequestError);
|
|
6
|
+
}
|
|
7
|
+
export declare class NonUniquePasswordError extends Error {
|
|
8
|
+
constructor(error: RequestError);
|
|
9
|
+
}
|
|
4
10
|
export declare function patchSession({ session, }: {
|
|
5
11
|
session: PatchSessionModel;
|
|
6
12
|
}): Promise<SessionModel>;
|
|
@@ -26,31 +32,6 @@ export declare function createSession({ accessToken, isGuest, keepMeSignedIn, pa
|
|
|
26
32
|
accessToken: string;
|
|
27
33
|
} & CreateSessionRequestBody): Promise<SessionModel>;
|
|
28
34
|
export declare function signOut(): Promise<void>;
|
|
29
|
-
export declare function createGuestAccount({ defaultWarehouseId, }: {
|
|
30
|
-
defaultWarehouseId: string;
|
|
31
|
-
}): Promise<AccountModel>;
|
|
32
35
|
export declare function recoverPassword({ userName, }: {
|
|
33
36
|
userName: string;
|
|
34
37
|
}): Promise<SessionModel>;
|
|
35
|
-
export declare class ExistingAccountError extends RequestError {
|
|
36
|
-
constructor(error: Error);
|
|
37
|
-
}
|
|
38
|
-
export interface CreateAccountRequestBase {
|
|
39
|
-
email: string;
|
|
40
|
-
firstName?: string;
|
|
41
|
-
isSubscribed: boolean;
|
|
42
|
-
lastName: string;
|
|
43
|
-
password: string;
|
|
44
|
-
}
|
|
45
|
-
export interface CreatePrivateAccountRequestBody extends CreateAccountRequestBase {
|
|
46
|
-
companyName?: string | undefined;
|
|
47
|
-
countryCode: string;
|
|
48
|
-
isPrivateAccount: true;
|
|
49
|
-
}
|
|
50
|
-
export interface CreateBusinessAccountRequestBody extends CreateAccountRequestBase {
|
|
51
|
-
companyName: string;
|
|
52
|
-
countryCode: string;
|
|
53
|
-
isPrivateAccount: false;
|
|
54
|
-
}
|
|
55
|
-
export type CreateAccountRequestBody = CreatePrivateAccountRequestBody | CreateBusinessAccountRequestBody;
|
|
56
|
-
export declare function createAccount({ companyName, countryCode, email, firstName, isPrivateAccount, isSubscribed, lastName, password, }: CreateAccountRequestBody): Promise<AccountModel>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { config } from '../../../../config.js';
|
|
2
|
-
import { request, isRequestError
|
|
2
|
+
import { request, isRequestError } from '../../../fetch/request.js';
|
|
3
3
|
|
|
4
4
|
async function fetchSession() {
|
|
5
5
|
const { body } = await request({
|
|
@@ -8,17 +8,43 @@ async function fetchSession() {
|
|
|
8
8
|
});
|
|
9
9
|
return body;
|
|
10
10
|
}
|
|
11
|
+
class InvalidPasswordError extends Error {
|
|
12
|
+
constructor(error) {
|
|
13
|
+
super(error.body?.message || error.message);
|
|
14
|
+
this.name = 'InvalidPasswordError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
class NonUniquePasswordError extends Error {
|
|
18
|
+
constructor(error) {
|
|
19
|
+
super(error.body?.message || error.message);
|
|
20
|
+
this.name = 'NonUniquePasswordError';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
11
23
|
async function patchSession({ session, }) {
|
|
12
|
-
|
|
13
|
-
body
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
try {
|
|
25
|
+
const { body } = await request({
|
|
26
|
+
body: session,
|
|
27
|
+
credentials: 'include',
|
|
28
|
+
headers: {
|
|
29
|
+
'Content-Type': 'application/json',
|
|
30
|
+
},
|
|
31
|
+
method: 'PATCH',
|
|
32
|
+
url: `${config.SHOP_API_URL}/api/v1/sessions/current`,
|
|
33
|
+
});
|
|
34
|
+
return body;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
if (isRequestError(error) && error.status === 400) {
|
|
38
|
+
if (error.body?.message ===
|
|
39
|
+
'New Password is required and must be different than Current Password') {
|
|
40
|
+
throw new NonUniquePasswordError(error);
|
|
41
|
+
}
|
|
42
|
+
if (error.body?.message === 'Current Password is invalid') {
|
|
43
|
+
throw new InvalidPasswordError(error);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
22
48
|
}
|
|
23
49
|
async function signIn({ password, userName, }) {
|
|
24
50
|
const params = new URLSearchParams();
|
|
@@ -70,21 +96,6 @@ async function signOut() {
|
|
|
70
96
|
throw error;
|
|
71
97
|
}
|
|
72
98
|
}
|
|
73
|
-
async function createGuestAccount({ defaultWarehouseId, }) {
|
|
74
|
-
const { body } = await request({
|
|
75
|
-
body: {
|
|
76
|
-
defaultFulfillmentMethod: 'Ship',
|
|
77
|
-
defaultWarehouseId,
|
|
78
|
-
isGuest: true,
|
|
79
|
-
},
|
|
80
|
-
headers: {
|
|
81
|
-
'Content-Type': 'application/json',
|
|
82
|
-
},
|
|
83
|
-
method: 'POST',
|
|
84
|
-
url: `${config.SHOP_API_URL}/api/v1/accounts`,
|
|
85
|
-
});
|
|
86
|
-
return body;
|
|
87
|
-
}
|
|
88
99
|
async function recoverPassword({ userName, }) {
|
|
89
100
|
const { body } = await request({
|
|
90
101
|
body: {
|
|
@@ -99,43 +110,5 @@ async function recoverPassword({ userName, }) {
|
|
|
99
110
|
});
|
|
100
111
|
return body;
|
|
101
112
|
}
|
|
102
|
-
class ExistingAccountError extends RequestError {
|
|
103
|
-
constructor(error) {
|
|
104
|
-
super(error);
|
|
105
|
-
this.name = 'ExistingAccountError';
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
async function createAccount({ companyName, countryCode, email, firstName, isPrivateAccount, isSubscribed, lastName, password, }) {
|
|
109
|
-
try {
|
|
110
|
-
const { body } = await request({
|
|
111
|
-
body: {
|
|
112
|
-
email,
|
|
113
|
-
firstName,
|
|
114
|
-
isSubscribed,
|
|
115
|
-
lastName,
|
|
116
|
-
password,
|
|
117
|
-
properties: {
|
|
118
|
-
PrivateAccount: isPrivateAccount,
|
|
119
|
-
companyName,
|
|
120
|
-
countryCode,
|
|
121
|
-
},
|
|
122
|
-
userName: '',
|
|
123
|
-
},
|
|
124
|
-
headers: {
|
|
125
|
-
'Content-Type': 'application/json',
|
|
126
|
-
},
|
|
127
|
-
method: 'POST',
|
|
128
|
-
url: `${config.SHOP_API_URL}/api/v1/accounts`,
|
|
129
|
-
});
|
|
130
|
-
return body;
|
|
131
|
-
}
|
|
132
|
-
catch (error) {
|
|
133
|
-
if (isRequestError(error) &&
|
|
134
|
-
error.status === 400 &&
|
|
135
|
-
error.body?.message === 'Email Address already exists')
|
|
136
|
-
throw new ExistingAccountError(error);
|
|
137
|
-
throw error;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
113
|
|
|
141
|
-
export {
|
|
114
|
+
export { InvalidPasswordError, NonUniquePasswordError, createSession, fetchSession, patchSession, recoverPassword, signIn, signOut };
|
|
@@ -28,6 +28,7 @@ const netherlands = {
|
|
|
28
28
|
id: '423f6a9b-0b7b-4b3b-8b3b-3b7b0b9a6f43',
|
|
29
29
|
languages: [dutch, english],
|
|
30
30
|
name: 'Netherlands',
|
|
31
|
+
states: null,
|
|
31
32
|
};
|
|
32
33
|
const unitedKingdom = {
|
|
33
34
|
abbreviation: 'UK',
|
|
@@ -35,6 +36,7 @@ const unitedKingdom = {
|
|
|
35
36
|
id: '423f6a9b-0b7b-4b3b-8b3b-3b7b0b9a6f42',
|
|
36
37
|
languages: [english],
|
|
37
38
|
name: 'United Kingdom',
|
|
39
|
+
states: null,
|
|
38
40
|
};
|
|
39
41
|
const germany = {
|
|
40
42
|
abbreviation: 'DE',
|
|
@@ -42,6 +44,7 @@ const germany = {
|
|
|
42
44
|
id: '423f6a9b-0b7b-4b3b-8b3b-3b7b0b9a6f45',
|
|
43
45
|
languages: [german, english],
|
|
44
46
|
name: 'Germany',
|
|
47
|
+
states: null,
|
|
45
48
|
};
|
|
46
49
|
const france = {
|
|
47
50
|
abbreviation: 'FR',
|
|
@@ -49,6 +52,7 @@ const france = {
|
|
|
49
52
|
id: '423f6a9b-0b7b-4b3b-8b3b-3b7b0b9a6f44',
|
|
50
53
|
languages: [french, english],
|
|
51
54
|
name: 'France',
|
|
55
|
+
states: null,
|
|
52
56
|
};
|
|
53
57
|
const countries = [
|
|
54
58
|
netherlands,
|
|
@@ -1,15 +1,30 @@
|
|
|
1
|
+
import { Country } from './countries-languages';
|
|
1
2
|
export declare const validatePhone: (value: string) => boolean;
|
|
2
3
|
export declare const validateEmail: (value: string) => boolean;
|
|
3
|
-
export interface
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
export interface AddressCountry {
|
|
5
|
+
abbreviation: string;
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
states: {
|
|
9
|
+
abbreviation: string;
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
}[] | null;
|
|
13
|
+
}
|
|
14
|
+
export interface Address {
|
|
15
|
+
address1: string;
|
|
16
|
+
address2: string;
|
|
17
|
+
address3: string;
|
|
18
|
+
attention: string;
|
|
19
|
+
city: string;
|
|
20
|
+
companyName: string;
|
|
21
|
+
country: AddressCountry | null | undefined;
|
|
22
|
+
email: string;
|
|
23
|
+
firstName: string;
|
|
24
|
+
lastName: string;
|
|
25
|
+
phone: string;
|
|
26
|
+
postalCode: string;
|
|
27
|
+
}
|
|
28
|
+
export interface ValidAddress extends Omit<Address, 'country'> {
|
|
29
|
+
country: Country;
|
|
15
30
|
}
|
|
@@ -11,6 +11,7 @@ export interface Country {
|
|
|
11
11
|
id: string;
|
|
12
12
|
languages: Language[];
|
|
13
13
|
name: string;
|
|
14
|
+
states: null;
|
|
14
15
|
}
|
|
15
16
|
export declare function isLanguage(language: unknown): language is Language;
|
|
16
17
|
export declare function isCountry(country: unknown): country is Country;
|