@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.
- package/dist/hooks/index.cjs +50 -0
- 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 +49 -1
- package/dist/hooks/index.js.map +1 -1
- package/dist/{index-CaNfLsEj.d.cts → index-DdY_1X-C.d.cts} +32 -1
- package/dist/{index-BWIYt7TO.d.ts → index-unbfwba0.d.ts} +32 -1
- package/dist/index.cjs +50 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +49 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/hooks/index.cjs
CHANGED
|
@@ -1135,8 +1135,57 @@ function useCartView(options = {}) {
|
|
|
1135
1135
|
isBusy
|
|
1136
1136
|
};
|
|
1137
1137
|
}
|
|
1138
|
+
var ORDER_STATUS_LABELS = {
|
|
1139
|
+
pending: "Pending Payment",
|
|
1140
|
+
processing: "Processing",
|
|
1141
|
+
"on-hold": "On Hold",
|
|
1142
|
+
completed: "Completed",
|
|
1143
|
+
cancelled: "Cancelled",
|
|
1144
|
+
refunded: "Refunded",
|
|
1145
|
+
failed: "Failed"
|
|
1146
|
+
};
|
|
1147
|
+
function getOrderStatusLabel(status) {
|
|
1148
|
+
return ORDER_STATUS_LABELS[status] ?? status.replace(/[_-]/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
|
|
1149
|
+
}
|
|
1150
|
+
function useOrderView(input, options = {}) {
|
|
1151
|
+
const storeContext = react.useContext(WooCommerceStoreContext);
|
|
1152
|
+
const storeConfig = storeContext?.config;
|
|
1153
|
+
const localeTag = options.localeTag ?? storeConfig?.locale?.localeTag ?? DEFAULT_STORE_CONFIG.locale.localeTag;
|
|
1154
|
+
const { data: rawOrder, isLoading, error } = useOrder(input);
|
|
1155
|
+
const order = react.useMemo(() => {
|
|
1156
|
+
if (!rawOrder) return void 0;
|
|
1157
|
+
const currencyCode = rawOrder.totals.currency_code ?? "USD";
|
|
1158
|
+
const lineItems = rawOrder.items.map((item) => ({
|
|
1159
|
+
id: item.id,
|
|
1160
|
+
name: item.name,
|
|
1161
|
+
quantity: item.quantity,
|
|
1162
|
+
price: formatStoreApiPriceIntl(item.prices.price, currencyCode, localeTag),
|
|
1163
|
+
total: formatStoreApiPriceIntl(item.totals.line_total, currencyCode, localeTag),
|
|
1164
|
+
imageUrl: item.images?.[0]?.src
|
|
1165
|
+
}));
|
|
1166
|
+
const status = rawOrder.status;
|
|
1167
|
+
return {
|
|
1168
|
+
id: rawOrder.id,
|
|
1169
|
+
number: String(rawOrder.id),
|
|
1170
|
+
status,
|
|
1171
|
+
statusLabel: getOrderStatusLabel(status),
|
|
1172
|
+
total: formatStoreApiPriceIntl(rawOrder.totals.total_price, currencyCode, localeTag),
|
|
1173
|
+
itemCount: lineItems.reduce((sum, item) => sum + item.quantity, 0),
|
|
1174
|
+
lineItems,
|
|
1175
|
+
needsPayment: rawOrder.needs_payment,
|
|
1176
|
+
paymentMethod: rawOrder.payment_method ?? "",
|
|
1177
|
+
raw: rawOrder
|
|
1178
|
+
};
|
|
1179
|
+
}, [rawOrder, localeTag]);
|
|
1180
|
+
return {
|
|
1181
|
+
order,
|
|
1182
|
+
isLoading,
|
|
1183
|
+
error
|
|
1184
|
+
};
|
|
1185
|
+
}
|
|
1138
1186
|
|
|
1139
1187
|
exports.createQueryKeys = createQueryKeys;
|
|
1188
|
+
exports.getOrderStatusLabel = getOrderStatusLabel;
|
|
1140
1189
|
exports.useAddToCart = useAddToCart;
|
|
1141
1190
|
exports.useApplyCoupon = useApplyCoupon;
|
|
1142
1191
|
exports.useCart = useCart;
|
|
@@ -1144,6 +1193,7 @@ exports.useCartView = useCartView;
|
|
|
1144
1193
|
exports.useCheckout = useCheckout;
|
|
1145
1194
|
exports.useInfiniteProducts = useInfiniteProducts;
|
|
1146
1195
|
exports.useOrder = useOrder;
|
|
1196
|
+
exports.useOrderView = useOrderView;
|
|
1147
1197
|
exports.useProcessCheckout = useProcessCheckout;
|
|
1148
1198
|
exports.useProduct = useProduct;
|
|
1149
1199
|
exports.useProductCategories = useProductCategories;
|