@sonic-equipment/ui 248.0.3 → 250.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.
@@ -1,6 +1,7 @@
1
1
  "use client";
2
2
  import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
3
3
  import { useMemo, useEffect } from 'react';
4
+ import Cookies from 'js-cookie';
4
5
  import { logger } from '../logging/logger.js';
5
6
  import { useCookiebot } from '../shared/hooks/use-cookiebot.js';
6
7
  import { useDisclosure } from '../shared/hooks/use-disclosure.js';
@@ -43,6 +44,10 @@ function ConnectedCountrySelector({ defaultCountryCode, defaultLanguageCode, onC
43
44
  return;
44
45
  setIsOpen(open);
45
46
  }, onSubmit: async ({ country, language }) => {
47
+ // set selected country and language IDs client side as a fallback; server response may overwrite values
48
+ const expires = 365; // 1 year
49
+ Cookies.set('CurrentCountryId', country.id, { expires });
50
+ Cookies.set('CurrentLanguageId', language.id, { expires });
46
51
  if (selectedCountry?.id === country.id &&
47
52
  selectedLanguage?.id === language.id)
48
53
  return close();
@@ -6,7 +6,7 @@ import clsx from 'clsx';
6
6
  import qs from 'query-string';
7
7
  import { useCultureCode } from '../../../../intl/use-culture-code.js';
8
8
  import { useFormattedMessage } from '../../../../intl/use-formatted-message.js';
9
- import { logger } from '../../../../logging/logger.js';
9
+ import { logger, consoleLogger } from '../../../../logging/logger.js';
10
10
  import { Message } from '../../../../message/message.js';
11
11
  import { useCreateAdyenSession } from '../../../../shared/api/storefront/hooks/payment/use-create-adyen-session.js';
12
12
  import { useFetchAdyenConfig } from '../../../../shared/api/storefront/hooks/payment/use-fetch-adyen-config.js';
@@ -18,7 +18,7 @@ function AdyenPayment({ amount, cartId, countryCode, currencyCode, customerId, d
18
18
  const t = useFormattedMessage();
19
19
  const cultureCode = useCultureCode();
20
20
  // Get and remove Adyen query string params and keep them in a ref
21
- const queryStringParams = useRef(getAndRemoveAdyenQueryParams());
21
+ const queryStringParams = useRef(getAdyenQueryParams());
22
22
  const { amount: adyenAmount, customerId: adyenCustomerId, redirectResult, } = queryStringParams.current;
23
23
  const dropinDivRef = useRef(null);
24
24
  const { data: adyenSettings } = useFetchAdyenConfig();
@@ -98,19 +98,27 @@ function AdyenPayment({ amount, cartId, countryCode, currencyCode, customerId, d
98
98
  },
99
99
  showPayButton: false,
100
100
  };
101
+ let removeParamsTimeout = null;
101
102
  (async function loadAdyen() {
102
103
  if (!dropinDivRef.current)
103
104
  return;
104
105
  const checkout = await AdyenCheckout(options);
105
106
  const dropIn = checkout.create('dropin');
106
- if (redirectResult)
107
+ if (redirectResult) {
107
108
  checkout.submitDetails({ details: { redirectResult } });
109
+ removeParamsTimeout = setTimeout(removeAdyenQueryParamsFromUrl, 0);
110
+ }
108
111
  // Remove Adyen query strings params from ref
109
- queryStringParams.current = {};
112
+ // queryStringParams.current = {}
110
113
  if (dropinRef.current)
111
114
  dropinRef.current.unmount();
112
115
  dropinRef.current = dropIn.mount(dropinDivRef.current);
113
116
  })();
117
+ return () => {
118
+ if (removeParamsTimeout) {
119
+ clearTimeout(removeParamsTimeout);
120
+ }
121
+ };
114
122
  }, [
115
123
  customerId,
116
124
  adyenSettings,
@@ -135,14 +143,18 @@ function AdyenPayment({ amount, cartId, countryCode, currencyCode, customerId, d
135
143
  }
136
144
  return (jsx("div", { ref: dropinDivRef, className: clsx(Boolean(redirectResult) && styles.loading, isDisabled && styles.loading), id: "dropin" }));
137
145
  }
138
- function getAndRemoveAdyenQueryParams() {
146
+ function getAdyenQueryParams() {
139
147
  if (typeof window === 'undefined')
140
148
  return {};
141
149
  const params = qs.parse(window.location.search || '');
142
150
  const { amount, customerId, redirectResult } = params;
143
151
  // eslint-disable-next-line no-console
144
152
  console.log('adyenQueryParam', { amount, customerId, redirectResult });
145
- return { amount, customerId, redirectResult };
153
+ return {
154
+ amount: typeof amount === 'string' ? amount : undefined,
155
+ customerId: typeof customerId === 'string' ? customerId : undefined,
156
+ redirectResult: typeof redirectResult === 'string' ? redirectResult : undefined,
157
+ };
146
158
  }
147
159
  async function handlePaymentResponse(result, onSubmit, onError) {
148
160
  try {
@@ -175,6 +187,20 @@ async function handlePaymentResponse(result, onSubmit, onError) {
175
187
  onError(error, result);
176
188
  }
177
189
  }
190
+ function removeAdyenQueryParamsFromUrl() {
191
+ if (typeof window === 'undefined')
192
+ return;
193
+ try {
194
+ const url = new URL(window.location.href);
195
+ url.searchParams.delete('amount');
196
+ url.searchParams.delete('customerId');
197
+ url.searchParams.delete('redirectResult');
198
+ window.history.replaceState(null, '', url.toString());
199
+ }
200
+ catch (error) {
201
+ consoleLogger.error(error);
202
+ }
203
+ }
178
204
  function handleRedirectPaymentAction(adyenPaymentResult) {
179
205
  if (typeof window === 'undefined' || typeof document === 'undefined')
180
206
  return;
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
3
  import { useRef, useState, useEffect, useCallback } from 'react';
4
4
  import { Form } from 'react-aria-components';
5
5
  import { useAlgoliaInsights } from '../../../../algolia/use-algolia-insights.js';
@@ -244,11 +244,11 @@ function Payment({ atp, cart: _cart, form, isProcessing, onError: _onError, onPa
244
244
  MA: t('industry.MA'),
245
245
  OT: t('industry.OT'),
246
246
  /* eslint-enable sort-keys-fix/sort-keys-fix */
247
- }, placeholder: t('Select an industry'), variant: "solid" }), jsx(TextField, { showLabel: true, defaultValue: cart.customerVatNumber, isDisabled: isDisabled, label: t('VAT Number'), minLength: 8, name: "customerVatNumber" }, `vat${Boolean(validationErrors.customerVatNumber)}`), jsx(TextField, { showLabel: true, defaultValue: cart.poNumber, isDisabled: isDisabled, isRequired: cart.requiresPoNumber, label: t('PO Number'), name: "poNumber" }), paymentMethodOptions && Object.keys(paymentMethodOptions).length > 1 && (jsx(Select, { "data-test-selector": "paymentMethodSelect", defaultSelectedOption: cart.paymentOptions?.paymentMethods?.[0]?.name || 'ADY', isDisabled: isDisabled, label: t('Payment method'), name: "paymentMethod", onChange: setSelectedPaymentMethod, options: paymentMethodOptions, selectedOption: selectedPaymentMethod, variant: "solid" })), isAdyenPayment && cart.billTo && (jsxs(Fragment, { children: [jsxs("p", { children: ["Will return to:", window?.location.pathname, " ", window?.location.search] }), jsx(AdyenPayment, { amount: cart.orderGrandTotal, cartId: cart.trackId, countryCode: countryCode, currencyCode: currencyCode, customerId: cart.billTo.id, dropinRef: dropinRef, environment: isProductionEnvironment ? 'live' : 'test', isDisabled: isDisabled, onComplete: onComplete, onError: onError, orderAmount: cart.orderGrandTotal, returnUrl:
248
- /* eslint-disable ssr-friendly/no-dom-globals-in-react-fc */
249
- typeof window === 'undefined'
250
- ? ''
251
- : `${window.location.pathname}${window.location.search}` })] })), Boolean(paymentError) && (jsx("div", { className: styles['error-message'], children: jsx(FormattedMessage, { id: "An error occurred while processing your payment. Please try again." }) })), jsx(InfoDisplay, { id: "shipping-and-invoice-information", label: t('Billing and shipping address'), value: jsx(Accordion, { variant: "select", children: jsx(AccordionItem, { "data-test-selector": "billingAndShippingInformation", id: "invoice-and-shipping", isDisabled: isDisabled, title: t('Billing and shipping information'), children: jsx(BillingAndInvoiceInformation, { billToAddress: cart.billTo && {
247
+ }, placeholder: t('Select an industry'), variant: "solid" }), jsx(TextField, { showLabel: true, defaultValue: cart.customerVatNumber, isDisabled: isDisabled, label: t('VAT Number'), minLength: 8, name: "customerVatNumber" }, `vat${Boolean(validationErrors.customerVatNumber)}`), jsx(TextField, { showLabel: true, defaultValue: cart.poNumber, isDisabled: isDisabled, isRequired: cart.requiresPoNumber, label: t('PO Number'), name: "poNumber" }), paymentMethodOptions && Object.keys(paymentMethodOptions).length > 1 && (jsx(Select, { "data-test-selector": "paymentMethodSelect", defaultSelectedOption: cart.paymentOptions?.paymentMethods?.[0]?.name || 'ADY', isDisabled: isDisabled, label: t('Payment method'), name: "paymentMethod", onChange: setSelectedPaymentMethod, options: paymentMethodOptions, selectedOption: selectedPaymentMethod, variant: "solid" })), isAdyenPayment && cart.billTo && (jsx(AdyenPayment, { amount: cart.orderGrandTotal, cartId: cart.trackId, countryCode: countryCode, currencyCode: currencyCode, customerId: cart.billTo.id, dropinRef: dropinRef, environment: isProductionEnvironment ? 'live' : 'test', isDisabled: isDisabled, onComplete: onComplete, onError: onError, orderAmount: cart.orderGrandTotal, returnUrl:
248
+ /* eslint-disable ssr-friendly/no-dom-globals-in-react-fc */
249
+ typeof window === 'undefined'
250
+ ? ''
251
+ : `${window.location.pathname}${window.location.search}` })), Boolean(paymentError) && (jsx("div", { className: styles['error-message'], children: jsx(FormattedMessage, { id: "An error occurred while processing your payment. Please try again." }) })), jsx(InfoDisplay, { id: "shipping-and-invoice-information", label: t('Billing and shipping address'), value: jsx(Accordion, { variant: "select", children: jsx(AccordionItem, { "data-test-selector": "billingAndShippingInformation", id: "invoice-and-shipping", isDisabled: isDisabled, title: t('Billing and shipping information'), children: jsx(BillingAndInvoiceInformation, { billToAddress: cart.billTo && {
252
252
  address1: cart.billTo.address1,
253
253
  address2: cart.billTo.address2,
254
254
  address3: cart.billTo.address3,
@@ -13,6 +13,11 @@ function useSignOut(options = {}) {
13
13
  onSuccess: (_data, variables) => {
14
14
  // TODO: Remove when Spire is deprecated
15
15
  Cookies.remove('NavigationMode');
16
+ // Removing certain cookies in case the session doesn't do this
17
+ // This is, however, following user action; in case the server cancels authentication, this does not get run
18
+ Cookies.remove('CurrentBillToId');
19
+ Cookies.remove('CurrentShipToId');
20
+ Cookies.remove('BillToIdShipToId');
16
21
  navigate((variables && variables.returnUrl) || paths.HOME, {
17
22
  reload: true,
18
23
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonic-equipment/ui",
3
- "version": "248.0.3",
3
+ "version": "250.0.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "engines": {