@tapcart/mobile-components 0.8.61 → 0.8.63
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-mock-cart.js +1 -1
- package/dist/components/hooks/use-order-details.d.ts +4 -0
- package/dist/components/hooks/use-order-details.d.ts.map +1 -1
- package/dist/components/hooks/use-order-details.js +192 -8
- package/dist/components/hooks/use-products.d.ts.map +1 -1
- package/dist/components/hooks/use-products.js +20 -21
- package/dist/components/libs/cache/ProductsLocalStorage.d.ts +1 -0
- package/dist/components/libs/cache/ProductsLocalStorage.d.ts.map +1 -1
- package/dist/components/libs/cache/ProductsLocalStorage.js +33 -5
- package/dist/components/ui/button.js +4 -3
- package/dist/components/ui/chip.d.ts +2 -0
- package/dist/components/ui/chip.d.ts.map +1 -1
- package/dist/components/ui/chip.js +11 -6
- package/dist/components/ui/quantity-pickerNEW.d.ts +1 -0
- package/dist/components/ui/quantity-pickerNEW.d.ts.map +1 -1
- package/dist/components/ui/quantity-pickerNEW.js +32 -40
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +2 -1
- package/dist/lib/variablesCart.util.d.ts.map +1 -1
- package/dist/lib/variablesCart.util.js +18 -8
- package/dist/lib/variablesCart.util.test.js +24 -0
- package/dist/styles.css +48 -0
- package/package.json +1 -1
|
@@ -359,7 +359,7 @@ const transformCart = ({ products, cartOrigin = cartMock, }) => {
|
|
|
359
359
|
totalDutyAmount: null,
|
|
360
360
|
} });
|
|
361
361
|
};
|
|
362
|
-
export const useMockCart = ({ apiUrl, appId, enabled = true, limit =
|
|
362
|
+
export const useMockCart = ({ apiUrl, appId, enabled = true, limit = 4, }) => {
|
|
363
363
|
const [isLoading, setIsLoading] = useState(true);
|
|
364
364
|
const [initialLoadHappened, setInitialLoadHappened] = useState(false);
|
|
365
365
|
const { products, error: productsError, isRefreshing: productsLoading, } = useProducts({
|
|
@@ -9,6 +9,10 @@ type UseOrderDetailsProps = {
|
|
|
9
9
|
type UseProductsReturn = {
|
|
10
10
|
orderDetails: Record<string, any>;
|
|
11
11
|
};
|
|
12
|
+
export declare const transformOrderDetails: (order: Record<string, any>) => {
|
|
13
|
+
orderDetails: Record<string, any>;
|
|
14
|
+
checkoutData: Record<string, any>;
|
|
15
|
+
};
|
|
12
16
|
export declare function useOrderDetails({ variables, apiUrl, appId, language, country, mock, }: UseOrderDetailsProps): UseProductsReturn;
|
|
13
17
|
export {};
|
|
14
18
|
//# sourceMappingURL=use-order-details.d.ts.map
|
|
@@ -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;
|
|
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;AAwLD,eAAO,MAAM,qBAAqB,UACzB,OAAO,MAAM,EAAE,GAAG,CAAC;kBACT,OAAO,MAAM,EAAE,GAAG,CAAC;kBAAgB,OAAO,MAAM,EAAE,GAAG,CAAC;CAuNxE,CAAA;AAED,wBAAgB,eAAe,CAAC,EAC9B,SAAS,EACT,MAAM,EACN,KAAK,EACL,QAAQ,EACR,OAAO,EACP,IAAY,GACb,EAAE,oBAAoB,GAAG,iBAAiB,CA4D1C"}
|
|
@@ -135,10 +135,189 @@ const updateLineDetails = (line, product) => {
|
|
|
135
135
|
line.sellingPlan = (_k = (_j = product.sellingPlanAllocation) === null || _j === void 0 ? void 0 : _j.sellingPlan) === null || _k === void 0 ? void 0 : _k.name;
|
|
136
136
|
line.variantName = (_l = product.variant) === null || _l === void 0 ? void 0 : _l.title;
|
|
137
137
|
};
|
|
138
|
+
export const transformOrderDetails = (order) => {
|
|
139
|
+
var _a;
|
|
140
|
+
// Helper function to safely parse amounts
|
|
141
|
+
const parseAmount = (amount) => {
|
|
142
|
+
if (typeof amount === "number")
|
|
143
|
+
return amount;
|
|
144
|
+
if (typeof amount === "string")
|
|
145
|
+
return parseFloat(amount) || 0;
|
|
146
|
+
return 0;
|
|
147
|
+
};
|
|
148
|
+
// Transform line items to cart lines
|
|
149
|
+
const cartLines = (order.lineItems || []).map((lineItem) => {
|
|
150
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
151
|
+
const variant = lineItem.variant || {};
|
|
152
|
+
const product = variant.product || {};
|
|
153
|
+
return {
|
|
154
|
+
image: {
|
|
155
|
+
lg: ((_a = variant.image) === null || _a === void 0 ? void 0 : _a.url) || ((_b = lineItem.image) === null || _b === void 0 ? void 0 : _b.url),
|
|
156
|
+
altText: ((_c = variant.image) === null || _c === void 0 ? void 0 : _c.altText) || ((_d = lineItem.image) === null || _d === void 0 ? void 0 : _d.altText),
|
|
157
|
+
},
|
|
158
|
+
discounts: (lineItem.discountAllocations || []).map((allocation) => {
|
|
159
|
+
var _a, _b, _c, _d, _e;
|
|
160
|
+
return ({
|
|
161
|
+
amount: allocation.allocatedAmount || {
|
|
162
|
+
amount: 0,
|
|
163
|
+
currencyCode: ((_a = lineItem.originalTotalPrice) === null || _a === void 0 ? void 0 : _a.currencyCode) ||
|
|
164
|
+
order.currency ||
|
|
165
|
+
"USD",
|
|
166
|
+
},
|
|
167
|
+
title: ((_b = allocation.discountApplication) === null || _b === void 0 ? void 0 : _b.title) || "Discount",
|
|
168
|
+
value: ((_d = (_c = allocation.discountApplication) === null || _c === void 0 ? void 0 : _c.value) === null || _d === void 0 ? void 0 : _d.percentage) || 0,
|
|
169
|
+
valueType: "percentage",
|
|
170
|
+
applicationType: (((_e = allocation.discountApplication) === null || _e === void 0 ? void 0 : _e.type) || "automatic").toLowerCase(),
|
|
171
|
+
});
|
|
172
|
+
}),
|
|
173
|
+
price: {
|
|
174
|
+
amount: parseAmount(((_e = lineItem.discountedTotalPrice) === null || _e === void 0 ? void 0 : _e.amount) ||
|
|
175
|
+
((_f = lineItem.finalLinePrice) === null || _f === void 0 ? void 0 : _f.amount)),
|
|
176
|
+
currencyCode: ((_g = lineItem.discountedTotalPrice) === null || _g === void 0 ? void 0 : _g.currencyCode) ||
|
|
177
|
+
((_h = lineItem.finalLinePrice) === null || _h === void 0 ? void 0 : _h.currencyCode) ||
|
|
178
|
+
((_j = lineItem.originalTotalPrice) === null || _j === void 0 ? void 0 : _j.currencyCode) ||
|
|
179
|
+
order.currency ||
|
|
180
|
+
"USD",
|
|
181
|
+
},
|
|
182
|
+
productId: ((_k = variant.product) === null || _k === void 0 ? void 0 : _k.id) || lineItem.productId,
|
|
183
|
+
merchandiseId: variant.id || lineItem.merchandiseId,
|
|
184
|
+
title: lineItem.title || product.title || "Unknown Product",
|
|
185
|
+
quantity: lineItem.quantity || 1,
|
|
186
|
+
uniqueId: crypto.randomUUID(),
|
|
187
|
+
vendor: product.vendor || lineItem.vendor || "Unknown",
|
|
188
|
+
compareAtPrice: {
|
|
189
|
+
amount: parseAmount(((_l = lineItem.originalTotalPrice) === null || _l === void 0 ? void 0 : _l.amount) ||
|
|
190
|
+
((_m = lineItem.compareAtPrice) === null || _m === void 0 ? void 0 : _m.amount)),
|
|
191
|
+
currencyCode: ((_o = lineItem.originalTotalPrice) === null || _o === void 0 ? void 0 : _o.currencyCode) ||
|
|
192
|
+
((_p = lineItem.compareAtPrice) === null || _p === void 0 ? void 0 : _p.currencyCode) ||
|
|
193
|
+
order.currency ||
|
|
194
|
+
"USD",
|
|
195
|
+
},
|
|
196
|
+
variantName: variant.title || lineItem.variantTitle || "Default",
|
|
197
|
+
};
|
|
198
|
+
});
|
|
199
|
+
const orderDetails = {
|
|
200
|
+
paymentMethods: [
|
|
201
|
+
{
|
|
202
|
+
type: "direct",
|
|
203
|
+
details: {
|
|
204
|
+
lastFourDigits: "****",
|
|
205
|
+
brand: "PAYMENT",
|
|
206
|
+
currency: order.currency || order.currencyCode || "USD",
|
|
207
|
+
amount: order.totalAmount || ((_a = order.totalPrice) === null || _a === void 0 ? void 0 : _a.amount) || "0",
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
],
|
|
211
|
+
cart: {
|
|
212
|
+
token: order.id || order.token,
|
|
213
|
+
lines: cartLines,
|
|
214
|
+
price: {
|
|
215
|
+
subtotal: order.subtotalAmount ||
|
|
216
|
+
order.subtotalPrice ||
|
|
217
|
+
order.currentSubtotalPrice,
|
|
218
|
+
orderLevelDiscounts: [],
|
|
219
|
+
shippingLevelDiscounts: [],
|
|
220
|
+
total: order.totalAmount || order.totalPrice || order.currentTotalPrice,
|
|
221
|
+
taxes: order.taxAmount || order.totalTax || order.currentTotalTax,
|
|
222
|
+
shipping: order.shippingAmount ||
|
|
223
|
+
order.totalShippingPrice ||
|
|
224
|
+
order.currentTotalShippingPrice,
|
|
225
|
+
oldShipping: order.shippingAmount ||
|
|
226
|
+
order.totalShippingPrice ||
|
|
227
|
+
order.currentTotalShippingPrice,
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
id: order.id,
|
|
231
|
+
};
|
|
232
|
+
// Helper to wrap price fields as { amount, currencyCode }
|
|
233
|
+
const wrapMoney = (amount, currencyCode) => ({
|
|
234
|
+
amount: typeof amount === "string" ? parseFloat(amount) : amount !== null && amount !== void 0 ? amount : 0,
|
|
235
|
+
currencyCode: currencyCode || order.currency || order.currencyCode || "USD",
|
|
236
|
+
});
|
|
237
|
+
// Transform checkout data (minimal for price/line updates)
|
|
238
|
+
const subtotal = order.subtotalAmount || order.subtotalPrice || order.currentSubtotalPrice;
|
|
239
|
+
const total = order.totalAmount || order.totalPrice || order.currentTotalPrice;
|
|
240
|
+
const taxes = order.taxAmount || order.totalTax || order.currentTotalTax;
|
|
241
|
+
const shipping = order.shippingAmount ||
|
|
242
|
+
order.totalShippingPrice ||
|
|
243
|
+
order.currentTotalShippingPrice;
|
|
244
|
+
const currencyCode = order.currency || order.currencyCode || "USD";
|
|
245
|
+
const checkoutData = {
|
|
246
|
+
shippingLine: {
|
|
247
|
+
price: wrapMoney(shipping, currencyCode),
|
|
248
|
+
},
|
|
249
|
+
discountApplications: (order.discountApplications || []).map((app) => ({
|
|
250
|
+
type: app.type || "AUTOMATIC",
|
|
251
|
+
title: app.title || "Discount",
|
|
252
|
+
allocationMethod: app.allocationMethod || "ACROSS",
|
|
253
|
+
targetType: app.targetType || "LINE_ITEM",
|
|
254
|
+
targetSelection: app.targetSelection || "ALL",
|
|
255
|
+
value: app.value || { percentage: 0 },
|
|
256
|
+
})),
|
|
257
|
+
subtotalPrice: wrapMoney(subtotal, currencyCode),
|
|
258
|
+
lineItems: (order.lineItems || []).map((lineItem) => {
|
|
259
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
260
|
+
const variant = lineItem.variant || {};
|
|
261
|
+
const product = variant.product || {};
|
|
262
|
+
const currencyCode = ((_a = lineItem.discountedTotalPrice) === null || _a === void 0 ? void 0 : _a.currencyCode) ||
|
|
263
|
+
((_b = lineItem.originalTotalPrice) === null || _b === void 0 ? void 0 : _b.currencyCode) ||
|
|
264
|
+
order.currency ||
|
|
265
|
+
order.currencyCode ||
|
|
266
|
+
"USD";
|
|
267
|
+
// Calculate finalLinePrice with full-discount logic
|
|
268
|
+
let finalLinePriceAmount = parseAmount((_d = (_c = lineItem.discountedTotalPrice) === null || _c === void 0 ? void 0 : _c.amount) !== null && _d !== void 0 ? _d : (_e = lineItem.finalLinePrice) === null || _e === void 0 ? void 0 : _e.amount);
|
|
269
|
+
if (Array.isArray(lineItem.discountAllocations) &&
|
|
270
|
+
lineItem.discountAllocations.length > 0) {
|
|
271
|
+
const totalDiscount = lineItem.discountAllocations.reduce((sum, discount) => { var _a; return sum + parseAmount((_a = discount.allocatedAmount) === null || _a === void 0 ? void 0 : _a.amount); }, 0);
|
|
272
|
+
const original = parseAmount((_f = lineItem.originalTotalPrice) === null || _f === void 0 ? void 0 : _f.amount);
|
|
273
|
+
if (totalDiscount >= original && original > 0) {
|
|
274
|
+
finalLinePriceAmount = 0;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return {
|
|
278
|
+
properties: lineItem.customAttributes || lineItem.properties || [],
|
|
279
|
+
finalLinePrice: wrapMoney(finalLinePriceAmount, currencyCode),
|
|
280
|
+
variant: {
|
|
281
|
+
title: variant.title || lineItem.variantTitle,
|
|
282
|
+
untranslatedTitle: variant.title || lineItem.variantTitle,
|
|
283
|
+
product: {
|
|
284
|
+
type: product.type || "",
|
|
285
|
+
vendor: product.vendor || lineItem.vendor || "Unknown",
|
|
286
|
+
id: ((_g = product.id) === null || _g === void 0 ? void 0 : _g.split("/").pop()) ||
|
|
287
|
+
((_h = lineItem.productId) === null || _h === void 0 ? void 0 : _h.split("/").pop()),
|
|
288
|
+
untranslatedTitle: lineItem.title || product.title,
|
|
289
|
+
title: lineItem.title || product.title,
|
|
290
|
+
url: `/products/${product.handle || ""}`,
|
|
291
|
+
},
|
|
292
|
+
id: ((_j = variant.id) === null || _j === void 0 ? void 0 : _j.split("/").pop()) ||
|
|
293
|
+
((_k = lineItem.variantId) === null || _k === void 0 ? void 0 : _k.split("/").pop()),
|
|
294
|
+
price: wrapMoney(((_l = variant.price) === null || _l === void 0 ? void 0 : _l.amount) || ((_m = lineItem.price) === null || _m === void 0 ? void 0 : _m.amount), currencyCode),
|
|
295
|
+
image: {
|
|
296
|
+
src: ((_o = variant.image) === null || _o === void 0 ? void 0 : _o.url) || ((_p = lineItem.image) === null || _p === void 0 ? void 0 : _p.url),
|
|
297
|
+
},
|
|
298
|
+
},
|
|
299
|
+
discountAllocations: (lineItem.discountAllocations || []).map((allocation) => {
|
|
300
|
+
var _a, _b;
|
|
301
|
+
return ({
|
|
302
|
+
amount: wrapMoney((_a = allocation.allocatedAmount) === null || _a === void 0 ? void 0 : _a.amount, ((_b = allocation.allocatedAmount) === null || _b === void 0 ? void 0 : _b.currencyCode) || currencyCode),
|
|
303
|
+
discountApplication: allocation.discountApplication || {},
|
|
304
|
+
});
|
|
305
|
+
}),
|
|
306
|
+
quantity: lineItem.quantity || 1,
|
|
307
|
+
title: lineItem.title || product.title,
|
|
308
|
+
id: ((_q = variant.id) === null || _q === void 0 ? void 0 : _q.split("/").pop()) || ((_r = lineItem.variantId) === null || _r === void 0 ? void 0 : _r.split("/").pop()),
|
|
309
|
+
};
|
|
310
|
+
}),
|
|
311
|
+
totalPrice: wrapMoney(total, currencyCode),
|
|
312
|
+
totalTax: wrapMoney(taxes, currencyCode),
|
|
313
|
+
};
|
|
314
|
+
return { orderDetails, checkoutData };
|
|
315
|
+
};
|
|
138
316
|
export function useOrderDetails({ variables, apiUrl, appId, language, country, mock = false, }) {
|
|
139
317
|
const [orderDetails, setOrderDetails] = useState({});
|
|
318
|
+
const orderVariables = useMemo(() => (variables === null || variables === void 0 ? void 0 : variables.order) ? transformOrderDetails(variables.order) : variables, [variables]);
|
|
140
319
|
const { products } = useProducts({
|
|
141
|
-
productIds: useMemo(() => { var _a, _b; return
|
|
320
|
+
productIds: useMemo(() => { var _a, _b; return !mock ? getProductIds((_b = (_a = orderVariables === null || orderVariables === void 0 ? void 0 : orderVariables.orderDetails) === null || _a === void 0 ? void 0 : _a.cart) === null || _b === void 0 ? void 0 : _b.lines) : []; }, [mock, orderVariables]),
|
|
142
321
|
productHandles: [],
|
|
143
322
|
baseURL: apiUrl,
|
|
144
323
|
queryVariables: {
|
|
@@ -151,23 +330,28 @@ export function useOrderDetails({ variables, apiUrl, appId, language, country, m
|
|
|
151
330
|
useEffect(() => {
|
|
152
331
|
var _a, _b;
|
|
153
332
|
if (products.length > 0) {
|
|
154
|
-
const updatedOrderDetails = Object.assign({},
|
|
333
|
+
const updatedOrderDetails = Object.assign({}, orderVariables === null || orderVariables === void 0 ? void 0 : orderVariables.orderDetails);
|
|
155
334
|
if (mock) {
|
|
156
335
|
updateOrderDetails(updatedOrderDetails, products);
|
|
157
336
|
}
|
|
158
337
|
else {
|
|
159
338
|
(_b = (_a = updatedOrderDetails === null || updatedOrderDetails === void 0 ? void 0 : updatedOrderDetails.cart) === null || _a === void 0 ? void 0 : _a.lines) === null || _b === void 0 ? void 0 : _b.forEach((line, index) => {
|
|
160
|
-
if (
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
updateLineDetails(line,
|
|
339
|
+
if (orderVariables.checkoutData &&
|
|
340
|
+
orderVariables.checkoutData.lineItems &&
|
|
341
|
+
orderVariables.checkoutData.lineItems.length > 0) {
|
|
342
|
+
updateLineDetails(line, orderVariables.checkoutData.lineItems[index]);
|
|
164
343
|
}
|
|
165
344
|
});
|
|
166
|
-
updateCartPriceDetails(updatedOrderDetails,
|
|
345
|
+
updateCartPriceDetails(updatedOrderDetails, orderVariables.checkoutData);
|
|
167
346
|
}
|
|
168
347
|
setOrderDetails(updatedOrderDetails);
|
|
169
348
|
}
|
|
170
|
-
}, [
|
|
349
|
+
}, [
|
|
350
|
+
products,
|
|
351
|
+
mock,
|
|
352
|
+
orderVariables === null || orderVariables === void 0 ? void 0 : orderVariables.orderDetails,
|
|
353
|
+
orderVariables === null || orderVariables === void 0 ? void 0 : orderVariables.checkoutData,
|
|
354
|
+
]);
|
|
171
355
|
return {
|
|
172
356
|
orderDetails,
|
|
173
357
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-products.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-products.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"use-products.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-products.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAK1C,KAAK,GAAG,GAAG,MAAM,CAAA;AACjB,KAAK,cAAc,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAA;AACxD,KAAK,gBAAgB,GAAG;IACtB,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;IACjC,cAAc,EAAE,MAAM,EAAE,CAAA;IACxB,OAAO,EAAE,GAAG,CAAA;IACZ,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACpC,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;IAC1E,UAAU,CAAC,EAAE,cAAc,EAAE,CAAA;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC,CAAA;AACD,KAAK,iBAAiB,GAAG;IACvB,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,KAAK,EAAE,GAAG,CAAA;IACV,SAAS,EAAE,OAAO,CAAA;IAClB,YAAY,EAAE,OAAO,CAAA;IACrB,YAAY,EAAE,CAAC,OAAO,EAAE,OAAO,KAC3B;QACE,EAAE,EAAE,MAAM,CAAA;QACV,MAAM,EAAE,MAAM,CAAA;KACf,GACD,SAAS,CAAA;CACd,CAAA;AAgCD,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI,GAAG,iBAAiB,CA8I7E"}
|
|
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
import useSWR from "swr";
|
|
12
12
|
import { getProductGidsFromIds, getVariantGidsFromIds } from "../../lib/utils";
|
|
13
|
-
import { useCollection } from "./use-collection";
|
|
14
13
|
import React from "react";
|
|
15
14
|
import ProductsLocalStorage from "../libs/cache/ProductsLocalStorage";
|
|
16
15
|
const isUseProductsProps = (props) => {
|
|
@@ -31,28 +30,21 @@ const formatProductData = ({ data, onlyAvailableProducts = false, }) => {
|
|
|
31
30
|
};
|
|
32
31
|
const productsLocalStorage = new ProductsLocalStorage();
|
|
33
32
|
export function useProducts(props) {
|
|
34
|
-
var _a
|
|
33
|
+
var _a;
|
|
35
34
|
let url = null;
|
|
36
35
|
let body = null;
|
|
37
36
|
const shouldMockProducts = Boolean(props === null || props === void 0 ? void 0 : props.mock);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
appId: ((_a = props === null || props === void 0 ? void 0 : props.queryVariables) === null || _a === void 0 ? void 0 : _a.appId) || "",
|
|
41
|
-
language: ((_b = props === null || props === void 0 ? void 0 : props.queryVariables) === null || _b === void 0 ? void 0 : _b.language) || "en",
|
|
42
|
-
collectionId: undefined,
|
|
43
|
-
getCollections: shouldMockProducts,
|
|
44
|
-
limit: 1,
|
|
45
|
-
});
|
|
46
|
-
const [cachedProducts, setCachedProducts] = React.useState(productsLocalStorage.getCacheItems({
|
|
37
|
+
// No collection logic needed for mock mode - we use direct product fetching
|
|
38
|
+
const [productResponse, setProductResponse] = React.useState(() => productsLocalStorage.getCacheItems({
|
|
47
39
|
productIds: props === null || props === void 0 ? void 0 : props.productIds,
|
|
48
40
|
productHandles: props === null || props === void 0 ? void 0 : props.productHandles,
|
|
49
41
|
}));
|
|
50
42
|
if (isUseProductsProps(props)) {
|
|
51
43
|
let { baseURL, productIds, variantIds, productHandles, metafields, collection, queryVariables, } = props;
|
|
52
44
|
if (shouldMockProducts) {
|
|
53
|
-
|
|
54
|
-
queryVariables = Object.assign(
|
|
55
|
-
collection
|
|
45
|
+
// In mock mode, always use direct product fetching without collections
|
|
46
|
+
queryVariables = Object.assign({}, queryVariables);
|
|
47
|
+
// Don't set collection to enable direct product fetching
|
|
56
48
|
}
|
|
57
49
|
let queryParams = new URLSearchParams();
|
|
58
50
|
if ((productIds === null || productIds === void 0 ? void 0 : productIds.length) > 0) {
|
|
@@ -79,9 +71,18 @@ export function useProducts(props) {
|
|
|
79
71
|
if (queryVariables === null || queryVariables === void 0 ? void 0 : queryVariables.language) {
|
|
80
72
|
queryParams.set("language", queryVariables.language);
|
|
81
73
|
}
|
|
82
|
-
queryParams.set("mediaLimit", (
|
|
74
|
+
queryParams.set("mediaLimit", (_a = queryVariables === null || queryVariables === void 0 ? void 0 : queryVariables.mediaLimit) !== null && _a !== void 0 ? _a : 10);
|
|
83
75
|
url = `${baseURL}/products/by-ids?${queryParams.toString()}`;
|
|
84
76
|
}
|
|
77
|
+
// Handle collection-free product fetching when in mock mode
|
|
78
|
+
if (shouldMockProducts &&
|
|
79
|
+
!collection &&
|
|
80
|
+
!(productIds === null || productIds === void 0 ? void 0 : productIds.length) &&
|
|
81
|
+
!(productHandles === null || productHandles === void 0 ? void 0 : productHandles.length) &&
|
|
82
|
+
!(variantIds === null || variantIds === void 0 ? void 0 : variantIds.length)) {
|
|
83
|
+
url = `${baseURL}/products/by-page?${queryParams.toString()}`;
|
|
84
|
+
body = queryVariables || {};
|
|
85
|
+
}
|
|
85
86
|
}
|
|
86
87
|
const defaultFetcher = (url, body) => fetch(url, {
|
|
87
88
|
method: body ? "POST" : "GET",
|
|
@@ -110,23 +111,21 @@ export function useProducts(props) {
|
|
|
110
111
|
};
|
|
111
112
|
// set local state when when SWR data is updated
|
|
112
113
|
React.useEffect(() => {
|
|
113
|
-
if (!data)
|
|
114
|
-
setCachedProducts([]);
|
|
114
|
+
if (!data)
|
|
115
115
|
return;
|
|
116
|
-
}
|
|
117
116
|
// Determine the products array from data
|
|
118
117
|
const productsArray = Array.isArray(data) ? data : data.products || [];
|
|
119
118
|
if (!productsArray.length)
|
|
120
119
|
return;
|
|
121
|
-
|
|
120
|
+
setProductResponse(productsArray);
|
|
122
121
|
}, [data]);
|
|
123
122
|
return {
|
|
124
123
|
products: formatProductData({
|
|
125
|
-
data:
|
|
124
|
+
data: productResponse,
|
|
126
125
|
onlyAvailableProducts: (props === null || props === void 0 ? void 0 : props.mock) && (props === null || props === void 0 ? void 0 : props.onlyAvailableProducts),
|
|
127
126
|
}),
|
|
128
127
|
error,
|
|
129
|
-
isLoading: !
|
|
128
|
+
isLoading: !productResponse.length && isLoading,
|
|
130
129
|
isRefreshing: isLoading,
|
|
131
130
|
cacheProduct,
|
|
132
131
|
};
|
|
@@ -36,6 +36,7 @@ export default class ProductsLocalStorage extends AppStudioCache {
|
|
|
36
36
|
} | undefined)[];
|
|
37
37
|
expireCacheData(numNewItems?: number): void;
|
|
38
38
|
clearCache(): void;
|
|
39
|
+
isQuotaExceeded(e: any): any;
|
|
39
40
|
}
|
|
40
41
|
export {};
|
|
41
42
|
//# sourceMappingURL=ProductsLocalStorage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProductsLocalStorage.d.ts","sourceRoot":"","sources":["../../../../components/libs/cache/ProductsLocalStorage.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAA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GAAG;CASvB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import AppStudioCache from "./AppStudioCache";
|
|
2
|
+
import { getProductGidsFromIds } from "../../../lib/utils";
|
|
2
3
|
export default class ProductsLocalStorage extends AppStudioCache {
|
|
3
4
|
getIdCacheKey(id) {
|
|
4
5
|
return `${this.cachePrefix}-data-${id}`;
|
|
@@ -31,8 +32,11 @@ export default class ProductsLocalStorage extends AppStudioCache {
|
|
|
31
32
|
getCacheItem({ id, handle, }) {
|
|
32
33
|
if (!(id === null || id === void 0 ? void 0 : id.length) && !(handle === null || handle === void 0 ? void 0 : handle.length))
|
|
33
34
|
return null;
|
|
34
|
-
let objectId =
|
|
35
|
-
if (
|
|
35
|
+
let objectId = null;
|
|
36
|
+
if (id === null || id === void 0 ? void 0 : id.length) {
|
|
37
|
+
objectId = getProductGidsFromIds([id])[0];
|
|
38
|
+
}
|
|
39
|
+
else if (handle === null || handle === void 0 ? void 0 : handle.length) {
|
|
36
40
|
objectId = localStorage.getItem(this.getHandleCacheKey(handle));
|
|
37
41
|
}
|
|
38
42
|
if (!(objectId === null || objectId === void 0 ? void 0 : objectId.length))
|
|
@@ -45,7 +49,7 @@ export default class ProductsLocalStorage extends AppStudioCache {
|
|
|
45
49
|
getCacheItems(products) {
|
|
46
50
|
var _a, _b;
|
|
47
51
|
const returnProducts = ((_a = products === null || products === void 0 ? void 0 : products.productIds) === null || _a === void 0 ? void 0 : _a.length)
|
|
48
|
-
? products.productIds.map((id) => this.getCacheItem({ id }))
|
|
52
|
+
? products.productIds.map((id) => this.getCacheItem({ id: getProductGidsFromIds([id])[0] }))
|
|
49
53
|
: ((_b = products === null || products === void 0 ? void 0 : products.productHandles) === null || _b === void 0 ? void 0 : _b.length)
|
|
50
54
|
? products.productHandles.map((handle) => this.getCacheItem({ handle }))
|
|
51
55
|
: [];
|
|
@@ -74,8 +78,25 @@ export default class ProductsLocalStorage extends AppStudioCache {
|
|
|
74
78
|
return Object.assign(Object.assign({}, merged), { [key]: value });
|
|
75
79
|
}, cachedProduct);
|
|
76
80
|
}
|
|
77
|
-
|
|
78
|
-
|
|
81
|
+
try {
|
|
82
|
+
localStorage.setItem(this.getIdCacheKey(productToCache.id), JSON.stringify(Object.assign(Object.assign({}, productToCache), { ct: Date.now() })));
|
|
83
|
+
localStorage.setItem(this.getHandleCacheKey(productToCache.handle), productToCache.id);
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
if (this.isQuotaExceeded(err)) {
|
|
87
|
+
this.expireCacheData(10);
|
|
88
|
+
try {
|
|
89
|
+
localStorage.setItem(this.getIdCacheKey(productToCache.id), JSON.stringify(Object.assign(Object.assign({}, productToCache), { ct: Date.now() })));
|
|
90
|
+
localStorage.setItem(this.getHandleCacheKey(productToCache.handle), productToCache.id);
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
console.warn("ProductsLocalStorage: quota exceeded, item not cached", err);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
console.error("ProductsLocalStorage: error setting cache item", err);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
79
100
|
return productToCache;
|
|
80
101
|
}
|
|
81
102
|
setCacheItems(items) {
|
|
@@ -102,4 +123,11 @@ export default class ProductsLocalStorage extends AppStudioCache {
|
|
|
102
123
|
localStorage.removeItem(this.getHandleCacheKey(item.handle));
|
|
103
124
|
});
|
|
104
125
|
}
|
|
126
|
+
isQuotaExceeded(e) {
|
|
127
|
+
return (e &&
|
|
128
|
+
(e.code === 22 ||
|
|
129
|
+
e.code === 1014 ||
|
|
130
|
+
e.name === "QuotaExceededError" ||
|
|
131
|
+
e.name === "NS_ERROR_DOM_QUOTA_REACHED"));
|
|
132
|
+
}
|
|
105
133
|
}
|
|
@@ -83,7 +83,7 @@ const labelVariants = cva("truncate", {
|
|
|
83
83
|
});
|
|
84
84
|
const Button = (_a) => {
|
|
85
85
|
var { className, labelClassName, labelStyle, variant, size, asChild = false, loading, icon, iconColor, iconStrokeColor, iconPosition, iconSize, iconUrl, iconClassName, onClick, type, disableHaptic = false } = _a, props = __rest(_a, ["className", "labelClassName", "labelStyle", "variant", "size", "asChild", "loading", "icon", "iconColor", "iconStrokeColor", "iconPosition", "iconSize", "iconUrl", "iconClassName", "onClick", "type", "disableHaptic"]);
|
|
86
|
-
const
|
|
86
|
+
const webbridgeActions = useActions();
|
|
87
87
|
const Comp = asChild
|
|
88
88
|
? Slot
|
|
89
89
|
: (onClick || type ? "button" : "div");
|
|
@@ -96,11 +96,12 @@ const Button = (_a) => {
|
|
|
96
96
|
const LoadingButton = () => (_jsx("div", Object.assign({ className: cn("flex items-center justify-center", size === "icon" ? "h-5" : "h-6") }, { children: _jsx(Icon, { className: cn(iconVariants({ variant }), "h-5 w-5 animate-spin"), name: "loader", style: { color: iconColor } }) })));
|
|
97
97
|
const handleClick = Comp === "button" && onClick
|
|
98
98
|
? (e) => {
|
|
99
|
+
var _a;
|
|
99
100
|
try {
|
|
100
|
-
onClick(e);
|
|
101
101
|
if (!disableHaptic) {
|
|
102
|
-
action("trigger/haptic");
|
|
102
|
+
(_a = webbridgeActions.action) === null || _a === void 0 ? void 0 : _a.call(webbridgeActions, "trigger/haptic");
|
|
103
103
|
}
|
|
104
|
+
onClick(e);
|
|
104
105
|
}
|
|
105
106
|
catch (error) {
|
|
106
107
|
console.error(error);
|
|
@@ -10,6 +10,7 @@ type ChipProps = React.ComponentPropsWithoutRef<"div"> & VariantProps<typeof chi
|
|
|
10
10
|
iconColor?: string;
|
|
11
11
|
iconPosition?: "left" | "right";
|
|
12
12
|
iconUrl?: string;
|
|
13
|
+
readOnly?: boolean;
|
|
13
14
|
onChipClick?: () => void;
|
|
14
15
|
onIconClick?: () => void;
|
|
15
16
|
loading?: boolean;
|
|
@@ -23,6 +24,7 @@ declare const Chip: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps
|
|
|
23
24
|
iconColor?: string | undefined;
|
|
24
25
|
iconPosition?: "left" | "right" | undefined;
|
|
25
26
|
iconUrl?: string | undefined;
|
|
27
|
+
readOnly?: boolean | undefined;
|
|
26
28
|
onChipClick?: (() => void) | undefined;
|
|
27
29
|
onIconClick?: (() => void) | undefined;
|
|
28
30
|
loading?: boolean | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chip.d.ts","sourceRoot":"","sources":["../../../components/ui/chip.tsx"],"names":[],"mappings":"AACA,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAEjE,OAAO,KAAsC,MAAM,OAAO,CAAA;AAI1D,QAAA,MAAM,YAAY;;;;mFAwBjB,CAAA;AAED,KAAK,SAAS,GAAG,KAAK,CAAC,wBAAwB,CAAC,KAAK,CAAC,GACpD,YAAY,CAAC,OAAO,YAAY,CAAC,GAAG;IAClC,IAAI,CAAC,EAAE,KAAK,CAAC,WAAW,CAAA;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,IAAI,CAAA;IACxB,WAAW,CAAC,EAAE,MAAM,IAAI,CAAA;IACxB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAEH,QAAA,MAAM,IAAI
|
|
1
|
+
{"version":3,"file":"chip.d.ts","sourceRoot":"","sources":["../../../components/ui/chip.tsx"],"names":[],"mappings":"AACA,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAEjE,OAAO,KAAsC,MAAM,OAAO,CAAA;AAI1D,QAAA,MAAM,YAAY;;;;mFAwBjB,CAAA;AAED,KAAK,SAAS,GAAG,KAAK,CAAC,wBAAwB,CAAC,KAAK,CAAC,GACpD,YAAY,CAAC,OAAO,YAAY,CAAC,GAAG;IAClC,IAAI,CAAC,EAAE,KAAK,CAAC,WAAW,CAAA;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,WAAW,CAAC,EAAE,MAAM,IAAI,CAAA;IACxB,WAAW,CAAC,EAAE,MAAM,IAAI,CAAA;IACxB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAEH,QAAA,MAAM,IAAI;;;;;;;;;;yBALc,IAAI;yBACJ,IAAI;;wCAgF3B,CAAA;AAGD,KAAK,kBAAkB,GAAG;IACxB,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,CAAA;IACzC,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IAC3B,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAA;CAC9C,CAAA;AAED,QAAA,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAoD/C,CAAA;AAED,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,SAAS,EAAE,KAAK,kBAAkB,EAAE,CAAA"}
|
|
@@ -10,7 +10,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
}
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
14
|
import { cva } from "class-variance-authority";
|
|
15
15
|
import { cn } from "../../lib/utils";
|
|
16
16
|
import React, { useState, useEffect } from "react";
|
|
@@ -39,7 +39,7 @@ const chipVariants = cva("inline-flex items-center justify-center rounded border
|
|
|
39
39
|
},
|
|
40
40
|
});
|
|
41
41
|
const Chip = React.forwardRef((_a, ref) => {
|
|
42
|
-
var { className, variant, direction, children, iconPosition, iconColor = "coreColors-secondaryIcon", iconUrl, loading = false, onChipClick, onIconClick } = _a, props = __rest(_a, ["className", "variant", "direction", "children", "iconPosition", "iconColor", "iconUrl", "loading", "onChipClick", "onIconClick"]);
|
|
42
|
+
var { className, variant, direction, children, iconPosition, iconColor = "coreColors-secondaryIcon", iconUrl, readOnly = false, loading = false, onChipClick, onIconClick } = _a, props = __rest(_a, ["className", "variant", "direction", "children", "iconPosition", "iconColor", "iconUrl", "readOnly", "loading", "onChipClick", "onIconClick"]);
|
|
43
43
|
const handleOnClick = () => {
|
|
44
44
|
onChipClick === null || onChipClick === void 0 ? void 0 : onChipClick();
|
|
45
45
|
};
|
|
@@ -47,9 +47,14 @@ const Chip = React.forwardRef((_a, ref) => {
|
|
|
47
47
|
onIconClick === null || onIconClick === void 0 ? void 0 : onIconClick();
|
|
48
48
|
};
|
|
49
49
|
const ChipIcon = ({ className }) => iconUrl ? (_jsx(Icon, { url: iconUrl, size: "xs", color: iconColor, className: className })) : (_jsx(Icon, { name: "square-x-filled", color: iconColor, className: className }));
|
|
50
|
-
return (_jsxs("div", Object.assign({ onClick: loading ? undefined : handleOnClick,
|
|
50
|
+
return (_jsxs("div", Object.assign({ onClick: loading ? undefined : handleOnClick, onKeyDown: (e) => {
|
|
51
|
+
if ((e.key === "Enter" || e.key === " ") && !loading) {
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
handleOnClick();
|
|
54
|
+
}
|
|
55
|
+
}, tabIndex: loading ? -1 : 0, role: "button", ref: ref, className: cn(chipVariants({ variant, direction, iconPosition }), className, {
|
|
51
56
|
relative: loading,
|
|
52
|
-
}) }, props, { children: [iconPosition === "left" && (_jsx("button", Object.assign({ onClick: loading ? undefined : handleIconClick, className: "h-full flex items-center justify-center pl-2" }, { children: _jsx(ChipIcon, { className: "mr-2 h-4 w-4 cursor-pointer" }) }))), children, iconPosition === "right" && (_jsx("button", Object.assign({ onClick: loading ? undefined : handleIconClick, className: "h-full flex items-center justify-center pr-2" }, { children: _jsx(ChipIcon, { className: "ml-2 h-4 w-4 cursor-pointer" }) }))), _jsx(LoadingDots, { show: loading, size: 1, iconColor: iconColor })] })));
|
|
57
|
+
}) }, props, { children: [iconPosition === "left" && !readOnly && (_jsx("button", Object.assign({ onClick: loading ? undefined : handleIconClick, className: "h-full flex items-center justify-center pl-2" }, { children: _jsx(ChipIcon, { className: "mr-2 h-4 w-4 cursor-pointer" }) }))), children, iconPosition === "right" && !readOnly && (_jsx("button", Object.assign({ onClick: loading ? undefined : handleIconClick, className: "h-full flex items-center justify-center pr-2" }, { children: _jsx(ChipIcon, { className: "ml-2 h-4 w-4 cursor-pointer" }) }))), readOnly && _jsx(_Fragment, { children: "\u00A0\u00A0" }), _jsx(LoadingDots, { show: loading, size: 1, iconColor: iconColor })] })));
|
|
53
58
|
});
|
|
54
59
|
Chip.displayName = "Chip";
|
|
55
60
|
const MultipleChips = ({ children, containerRef, style, }) => {
|
|
@@ -65,10 +70,10 @@ const MultipleChips = ({ children, containerRef, style, }) => {
|
|
|
65
70
|
window.addEventListener("resize", handleResize);
|
|
66
71
|
checkOverflow();
|
|
67
72
|
return () => window.removeEventListener("resize", handleResize);
|
|
68
|
-
}, []);
|
|
73
|
+
}, [checkOverflow]);
|
|
69
74
|
useEffect(() => {
|
|
70
75
|
checkOverflow();
|
|
71
|
-
}, [children]);
|
|
76
|
+
}, [children, checkOverflow]);
|
|
72
77
|
return (_jsxs("div", Object.assign({ className: "relative no-scrollbar" }, { children: [_jsx("div", Object.assign({ ref: containerRef, className: "flex overflow-x-auto overflow-y-hidden", onScroll: checkOverflow, style: style }, { children: children.map((chip, index) => (_jsx("div", Object.assign({ className: cn("shrink-0", {
|
|
73
78
|
"mr-2": index < children.length - 1,
|
|
74
79
|
}) }, { children: chip }), index))) })), showFadeLeft && (_jsx("div", { className: "absolute top-0 left-0 w-8 h-full pointer-events-none bg-fade-left" })), showFadeRight && (_jsx("div", { className: "absolute top-0 right-0 w-8 h-full pointer-events-none bg-fade-right" }))] })));
|
|
@@ -19,6 +19,7 @@ export interface QuantityPickerNEWProps extends React.HTMLAttributes<HTMLDivElem
|
|
|
19
19
|
buttonCornerRadius?: number;
|
|
20
20
|
debounceTime?: number;
|
|
21
21
|
max?: number;
|
|
22
|
+
parentRef?: React.RefObject<HTMLDivElement>;
|
|
22
23
|
}
|
|
23
24
|
declare const QuantityPickerNEW: React.ForwardRefExoticComponent<QuantityPickerNEWProps & React.RefAttributes<HTMLDivElement>>;
|
|
24
25
|
export { QuantityPickerNEW };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quantity-pickerNEW.d.ts","sourceRoot":"","sources":["../../../components/ui/quantity-pickerNEW.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"quantity-pickerNEW.d.ts","sourceRoot":"","sources":["../../../components/ui/quantity-pickerNEW.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAM9B,MAAM,WAAW,sBACf,SAAQ,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC;IAC5C,eAAe,EAAE,MAAM,CAAA;IACvB,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,EAAE,MAAM,CAAA;IACrB,YAAY,EAAE,OAAO,CAAA;IACrB,SAAS,EAAE,MAAM,CAAA;IACjB,eAAe,EAAE,KAAK,CAAC,iBAAiB,CAAA;IACxC,eAAe,EAAE,KAAK,CAAC,iBAAiB,CAAA;IACxC,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IAC/B,gBAAgB,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IACrC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IAChC,WAAW,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IACjC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAA;CAC5C;AAwED,QAAA,MAAM,iBAAiB,+FA0KtB,CAAA;AAID,OAAO,EAAE,iBAAiB,EAAE,CAAA"}
|
|
@@ -14,11 +14,8 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
14
14
|
import * as React from "react";
|
|
15
15
|
import { cn } from "../../lib/utils";
|
|
16
16
|
import { Icon } from "./icon";
|
|
17
|
-
import { useTap } from "./tap";
|
|
18
17
|
import { LoadingDots } from "./loading-dots";
|
|
19
|
-
import debounce from "lodash/debounce";
|
|
20
18
|
const IconButton = ({ iconUrl, iconColor, handler, className, style, disabled }) => {
|
|
21
|
-
const { onTap, isPressed, ref: tapRef } = useTap();
|
|
22
19
|
const [isButtonPressed, setIsButtonPressed] = React.useState(false);
|
|
23
20
|
// Handle press state manually for the invisible button
|
|
24
21
|
const handleMouseDown = React.useCallback(() => {
|
|
@@ -31,8 +28,8 @@ const IconButton = ({ iconUrl, iconColor, handler, className, style, disabled })
|
|
|
31
28
|
// Calculate the visual styles for the button
|
|
32
29
|
const visualButtonStyle = Object.assign({}, style);
|
|
33
30
|
return (_jsxs("div", Object.assign({ className: "relative h-7 w-7", style: { touchAction: "manipulation" } }, { children: [_jsx("div", Object.assign({ className: cn("absolute inset-0 flex items-center justify-center bg-stateColors-skeleton border border-coreColors-dividingLines", className, disabled ? "opacity-50" : ""), style: visualButtonStyle, "aria-hidden": "true" }, { children: _jsx(Icon, { url: iconUrl, size: "sm", strokeColor: iconColor, strokeWidth: 4, style: {
|
|
34
|
-
opacity:
|
|
35
|
-
} }) })), _jsx("button", { onClick:
|
|
31
|
+
opacity: isButtonPressed ? 0.7 : 1,
|
|
32
|
+
} }) })), _jsx("button", { onClick: handler, onMouseDown: handleMouseDown, onMouseUp: handleMouseUp, onMouseLeave: handleMouseUp, onTouchStart: handleMouseDown, onTouchEnd: handleMouseUp, onTouchCancel: handleMouseUp, className: "absolute cursor-pointer", style: {
|
|
36
33
|
top: "-8px",
|
|
37
34
|
right: "-8px",
|
|
38
35
|
bottom: "-8px",
|
|
@@ -42,23 +39,14 @@ const IconButton = ({ iconUrl, iconColor, handler, className, style, disabled })
|
|
|
42
39
|
}, disabled: disabled, "aria-label": "Quantity button" })] })));
|
|
43
40
|
};
|
|
44
41
|
const QuantityPickerNEW = React.forwardRef((_a, ref) => {
|
|
45
|
-
var { className, decreaseIconUrl, increaseIconUrl, deleteIconUrl, isDeleteOnly = false, iconColor, onDecreaseClick, onIncreaseClick, isDecreaseDisabled, isIncreaseDisabled, value, onValueSet, onAdjustQuantity, inputStyle, buttonStyle, buttonCornerRadius = 4, max = 99, loading = false, debounceTime = 300 } = _a, props = __rest(_a, ["className", "decreaseIconUrl", "increaseIconUrl", "deleteIconUrl", "isDeleteOnly", "iconColor", "onDecreaseClick", "onIncreaseClick", "isDecreaseDisabled", "isIncreaseDisabled", "value", "onValueSet", "onAdjustQuantity", "inputStyle", "buttonStyle", "buttonCornerRadius", "max", "loading", "debounceTime"]);
|
|
42
|
+
var { className, decreaseIconUrl, increaseIconUrl, deleteIconUrl, isDeleteOnly = false, iconColor, onDecreaseClick, onIncreaseClick, isDecreaseDisabled, isIncreaseDisabled, value, onValueSet, onAdjustQuantity, inputStyle, buttonStyle, buttonCornerRadius = 4, max = 99, loading = false, debounceTime = 300, parentRef } = _a, props = __rest(_a, ["className", "decreaseIconUrl", "increaseIconUrl", "deleteIconUrl", "isDeleteOnly", "iconColor", "onDecreaseClick", "onIncreaseClick", "isDecreaseDisabled", "isIncreaseDisabled", "value", "onValueSet", "onAdjustQuantity", "inputStyle", "buttonStyle", "buttonCornerRadius", "max", "loading", "debounceTime", "parentRef"]);
|
|
43
|
+
const inputRef = React.useRef(null);
|
|
46
44
|
const [isFocused, setIsFocused] = React.useState(false);
|
|
47
|
-
const pendingQuantityAdjustment = React.useRef(0);
|
|
48
45
|
const [localInputValue, setLocalInputValue] = React.useState(value);
|
|
49
46
|
// Update local state when external value changes
|
|
50
47
|
React.useEffect(() => {
|
|
51
|
-
|
|
52
|
-
setLocalInputValue(value);
|
|
53
|
-
}
|
|
48
|
+
setLocalInputValue(value);
|
|
54
49
|
}, [value]);
|
|
55
|
-
// Create debounced function for applying changes
|
|
56
|
-
const debouncedApplyChanges = React.useMemo(() => debounce(() => {
|
|
57
|
-
if (pendingQuantityAdjustment.current !== 0) {
|
|
58
|
-
onAdjustQuantity(pendingQuantityAdjustment.current);
|
|
59
|
-
pendingQuantityAdjustment.current = 0;
|
|
60
|
-
}
|
|
61
|
-
}, debounceTime), [debounceTime, onAdjustQuantity]);
|
|
62
50
|
const leftButtonStyle = Object.assign(Object.assign({}, buttonStyle), { borderTopLeftRadius: buttonCornerRadius
|
|
63
51
|
? `${buttonCornerRadius}px`
|
|
64
52
|
: undefined, borderBottomLeftRadius: buttonCornerRadius
|
|
@@ -70,56 +58,60 @@ const QuantityPickerNEW = React.forwardRef((_a, ref) => {
|
|
|
70
58
|
? `${buttonCornerRadius}px`
|
|
71
59
|
: undefined });
|
|
72
60
|
const singleButtonStyle = Object.assign(Object.assign({}, buttonStyle), { borderRadius: buttonCornerRadius ? `${buttonCornerRadius}px` : undefined });
|
|
73
|
-
const adjustQuantity = (amount) => {
|
|
74
|
-
const newAmount = localInputValue + amount;
|
|
75
|
-
const clampedNewAmount = Math.min(Math.max(newAmount, 0), max);
|
|
76
|
-
// Update local value immediately
|
|
77
|
-
setLocalInputValue(clampedNewAmount);
|
|
78
|
-
// Track pending change for batched update
|
|
79
|
-
pendingQuantityAdjustment.current += amount;
|
|
80
|
-
// Trigger debounced API update
|
|
81
|
-
debouncedApplyChanges();
|
|
82
|
-
};
|
|
83
61
|
const handleDecreaseClick = (e) => {
|
|
84
62
|
e.preventDefault();
|
|
85
63
|
e.stopPropagation();
|
|
86
|
-
|
|
64
|
+
onAdjustQuantity(-1);
|
|
87
65
|
onDecreaseClick(e);
|
|
88
66
|
};
|
|
89
67
|
const handleIncreaseClick = (e) => {
|
|
90
68
|
e.preventDefault();
|
|
91
69
|
e.stopPropagation();
|
|
92
|
-
|
|
70
|
+
onAdjustQuantity(1);
|
|
93
71
|
onIncreaseClick(e);
|
|
94
72
|
};
|
|
95
|
-
return (_jsxs("div", Object.assign({ className: cn("flex relative", className), ref: ref }, props, { children: [isDeleteOnly ? (_jsx(IconButton, { handler: handleDecreaseClick, iconUrl: deleteIconUrl, iconColor: iconColor, style: singleButtonStyle })) : (_jsxs(_Fragment, { children: [_jsx(IconButton, { handler: handleDecreaseClick, iconUrl:
|
|
73
|
+
return (_jsxs("div", Object.assign({ className: cn("flex relative", className), ref: ref }, props, { children: [isDeleteOnly ? (_jsx(IconButton, { handler: handleDecreaseClick, iconUrl: deleteIconUrl, iconColor: iconColor, style: singleButtonStyle })) : (_jsxs(_Fragment, { children: [_jsx(IconButton, { handler: handleDecreaseClick, iconUrl: value <= 1 ? deleteIconUrl : decreaseIconUrl, iconColor: iconColor, style: leftButtonStyle, disabled: isDecreaseDisabled || loading }), _jsx("input", { type: "number", step: 1, enterKeyHint: "done", ref: inputRef, disabled: loading, max: max, value: localInputValue, onBlur: (e) => {
|
|
96
74
|
setIsFocused(false);
|
|
75
|
+
if (e.target.value === "") {
|
|
76
|
+
setLocalInputValue(value);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
97
79
|
const parsedValue = parseInt(e.target.value) || 0;
|
|
98
80
|
const clampedValue = Math.min(parsedValue, max);
|
|
99
|
-
// Cancel any pending debounced operations
|
|
100
|
-
debouncedApplyChanges.cancel();
|
|
101
|
-
// Update and apply changes
|
|
102
|
-
const delta = clampedValue - value;
|
|
103
|
-
pendingQuantityAdjustment.current = delta;
|
|
104
|
-
setLocalInputValue(clampedValue);
|
|
105
81
|
onValueSet(clampedValue);
|
|
106
|
-
}, onFocus: () => {
|
|
82
|
+
}, onFocus: (e) => {
|
|
83
|
+
setLocalInputValue("");
|
|
107
84
|
setIsFocused(true);
|
|
85
|
+
setTimeout(() => {
|
|
86
|
+
var _a;
|
|
87
|
+
(_a = parentRef === null || parentRef === void 0 ? void 0 : parentRef.current) === null || _a === void 0 ? void 0 : _a.scrollIntoView({
|
|
88
|
+
block: "start",
|
|
89
|
+
inline: "nearest",
|
|
90
|
+
behavior: "smooth",
|
|
91
|
+
});
|
|
92
|
+
}, 250);
|
|
108
93
|
}, onChange: (e) => {
|
|
109
94
|
const inputValue = e.target.value;
|
|
110
95
|
if (inputValue === "") {
|
|
111
|
-
setLocalInputValue(
|
|
96
|
+
setLocalInputValue("");
|
|
112
97
|
}
|
|
113
98
|
else {
|
|
114
|
-
const parsedValue = parseInt(inputValue);
|
|
99
|
+
const parsedValue = parseInt(inputValue, 10);
|
|
115
100
|
if (!isNaN(parsedValue)) {
|
|
116
101
|
const clampedValue = Math.min(parsedValue, max);
|
|
117
102
|
setLocalInputValue(clampedValue);
|
|
118
103
|
}
|
|
119
104
|
}
|
|
105
|
+
}, onKeyDown: (e) => {
|
|
106
|
+
var _a;
|
|
107
|
+
if (e.key === "Enter") {
|
|
108
|
+
e.preventDefault();
|
|
109
|
+
e.stopPropagation();
|
|
110
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
111
|
+
}
|
|
120
112
|
}, className: "w-8 h-7 focus-visible:outline-no ne text-center bg-coreColors-inputBackground text-textColors-primaryColor border-t border-b border-coreColors-dividingLines", style: Object.assign(Object.assign({}, inputStyle), { borderRadius: (inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.borderRadius)
|
|
121
113
|
? `${inputStyle.borderRadius}px`
|
|
122
|
-
: 0 }), inputMode: "numeric" }), _jsx(IconButton, { handler: handleIncreaseClick, iconUrl: increaseIconUrl, iconColor: iconColor, style: rightButtonStyle, disabled: isIncreaseDisabled || loading ||
|
|
114
|
+
: 0 }), inputMode: "numeric" }), _jsx(IconButton, { handler: handleIncreaseClick, iconUrl: increaseIconUrl, iconColor: iconColor, style: rightButtonStyle, disabled: isIncreaseDisabled || loading || value >= max })] })), _jsx(LoadingDots, { show: loading, size: 1, iconColor: iconColor })] })));
|
|
123
115
|
});
|
|
124
116
|
QuantityPickerNEW.displayName = "QuantityPickerNEW";
|
|
125
117
|
export { QuantityPickerNEW };
|
package/dist/lib/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,4BAA4B,EAC5B,yBAAyB,EACzB,UAAU,EACV,eAAe,EACf,OAAO,EACP,QAAQ,EACR,gBAAgB,EACjB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,UAAU,EAAQ,MAAM,MAAM,CAAA;AAMvC,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAErC,eAAO,MAAM,gBAAgB,UAAW,MAAM,YAAY,MAAM,gCACrC,CAAA;AAE3B,MAAM,MAAM,KAAK,GAAG;IAAE,IAAI,EAAE,QAAQ,GAAG,WAAW,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AAEnE,wBAAgB,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,UAEzC;AAED,eAAO,MAAM,eAAe,UAc3B,CAAA;AAED,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,CAAA;AAMjE,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAA;AAI9C,eAAO,MAAM,QAAQ,gBAAiB,KAAK,GAAG,SAAS,uBAUtD,CAAA;AAED,KAAK,UAAU,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,GA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AO,MAAM,kBAAkB,UACtB,UAAU,WACR,GAAG,KACX,OAyBF,CAAA"}
|
package/dist/lib/utils.js
CHANGED
|
@@ -182,10 +182,11 @@ export const mapFlexToAlignment = (flexClass) => {
|
|
|
182
182
|
return "";
|
|
183
183
|
};
|
|
184
184
|
export function getIdFromGid(gid) {
|
|
185
|
+
var _a;
|
|
185
186
|
if (!gid)
|
|
186
187
|
return "";
|
|
187
188
|
const arr = gid.split("/");
|
|
188
|
-
return arr[arr.length - 1] || "";
|
|
189
|
+
return ((_a = arr[arr.length - 1]) === null || _a === void 0 ? void 0 : _a.split("?")[0]) || "";
|
|
189
190
|
}
|
|
190
191
|
export function productGidFromId(id) {
|
|
191
192
|
if (!id)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variablesCart.util.d.ts","sourceRoot":"","sources":["../../lib/variablesCart.util.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,sBAAsB,EACtB,6BAA6B,EAO9B,MAAM,kBAAkB,CAAA;AAEzB,eAAO,MAAM,2BAA2B;;cAM5B,MAAM;;0BAEI;YAChB,gBAAgB,CAAC,EAAE,MAAM,CAAA;YACzB,KAAK,EAAE,MAAM,CAAA;YACb,cAAc,CAAC,EAAE,MAAM,CAAA;SACxB,EAAE;;;;;;CAyBN,CAAA;
|
|
1
|
+
{"version":3,"file":"variablesCart.util.d.ts","sourceRoot":"","sources":["../../lib/variablesCart.util.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,sBAAsB,EACtB,6BAA6B,EAO9B,MAAM,kBAAkB,CAAA;AAEzB,eAAO,MAAM,2BAA2B;;cAM5B,MAAM;;0BAEI;YAChB,gBAAgB,CAAC,EAAE,MAAM,CAAA;YACzB,KAAK,EAAE,MAAM,CAAA;YACb,cAAc,CAAC,EAAE,MAAM,CAAA;SACxB,EAAE;;;;;;CAyBN,CAAA;AA4FD,eAAO,MAAM,6BAA6B,SAClC,MAAM,QACN,SAAS,GAAG,IAAI,YAUvB,CAAA;AAED,eAAO,MAAM,2BAA2B,SAChC,MAAM,QACN,SAAS,GAAG,IAAI,YAUvB,CAAA;AAoLD,MAAM,MAAM,uBAAuB,GAAG;IACpC,yBAAyB,EAAE,sBAAsB,EAAE,CAAA;IACnD,gBAAgB,EAAE,6BAA6B,EAAE,CAAA;IACjD,cAAc,EAAE,OAAO,CAAA;IACvB,oBAAoB,EAAE,MAAM,CAAA;IAC5B,oBAAoB,EAAE,MAAM,CAAA;IAC5B,WAAW,EAAE,MAAM,CAAA;IACnB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,oBAAoB,EAAE,MAAM,CAAA;IAC5B,gBAAgB,EAAE,MAAM,CAAA;CACzB,CAAA;AAED,eAAO,MAAM,iCAAiC,EAAE,uBAU/C,CAAA;AAED,eAAO,MAAM,8BAA8B,SACnC,SAAS,GAAG,IAAI,KACrB,uBAmCF,CAAA"}
|
|
@@ -32,11 +32,12 @@ const getOrderLevelDiscounts = (cart) => {
|
|
|
32
32
|
const discountAllocations = cart === null || cart === void 0 ? void 0 : cart.discountAllocations;
|
|
33
33
|
if (!discountAllocations)
|
|
34
34
|
return [];
|
|
35
|
+
// We'll build a map of code -> { amount, isAutomatic }
|
|
35
36
|
const discountMap = discountAllocations
|
|
36
37
|
.filter((discount) => discount.targetType !== DiscountApplicationTargetType.ShippingLine)
|
|
37
38
|
.reduce((acc, discount) => {
|
|
38
|
-
var _a, _b, _c, _d, _e, _f;
|
|
39
|
-
//
|
|
39
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
40
|
+
// Figure out the code for this discount
|
|
40
41
|
let code = "unknown";
|
|
41
42
|
if (discount.code) {
|
|
42
43
|
code = ((discount === null || discount === void 0 ? void 0 : discount.code) || "").toUpperCase();
|
|
@@ -44,25 +45,34 @@ const getOrderLevelDiscounts = (cart) => {
|
|
|
44
45
|
else if ((_b = (_a = discount.kind) === null || _a === void 0 ? void 0 : _a.manual) === null || _b === void 0 ? void 0 : _b.code) {
|
|
45
46
|
code = (((_d = (_c = discount === null || discount === void 0 ? void 0 : discount.kind) === null || _c === void 0 ? void 0 : _c.manual) === null || _d === void 0 ? void 0 : _d.code) || "").toUpperCase();
|
|
46
47
|
}
|
|
48
|
+
else if ((_f = (_e = discount.kind) === null || _e === void 0 ? void 0 : _e.automatic) === null || _f === void 0 ? void 0 : _f.title) {
|
|
49
|
+
code = (((_h = (_g = discount === null || discount === void 0 ? void 0 : discount.kind) === null || _g === void 0 ? void 0 : _g.automatic) === null || _h === void 0 ? void 0 : _h.title) || "").toUpperCase();
|
|
50
|
+
}
|
|
51
|
+
// Determine if this discount is automatic
|
|
52
|
+
const isAutomatic = Boolean((_j = discount.kind) === null || _j === void 0 ? void 0 : _j.automatic);
|
|
47
53
|
if (!acc[code]) {
|
|
48
|
-
acc[code] = 0;
|
|
54
|
+
acc[code] = { amount: 0, isAutomatic };
|
|
49
55
|
}
|
|
50
|
-
//
|
|
51
|
-
if ((
|
|
52
|
-
acc[code] += parseFloat(((
|
|
56
|
+
// Add the amount for this discount
|
|
57
|
+
if ((_k = discount.discountedAmount) === null || _k === void 0 ? void 0 : _k.amount) {
|
|
58
|
+
acc[code].amount += parseFloat(((_l = discount === null || discount === void 0 ? void 0 : discount.discountedAmount) === null || _l === void 0 ? void 0 : _l.amount) || "0");
|
|
53
59
|
}
|
|
54
60
|
else if (discount.amount) {
|
|
55
|
-
acc[code] += parseFloat(String(discount.amount));
|
|
61
|
+
acc[code].amount += parseFloat(String(discount.amount));
|
|
56
62
|
}
|
|
63
|
+
// If any instance of this code is automatic, mark it as automatic
|
|
64
|
+
acc[code].isAutomatic = acc[code].isAutomatic || isAutomatic;
|
|
57
65
|
return acc;
|
|
58
66
|
}, {});
|
|
59
67
|
if (!discountMap)
|
|
60
68
|
return [];
|
|
61
|
-
|
|
69
|
+
// Only set readOnly to true if the discount is automatic
|
|
70
|
+
return Object.entries(discountMap).map(([code, { amount, isAutomatic }]) => ({
|
|
62
71
|
id: code,
|
|
63
72
|
amount: amount,
|
|
64
73
|
name: `Discount - ${code}`,
|
|
65
74
|
type: "ORDER_LEVEL",
|
|
75
|
+
readOnly: isAutomatic,
|
|
66
76
|
}));
|
|
67
77
|
};
|
|
68
78
|
const getShippingDiscounts = (cart) => {
|
|
@@ -37,6 +37,30 @@ describe("cart-provider.util", () => {
|
|
|
37
37
|
amount: 10,
|
|
38
38
|
name: "Discount - DISCOUNT10",
|
|
39
39
|
type: "ORDER_LEVEL",
|
|
40
|
+
readOnly: false,
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
it("should calculate readonly discounts correctly", () => {
|
|
44
|
+
const mockCart = Object.assign(Object.assign({}, baseCartData), { discounts: ["DISCOUNT10"], items: [], discountAllocations: [
|
|
45
|
+
{
|
|
46
|
+
targetType: DiscountApplicationTargetType.LineItem,
|
|
47
|
+
discountedAmount: { amount: "10.00", currencyCode: "USD" },
|
|
48
|
+
code: "DISCOUNT10",
|
|
49
|
+
kind: {
|
|
50
|
+
automatic: {
|
|
51
|
+
title: "Discount - DISCOUNT10",
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
] });
|
|
56
|
+
const result = getVariablesCalculatedCartData(mockCart);
|
|
57
|
+
expect(result.orderAndLineItemDiscounts).toHaveLength(1);
|
|
58
|
+
expect(result.orderAndLineItemDiscounts[0]).toEqual({
|
|
59
|
+
id: "DISCOUNT10",
|
|
60
|
+
amount: 10,
|
|
61
|
+
name: "Discount - DISCOUNT10",
|
|
62
|
+
type: "ORDER_LEVEL",
|
|
63
|
+
readOnly: true,
|
|
40
64
|
});
|
|
41
65
|
});
|
|
42
66
|
it("should calculate gift cards correctly", () => {
|
package/dist/styles.css
CHANGED
|
@@ -790,6 +790,9 @@ video {
|
|
|
790
790
|
.z-30 {
|
|
791
791
|
z-index: 30;
|
|
792
792
|
}
|
|
793
|
+
.z-40 {
|
|
794
|
+
z-index: 40;
|
|
795
|
+
}
|
|
793
796
|
.z-50 {
|
|
794
797
|
z-index: 50;
|
|
795
798
|
}
|
|
@@ -844,6 +847,10 @@ video {
|
|
|
844
847
|
margin-top: 0.75rem;
|
|
845
848
|
margin-bottom: 0.75rem;
|
|
846
849
|
}
|
|
850
|
+
.my-4 {
|
|
851
|
+
margin-top: 1rem;
|
|
852
|
+
margin-bottom: 1rem;
|
|
853
|
+
}
|
|
847
854
|
.my-auto {
|
|
848
855
|
margin-top: auto;
|
|
849
856
|
margin-bottom: auto;
|
|
@@ -1583,6 +1590,9 @@ video {
|
|
|
1583
1590
|
.rounded-sm {
|
|
1584
1591
|
border-radius: calc(var(--radius) - 4px);
|
|
1585
1592
|
}
|
|
1593
|
+
.rounded-xl {
|
|
1594
|
+
border-radius: 0.75rem;
|
|
1595
|
+
}
|
|
1586
1596
|
.rounded-b-lg {
|
|
1587
1597
|
border-bottom-right-radius: var(--radius);
|
|
1588
1598
|
border-bottom-left-radius: var(--radius);
|
|
@@ -1871,6 +1881,10 @@ video {
|
|
|
1871
1881
|
padding-left: 1.25rem;
|
|
1872
1882
|
padding-right: 1.25rem;
|
|
1873
1883
|
}
|
|
1884
|
+
.px-6 {
|
|
1885
|
+
padding-left: 1.5rem;
|
|
1886
|
+
padding-right: 1.5rem;
|
|
1887
|
+
}
|
|
1874
1888
|
.px-8 {
|
|
1875
1889
|
padding-left: 2rem;
|
|
1876
1890
|
padding-right: 2rem;
|
|
@@ -1883,6 +1897,10 @@ video {
|
|
|
1883
1897
|
padding-top: 0.25rem;
|
|
1884
1898
|
padding-bottom: 0.25rem;
|
|
1885
1899
|
}
|
|
1900
|
+
.py-12 {
|
|
1901
|
+
padding-top: 3rem;
|
|
1902
|
+
padding-bottom: 3rem;
|
|
1903
|
+
}
|
|
1886
1904
|
.py-2 {
|
|
1887
1905
|
padding-top: 0.5rem;
|
|
1888
1906
|
padding-bottom: 0.5rem;
|
|
@@ -1998,6 +2016,10 @@ video {
|
|
|
1998
2016
|
.text-\[23px\] {
|
|
1999
2017
|
font-size: 23px;
|
|
2000
2018
|
}
|
|
2019
|
+
.text-base {
|
|
2020
|
+
font-size: 1rem;
|
|
2021
|
+
line-height: 1.5rem;
|
|
2022
|
+
}
|
|
2001
2023
|
.text-lg {
|
|
2002
2024
|
font-size: 1.125rem;
|
|
2003
2025
|
line-height: 1.75rem;
|
|
@@ -2157,6 +2179,10 @@ video {
|
|
|
2157
2179
|
.text-productBadging-text {
|
|
2158
2180
|
color: var(--productBadging-text);
|
|
2159
2181
|
}
|
|
2182
|
+
.text-red-600 {
|
|
2183
|
+
--tw-text-opacity: 1;
|
|
2184
|
+
color: rgb(220 38 38 / var(--tw-text-opacity, 1));
|
|
2185
|
+
}
|
|
2160
2186
|
.text-stateColors-disabled {
|
|
2161
2187
|
color: var(--stateColors-disabled);
|
|
2162
2188
|
}
|
|
@@ -2314,6 +2340,10 @@ video {
|
|
|
2314
2340
|
.ring-offset-background {
|
|
2315
2341
|
--tw-ring-offset-color: hsl(var(--background));
|
|
2316
2342
|
}
|
|
2343
|
+
.blur {
|
|
2344
|
+
--tw-blur: blur(8px);
|
|
2345
|
+
filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
|
|
2346
|
+
}
|
|
2317
2347
|
.drop-shadow-\[0_3px_1px_0_rgba\(0\2c 0\2c 0\2c 1\)\] {
|
|
2318
2348
|
--tw-drop-shadow: drop-shadow(0 3px 1px 0 rgba(0,0,0,1));
|
|
2319
2349
|
filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
|
|
@@ -2321,6 +2351,11 @@ video {
|
|
|
2321
2351
|
.filter {
|
|
2322
2352
|
filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
|
|
2323
2353
|
}
|
|
2354
|
+
.backdrop-blur-md {
|
|
2355
|
+
--tw-backdrop-blur: blur(12px);
|
|
2356
|
+
-webkit-backdrop-filter: var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia);
|
|
2357
|
+
backdrop-filter: var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia);
|
|
2358
|
+
}
|
|
2324
2359
|
.transition {
|
|
2325
2360
|
transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, -webkit-backdrop-filter;
|
|
2326
2361
|
transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter;
|
|
@@ -2583,6 +2618,19 @@ body::-webkit-scrollbar {
|
|
|
2583
2618
|
border-color: var(--coreColors-brandColorPrimary);
|
|
2584
2619
|
}
|
|
2585
2620
|
|
|
2621
|
+
.hover\:bg-gray-100:hover {
|
|
2622
|
+
--tw-bg-opacity: 1;
|
|
2623
|
+
background-color: rgb(243 244 246 / var(--tw-bg-opacity, 1));
|
|
2624
|
+
}
|
|
2625
|
+
|
|
2626
|
+
.hover\:no-underline:hover {
|
|
2627
|
+
text-decoration-line: none;
|
|
2628
|
+
}
|
|
2629
|
+
|
|
2630
|
+
.hover\:opacity-90:hover {
|
|
2631
|
+
opacity: 0.9;
|
|
2632
|
+
}
|
|
2633
|
+
|
|
2586
2634
|
.focus\:border-coreColors-brandColorPrimary:focus {
|
|
2587
2635
|
border-color: var(--coreColors-brandColorPrimary);
|
|
2588
2636
|
}
|