@sonic-equipment/ui 137.0.0 → 138.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 (66) hide show
  1. package/dist/algolia/algolia-categories-filters.js +1 -1
  2. package/dist/algolia/algolia-query-string-routing.js +4 -2
  3. package/dist/buttons/add-to-cart-button/add-to-cart-button.js +1 -1
  4. package/dist/buttons/link/link.d.ts +1 -2
  5. package/dist/buttons/link/link.js +4 -6
  6. package/dist/collapsables/accordion/accordion-item.js +1 -1
  7. package/dist/collapsables/accordion/accordion.module.css.js +1 -1
  8. package/dist/exports.d.ts +4 -1
  9. package/dist/footer/footer.js +1 -1
  10. package/dist/forms/textarea/textarea.js +1 -1
  11. package/dist/index.js +4 -1
  12. package/dist/intl/translation-id.d.ts +1 -1
  13. package/dist/lists/orderline-list/orderline-list.js +1 -1
  14. package/dist/media/image/image.js +3 -3
  15. package/dist/message/message.d.ts +6 -0
  16. package/dist/message/message.js +19 -0
  17. package/dist/message/message.module.css.js +3 -0
  18. package/dist/pages/account/layouts/sign-in-page-layout/sign-in-page-layout.d.ts +8 -0
  19. package/dist/pages/account/layouts/sign-in-page-layout/sign-in-page-layout.js +12 -0
  20. package/dist/pages/account/layouts/sign-in-page-layout/sign-in-page-layout.module.css.js +3 -0
  21. package/dist/pages/account/sign-in-page/sign-in-page.d.ts +3 -0
  22. package/dist/pages/account/sign-in-page/sign-in-page.js +56 -0
  23. package/dist/pages/checkout/cart-page/cart-page.js +6 -6
  24. package/dist/pages/checkout/order-confirmation-page/order-confirmation-page-content.js +4 -4
  25. package/dist/pages/checkout/order-confirmation-page/order-confirmation-page.js +3 -3
  26. package/dist/pages/checkout/payment-page/components/adyen-payment.d.ts +2 -1
  27. package/dist/pages/checkout/payment-page/components/adyen-payment.js +2 -2
  28. package/dist/pages/checkout/payment-page/components/payment.d.ts +7 -3
  29. package/dist/pages/checkout/payment-page/components/payment.js +42 -41
  30. package/dist/pages/checkout/payment-page/payment-page-content.d.ts +3 -3
  31. package/dist/pages/checkout/payment-page/payment-page-content.js +7 -7
  32. package/dist/pages/checkout/payment-page/payment-page.js +7 -7
  33. package/dist/pages/checkout/shipping-page/components/readonly-address.js +3 -3
  34. package/dist/pages/checkout/shipping-page/shipping-page-content.js +4 -4
  35. package/dist/pages/checkout/shipping-page/shipping-page.js +5 -5
  36. package/dist/pages/components/page/page.d.ts +4 -2
  37. package/dist/pages/components/page/page.js +4 -6
  38. package/dist/pages/components/page-container/page-container.d.ts +5 -1
  39. package/dist/pages/components/page-container/page-container.js +3 -3
  40. package/dist/pages/components/page-container/page-container.module.css.js +1 -1
  41. package/dist/pages/error-page/error-page.js +4 -3
  42. package/dist/pages/{checkout/constants.d.ts → paths.d.ts} +4 -1
  43. package/dist/pages/{checkout/constants.js → paths.js} +5 -2
  44. package/dist/pages/product/product-details-page/product-details.js +1 -1
  45. package/dist/pages/product/product-listing-page/no-results/no-results.js +1 -1
  46. package/dist/pages/product/product-listing-page/product-listing.js +1 -1
  47. package/dist/pages/product/search-result-page/search-results-page.js +3 -1
  48. package/dist/shared/api/storefront/hooks/authentication/use-create-guest-account.d.ts +1 -3
  49. package/dist/shared/api/storefront/hooks/authentication/use-create-guest-account.js +26 -11
  50. package/dist/shared/api/storefront/hooks/authentication/use-fetch-session.js +1 -0
  51. package/dist/shared/api/storefront/hooks/authentication/use-sign-in.d.ts +1 -0
  52. package/dist/shared/api/storefront/hooks/authentication/use-sign-in.js +4 -4
  53. package/dist/shared/api/storefront/services/authentication-service.d.ts +6 -7
  54. package/dist/shared/api/storefront/services/authentication-service.js +5 -3
  55. package/dist/shared/api/storefront/services/translation-service.js +2 -1
  56. package/dist/shared/model/currency.d.ts +1 -28
  57. package/dist/shared/model/image.d.ts +3 -3
  58. package/dist/shared/routing/with-routing.js +1 -1
  59. package/dist/shared/utils/local-storage.d.ts +1 -1
  60. package/dist/shared/utils/local-storage.js +4 -5
  61. package/dist/shared/utils/price.d.ts +3 -37
  62. package/dist/sign-in-form/sign-in-form.d.ts +12 -6
  63. package/dist/sign-in-form/sign-in-form.js +9 -6
  64. package/dist/styles.css +399 -158
  65. package/package.json +1 -1
  66. package/dist/pages/components/page/page.module.css.js +0 -3
