@sonic-equipment/ui 254.0.0 → 256.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.
@@ -2,9 +2,11 @@ import { AddToCartHandler } from '../../buttons/add-to-cart-button/connected-add
2
2
  import { NavigateOptions } from '../../shared/routing/types';
3
3
  import { ProductCardProps } from './product-card';
4
4
  export interface ConnectedProductCardProps extends Omit<ProductCardProps, 'addToCartButton' | 'favoriteButton'> {
5
+ addToCartEnabled?: boolean;
6
+ addToFavoritesEnabled?: boolean;
5
7
  onAddToCart?: AddToCartHandler;
6
8
  onFavorited?: VoidFunction;
7
9
  onFavoriting?: VoidFunction;
8
10
  route?: NavigateOptions;
9
11
  }
10
- export declare function ConnectedProductCard({ id, onAddToCart, onFavorited, onFavoriting, ...props }: ConnectedProductCardProps): import("react/jsx-runtime").JSX.Element;
12
+ export declare function ConnectedProductCard({ addToCartEnabled, addToFavoritesEnabled, id, onAddToCart, onFavorited, onFavoriting, ...props }: ConnectedProductCardProps): import("react/jsx-runtime").JSX.Element;
@@ -4,8 +4,8 @@ import { ConnectedAddToCartButton } from '../../buttons/add-to-cart-button/conne
4
4
  import { ConnectedFavoriteButton } from '../../buttons/favorite/connected-favorite-button.js';
5
5
  import { ProductCard } from './product-card.js';
6
6
 
7
- function ConnectedProductCard({ id, onAddToCart, onFavorited, onFavoriting, ...props }) {
8
- return (jsx(ProductCard, { id: id, ...props, addToCartButton: jsx(ConnectedAddToCartButton, { onAddToCart: onAddToCart, productId: id }), favoriteButton: jsx(ConnectedFavoriteButton, { onFavorited: onFavorited, onFavoriting: onFavoriting, productId: id }) }));
7
+ function ConnectedProductCard({ addToCartEnabled = true, addToFavoritesEnabled = true, id, onAddToCart, onFavorited, onFavoriting, ...props }) {
8
+ return (jsx(ProductCard, { id: id, ...props, addToCartButton: addToCartEnabled ? (jsx(ConnectedAddToCartButton, { onAddToCart: onAddToCart, productId: id })) : undefined, favoriteButton: addToFavoritesEnabled ? (jsx(ConnectedFavoriteButton, { onFavorited: onFavorited, onFavoriting: onFavoriting, productId: id })) : undefined }));
9
9
  }
10
10
 
11
11
  export { ConnectedProductCard };
@@ -3,7 +3,7 @@ import type { ImageSourceType } from '../../shared/model/image';
3
3
  import type { ProductPriceType } from '../../shared/model/price';
4
4
  import { NavigateOptions } from '../../shared/routing/types';
5
5
  export interface ProductCardProps {
6
- addToCartButton: ReactElement;
6
+ addToCartButton?: ReactElement;
7
7
  favoriteButton?: ReactElement;
8
8
  href: string;
9
9
  id: string;
@@ -16,7 +16,7 @@ function ProductCard({ addToCartButton: AddToCartButton, favoriteButton: Favorit
16
16
  return;
17
17
  logger.error(`Product '${sku}' does not have a currency code`);
18
18
  }, [price.currencyCode, sku]);
19
- return (jsx("div", { className: styles['product-card-container'], children: jsxs("article", { "aria-labelledby": `title-${id}`, className: styles['product-card'], "data-product-id": sku, id: id, children: [jsx(Link, { className: styles.title, href: href, id: `title-${id}`, onClick: onClick, route: route, children: title }), tags && tags.length > 0 && (jsx("div", { className: styles.tags, children: tags.map(tag => (jsx(Tag, { children: jsx(FormattedMessage, { noTranslationId: true, fallbackValue: tag, id: `tag.${tag.toLowerCase()}` }) }, tag))) })), jsx(ProductSku, { className: styles.sku, sku: sku }), price.currencyCode && (jsx(Price, { className: styles.price, currencyCode: price.currencyCode, isVatIncluded: price.isVatIncluded, originalPrice: price.originalPrice, price: price.price, variant: "sonic" })), jsx("div", { className: styles['image-container'], children: jsx(Image, { ...image, fit: "contain" }) }), jsx("div", { className: styles['add-to-cart-button'], children: AddToCartButton }), jsx("div", { className: styles['favorite-button'], children: FavoriteButton && FavoriteButton })] }) }));
19
+ return (jsx("div", { className: styles['product-card-container'], children: jsxs("article", { "aria-labelledby": `title-${id}`, className: styles['product-card'], "data-product-id": sku, id: id, children: [jsx(Link, { className: styles.title, href: href, id: `title-${id}`, onClick: onClick, route: route, children: title }), tags && tags.length > 0 && (jsx("div", { className: styles.tags, children: tags.map(tag => (jsx(Tag, { children: jsx(FormattedMessage, { noTranslationId: true, fallbackValue: tag, id: `tag.${tag.toLowerCase()}` }) }, tag))) })), jsx(ProductSku, { className: styles.sku, sku: sku }), price.currencyCode && (jsx(Price, { className: styles.price, currencyCode: price.currencyCode, isVatIncluded: price.isVatIncluded, originalPrice: price.originalPrice, price: price.price, variant: "sonic" })), jsx("div", { className: styles['image-container'], children: jsx(Image, { ...image, fit: "contain" }) }), jsx("div", { className: styles['add-to-cart-button'], children: AddToCartButton && AddToCartButton }), jsx("div", { className: styles['favorite-button'], children: FavoriteButton && FavoriteButton })] }) }));
20
20
  }
21
21
 
22
22
  export { ProductCard };
@@ -52,12 +52,14 @@ function SuggestionsSection() {
52
52
  }), icon: jsx(StrokeSearchIcon, { role: "presentation" }), text: jsxs("span", { children: [jsx("span", { children: item.listCategories.at(-1) }), jsx("span", { children: item.listCategories.slice(0, -1).join(' > ') })] }) }, item.objectID))) }))] }));
