@atomic-solutions/woocommerce-react 0.2.6 → 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.
@@ -8722,4 +8722,35 @@ interface UseCartViewReturn {
8722
8722
  }
8723
8723
  declare function useCartView(options?: UseCartViewOptions): UseCartViewReturn;
8724
8724
 
8725
- export { type AppliedCoupon as A, useProcessCheckout as B, type CartTotals as C, useProduct as D, useProductCategories as E, useProductCategoryTree as F, useProductView as G, useProducts as H, type ImageSize as I, useProductsFeed as J, useRemoveCoupon as K, useRemoveFromCart as L, useSelectShippingRate as M, useStore as N, useStoreFeatures as O, PLACEHOLDER_IMAGE_URL as P, useStoreLocale as Q, useStoreTheme as R, type ShippingRate as S, useUpdateCartItem as T, type UseCartViewOptions as U, useUpdateCustomer as V, useWooCommerceClient as W, useWooCommerceQueryKeys as X, type InfiniteQueryOptions as Y, type MutationOptions as Z, type QueryOptions as _, type PaymentMethod as a, type ProcessedCartItem as b, type ProcessedCategory as c, type ProcessedProduct as d, type ProcessedProductDetails as e, type ProductCartState as f, type ProductCategoryTreeNode as g, type UseCartViewReturn as h, type UseProductViewOptions as i, type UseProductViewReturn as j, type UseProductsFeedOptions as k, type UseProductsFeedReturn as l, getAllImageUrls as m, getImageUrl as n, getImageUrlOrPlaceholder as o, getPrimaryImage as p, getSizedImageUrl as q, preloadImage as r, preloadImages as s, useApplyCoupon as t, useAddToCart as u, useCart as v, useCartView as w, useCheckout as x, useInfiniteProducts as y, useOrder as z };
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 };
@@ -8722,4 +8722,35 @@ interface UseCartViewReturn {
8722
8722
  }
8723
8723
  declare function useCartView(options?: UseCartViewOptions): UseCartViewReturn;
8724
8724
 
8725
- export { type AppliedCoupon as A, useProcessCheckout as B, type CartTotals as C, useProduct as D, useProductCategories as E, useProductCategoryTree as F, useProductView as G, useProducts as H, type ImageSize as I, useProductsFeed as J, useRemoveCoupon as K, useRemoveFromCart as L, useSelectShippingRate as M, useStore as N, useStoreFeatures as O, PLACEHOLDER_IMAGE_URL as P, useStoreLocale as Q, useStoreTheme as R, type ShippingRate as S, useUpdateCartItem as T, type UseCartViewOptions as U, useUpdateCustomer as V, useWooCommerceClient as W, useWooCommerceQueryKeys as X, type InfiniteQueryOptions as Y, type MutationOptions as Z, type QueryOptions as _, type PaymentMethod as a, type ProcessedCartItem as b, type ProcessedCategory as c, type ProcessedProduct as d, type ProcessedProductDetails as e, type ProductCartState as f, type ProductCategoryTreeNode as g, type UseCartViewReturn as h, type UseProductViewOptions as i, type UseProductViewReturn as j, type UseProductsFeedOptions as k, type UseProductsFeedReturn as l, getAllImageUrls as m, getImageUrl as n, getImageUrlOrPlaceholder as o, getPrimaryImage as p, getSizedImageUrl as q, preloadImage as r, preloadImages as s, useApplyCoupon as t, useAddToCart as u, useCart as v, useCartView as w, useCheckout as x, useInfiniteProducts as y, useOrder as z };
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
@@ -1646,6 +1646,54 @@ function useCartView(options = {}) {
1646
1646
  isBusy
1647
1647
  };
1648
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
+ }
1649
1697
 
1650
1698
  // src/events/composeHandlers.ts
1651
1699
  function composeHandlers(...handlers) {
@@ -1746,6 +1794,7 @@ exports.getGlobalRateLimiter = getGlobalRateLimiter;
1746
1794
  exports.getImageUrl = getImageUrl;
1747
1795
  exports.getImageUrlOrPlaceholder = getImageUrlOrPlaceholder;
1748
1796
  exports.getMaxAddToCartQuantity = getMaxAddToCartQuantity;
1797
+ exports.getOrderStatusLabel = getOrderStatusLabel;
1749
1798
  exports.getPrimaryImage = getPrimaryImage;
1750
1799
  exports.getSizedImageUrl = getSizedImageUrl;
1751
1800
  exports.getStockSeverity = getStockSeverity;
@@ -1765,6 +1814,7 @@ exports.useCartView = useCartView;
1765
1814
  exports.useCheckout = useCheckout;
1766
1815
  exports.useInfiniteProducts = useInfiniteProducts;
1767
1816
  exports.useOrder = useOrder;
1817
+ exports.useOrderView = useOrderView;
1768
1818
  exports.useProcessCheckout = useProcessCheckout;
1769
1819
  exports.useProduct = useProduct;
1770
1820
  exports.useProductCategories = useProductCategories;