@@ -1,19 +1,34 @@
1
1
  import { useQueryClient, useMutation } from '@tanstack/react-query';
2
- import { createGuestAccount, createSession } from '../../services/authentication-service.js';
2
+ import { fetchSession, createGuestAccount, createSession } from '../../services/authentication-service.js';
3
3
 
4
4
  function useCreateGuestAccount() {
5
5
  const queryClient = useQueryClient();
6
6
  return useMutation({
7
- mutationFn: async ({ defaultWarehouseId }) => {
8
- const body = await createGuestAccount({ defaultWarehouseId });
9
- await createSession({
10
- accessToken: body.accessToken,
11
- password: body.password,
12
- userName: body.userName,
13
- });
14
- queryClient.resetQueries();
15
- queryClient.clear();
16
- return body;
7
+ mutationFn: async () => {
8
+ try {
9
+ let session = queryClient.getQueryData(['session']);
10
+ if (!session) {
11
+ session = await fetchSession();
12
+ queryClient.setQueryData(['session'], session);
13
+ }
14
+ if (!session.pickUpWarehouse) {
15
+ throw new Error('No default pick up warehouse found');
16
+ }
17
+ const defaultWarehouseId = session.pickUpWarehouse.id;
18
+ const body = await createGuestAccount({ defaultWarehouseId });
19
+ await createSession({
20
+ accessToken: body.accessToken,
21
+ isGuest: true,
22
+ password: body.password,
23
+ rememberMe: false,
24
+ userName: body.userName,
25
+ });
26
+ return body;
27
+ }
28
+ finally {
29
+ queryClient.resetQueries();
30
+ queryClient.clear();
31
+ }
17
32
  },
18
33
  });
19
34
  }
@@ -6,6 +6,7 @@ function useFetchSession({ enabled = true, } = {}) {
6
6
  return useQuery({
7
7
  enabled,
8
8
  gcTime: 15 * TIME.MINUTE,
9
+ placeholderData: prev => prev,
9
10
  queryFn: async () => {
10
11
  return await fetchSession();
11
12
  },
@@ -1,5 +1,6 @@
1
1
  import { AuthenticationResponse } from '../../services/authentication-service';
2
2
  export declare function useSignIn(): import("@tanstack/react-query").UseMutationResult<AuthenticationResponse, Error, {
3
3
  password: string;
4
+ rememberMe: boolean;
4
5
  userName: string;
5
6
  }, unknown>;
@@ -4,20 +4,20 @@ import { signIn, createSession } from '../../services/authentication-service.js'
4
4
  function useSignIn() {
5
5
  const queryClient = useQueryClient();
6
6
  return useMutation({
7
- mutationFn: async ({ password, userName }) => {
7
+ mutationFn: async ({ password, rememberMe, userName }) => {
8
8
  try {
9
9
  const body = await signIn({ password, userName });
10
10
  await createSession({
11
11
  accessToken: body.access_token,
12
+ isGuest: false,
12
13
  password,
14
+ rememberMe,
13
15
  userName,
14
16
  });
15
- queryClient.resetQueries();
16
17
  return body;
17
18
  }
18
- catch (error) {
19
+ finally {
19
20
  queryClient.resetQueries();
20
- throw error;
21
21
  }
22
22
  },
23
23
  });
@@ -14,17 +14,16 @@ export declare function signIn({ password, userName, }: {
14
14
  userName: string;
15
15
  }): Promise<AuthenticationResponse>;
16
16
  export interface CreateSessionRequestBody {
17
- isGuest?: boolean | undefined;
18
- password?: string | undefined;
19
- rememberMe?: boolean | undefined;
17
+ isGuest: boolean;
18
+ keepMeSignedIn?: boolean;
19
+ password: string | undefined;
20
+ rememberMe: boolean | undefined;
20
21
  returnUrl?: string | undefined;
21
22
  userName: string;
22
23
  }
23
- export declare function createSession({ accessToken, password, userName, }: {
24
+ export declare function createSession({ accessToken, isGuest, keepMeSignedIn, password, rememberMe, returnUrl, userName, }: {
24
25
  accessToken: string;
25
- password: string;
26
- userName: string;
27
- }): Promise<SessionModel>;
26
+ } & CreateSessionRequestBody): Promise<SessionModel>;
28
27
  export declare function signOut(): Promise<void>;
29
28
  export declare function createGuestAccount({ defaultWarehouseId, }: {
30
29
  defaultWarehouseId: string;
@@ -37,12 +37,14 @@ async function signIn({ password, userName, }) {
37
37
  });
38
38
  return body;
39
39
  }
40
- async function createSession({ accessToken, password, userName, }) {
40
+ async function createSession({ accessToken, isGuest, keepMeSignedIn, password, rememberMe, returnUrl, userName, }) {
41
41
  const { body } = await request({
42
42
  body: {
43
- isGuest: false,
43
+ isGuest,
44
+ keepMeSignedIn,
44
45
  password,
45
- rememberMe: true,
46
+ rememberMe,
47
+ returnUrl,
46
48
  userName,
47
49
  },
48
50
  headers: {
@@ -8,7 +8,8 @@ async function fetchTranslations(languageCode) {
8
8
  url: `${config.SHOP_API_URL}/api/v1/translationdictionaries?page=1&pageSize=9999&languageCode=${languageCode}`,
9
9
  });
10
10
  body.translationDictionaries?.forEach(dictionary => {
11
- translations[dictionary.keyword.toLowerCase()] = dictionary.translation;
11
+ translations[dictionary.keyword.toLowerCase()] =
12
+ dictionary.translation;
12
13
  });
13
14
  return translations;
14
15
  }
@@ -1,28 +1 @@
1
- export declare const currencySymbolToISO: {
2
- readonly '': "EUR";
3
- readonly $: "USD";
4
- readonly 'Bs.': "VES";
5
- readonly Ft: "HUF";
6
- readonly Kč: "CZK";
7
- readonly R: "ZAR";
8
- readonly kr: "SEK";
9
- readonly lei: "RON";
10
- readonly zł: "PLN";
11
- readonly '\u00A3': "GBP";
12
- readonly '\u00A5': "JPY";
13
- readonly '\u0E3F': "THB";
14
- readonly '\u20A1': "CRC";
15
- readonly '\u20A6': "NGN";
16
- readonly '\u20A9': "KRW";
17
- readonly '\u20AA': "ILS";
18
- readonly '\u20AB': "VND";
19
- readonly '\u20AC': "EUR";
20
- readonly '\u20AE': "MNT";
21
- readonly '\u20B1': "PHP";
22
- readonly '\u20B2': "PYG";
23
- readonly '\u20B4': "UAH";
24
- readonly '\u20B5': "GHS";
25
- readonly '\u20B9': "INR";
26
- readonly '\u20BA': "TRY";
27
- readonly '\u20BD': "RUB";
28
- };
1
+ export declare const currencySymbolToISO: Record<string, string>;
@@ -19,8 +19,8 @@ export interface ImageSourceType {
19
19
  }
20
20
  export interface ResponsiveImageType {
21
21
  altText: string;
22
- lg: DPRSrcSet;
23
- md: DPRSrcSet;
24
- sm: DPRSrcSet;
22
+ lg?: DPRSrcSet;
23
+ md?: DPRSrcSet;
24
+ sm?: DPRSrcSet;
25
25
  }
26
26
  export declare function isResponsiveImage(image: ImageType | ResponsiveImageType | undefined): image is ResponsiveImageType;
@@ -24,7 +24,7 @@ function withRouting(component) {
24
24
  if (e.ctrlKey || e.metaKey || e.shiftKey) {
25
25
  return window?.open(href, '_blank');
26
26
  }
27
- navigate(href, route);
27
+ return navigate(href, route);
28
28
  },
29
29
  };
30
30
  return createElement(component, props);
@@ -3,5 +3,5 @@
3
3
  declare const HAS_LOCAL_STORAGE_SUPPORT: boolean;
4
4
  declare function mockStorage(): void;
5
5
  declare const noopCallback: () => void;
6
- declare function createStorage(): {};
6
+ declare function createStorage(): Record<string, string>;
7
7
  declare const _: void;
@@ -57,14 +57,14 @@ function createStorage() {
57
57
  });
58
58
  Object.defineProperty(s, 'getItem', {
59
59
  get: () => {
60
- return k => {
60
+ return (k) => {
61
61
  return s.hasOwnProperty(String(k)) ? s[String(k)] : null;
62
62
  };
63
63
  },
64
64
  });
65
65
  Object.defineProperty(s, 'removeItem', {
66
66
  get: () => {
67
- return k => {
67
+ return (k) => {
68
68
  if (s.hasOwnProperty(String(k))) {
69
69
  delete s[String(k)];
70
70
  }
@@ -86,9 +86,8 @@ function createStorage() {
86
86
  },
87
87
  });
88
88
  Object.defineProperty(s, 'key', {
89
- value: k => {
90
- const key = Object.keys(s)[String(k)];
91
- return key ?? null;
89
+ value: (k) => {
90
+ return Object.keys(s)[k] || null;
92
91
  },
93
92
  });
94
93
  Object.defineProperty(s, 'itemInsertionCallback', {
@@ -1,39 +1,5 @@
1
1
  export declare const formatPrice: (price: number) => string;
2
- export declare const currencies: {
3
- AR: string;
4
- AU: string;
5
- BR: string;
6
- CA: string;
7
- CH: string;
8
- CN: string;
9
- CZ: string;
10
- DK: string;
11
- GB: string;
12
- HK: string;
13
- HR: string;
14
- HU: string;
15
- ID: string;
16
- IN: string;
17
- JP: string;
18
- KR: string;
19
- LA: string;
20
- MG: string;
21
- MX: string;
22
- MY: string;
23
- NO: string;
24
- NZ: string;
25
- PH: string;
26
- PL: string;
27
- RO: string;
28
- RS: string;
29
- RU: string;
30
- SE: string;
31
- SG: string;
32
- SK: string;
33
- TH: string;
34
- TW: string;
35
- US: string;
36
- VN: string;
37
- default: string;
2
+ export declare const currencies: Record<string, string> & {
3
+ default: 'EUR';
38
4
  };
39
- export declare const getCurrencyByCountryCode: (countryCode: string) => any;
5
+ export declare const getCurrencyByCountryCode: (countryCode: string) => string;
@@ -1,19 +1,25 @@
1
1
  interface LoginData {
2
2
  email: string;
3
- guestSignin: false;
3
+ guestSignIn: false;
4
4
  password: string;
5
- remember?: boolean;
5
+ rememberMe: boolean;
6
6
  }
7
7
  interface GuestLoginData {
8
- guestSignin: true;
8
+ guestSignIn: true;
9
9
  }
10
+ export type SubmitData = LoginData | GuestLoginData;
11
+ export type ErrorMessage = 'Access denied' | 'Unexpected error';
10
12
  export interface SignInFormProps {
11
13
  allowGuestSignIn?: boolean;
14
+ errorMessage?: ErrorMessage;
12
15
  initialEmail?: string;
13
- initialRemember?: boolean;
16
+ initialRememberMe?: boolean;
17
+ isDisabled?: boolean;
18
+ isPendingGuestSignIn?: boolean;
19
+ isPendingUserSignIn?: boolean;
14
20
  onSubmit?: ({ data }: {
15
- data: LoginData | GuestLoginData;
21
+ data: SubmitData;
16
22
  }) => void;
17
23
  }
18
- export declare function SignInForm({ allowGuestSignIn, initialEmail, initialRemember, onSubmit, }: SignInFormProps): import("react/jsx-runtime").JSX.Element;
24
+ export declare function SignInForm({ allowGuestSignIn, errorMessage, initialEmail, initialRememberMe, isDisabled: _isDisabled, isPendingGuestSignIn, isPendingUserSignIn, onSubmit, }: SignInFormProps): import("react/jsx-runtime").JSX.Element;
19
25
  export {};
@@ -7,12 +7,15 @@ import { Link } from '../buttons/link/link.js';
7
7
  import { Switch } from '../forms/switch/switch.js';
8
8
  import { TextField } from '../forms/text-field/text-field.js';
9
9
  import { useFormattedMessage } from '../intl/use-formatted-message.js';
10
+ import { Message } from '../message/message.js';
10
11
  import { Heading } from '../typography/heading/heading.js';
11
12
  import styles from './sign-in-form.module.css.js';
12
13
 
13
14
  const GUEST_SIGN_IN_BUTTON_NAME = 'guestSignin';
14
- function SignInForm({ allowGuestSignIn = false, initialEmail, initialRemember, onSubmit = () => { }, }) {
15
+ function SignInForm({ allowGuestSignIn = false, errorMessage, initialEmail, initialRememberMe, isDisabled: _isDisabled = false, isPendingGuestSignIn = false, isPendingUserSignIn = false, onSubmit = () => { }, }) {
15
16
  const t = useFormattedMessage();
17
+ const title = t('sign in');
18
+ const isDisabled = isPendingUserSignIn || isPendingGuestSignIn || _isDisabled;
16
19
  const handleSubmit = (event) => {
17
20
  event.preventDefault();
18
21
  const form = event.currentTarget;
@@ -22,14 +25,14 @@ function SignInForm({ allowGuestSignIn = false, initialEmail, initialRemember, o
22
25
  if (submitter?.name === GUEST_SIGN_IN_BUTTON_NAME) {
23
26
  return onSubmit({
24
27
  data: {
25
- guestSignin: true,
28
+ guestSignIn: true,
26
29
  },
27
30
  });
28
31
  }
29
32
  // regular sign-in
30
33
  const email = formData.get('email')?.toString();
31
34
  const password = formData.get('password')?.toString();
32
- const remember = Boolean(formData.get('remember'));
35
+ const rememberMe = Boolean(formData.get('rememberMe'));
33
36
  if (!email)
34
37
  throw new Error('Email value is required');
35
38
  if (!password)
@@ -37,13 +40,13 @@ function SignInForm({ allowGuestSignIn = false, initialEmail, initialRemember, o
37
40
  onSubmit({
38
41
  data: {
39
42
  email,
40
- guestSignin: false,
43
+ guestSignIn: false,
41
44
  password,
42
- remember,
45
+ rememberMe,
43
46
  },
44
47
  });
45
48
  };
46
- return (jsxs(Form, { "aria-label": t('sign in'), autoComplete: "off", className: clsx(styles['sign-in-form'], styles['form']), onSubmit: handleSubmit, validationBehavior: "native", children: [jsx("header", { className: styles['form-header'], children: jsx(Heading, { "data-test-selector": "PageTitle", italic: true, size: "m", tag: "h1", uppercase: true, children: t('sign in') }) }), jsxs("fieldset", { className: clsx(styles['form-fieldset'], styles['columns']), children: [jsx("div", { className: styles['form-segment'], children: jsx(TextField, { "data-test-selector": "signIn_userName", defaultValue: initialEmail, isRequired: true, label: t('Email'), name: "email", showLabel: true, type: "email" }) }), jsx("div", { className: styles['form-segment'], children: jsx(TextField, { "data-test-selector": "signIn_password", isRequired: true, label: t('Password'), name: "password", showLabel: true, type: "password" }) })] }), jsxs("footer", { className: styles['form-footer'], children: [jsx("div", { className: styles['form-segment'], children: jsx(Switch, { className: styles['floating'], defaultSelected: initialRemember, name: "remember", value: "true", children: t('Remember me') }) }), jsx("div", { className: styles['form-segment'], children: jsx(Button, { "data-test-selector": "signIn_submit", type: "submit", withArrow: true, children: t('sign in') }) }), jsxs("div", { className: styles['form-segment'], children: [jsx("p", { children: jsx(Link, { "data-test-selector": "signIn_forgotPassword", hasUnderline: true, href: "#", children: t('Forgot password?') }) }), jsxs("p", { children: [t('New user?'), ' ', jsx(Link, { "data-test-selector": "signInCreateNewAccount_createNewAccount", hasUnderline: true, href: "#", children: t('create account') })] })] }), allowGuestSignIn && (jsx("div", { className: styles['form-segment'], children: jsx(Button, { color: "secondary", isValidating: false, name: GUEST_SIGN_IN_BUTTON_NAME, type: "submit", value: "true", variant: "outline", children: t('Or sign in as guest') }) }))] })] }));
49
+ return (jsxs(Form, { "aria-label": title, autoComplete: "off", className: clsx(styles['sign-in-form'], styles['form']), onSubmit: handleSubmit, validationBehavior: "native", children: [jsx("header", { className: styles['form-header'], children: jsx(Heading, { "data-test-selector": "PageTitle", italic: true, size: "m", tag: "h1", uppercase: true, children: title }) }), errorMessage === 'Access denied' && (jsx(Message, { type: "danger", children: t('Your email and password were not recognized.') })), errorMessage === 'Unexpected error' && (jsx(Message, { type: "danger", children: t('An unexpected error occured. Please try again.') })), jsxs("fieldset", { className: clsx(styles['form-fieldset'], styles['columns']), children: [jsx("div", { className: styles['form-segment'], children: jsx(TextField, { "data-test-selector": "signIn_userName", defaultValue: initialEmail, isDisabled: isDisabled, isRequired: true, label: t('Email'), name: "email", showLabel: true, type: "email" }) }), jsx("div", { className: styles['form-segment'], children: jsx(TextField, { "data-test-selector": "signIn_password", isDisabled: isDisabled, isRequired: true, label: t('Password'), name: "password", showLabel: true, type: "password" }) })] }), jsxs("footer", { className: styles['form-footer'], children: [jsx("div", { className: styles['form-segment'], children: jsx(Switch, { className: styles['floating'], defaultSelected: initialRememberMe, isDisabled: isDisabled, name: "rememberMe", value: "true", children: t('Remember me') }) }), jsx("div", { className: styles['form-segment'], children: jsx(Button, { "data-test-selector": "signIn_submit", isDisabled: isDisabled, isLoading: isPendingUserSignIn && t('Signing in…'), type: "submit", withArrow: true, children: t('sign in') }) }), jsxs("div", { className: styles['form-segment'], children: [jsx("p", { children: jsx(Link, { color: "primary", "data-test-selector": "signIn_forgotPassword", hasUnderline: true, href: "#", isDisabled: isDisabled, children: t('Forgot password?') }) }), jsxs("p", { children: [t('New user?'), ' ', jsx(Link, { "data-test-selector": "signInCreateNewAccount_createNewAccount", hasUnderline: true, href: "#", isDisabled: isDisabled, children: t('create account') })] })] }), allowGuestSignIn && (jsx("div", { className: styles['form-segment'], children: jsx(Button, { color: "secondary", isDisabled: isDisabled, isLoading: isPendingGuestSignIn && t('Signing in…'), isValidating: false, name: GUEST_SIGN_IN_BUTTON_NAME, type: "submit", value: "true", variant: "outline", children: t('Or continue as guest') }) }))] })] }));
47
50
  }
48
51
 
49
52
  export { SignInForm };