@atomic-solutions/woocommerce-react 0.6.2 → 0.8.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.
- package/dist/hooks/index.cjs +35 -3
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +2 -2
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.js +34 -4
- package/dist/hooks/index.js.map +1 -1
- package/dist/{index-Dmlapl9c.d.ts → index-C6OkRa8P.d.ts} +202 -5
- package/dist/{index-DEvJWFSF.d.cts → index-DtuDPfTl.d.cts} +202 -5
- package/dist/index.cjs +35 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +34 -4
- package/dist/index.js.map +1 -1
- package/dist/provider/index.d.cts +2 -2
- package/dist/provider/index.d.ts +2 -2
- package/dist/{types-Dnq60zh-.d.cts → types-DABmdACe.d.cts} +3 -1
- package/dist/{types-Dnq60zh-.d.ts → types-DABmdACe.d.ts} +3 -1
- package/package.json +2 -2
package/dist/hooks/index.cjs
CHANGED
|
@@ -42,6 +42,8 @@ var StaleTimes = {
|
|
|
42
42
|
product: STALE_TIME_SHORT,
|
|
43
43
|
/** Product categories - always fresh */
|
|
44
44
|
categories: STALE_TIME_NONE,
|
|
45
|
+
/** Product tags - names rarely change, 1 hour */
|
|
46
|
+
tags: STALE_TIME_LONG,
|
|
45
47
|
/** Orders - always fresh */
|
|
46
48
|
orders: STALE_TIME_NONE,
|
|
47
49
|
/** Default for infinite queries - 1 hour */
|
|
@@ -139,6 +141,16 @@ var processCategoriesToTree = (data) => {
|
|
|
139
141
|
});
|
|
140
142
|
return rootCategories?.map(processCategory) ?? [];
|
|
141
143
|
};
|
|
144
|
+
var useProductTags = (params, options) => {
|
|
145
|
+
const client = useWooCommerceClient();
|
|
146
|
+
const queryKeys = useWooCommerceQueryKeys();
|
|
147
|
+
return reactQuery.useQuery({
|
|
148
|
+
queryKey: queryKeys.products.tags(params),
|
|
149
|
+
queryFn: () => client.products.tags(params),
|
|
150
|
+
staleTime: StaleTimes.tags,
|
|
151
|
+
...options
|
|
152
|
+
});
|
|
153
|
+
};
|
|
142
154
|
var useProductCategoryTree = () => {
|
|
143
155
|
const query = useProductCategories();
|
|
144
156
|
const flatData = query.data ?? [];
|
|
@@ -357,6 +369,19 @@ var useRemoveCoupon = () => {
|
|
|
357
369
|
}
|
|
358
370
|
});
|
|
359
371
|
};
|
|
372
|
+
var useUpdateCartExtensions = () => {
|
|
373
|
+
const client = useWooCommerceClient();
|
|
374
|
+
const queryKeys = useWooCommerceQueryKeys();
|
|
375
|
+
const queryClient = reactQuery.useQueryClient();
|
|
376
|
+
return reactQuery.useMutation({
|
|
377
|
+
mutationKey: queryKeys.cart.mutations.updateExtensions(),
|
|
378
|
+
mutationFn: (input) => client.cart.updateExtensions(input),
|
|
379
|
+
onSuccess: (cart) => {
|
|
380
|
+
queryClient.setQueryData(queryKeys.cart.details(), cart);
|
|
381
|
+
queryClient.invalidateQueries({ queryKey: queryKeys.cart.all });
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
};
|
|
360
385
|
var useUpdateCustomer = () => {
|
|
361
386
|
const client = useWooCommerceClient();
|
|
362
387
|
const queryKeys = useWooCommerceQueryKeys();
|
|
@@ -463,7 +488,9 @@ var createQueryKeys = (prefix = ["woocommerce"]) => ({
|
|
|
463
488
|
list: (params) => [...prefix, "products", "list", params],
|
|
464
489
|
details: () => [...prefix, "products", "detail"],
|
|
465
490
|
detail: (id) => [...prefix, "products", "detail", id],
|
|
466
|
-
categories: () => [...prefix, "products", "categories"]
|
|
491
|
+
categories: () => [...prefix, "products", "categories"],
|
|
492
|
+
// Params are in the key, so each set of tag ids is cached apart.
|
|
493
|
+
tags: (params) => [...prefix, "products", "tags", params]
|
|
467
494
|
},
|
|
468
495
|
// Cart
|
|
469
496
|
cart: {
|
|
@@ -477,6 +504,7 @@ var createQueryKeys = (prefix = ["woocommerce"]) => ({
|
|
|
477
504
|
removeItem: () => [...prefix, "cart", "mutation", "removeItem"],
|
|
478
505
|
applyCoupon: () => [...prefix, "cart", "mutation", "applyCoupon"],
|
|
479
506
|
removeCoupon: () => [...prefix, "cart", "mutation", "removeCoupon"],
|
|
507
|
+
updateExtensions: () => [...prefix, "cart", "mutation", "updateExtensions"],
|
|
480
508
|
updateCustomer: () => [...prefix, "cart", "mutation", "updateCustomer"],
|
|
481
509
|
selectShippingRate: () => [...prefix, "cart", "mutation", "selectShippingRate"]
|
|
482
510
|
}
|
|
@@ -1224,6 +1252,8 @@ function useOrderView(input, options = {}) {
|
|
|
1224
1252
|
const storeContext = react.useContext(WooCommerceStoreContext);
|
|
1225
1253
|
const storeConfig = storeContext?.config;
|
|
1226
1254
|
const localeTag = options.localeTag ?? storeConfig?.locale?.localeTag ?? DEFAULT_STORE_CONFIG.locale.localeTag;
|
|
1255
|
+
const { imageSize = "thumbnail" } = options;
|
|
1256
|
+
const getProcessedImageUrl = useProcessedImageUrl(imageSize, options.fallbackImageUrl);
|
|
1227
1257
|
const { data: rawOrder, isLoading, error } = useOrder(input);
|
|
1228
1258
|
const order = react.useMemo(() => {
|
|
1229
1259
|
if (!rawOrder) return void 0;
|
|
@@ -1234,7 +1264,7 @@ function useOrderView(input, options = {}) {
|
|
|
1234
1264
|
quantity: item.quantity,
|
|
1235
1265
|
price: formatStoreApiPriceIntl(item.prices.price, currencyCode, localeTag),
|
|
1236
1266
|
total: formatStoreApiPriceIntl(item.totals.line_total, currencyCode, localeTag),
|
|
1237
|
-
imageUrl: item.images
|
|
1267
|
+
imageUrl: getProcessedImageUrl(item.images)
|
|
1238
1268
|
}));
|
|
1239
1269
|
const status = rawOrder.status;
|
|
1240
1270
|
return {
|
|
@@ -1249,7 +1279,7 @@ function useOrderView(input, options = {}) {
|
|
|
1249
1279
|
paymentMethod: rawOrder.payment_method ?? "",
|
|
1250
1280
|
raw: rawOrder
|
|
1251
1281
|
};
|
|
1252
|
-
}, [rawOrder, localeTag]);
|
|
1282
|
+
}, [rawOrder, localeTag, getProcessedImageUrl]);
|
|
1253
1283
|
return {
|
|
1254
1284
|
order,
|
|
1255
1285
|
isLoading,
|
|
@@ -1272,6 +1302,7 @@ exports.useProcessCheckout = useProcessCheckout;
|
|
|
1272
1302
|
exports.useProduct = useProduct;
|
|
1273
1303
|
exports.useProductCategories = useProductCategories;
|
|
1274
1304
|
exports.useProductCategoryTree = useProductCategoryTree;
|
|
1305
|
+
exports.useProductTags = useProductTags;
|
|
1275
1306
|
exports.useProductView = useProductView;
|
|
1276
1307
|
exports.useProducts = useProducts;
|
|
1277
1308
|
exports.useProductsFeed = useProductsFeed;
|
|
@@ -1283,6 +1314,7 @@ exports.useStore = useStore;
|
|
|
1283
1314
|
exports.useStoreFeatures = useStoreFeatures;
|
|
1284
1315
|
exports.useStoreLocale = useStoreLocale;
|
|
1285
1316
|
exports.useStoreTheme = useStoreTheme;
|
|
1317
|
+
exports.useUpdateCartExtensions = useUpdateCartExtensions;
|
|
1286
1318
|
exports.useUpdateCartItem = useUpdateCartItem;
|
|
1287
1319
|
exports.useUpdateCustomer = useUpdateCustomer;
|
|
1288
1320
|
exports.useWooCommerceClient = useWooCommerceClient;
|