@sonic-equipment/ui 143.0.0 → 145.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.
@@ -10,4 +10,4 @@ export interface IconButtonProps {
10
10
  title?: string;
11
11
  type?: 'button' | 'submit' | 'reset';
12
12
  }
13
- export declare function IconButton({ children, className, color, href, isDisabled, onClick: _onClick, size, target, title, type, }: IconButtonProps): import("react/jsx-runtime").JSX.Element;
13
+ export declare function IconButton({ children, className, color, href, isDisabled, onClick: _onClick, size, target, title, type, ...rest }: IconButtonProps): import("react/jsx-runtime").JSX.Element;
@@ -3,16 +3,16 @@ import { jsx } from 'react/jsx-runtime';
3
3
  import clsx from 'clsx';
4
4
  import styles from './icon-button.module.css.js';
5
5
 
6
- function IconButton({ children, className, color = 'primary', href, isDisabled, onClick: _onClick, size = 'md', target, title, type = 'button', }) {
6
+ function IconButton({ children, className, color = 'primary', href, isDisabled, onClick: _onClick, size = 'md', target, title, type = 'button', ...rest }) {
7
7
  const onClick = (e) => {
8
8
  e.preventDefault();
9
9
  e.stopPropagation();
10
10
  _onClick?.(e);
11
11
  };
12
12
  if (href) {
13
- return (jsx("a", { className: clsx(styles['icon-button'], styles[size], styles[color], className), "data-disabled": isDisabled ? true : undefined, href: href, onClick: onClick, target: target, title: title, children: children }));
13
+ return (jsx("a", { className: clsx(styles['icon-button'], styles[size], styles[color], className), "data-disabled": isDisabled ? true : undefined, href: href, onClick: onClick, target: target, title: title, ...rest, children: children }));
14
14
  }
15
- return (jsx("button", { className: clsx(styles['icon-button'], styles[size], styles[color], className), "data-disabled": isDisabled ? true : undefined, disabled: isDisabled, onClick: onClick, title: title, type: type, children: children }));
15
+ return (jsx("button", { className: clsx(styles['icon-button'], styles[size], styles[color], className), "data-disabled": isDisabled ? true : undefined, disabled: isDisabled, onClick: onClick, title: title, type: type, ...rest, children: children }));
16
16
  }
17
17
 
18
18
  export { IconButton };
@@ -1,5 +1,4 @@
1
1
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
- import { useMemo } from 'react';
3
2
  import { Button } from '../../../buttons/button/button.js';
4
3
  import { CartTotals } from '../../../cart-totals/cart-totals.js';
5
4
  import { CartTotalsSummary } from '../../../cart-totals/cart-totals-summary.js';
@@ -20,10 +19,7 @@ function ShippingPageContent({ cart, editAddress, errorPatchBillingAddress, fulf
20
19
  ...acc,
21
20
  [method]: t(`fulfillmentMethod.${method}`),
22
21
  }), {});
23
- const hasBillToAddress = useMemo(() => {
24
- return Boolean(cart.billTo?.address1);
25
- // eslint-disable-next-line react-hooks/exhaustive-deps
26
- }, [Boolean(cart)]);
22
+ const hasBillToAddress = Boolean(cart.billTo?.address1);
27
23
  return (jsx(Page, { breadcrumb: [
28
24
  { href: PATHS.HOME, label: t('Home') },
29
25
  {
@@ -23,8 +23,10 @@ function ShippingPage() {
23
23
  const gaEventPushed = useRef(false);
24
24
  const { data: cart, error: errorFetchCart, isLoading: isLoadingCart, refetch: refetchCart, } = useFetchCurrentCart();
25
25
  const { data: session } = useFetchSession();
26
+ const hasNoBillToAddress = hasNo(cart?.billTo?.address1);
27
+ const isGuest = Boolean(session?.isGuest);
26
28
  const { countries, currentCountry: selectedCountry, isFetching: isLoadingCountries, } = useCountries({
27
- enabled: hasNo(cart?.billTo?.address1) || Boolean(session?.isGuest),
29
+ enabled: hasNoBillToAddress || isGuest,
28
30
  });
29
31
  const currentCountry = countries && cart?.billTo?.country
30
32
  ? countries.find(country => country.id === cart.billTo?.country?.id)
@@ -80,14 +82,14 @@ function ShippingPage() {
80
82
  return jsx(ErrorPage, { error: errorFetchCart });
81
83
  if (isLoading || isNavigating || isError || isSuccess)
82
84
  return jsx(LoadingPage, {});
85
+ if (hasNoBillToAddress && !countries)
86
+ throw new Error('Countries are missing');
83
87
  if (!isAuthenticated ||
84
88
  hasNo(session) ||
85
89
  hasNo(cart) ||
86
- hasNo(countries) ||
87
90
  hasNo(cart.cartLines) ||
88
91
  cart.cartLines.length === 0 ||
89
- hasNo(cart.billTo) ||
90
- (hasNo(cart.billTo.address1) && hasNo(countries)))
92
+ hasNo(cart.billTo))
91
93
  // TODO: Return error page, but first check all the conditions
92
94
  return null;
93
95
  async function handleSubmit({ address, cart, notes, }) {
@@ -117,7 +119,10 @@ function ShippingPage() {
117
119
  event: { event: 'add_shipping_info' },
118
120
  }));
119
121
  }
120
- return (jsx(ShippingPageContent, { cart: cart, editAddress: jsxs(Fragment, { children: [jsx(EditAddressesForm, { billTo: cart.billTo, countries: countries, currentCountry: currentCountry, isLoading: isPatching, isPickup: isPickup, onSubmit: async ({ address, notes }) => {
122
+ return (jsx(ShippingPageContent, { cart: cart,
123
+ // TODO: Combine editAddress and readOnlyAddress into one section in order
124
+ // for typescript to correctly infer which properties are set in what case
125
+ editAddress: jsxs(Fragment, { children: [jsx(EditAddressesForm, { billTo: cart.billTo, countries: countries || [], currentCountry: currentCountry, isLoading: isPatching, isPickup: isPickup, onSubmit: async ({ address, notes }) => {
121
126
  if (!cart.billTo)
122
127
  return;
123
128
  formData.current = { address, notes };
@@ -139,7 +144,7 @@ function ShippingPage() {
139
144
  cart,
140
145
  notes: formData.current.notes,
141
146
  });
142
- } })] }), errorPatchBillingAddress: errorPatchBillingAddress, fulfillmentMethods: fulfillmentMethods, isGuest: session.isGuest, isLoadingFulfillmentMethods: isLoadingFulfillmentMethods, isPatching: isPatching, isPatchingSession: isPatchingSession, onChangeFulfillmentMethod: async (value) => {
147
+ } })] }), errorPatchBillingAddress: errorPatchBillingAddress, fulfillmentMethods: fulfillmentMethods, isGuest: isGuest, isLoadingFulfillmentMethods: isLoadingFulfillmentMethods, isPatching: isPatching, isPatchingSession: isPatchingSession, onChangeFulfillmentMethod: async (value) => {
143
148
  await patchSession({
144
149
  session: {
145
150
  ...session,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonic-equipment/ui",
3
- "version": "143.0.0",
3
+ "version": "145.0.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "engines": {