53
53
  }
54
54
  function ProductHitCard({ autocomplete, hit, index, source, }) {
55
+ // TODO: re-enable addToCart and addToFavorites when authentication problems are solved (or we got rid of the split domains)
56
+ // It is just a boolean prop defaulting to true
55
57
  const { close } = useGlobalSearchDisclosure();
56
58
  const { sendAddToCartFromSearchEvent, sendAddToWishListFromSearchEvent, sendProductClickFromSearchEvent, } = useAlgoliaInsights();
57
59
  return (jsx(ConnectedProductCard, { ...autocomplete.getItemProps({
58
60
  item: hit.hit,
59
61
  source,
60
- }), href: hit.storefrontSlug, id: hit.storefrontId, image: {
62
+ }), addToCartEnabled: false, addToFavoritesEnabled: false, href: hit.storefrontSlug, id: hit.storefrontId, image: {
61
63
  fit: 'contain',
62
64
  image: hit.image,
63
65
  title: hit.name,
package/dist/index.js CHANGED
@@ -390,7 +390,7 @@ export { ExistingAccountError, createAccount, createGuestAccount, fetchCurrentAc
390
390
  export { AccountLockedOutError, InvalidEmailPasswordCombinationError, InvalidGrantError, InvalidPasswordError, NonUniquePasswordError, UnableToChangePasswordError, UserNotFoundError, createSession, fetchSession, patchSession, recoverPassword, signIn, signOut } from './shared/api/storefront/services/authentication-service.js';
391
391
  export { addBulkProductsToCurrentCart, addProductToCurrentCart, convertToMinorUnits, deleteCartLineById, deleteCurrentCart, fetchCart, fetchCurrentCart, fetchCurrentCartLines, fetchCurrentCartProductAtp, fetchCurrentCartPromotions, fetchCurrentCheckoutAtp, getAdyenPaymentDetails, patchCartLineById, postAdyenPayment } from './shared/api/storefront/services/cart-service.js';
392
392
  export { fetchCategories } from './shared/api/storefront/services/category-service.js';
393
- export { fetchBillToAddress, fetchBillToAddresses, fetchCurrentBillToAddress, fetchCurrentShipToAddress, fetchFulfillmentMethods, fetchPagedShipToAddresses, fetchShipToAddress, fetchShipToAddresses, patchBillToAddress, patchShipToAddress, postShipToAddress } from './shared/api/storefront/services/customer-service.js';
393
+ export { fetchBillToAddress, fetchBillToAddresses, fetchCurrentBillToAddress, fetchCurrentShipToAddress, fetchFulfillmentMethods, fetchPagedShipToAddresses, fetchShipByBillTo, fetchShipToAddress, fetchShipToAddresses, patchBillToAddress, patchShipToAddress, postShipToAddress } from './shared/api/storefront/services/customer-service.js';
394
394
  export { validateVATNumber } from './shared/api/storefront/services/finance-service.js';
395
395
  export { fetchOrderById, fetchOrders } from './shared/api/storefront/services/order-service.js';
396
396
  export { createAdyenSession, fetchAdyenConfig } from './shared/api/storefront/services/payment-service.js';
@@ -27,9 +27,9 @@ function Image({ className, 'data-test-selector': dataTestSelector, fallbackSrc
27
27
  }
28
28
  function createSrcSet(image) {
29
29
  return ([
30
- image[1] && `${image[1]} 1x`,
31
- image[2] && `${image[2]} 2x`,
32
- image[3] && `${image[3]} 3x`,
30
+ image[1] && `${encodeURI(image[1])} 1x`,
31
+ image[2] && `${encodeURI(image[2])} 2x`,
32
+ image[3] && `${encodeURI(image[3])} 3x`,
33
33
  ]
34
34
  .filter(Boolean)
35
35
  .join(', ') || undefined);
@@ -57,7 +57,7 @@ function PictureComponent({ className, fallbackSrc, fit = 'cover', hasError, ima
57
57
  return (jsx("picture", { className: clsx(styles.picture, className), children: jsx("img", { alt: "Missing", className: clsx(styles.image, styles[fit], styles['has-error']), src: fallbackSrc, ...rest }) }));
58
58
  return (jsxs("picture", { className: clsx(styles.picture, className), children: [image.sm && (jsx("source", { media: "(max-width: 768px)", srcSet: createSrcSet(image.sm) })), image.md && (jsx("source", { media: "(max-width: 1439px)", srcSet: createSrcSet(image.md) })), image.lg && (jsx("source", { media: "(min-width: 1440px)", srcSet: createSrcSet(image.lg) })), jsx("img", { alt: image.altText, className: clsx(styles.image, styles[fit], {
59
59
  [styles['has-error']]: hasError,
60
- }), src: hasError ? fallbackSrc : getPrimarySrc(image), ...rest })] }));
60
+ }), src: encodeURI((hasError ? fallbackSrc : getPrimarySrc(image)) || ''), ...rest })] }));
61
61
  }
