@atomic-solutions/woocommerce-react 0.6.0 → 0.6.2

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.
@@ -198,7 +198,6 @@ var useCart = (options) => {
198
198
  var toWooError = (error) => error instanceof woocommerceApiClient.WooCommerceApiError ? error : new woocommerceApiClient.WooCommerceApiError({
199
199
  code: "unknown_error",
200
200
  message: error instanceof Error ? error.message : "Unknown error",
201
- statusCode: 500,
202
201
  url: "",
203
202
  method: "POST",
204
203
  originalCode: "unknown_error"
@@ -433,7 +432,6 @@ var useProcessCheckout = () => {
433
432
  const wooError = error instanceof woocommerceApiClient.WooCommerceApiError ? error : new woocommerceApiClient.WooCommerceApiError({
434
433
  code: "unknown_error",
435
434
  message: error instanceof Error ? error.message : "Unknown error",
436
- statusCode: 500,
437
435
  url: "",
438
436
  method: "POST",
439
437
  originalCode: "unknown_error"
@@ -755,6 +753,18 @@ function getAllImageUrls(images, size = "full") {
755
753
  }
756
754
  return images.map((img) => getSizedImageUrl(img.src, size));
757
755
  }
756
+ var useProcessedImageUrl = (imageSize, fallbackOverride) => {
757
+ const config = react.useContext(WooCommerceStoreContext)?.config;
758
+ const transformer = config?.imageUrlTransformer;
759
+ const fallbackImageUrl = fallbackOverride ?? config?.fallbackImageUrl;
760
+ return react.useCallback(
761
+ (images) => {
762
+ const baseUrl = getImageUrl(images, imageSize, fallbackImageUrl);
763
+ return baseUrl && transformer ? transformer(baseUrl, imageSize) : baseUrl;
764
+ },
765
+ [imageSize, fallbackImageUrl, transformer]
766
+ );
767
+ };
758
768
 
759
769
  // src/hooks/useProductsFeed.ts
760
770
  function useProductsFeed(options = {}) {
@@ -762,8 +772,6 @@ function useProductsFeed(options = {}) {
762
772
  const storeContext = react.useContext(WooCommerceStoreContext);
763
773
  const storeConfig = storeContext?.config;
764
774
  const localeTag = options.localeTag ?? storeConfig?.locale?.localeTag ?? DEFAULT_STORE_CONFIG.locale.localeTag;
765
- const fallbackImageUrl = options.fallbackImageUrl ?? storeConfig?.fallbackImageUrl;
766
- const imageUrlTransformer = storeConfig?.imageUrlTransformer;
767
775
  const {
768
776
  data: productsData,
769
777
  isLoading,
@@ -775,16 +783,7 @@ function useProductsFeed(options = {}) {
775
783
  isRefetching
776
784
  } = useInfiniteProducts(params);
777
785
  const { treeData: categoryTree = [], findById } = useProductCategoryTree();
778
- const getProcessedImageUrl = react.useCallback(
779
- (images) => {
780
- const baseUrl = getImageUrl(images, imageSize, fallbackImageUrl);
781
- if (baseUrl && imageUrlTransformer) {
782
- return imageUrlTransformer(baseUrl, imageSize);
783
- }
784
- return baseUrl;
785
- },
786
- [imageSize, fallbackImageUrl, imageUrlTransformer]
787
- );
786
+ const getProcessedImageUrl = useProcessedImageUrl(imageSize, options.fallbackImageUrl);
788
787
  const products = react.useMemo(() => {
789
788
  if (!productsData) return [];
790
789
  const productList = Array.isArray(productsData) ? productsData : [];
@@ -836,7 +835,6 @@ function useProductView(options) {
836
835
  const storeContext = react.useContext(WooCommerceStoreContext);
837
836
  const storeConfig = storeContext?.config;
838
837
  const localeTag = options.localeTag ?? storeConfig?.locale?.localeTag ?? DEFAULT_STORE_CONFIG.locale.localeTag;
839
- const fallbackImageUrl = options.fallbackImageUrl ?? storeConfig?.fallbackImageUrl;
840
838
  const imageUrlTransformer = storeConfig?.imageUrlTransformer;
841
839
  const [draftQuantity, setDraftQuantity] = react.useState(1);
842
840
  const { data: productData, isLoading, error, refetch } = useProduct(productId);
@@ -844,6 +842,7 @@ function useProductView(options) {
844
842
  const addToCartMutation = useAddToCart();
845
843
  const removeFromCartMutation = useRemoveFromCart();
846
844
  const updateCartMutation = useUpdateCartItem();
845
+ const getProcessedImageUrl = useProcessedImageUrl(imageSize, options.fallbackImageUrl);
847
846
  const processImageUrl = react.useCallback(
848
847
  (url) => {
849
848
  if (!url) return url;
@@ -859,7 +858,6 @@ function useProductView(options) {
859
858
  const currencyCode = productData.prices?.currency_code;
860
859
  const stockStatus = productData.is_on_backorder ? "onbackorder" : productData.is_in_stock ? "instock" : "outofstock";
861
860
  const lowStockRemaining = productData.low_stock_remaining;
862
- const baseImageUrl = getImageUrl(productData.images, imageSize, fallbackImageUrl);
863
861
  const baseImageUrls = getAllImageUrls(productData.images, imageSize);
864
862
  return {
865
863
  id: productData.id,
@@ -869,7 +867,7 @@ function useProductView(options) {
869
867
  description: productData.description,
870
868
  shortDescription: productData.short_description,
871
869
  sku: productData.sku,
872
- imageUrl: processImageUrl(baseImageUrl),
870
+ imageUrl: getProcessedImageUrl(productData.images),
873
871
  imageUrls: baseImageUrls.map((url) => processImageUrl(url) ?? url),
874
872
  price: formatStoreApiPriceIntl(productData.prices?.price, currencyCode, localeTag),
875
873
  regularPrice: formatStoreApiPriceIntl(
@@ -899,7 +897,7 @@ function useProductView(options) {
899
897
  minQuantity: productData.add_to_cart?.minimum ?? 1,
900
898
  raw: productData
901
899
  };
902
- }, [productData, localeTag, fallbackImageUrl, imageSize, lowStockThreshold, processImageUrl]);
900
+ }, [productData, localeTag, imageSize, lowStockThreshold, getProcessedImageUrl, processImageUrl]);
903
901
  const cartItem = react.useMemo(() => {
904
902
  return cartData?.items.find((item) => item.id === productId);
905
903
  }, [cartData?.items, productId]);
@@ -982,24 +980,13 @@ function useCartView(options = {}) {
982
980
  const storeContext = react.useContext(WooCommerceStoreContext);
983
981
  const storeConfig = storeContext?.config;
984
982
  const localeTag = options.localeTag ?? storeConfig?.locale?.localeTag ?? DEFAULT_STORE_CONFIG.locale.localeTag;
985
- const fallbackImageUrl = options.fallbackImageUrl ?? storeConfig?.fallbackImageUrl;
986
- const imageUrlTransformer = storeConfig?.imageUrlTransformer;
987
983
  const { data: cartData, isLoading, error, refetch } = useCart();
988
984
  const updateItemMutation = useUpdateCartItem();
989
985
  const removeItemMutation = useRemoveFromCart();
990
986
  const applyCouponMutation = useApplyCoupon();
991
987
  const removeCouponMutation = useRemoveCoupon();
992
988
  const selectShippingMutation = useSelectShippingRate();
993
- const getProcessedImageUrl = react.useCallback(
994
- (images) => {
995
- const baseUrl = getImageUrl(images, imageSize, fallbackImageUrl);
996
- if (baseUrl && imageUrlTransformer) {
997
- return imageUrlTransformer(baseUrl, imageSize);
998
- }
999
- return baseUrl;
1000
- },
1001
- [imageSize, fallbackImageUrl, imageUrlTransformer]
1002
- );
989
+ const getProcessedImageUrl = useProcessedImageUrl(imageSize, options.fallbackImageUrl);
1003
990
  const items = react.useMemo(() => {
1004
991
  if (!cartData?.items) return [];
1005
992
  const currencyCode = cartData.totals.currency_code;
@@ -1145,8 +1132,6 @@ function useReorderView(items, options = {}) {
1145
1132
  const storeContext = react.useContext(WooCommerceStoreContext);
1146
1133
  const storeConfig = storeContext?.config;
1147
1134
  const localeTag = options.localeTag ?? storeConfig?.locale?.localeTag ?? DEFAULT_STORE_CONFIG.locale.localeTag;
1148
- const fallbackImageUrl = options.fallbackImageUrl ?? storeConfig?.fallbackImageUrl;
1149
- const imageUrlTransformer = storeConfig?.imageUrlTransformer;
1150
1135
  const productIds = react.useMemo(() => [...new Set(items.map((item) => item.productId))], [items]);
1151
1136
  const {
1152
1137
  data: productsPage,
@@ -1157,16 +1142,7 @@ function useReorderView(items, options = {}) {
1157
1142
  { enabled: productIds.length > 0 }
1158
1143
  );
1159
1144
  const { data: cart } = useCart();
1160
- const getProcessedImageUrl = react.useCallback(
1161
- (images) => {
1162
- const baseUrl = getImageUrl(images, imageSize, fallbackImageUrl);
1163
- if (baseUrl && imageUrlTransformer) {
1164
- return imageUrlTransformer(baseUrl, imageSize);
1165
- }
1166
- return baseUrl;
1167
- },
1168
- [imageSize, fallbackImageUrl, imageUrlTransformer]
1169
- );
1145
+ const getProcessedImageUrl = useProcessedImageUrl(imageSize, options.fallbackImageUrl);
1170
1146
  const views = react.useMemo(() => {
1171
1147
  const products = new Map((productsPage?.data ?? []).map((product) => [product.id, product]));
1172
1148
  return items.map((item) => {