@tapcart/mobile-components 0.15.1 → 0.15.2
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/components/hooks/use-order-details.d.ts.map +1 -1
- package/dist/components/hooks/use-order-details.js +13 -11
- package/dist/components/ui/carousel.js +1 -1
- package/dist/styles.css +3 -0
- package/dist/tests/use-order-details.test.d.ts +2 -0
- package/dist/tests/use-order-details.test.d.ts.map +1 -0
- package/dist/tests/use-order-details.test.js +65 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-order-details.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-order-details.ts"],"names":[],"mappings":"AAKA,KAAK,oBAAoB,GAAG;IAC1B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,OAAO,CAAA;CACf,CAAA;AAED,KAAK,iBAAiB,GAAG;IACvB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAClC,CAAA;AA0LD,eAAO,MAAM,qBAAqB,UACzB,OAAO,MAAM,EAAE,GAAG,CAAC;kBACT,OAAO,MAAM,EAAE,GAAG,CAAC;kBAAgB,OAAO,MAAM,EAAE,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"use-order-details.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-order-details.ts"],"names":[],"mappings":"AAKA,KAAK,oBAAoB,GAAG;IAC1B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,OAAO,CAAA;CACf,CAAA;AAED,KAAK,iBAAiB,GAAG;IACvB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAClC,CAAA;AA0LD,eAAO,MAAM,qBAAqB,UACzB,OAAO,MAAM,EAAE,GAAG,CAAC;kBACT,OAAO,MAAM,EAAE,GAAG,CAAC;kBAAgB,OAAO,MAAM,EAAE,GAAG,CAAC;CAmOxE,CAAA;AAED,wBAAgB,eAAe,CAAC,EAC9B,SAAS,EACT,MAAM,EACN,KAAK,EACL,QAAQ,EACR,OAAO,EACP,IAAY,GACb,EAAE,oBAAoB,GAAG,iBAAiB,CAiE1C"}
|
|
@@ -148,9 +148,12 @@ export const transformOrderDetails = (order) => {
|
|
|
148
148
|
return parseFloat(amount) || 0;
|
|
149
149
|
return 0;
|
|
150
150
|
};
|
|
151
|
+
// Shopify Order Editing sets currentQuantity to 0 for removed/refunded
|
|
152
|
+
// line items — those must not be shown to the customer
|
|
153
|
+
const activeLineItems = (order.lineItems || []).filter((lineItem) => { var _a, _b; return ((_b = (_a = lineItem.currentQuantity) !== null && _a !== void 0 ? _a : lineItem.quantity) !== null && _b !== void 0 ? _b : 1) > 0; });
|
|
151
154
|
// Transform line items to cart lines
|
|
152
|
-
const cartLines =
|
|
153
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
155
|
+
const cartLines = activeLineItems.map((lineItem) => {
|
|
156
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
154
157
|
const variant = lineItem.variant || {};
|
|
155
158
|
const product = variant.product || {};
|
|
156
159
|
return {
|
|
@@ -185,14 +188,13 @@ export const transformOrderDetails = (order) => {
|
|
|
185
188
|
productId: ((_k = variant.product) === null || _k === void 0 ? void 0 : _k.id) || lineItem.productId,
|
|
186
189
|
merchandiseId: variant.id || lineItem.merchandiseId,
|
|
187
190
|
title: lineItem.title || product.title || "Unknown Product",
|
|
188
|
-
quantity: lineItem.quantity
|
|
191
|
+
quantity: (_m = (_l = lineItem.currentQuantity) !== null && _l !== void 0 ? _l : lineItem.quantity) !== null && _m !== void 0 ? _m : 1,
|
|
189
192
|
uniqueId: crypto.randomUUID(),
|
|
190
193
|
vendor: product.vendor || lineItem.vendor || "Unknown",
|
|
191
194
|
compareAtPrice: {
|
|
192
|
-
amount: parseAmount(((
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
((_p = lineItem.compareAtPrice) === null || _p === void 0 ? void 0 : _p.currencyCode) ||
|
|
195
|
+
amount: parseAmount(((_o = lineItem.originalTotalPrice) === null || _o === void 0 ? void 0 : _o.amount) || ((_p = lineItem.compareAtPrice) === null || _p === void 0 ? void 0 : _p.amount)),
|
|
196
|
+
currencyCode: ((_q = lineItem.originalTotalPrice) === null || _q === void 0 ? void 0 : _q.currencyCode) ||
|
|
197
|
+
((_r = lineItem.compareAtPrice) === null || _r === void 0 ? void 0 : _r.currencyCode) ||
|
|
196
198
|
order.currency ||
|
|
197
199
|
"USD",
|
|
198
200
|
},
|
|
@@ -262,8 +264,8 @@ export const transformOrderDetails = (order) => {
|
|
|
262
264
|
value: app.value || { percentage: 0 },
|
|
263
265
|
})),
|
|
264
266
|
subtotalPrice: wrapMoney(subtotal, currencyCode),
|
|
265
|
-
lineItems:
|
|
266
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
267
|
+
lineItems: activeLineItems.map((lineItem) => {
|
|
268
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
267
269
|
const variant = lineItem.variant || {};
|
|
268
270
|
const product = variant.product || {};
|
|
269
271
|
const currencyCode = ((_a = lineItem.discountedTotalPrice) === null || _a === void 0 ? void 0 : _a.currencyCode) ||
|
|
@@ -313,9 +315,9 @@ export const transformOrderDetails = (order) => {
|
|
|
313
315
|
discountApplication: allocation.discountApplication || {},
|
|
314
316
|
});
|
|
315
317
|
}),
|
|
316
|
-
quantity: lineItem.quantity
|
|
318
|
+
quantity: (_t = (_s = lineItem.currentQuantity) !== null && _s !== void 0 ? _s : lineItem.quantity) !== null && _t !== void 0 ? _t : 1,
|
|
317
319
|
title: lineItem.title || product.title,
|
|
318
|
-
id: ((
|
|
320
|
+
id: ((_u = variant.id) === null || _u === void 0 ? void 0 : _u.split("/").pop()) || ((_v = lineItem.variantId) === null || _v === void 0 ? void 0 : _v.split("/").pop()),
|
|
319
321
|
};
|
|
320
322
|
}),
|
|
321
323
|
totalPrice: wrapMoney(total, currencyCode),
|
|
@@ -145,7 +145,7 @@ Carousel.displayName = "Carousel";
|
|
|
145
145
|
const CarouselContent = React.forwardRef((_a, ref) => {
|
|
146
146
|
var { className, showOverflow = false } = _a, props = __rest(_a, ["className", "showOverflow"]);
|
|
147
147
|
const { carouselRef, orientation } = useCarousel();
|
|
148
|
-
return (_jsx("div", Object.assign({ ref: carouselRef, className:
|
|
148
|
+
return (_jsx("div", Object.assign({ ref: carouselRef, className: `touch-pan-y ${showOverflow ? "overflow-visible" : "overflow-hidden"}` }, { children: _jsx("div", Object.assign({ ref: ref, className: cn("flex", orientation === "horizontal" ? "" : "-mt-4 flex-col", className) }, props)) })));
|
|
149
149
|
});
|
|
150
150
|
CarouselContent.displayName = "CarouselContent";
|
|
151
151
|
const CarouselItem = React.forwardRef((_a, ref) => {
|
package/dist/styles.css
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-order-details.test.d.ts","sourceRoot":"","sources":["../../tests/use-order-details.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { transformOrderDetails } from "../components/hooks/use-order-details";
|
|
2
|
+
// jsdom does not implement crypto.randomUUID, which transformOrderDetails
|
|
3
|
+
// uses for line uniqueIds
|
|
4
|
+
beforeAll(() => {
|
|
5
|
+
if (typeof crypto.randomUUID !== "function") {
|
|
6
|
+
Object.defineProperty(crypto, "randomUUID", {
|
|
7
|
+
configurable: true,
|
|
8
|
+
value: () => `00000000-0000-4000-8000-${`${Math.random()}`
|
|
9
|
+
.slice(2, 14)
|
|
10
|
+
.padEnd(12, "0")}`,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
const buildLineItem = (overrides = {}) => (Object.assign({ title: "Pink Palm Pajamas", quantity: 1, variant: {
|
|
15
|
+
id: "gid://shopify/ProductVariant/111",
|
|
16
|
+
title: "Blush Bay / XS",
|
|
17
|
+
price: { amount: "95.23", currencyCode: "USD" },
|
|
18
|
+
product: {
|
|
19
|
+
id: "gid://shopify/Product/11",
|
|
20
|
+
title: "Pink Palm Pajamas",
|
|
21
|
+
vendor: "Pink Palm Puff",
|
|
22
|
+
},
|
|
23
|
+
}, discountedTotalPrice: { amount: "95.23", currencyCode: "USD" }, originalTotalPrice: { amount: "95.23", currencyCode: "USD" } }, overrides));
|
|
24
|
+
const buildOrder = (lineItems) => ({
|
|
25
|
+
id: "gid://shopify/Order/92625831",
|
|
26
|
+
currency: "USD",
|
|
27
|
+
totalAmount: "95.23",
|
|
28
|
+
lineItems,
|
|
29
|
+
});
|
|
30
|
+
describe("transformOrderDetails — Shopify Order Editing (currentQuantity)", () => {
|
|
31
|
+
it("prefers currentQuantity over quantity for edited orders", () => {
|
|
32
|
+
const { orderDetails, checkoutData } = transformOrderDetails(buildOrder([buildLineItem({ quantity: 3, currentQuantity: 2 })]));
|
|
33
|
+
expect(orderDetails.cart.lines).toHaveLength(1);
|
|
34
|
+
expect(orderDetails.cart.lines[0].quantity).toBe(2);
|
|
35
|
+
expect(checkoutData.lineItems[0].quantity).toBe(2);
|
|
36
|
+
});
|
|
37
|
+
it("excludes line items removed via order editing (currentQuantity 0)", () => {
|
|
38
|
+
const { orderDetails, checkoutData } = transformOrderDetails(buildOrder([
|
|
39
|
+
buildLineItem({
|
|
40
|
+
title: "Pink Palm Pajamas",
|
|
41
|
+
quantity: 1,
|
|
42
|
+
currentQuantity: 1,
|
|
43
|
+
}),
|
|
44
|
+
buildLineItem({
|
|
45
|
+
title: "Live in the Moment Hoodie",
|
|
46
|
+
quantity: 1,
|
|
47
|
+
currentQuantity: 0,
|
|
48
|
+
}),
|
|
49
|
+
]));
|
|
50
|
+
expect(orderDetails.cart.lines).toHaveLength(1);
|
|
51
|
+
expect(orderDetails.cart.lines[0].title).toBe("Pink Palm Pajamas");
|
|
52
|
+
expect(checkoutData.lineItems).toHaveLength(1);
|
|
53
|
+
expect(checkoutData.lineItems[0].title).toBe("Pink Palm Pajamas");
|
|
54
|
+
});
|
|
55
|
+
it("falls back to quantity when currentQuantity is absent (unedited orders)", () => {
|
|
56
|
+
const { orderDetails } = transformOrderDetails(buildOrder([buildLineItem({ quantity: 2 })]));
|
|
57
|
+
expect(orderDetails.cart.lines).toHaveLength(1);
|
|
58
|
+
expect(orderDetails.cart.lines[0].quantity).toBe(2);
|
|
59
|
+
});
|
|
60
|
+
it("defaults quantity to 1 when neither field is present", () => {
|
|
61
|
+
const { orderDetails } = transformOrderDetails(buildOrder([buildLineItem({ quantity: undefined })]));
|
|
62
|
+
expect(orderDetails.cart.lines).toHaveLength(1);
|
|
63
|
+
expect(orderDetails.cart.lines[0].quantity).toBe(1);
|
|
64
|
+
});
|
|
65
|
+
});
|