62
62
 
63
63
  export { Image };
@@ -24,11 +24,14 @@ function ReadOnlyAddresses({ billTo, isLoading, isPickup, notes, onSubmit, shipT
24
24
  const href = `${pathname}${search}`;
25
25
  const billToId = billTo?.id;
26
26
  const shipToId = shipTo?.id;
27
+ const isShipToABillToAddress = billToId && shipToId && billToId === shipToId;
27
28
  const editBillToAddressUrl = environment.includes('next')
28
29
  ? `${paths.ACCOUNT_EDIT_BILL_TO_ADDRESS}/${billToId}?returnUrl=${encodeURIComponent(href)}`
29
30
  : paths.ACCOUNT_ADDRESSES;
30
31
  const editShipToAddressUrl = environment.includes('next')
31
- ? `${paths.ACCOUNT_EDIT_BILL_TO_ADDRESS}/${billToId}${paths.ACCOUNT_EDIT_SHIP_TO_ADDRESS}/${shipToId}?returnUrl=${encodeURIComponent(href)}`
32
+ ? isShipToABillToAddress
33
+ ? `${paths.ACCOUNT_EDIT_BILL_TO_ADDRESS}/${billToId}${paths.ACCOUNT_EDIT_SHIP_TO_ADDRESS}/new?returnUrl=${encodeURIComponent(href)}&makeDefault=true`
34
+ : `${paths.ACCOUNT_EDIT_BILL_TO_ADDRESS}/${billToId}${paths.ACCOUNT_EDIT_SHIP_TO_ADDRESS}/${shipToId}?returnUrl=${encodeURIComponent(href)}`
32
35
  : paths.ACCOUNT_ADDRESSES;
33
36
  return (jsxs(Form, { id: EDIT_ADDRESS_FORM_ID, onSubmit: e => {
34
37
  e.preventDefault();
@@ -4,6 +4,7 @@ import { useState, useEffect } from 'react';
4
4
  import { useFetchCurrentAccount } from '../../../../shared/api/storefront/hooks/account/use-fetch-current-account.js';
5
5
  import { usePatchSession } from '../../../../shared/api/storefront/hooks/authentication/use-patch-session.js';
6
6
  import { useFetchBillToAddresses } from '../../../../shared/api/storefront/hooks/customer/use-fetch-bill-to-addresses.js';
7
+ import { fetchShipByBillTo } from '../../../../shared/api/storefront/services/customer-service.js';
7
8
  import { ChangeCustomerDialog } from './change-customer-dialog.js';
8
9
 
9
10
  function ConnectedChangeCustomerDialog({ allowSetDefault = false, isOpen, onClose, onCustomerSelected, }) {
@@ -17,6 +18,12 @@ function ConnectedChangeCustomerDialog({ allowSetDefault = false, isOpen, onClos
17
18
  useEffect(() => reset(), [isOpen, reset]);
18
19
  return (jsx(ChangeCustomerDialog, { allowSetDefault: allowSetDefault, data: data, defaultCustomerId: account?.defaultCustomerId || undefined, error: error, filter: filter, hasErrorSubmitting: Boolean(errorMutation), isLoading: isLoading || isFetching, isOpen: isOpen, isUpdating: isMutating, onClose: onClose, onCustomerSelected: async (id, setAsDefault) => {
19
20
  id = `${id}`;
21
+ const shipToAddress = await fetchShipByBillTo({ billToId: id });
22
+ const defaultShipTo = shipToAddress.shipTos?.find(shipTo => shipTo.isDefault);
23
+ const firstShipToWithId = shipToAddress.shipTos?.find(shipTo => shipTo.id !== '');
24
+ const shipToId = defaultShipTo
25
+ ? defaultShipTo.id
26
+ : (firstShipToWithId?.id ?? id);
20
27
  try {
21
28
  await mutate({
22
29
  session: {
@@ -28,8 +35,8 @@ function ConnectedChangeCustomerDialog({ allowSetDefault = false, isOpen, onClos
28
35
  customerWasUpdated: false,
29
36
  fulfillmentMethod: 'Ship',
30
37
  pickUpWarehouse: null,
31
- shipTo: { id },
32
- shipToId: id,
38
+ shipTo: { id: shipToId },
39
+ shipToId,
33
40
  },
34
41
  });
35
42
  onCustomerSelected(id, setAsDefault);
@@ -1,4 +1,5 @@
1
- export declare function ConnectedCreateShipToAddressForm({ billToId, returnUrl, }: {
1
+ export declare function ConnectedCreateShipToAddressForm({ billToId, makeDefault, returnUrl, }: {
2
2
  billToId: string;
3
+ makeDefault?: boolean;
3
4
  returnUrl?: string;
4
5
  }): import("react/jsx-runtime").JSX.Element;
@@ -18,7 +18,7 @@ import { LoadingPage } from '../../../loading-page/loading-page.js';
18
18
  import formStyles from '../../../../forms/partials/address-form/address-form.module.css.js';
19
19
  import styles from './create-ship-to-address.module.css.js';
20
20
 
21
- function ConnectedCreateShipToAddressForm({ billToId, returnUrl, }) {
21
+ function ConnectedCreateShipToAddressForm({ billToId, makeDefault, returnUrl, }) {
22
22
  const paths = usePaths();
23
23
  const { navigate } = useNavigate();
24
24
  const { countries, currentCountry, error: errorCountries, isFetching: isLoadingCountries, } = useCountries();
@@ -83,7 +83,7 @@ function ConnectedCreateShipToAddressForm({ billToId, returnUrl, }) {
83
83
  });
84
84
  }
85
85
  return navigate(`${paths.ACCOUNT_EDIT_BILL_TO_ADDRESS}/${billToId}${paths.ACCOUNT_EDIT_SHIP_TO_ADDRESS}/${createdShipToAddress.id}?returnUrl=${encodeURIComponent(returnUrl || '')}`);
86
- }, children: [jsx(AddressForm, { address: undefined, countries: countries, currentCountry: currentCountry, isLoading: isPatching }), jsx(Checkbox, { isDisabled: isPatching, name: "setAsDefault", value: "TRUE", children: jsx(FormattedMessage, { id: "Make this the default ship to address" }) }), Boolean(errorShipToAddress) && (jsx("div", { className: styles.info, children: jsx(Message, { type: "danger", children: jsx(FormattedMessage, { id: "An unexpected error occured" }) }) })), 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" }) })), jsx(Button, { isLoading: isPatching ? jsx(FormattedMessage, { id: "Saving" }) : undefined, type: "submit", children: jsx(FormattedMessage, { id: "Save" }) })] })] }));
86
+ }, children: [jsx(AddressForm, { address: undefined, countries: countries, currentCountry: currentCountry, isLoading: isPatching }), jsx(Checkbox, { defaultSelected: makeDefault, isDisabled: isPatching, name: "setAsDefault", value: "TRUE", children: jsx(FormattedMessage, { id: "Make this the default ship to address" }) }), Boolean(errorShipToAddress) && (jsx("div", { className: styles.info, children: jsx(Message, { type: "danger", children: jsx(FormattedMessage, { id: "An unexpected error occured" }) }) })), 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" }) })), jsx(Button, { isLoading: isPatching ? jsx(FormattedMessage, { id: "Saving" }) : undefined, type: "submit", children: jsx(FormattedMessage, { id: "Save" }) })] })] }));
87
87
  }
88
88
 
89
89
  export { ConnectedCreateShipToAddressForm };
@@ -1,5 +1,6 @@
1
- export declare function CreateShipToAddressDetailsPage({ billToId, returnUrl, }: {
1
+ export declare function CreateShipToAddressDetailsPage({ billToId, makeDefault, returnUrl, }: {
2
2
  billToId: string;
3
+ makeDefault?: boolean;
3
4
  returnUrl?: string;
4
5
  }): import("react/jsx-runtime").JSX.Element;
5
6
  export declare function CreateShipToAddressDetailsPageBreadcrumb({ billToId, }: {
@@ -7,10 +7,10 @@ import { ConnectedCreateShipToAddressForm } from '../../actions/create-ship-to-a
7
7
  import { MySonicLayoutBreadcrumb } from '../../layouts/my-sonic-layout/my-sonic-layout-breadcrumb.js';
8
8
  import { MySonicLayoutPage } from '../../layouts/my-sonic-layout/my-sonic-layout-page.js';
9
9
 
10
- function CreateShipToAddressDetailsPage({ billToId, returnUrl, }) {
10
+ function CreateShipToAddressDetailsPage({ billToId, makeDefault, returnUrl, }) {
11
11
  const t = useFormattedMessage();
12
12
  const paths = usePaths();
13
- return (jsx(MySonicLayoutPage, { title: t('Shipping address'), children: jsx(ConnectedCreateShipToAddressForm, { billToId: billToId, returnUrl: returnUrl || paths.ACCOUNT }) }));
13
+ return (jsx(MySonicLayoutPage, { title: t('Shipping address'), children: jsx(ConnectedCreateShipToAddressForm, { billToId: billToId, makeDefault: makeDefault, returnUrl: returnUrl || paths.ACCOUNT }) }));
14
14
  }
15
15
  function CreateShipToAddressDetailsPageBreadcrumb({ billToId, }) {
16
16
  const t = useFormattedMessage();
@@ -14,6 +14,9 @@ export declare function fetchShipToAddress({ billToId, includeValidation, shipTo
14
14
  includeValidation?: boolean;
15
15
  shipToId: string;
16
16
  }): Promise<ShipToModel>;
17
+ export declare function fetchShipByBillTo({ billToId }: {
18
+ billToId: string;
19
+ }): Promise<ShipToCollectionModel>;
17
20
  export interface FetchBillToAddressesParams {
18
21
  filter?: string;
19
22
  pageSize?: number;
@@ -25,6 +25,13 @@ async function fetchShipToAddress({ billToId, includeValidation = false, shipToI
25
25
  });
26
26
  return body;
27
27
  }
28
+ async function fetchShipByBillTo({ billToId }) {
29
+ const { body } = await request({
30
+ credentials: 'include',
31
+ url: `${config.SHOP_API_URL}/api/v1/billtos/${billToId}/shiptos`,
32
+ });
33
+ return body;
34
+ }
28
35
  async function fetchBillToAddresses({ filter, pageSize = 20, } = {}) {
29
36
  const { body } = await request({
30
37
  credentials: 'include',
@@ -102,4 +109,4 @@ async function fetchFulfillmentMethods({ customerId, }) {
102
109
  return updatedBillTo;
103
110
  }
104
111
 
105
- export { fetchBillToAddress, fetchBillToAddresses, fetchCurrentBillToAddress, fetchCurrentShipToAddress, fetchFulfillmentMethods, fetchPagedShipToAddresses, fetchShipToAddress, fetchShipToAddresses, patchBillToAddress, patchShipToAddress, postShipToAddress };
112
+ export { fetchBillToAddress, fetchBillToAddresses, fetchCurrentBillToAddress, fetchCurrentShipToAddress, fetchFulfillmentMethods, fetchPagedShipToAddresses, fetchShipByBillTo, fetchShipToAddress, fetchShipToAddresses, patchBillToAddress, patchShipToAddress, postShipToAddress };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonic-equipment/ui",
3
- "version": "254.0.0",
3
+ "version": "256.0.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "engines": {