@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
package/dist/hooks/index.cjs
CHANGED
|
@@ -426,10 +426,11 @@ var useProcessCheckout = () => {
|
|
|
426
426
|
mutationKey: queryKeys.checkout.mutations.process(),
|
|
427
427
|
mutationFn: (input) => client.checkout.process(input),
|
|
428
428
|
onSuccess: (checkout) => {
|
|
429
|
+
const cart = queryClient.getQueryData(queryKeys.cart.details()) ?? null;
|
|
429
430
|
queryClient.invalidateQueries({ queryKey: queryKeys.cart.all });
|
|
430
431
|
queryClient.invalidateQueries({ queryKey: queryKeys.checkout.all });
|
|
431
432
|
if (emitEvent) {
|
|
432
|
-
emitEvent(createSuccessEvent("checkout:processed", { checkout }));
|
|
433
|
+
emitEvent(createSuccessEvent("checkout:processed", { checkout, cart }));
|
|
433
434
|
}
|
|
434
435
|
},
|
|
435
436
|
onError: (error) => {
|
|
@@ -1134,8 +1135,57 @@ function useCartView(options = {}) {
|
|
|
1134
1135
|
isBusy
|
|
1135
1136
|
};
|
|
1136
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
|
+
}
|
|
1137
1186
|
|
|
1138
1187
|
exports.createQueryKeys = createQueryKeys;
|
|
1188
|
+
exports.getOrderStatusLabel = getOrderStatusLabel;
|
|
1139
1189
|
exports.useAddToCart = useAddToCart;
|
|
1140
1190
|
exports.useApplyCoupon = useApplyCoupon;
|
|
1141
1191
|
exports.useCart = useCart;
|
|
@@ -1143,6 +1193,7 @@ exports.useCartView = useCartView;
|
|
|
1143
1193
|
exports.useCheckout = useCheckout;
|
|
1144
1194
|
exports.useInfiniteProducts = useInfiniteProducts;
|
|
1145
1195
|
exports.useOrder = useOrder;
|
|
1196
|
+
exports.useOrderView = useOrderView;
|
|
1146
1197
|
exports.useProcessCheckout = useProcessCheckout;
|
|
1147
1198
|
exports.useProduct = useProduct;
|
|
1148
1199
|
exports.useProductCategories = useProductCategories;
|