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