@atomic-solutions/woocommerce-react 0.2.5 → 0.3.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 +52 -1
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +3 -3
- package/dist/hooks/index.d.ts +3 -3
- package/dist/hooks/index.js +51 -2
- package/dist/hooks/index.js.map +1 -1
- package/dist/{index-BP5iXDIj.d.cts → index-DdY_1X-C.d.cts} +33 -2
- package/dist/{index-BPa3-Cyt.d.ts → index-unbfwba0.d.ts} +33 -2
- package/dist/index.cjs +60 -4
- 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 +59 -5
- 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-D7dDI9Lr.d.cts → types-_8YqnkO-.d.cts} +1 -0
- package/dist/{types-D7dDI9Lr.d.ts → types-_8YqnkO-.d.ts} +1 -0
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
2
2
|
import { UseQueryOptions, UseInfiniteQueryOptions, InfiniteData, UseMutationOptions } from '@tanstack/react-query';
|
|
3
3
|
import { WooCommerceClient, ProductCategory, ProductParams, PaginatedResponse, Product, Cart, Checkout, GetOrderInput, StoreApiOrder, ProductImage, CartItemImage, CartItem } from '@atomic-solutions/woocommerce-api-client';
|
|
4
|
-
import { Q as QueryKeys, k as StoreContextValue, l as StoreFeatures, S as StoreLocale, n as StoreTheme } from './types-
|
|
4
|
+
import { Q as QueryKeys, k as StoreContextValue, l as StoreFeatures, S as StoreLocale, n as StoreTheme } from './types-_8YqnkO-.cjs';
|
|
5
5
|
|
|
6
6
|
type QueryOptions<TData, TError = Error> = Omit<UseQueryOptions<TData, TError>, 'queryKey' | 'queryFn'>;
|
|
7
7
|
type MutationOptions<TData, TError = Error, TVariables = unknown> = Omit<UseMutationOptions<TData, TError, TVariables>, 'mutationFn'>;
|
|
@@ -8722,4 +8722,35 @@ interface UseCartViewReturn {
|
|
|
8722
8722
|
}
|
|
8723
8723
|
declare function useCartView(options?: UseCartViewOptions): UseCartViewReturn;
|
|
8724
8724
|
|
|
8725
|
-
|
|
8725
|
+
declare function getOrderStatusLabel(status: string): string;
|
|
8726
|
+
interface ProcessedOrderLineItem {
|
|
8727
|
+
id: number;
|
|
8728
|
+
name: string;
|
|
8729
|
+
quantity: number;
|
|
8730
|
+
price: string;
|
|
8731
|
+
total: string;
|
|
8732
|
+
imageUrl?: string;
|
|
8733
|
+
}
|
|
8734
|
+
interface ProcessedOrderDetails {
|
|
8735
|
+
id: number;
|
|
8736
|
+
number: string;
|
|
8737
|
+
status: string;
|
|
8738
|
+
statusLabel: string;
|
|
8739
|
+
total: string;
|
|
8740
|
+
itemCount: number;
|
|
8741
|
+
lineItems: ProcessedOrderLineItem[];
|
|
8742
|
+
needsPayment: boolean;
|
|
8743
|
+
paymentMethod: string;
|
|
8744
|
+
raw: StoreApiOrder;
|
|
8745
|
+
}
|
|
8746
|
+
interface UseOrderViewOptions {
|
|
8747
|
+
localeTag?: string;
|
|
8748
|
+
}
|
|
8749
|
+
interface UseOrderViewReturn {
|
|
8750
|
+
order: ProcessedOrderDetails | undefined;
|
|
8751
|
+
isLoading: boolean;
|
|
8752
|
+
error: Error | null;
|
|
8753
|
+
}
|
|
8754
|
+
declare function useOrderView(input: GetOrderInput, options?: UseOrderViewOptions): UseOrderViewReturn;
|
|
8755
|
+
|
|
8756
|
+
export { useUpdateCustomer as $, type AppliedCoupon as A, useCart as B, type CartTotals as C, useCartView as D, useCheckout as E, useInfiniteProducts as F, useOrder as G, useOrderView as H, type ImageSize as I, useProcessCheckout as J, useProduct as K, useProductCategories as L, useProductCategoryTree as M, useProductView as N, useProducts as O, PLACEHOLDER_IMAGE_URL as P, useProductsFeed as Q, useRemoveCoupon as R, type ShippingRate as S, useRemoveFromCart as T, type UseCartViewOptions as U, useSelectShippingRate as V, useStore as W, useStoreFeatures as X, useStoreLocale as Y, useStoreTheme as Z, useUpdateCartItem as _, type PaymentMethod as a, useWooCommerceClient as a0, useWooCommerceQueryKeys as a1, type InfiniteQueryOptions as a2, type MutationOptions as a3, type QueryOptions as a4, type ProcessedCartItem as b, type ProcessedCategory as c, type ProcessedOrderDetails as d, type ProcessedOrderLineItem as e, type ProcessedProduct as f, type ProcessedProductDetails as g, type ProductCartState as h, type ProductCategoryTreeNode as i, type UseCartViewReturn as j, type UseOrderViewOptions as k, type UseOrderViewReturn as l, type UseProductViewOptions as m, type UseProductViewReturn as n, type UseProductsFeedOptions as o, type UseProductsFeedReturn as p, getAllImageUrls as q, getImageUrl as r, getImageUrlOrPlaceholder as s, getOrderStatusLabel as t, getPrimaryImage as u, getSizedImageUrl as v, preloadImage as w, preloadImages as x, useAddToCart as y, useApplyCoupon as z };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
2
2
|
import { UseQueryOptions, UseInfiniteQueryOptions, InfiniteData, UseMutationOptions } from '@tanstack/react-query';
|
|
3
3
|
import { WooCommerceClient, ProductCategory, ProductParams, PaginatedResponse, Product, Cart, Checkout, GetOrderInput, StoreApiOrder, ProductImage, CartItemImage, CartItem } from '@atomic-solutions/woocommerce-api-client';
|
|
4
|
-
import { Q as QueryKeys, k as StoreContextValue, l as StoreFeatures, S as StoreLocale, n as StoreTheme } from './types-
|
|
4
|
+
import { Q as QueryKeys, k as StoreContextValue, l as StoreFeatures, S as StoreLocale, n as StoreTheme } from './types-_8YqnkO-.js';
|
|
5
5
|
|
|
6
6
|
type QueryOptions<TData, TError = Error> = Omit<UseQueryOptions<TData, TError>, 'queryKey' | 'queryFn'>;
|
|
7
7
|
type MutationOptions<TData, TError = Error, TVariables = unknown> = Omit<UseMutationOptions<TData, TError, TVariables>, 'mutationFn'>;
|
|
@@ -8722,4 +8722,35 @@ interface UseCartViewReturn {
|
|
|
8722
8722
|
}
|
|
8723
8723
|
declare function useCartView(options?: UseCartViewOptions): UseCartViewReturn;
|
|
8724
8724
|
|
|
8725
|
-
|
|
8725
|
+
declare function getOrderStatusLabel(status: string): string;
|
|
8726
|
+
interface ProcessedOrderLineItem {
|
|
8727
|
+
id: number;
|
|
8728
|
+
name: string;
|
|
8729
|
+
quantity: number;
|
|
8730
|
+
price: string;
|
|
8731
|
+
total: string;
|
|
8732
|
+
imageUrl?: string;
|
|
8733
|
+
}
|
|
8734
|
+
interface ProcessedOrderDetails {
|
|
8735
|
+
id: number;
|
|
8736
|
+
number: string;
|
|
8737
|
+
status: string;
|
|
8738
|
+
statusLabel: string;
|
|
8739
|
+
total: string;
|
|
8740
|
+
itemCount: number;
|
|
8741
|
+
lineItems: ProcessedOrderLineItem[];
|
|
8742
|
+
needsPayment: boolean;
|
|
8743
|
+
paymentMethod: string;
|
|
8744
|
+
raw: StoreApiOrder;
|
|
8745
|
+
}
|
|
8746
|
+
interface UseOrderViewOptions {
|
|
8747
|
+
localeTag?: string;
|
|
8748
|
+
}
|
|
8749
|
+
interface UseOrderViewReturn {
|
|
8750
|
+
order: ProcessedOrderDetails | undefined;
|
|
8751
|
+
isLoading: boolean;
|
|
8752
|
+
error: Error | null;
|
|
8753
|
+
}
|
|
8754
|
+
declare function useOrderView(input: GetOrderInput, options?: UseOrderViewOptions): UseOrderViewReturn;
|
|
8755
|
+
|
|
8756
|
+
export { useUpdateCustomer as $, type AppliedCoupon as A, useCart as B, type CartTotals as C, useCartView as D, useCheckout as E, useInfiniteProducts as F, useOrder as G, useOrderView as H, type ImageSize as I, useProcessCheckout as J, useProduct as K, useProductCategories as L, useProductCategoryTree as M, useProductView as N, useProducts as O, PLACEHOLDER_IMAGE_URL as P, useProductsFeed as Q, useRemoveCoupon as R, type ShippingRate as S, useRemoveFromCart as T, type UseCartViewOptions as U, useSelectShippingRate as V, useStore as W, useStoreFeatures as X, useStoreLocale as Y, useStoreTheme as Z, useUpdateCartItem as _, type PaymentMethod as a, useWooCommerceClient as a0, useWooCommerceQueryKeys as a1, type InfiniteQueryOptions as a2, type MutationOptions as a3, type QueryOptions as a4, type ProcessedCartItem as b, type ProcessedCategory as c, type ProcessedOrderDetails as d, type ProcessedOrderLineItem as e, type ProcessedProduct as f, type ProcessedProductDetails as g, type ProductCartState as h, type ProductCategoryTreeNode as i, type UseCartViewReturn as j, type UseOrderViewOptions as k, type UseOrderViewReturn as l, type UseProductViewOptions as m, type UseProductViewReturn as n, type UseProductsFeedOptions as o, type UseProductsFeedReturn as p, getAllImageUrls as q, getImageUrl as r, getImageUrlOrPlaceholder as s, getOrderStatusLabel as t, getPrimaryImage as u, getSizedImageUrl as v, preloadImage as w, preloadImages as x, useAddToCart as y, useApplyCoupon as z };
|
package/dist/index.cjs
CHANGED
|
@@ -858,10 +858,11 @@ var useProcessCheckout = () => {
|
|
|
858
858
|
mutationKey: queryKeys.checkout.mutations.process(),
|
|
859
859
|
mutationFn: (input) => client.checkout.process(input),
|
|
860
860
|
onSuccess: (checkout) => {
|
|
861
|
+
const cart = queryClient.getQueryData(queryKeys.cart.details()) ?? null;
|
|
861
862
|
queryClient.invalidateQueries({ queryKey: queryKeys.cart.all });
|
|
862
863
|
queryClient.invalidateQueries({ queryKey: queryKeys.checkout.all });
|
|
863
864
|
if (emitEvent) {
|
|
864
|
-
emitEvent(createSuccessEvent("checkout:processed", { checkout }));
|
|
865
|
+
emitEvent(createSuccessEvent("checkout:processed", { checkout, cart }));
|
|
865
866
|
}
|
|
866
867
|
},
|
|
867
868
|
onError: (error) => {
|
|
@@ -1645,6 +1646,54 @@ function useCartView(options = {}) {
|
|
|
1645
1646
|
isBusy
|
|
1646
1647
|
};
|
|
1647
1648
|
}
|
|
1649
|
+
var ORDER_STATUS_LABELS = {
|
|
1650
|
+
pending: "Pending Payment",
|
|
1651
|
+
processing: "Processing",
|
|
1652
|
+
"on-hold": "On Hold",
|
|
1653
|
+
completed: "Completed",
|
|
1654
|
+
cancelled: "Cancelled",
|
|
1655
|
+
refunded: "Refunded",
|
|
1656
|
+
failed: "Failed"
|
|
1657
|
+
};
|
|
1658
|
+
function getOrderStatusLabel(status) {
|
|
1659
|
+
return ORDER_STATUS_LABELS[status] ?? status.replace(/[_-]/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
|
|
1660
|
+
}
|
|
1661
|
+
function useOrderView(input, options = {}) {
|
|
1662
|
+
const storeContext = react.useContext(WooCommerceStoreContext);
|
|
1663
|
+
const storeConfig = storeContext?.config;
|
|
1664
|
+
const localeTag = options.localeTag ?? storeConfig?.locale?.localeTag ?? DEFAULT_STORE_CONFIG.locale.localeTag;
|
|
1665
|
+
const { data: rawOrder, isLoading, error } = useOrder(input);
|
|
1666
|
+
const order = react.useMemo(() => {
|
|
1667
|
+
if (!rawOrder) return void 0;
|
|
1668
|
+
const currencyCode = rawOrder.totals.currency_code ?? "USD";
|
|
1669
|
+
const lineItems = rawOrder.items.map((item) => ({
|
|
1670
|
+
id: item.id,
|
|
1671
|
+
name: item.name,
|
|
1672
|
+
quantity: item.quantity,
|
|
1673
|
+
price: formatStoreApiPriceIntl(item.prices.price, currencyCode, localeTag),
|
|
1674
|
+
total: formatStoreApiPriceIntl(item.totals.line_total, currencyCode, localeTag),
|
|
1675
|
+
imageUrl: item.images?.[0]?.src
|
|
1676
|
+
}));
|
|
1677
|
+
const status = rawOrder.status;
|
|
1678
|
+
return {
|
|
1679
|
+
id: rawOrder.id,
|
|
1680
|
+
number: String(rawOrder.id),
|
|
1681
|
+
status,
|
|
1682
|
+
statusLabel: getOrderStatusLabel(status),
|
|
1683
|
+
total: formatStoreApiPriceIntl(rawOrder.totals.total_price, currencyCode, localeTag),
|
|
1684
|
+
itemCount: lineItems.reduce((sum, item) => sum + item.quantity, 0),
|
|
1685
|
+
lineItems,
|
|
1686
|
+
needsPayment: rawOrder.needs_payment,
|
|
1687
|
+
paymentMethod: rawOrder.payment_method ?? "",
|
|
1688
|
+
raw: rawOrder
|
|
1689
|
+
};
|
|
1690
|
+
}, [rawOrder, localeTag]);
|
|
1691
|
+
return {
|
|
1692
|
+
order,
|
|
1693
|
+
isLoading,
|
|
1694
|
+
error
|
|
1695
|
+
};
|
|
1696
|
+
}
|
|
1648
1697
|
|
|
1649
1698
|
// src/events/composeHandlers.ts
|
|
1650
1699
|
function composeHandlers(...handlers) {
|
|
@@ -1698,12 +1747,17 @@ function createAnalyticsHandler(provider) {
|
|
|
1698
1747
|
coupon_code: event.data.code
|
|
1699
1748
|
});
|
|
1700
1749
|
break;
|
|
1701
|
-
case "checkout:processed":
|
|
1750
|
+
case "checkout:processed": {
|
|
1751
|
+
const { checkout, cart } = event.data;
|
|
1752
|
+
const parsedTotal = cart ? parseFloat(cart.totals.total_price) : void 0;
|
|
1702
1753
|
provider.log("purchase", {
|
|
1703
|
-
order_id:
|
|
1704
|
-
payment_method:
|
|
1754
|
+
order_id: checkout.order_id,
|
|
1755
|
+
payment_method: checkout.payment_method,
|
|
1756
|
+
order_total: Number.isFinite(parsedTotal) ? parsedTotal : void 0,
|
|
1757
|
+
items_count: cart?.items_count
|
|
1705
1758
|
});
|
|
1706
1759
|
break;
|
|
1760
|
+
}
|
|
1707
1761
|
}
|
|
1708
1762
|
};
|
|
1709
1763
|
}
|
|
@@ -1740,6 +1794,7 @@ exports.getGlobalRateLimiter = getGlobalRateLimiter;
|
|
|
1740
1794
|
exports.getImageUrl = getImageUrl;
|
|
1741
1795
|
exports.getImageUrlOrPlaceholder = getImageUrlOrPlaceholder;
|
|
1742
1796
|
exports.getMaxAddToCartQuantity = getMaxAddToCartQuantity;
|
|
1797
|
+
exports.getOrderStatusLabel = getOrderStatusLabel;
|
|
1743
1798
|
exports.getPrimaryImage = getPrimaryImage;
|
|
1744
1799
|
exports.getSizedImageUrl = getSizedImageUrl;
|
|
1745
1800
|
exports.getStockSeverity = getStockSeverity;
|
|
@@ -1759,6 +1814,7 @@ exports.useCartView = useCartView;
|
|
|
1759
1814
|
exports.useCheckout = useCheckout;
|
|
1760
1815
|
exports.useInfiniteProducts = useInfiniteProducts;
|
|
1761
1816
|
exports.useOrder = useOrder;
|
|
1817
|
+
exports.useOrderView = useOrderView;
|
|
1762
1818
|
exports.useProcessCheckout = useProcessCheckout;
|
|
1763
1819
|
exports.useProduct = useProduct;
|
|
1764
1820
|
exports.useProductCategories = useProductCategories;
|