@simpleapps-com/augur-hooks 0.1.5 → 0.1.7
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/{chunk-V3RMLU3V.js → chunk-DS2ECDHJ.js} +63 -2
- package/dist/{chunk-V3RMLU3V.js.map → chunk-DS2ECDHJ.js.map} +1 -1
- package/dist/{chunk-MRQREI4L.cjs → chunk-YSRBE3YI.cjs} +63 -2
- package/dist/chunk-YSRBE3YI.cjs.map +1 -0
- package/dist/index.cjs +167 -128
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +28 -28
- package/dist/index.d.ts +28 -28
- package/dist/index.js +136 -97
- package/dist/index.js.map +1 -1
- package/dist/{server-ZsiDw2HO.d.cts → server-CF43MUMf.d.cts} +188 -31
- package/dist/{server-ZsiDw2HO.d.ts → server-CF43MUMf.d.ts} +188 -31
- package/dist/server.cjs +6 -2
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +5 -1
- package/package.json +2 -2
- package/dist/chunk-MRQREI4L.cjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
SEARCH_SUGGESTIONS_CACHE_OPTIONS,
|
|
7
7
|
getCartPricingQueryOptions,
|
|
8
8
|
getCategoryItemsInfiniteKey,
|
|
9
|
+
getCategoryItemsInfiniteOptions,
|
|
9
10
|
getInvMastDocKey,
|
|
10
11
|
getInvMastDocOptions,
|
|
11
12
|
getInvMastKey,
|
|
@@ -21,20 +22,32 @@ import {
|
|
|
21
22
|
getItemPriceKey,
|
|
22
23
|
getItemPriceOptions,
|
|
23
24
|
getItemSearchInfiniteKey,
|
|
25
|
+
getItemSearchInfiniteOptions,
|
|
24
26
|
getProductCategoryKey,
|
|
25
27
|
getProductCategoryOptions,
|
|
26
28
|
getProductSearchKey,
|
|
27
29
|
getProductSearchOptions,
|
|
28
30
|
getSearchSuggestionsKey,
|
|
29
31
|
getSearchSuggestionsOptions
|
|
30
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-DS2ECDHJ.js";
|
|
31
33
|
|
|
32
34
|
// src/provider.tsx
|
|
33
35
|
import { createContext, useContext } from "react";
|
|
34
36
|
import { jsx } from "react/jsx-runtime";
|
|
35
37
|
var AugurApiContext = createContext(null);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
var AugurCallbacksContext = createContext(
|
|
39
|
+
void 0
|
|
40
|
+
);
|
|
41
|
+
var AugurAuthReactContext = createContext(
|
|
42
|
+
void 0
|
|
43
|
+
);
|
|
44
|
+
function AugurHooksProvider({
|
|
45
|
+
api,
|
|
46
|
+
callbacks,
|
|
47
|
+
auth,
|
|
48
|
+
children
|
|
49
|
+
}) {
|
|
50
|
+
return /* @__PURE__ */ jsx(AugurApiContext.Provider, { value: api, children: /* @__PURE__ */ jsx(AugurCallbacksContext.Provider, { value: callbacks, children: /* @__PURE__ */ jsx(AugurAuthReactContext.Provider, { value: auth, children }) }) });
|
|
38
51
|
}
|
|
39
52
|
function useAugurApi() {
|
|
40
53
|
const api = useContext(AugurApiContext);
|
|
@@ -45,6 +58,12 @@ function useAugurApi() {
|
|
|
45
58
|
}
|
|
46
59
|
return api;
|
|
47
60
|
}
|
|
61
|
+
function useAugurCallbacks() {
|
|
62
|
+
return useContext(AugurCallbacksContext);
|
|
63
|
+
}
|
|
64
|
+
function useAugurAuth() {
|
|
65
|
+
return useContext(AugurAuthReactContext);
|
|
66
|
+
}
|
|
48
67
|
|
|
49
68
|
// src/stores/cart-store.ts
|
|
50
69
|
import { create } from "zustand";
|
|
@@ -135,11 +154,15 @@ function useFormatPrice(locale = "en-US", currency = "USD") {
|
|
|
135
154
|
import { useQuery } from "@tanstack/react-query";
|
|
136
155
|
function useItemPrice(itemId, customerId, quantity = 1, options = {}) {
|
|
137
156
|
const api = useAugurApi();
|
|
138
|
-
const
|
|
157
|
+
const callbacks = useAugurCallbacks();
|
|
158
|
+
const auth = useAugurAuth();
|
|
159
|
+
const effectiveCustomerId = customerId ?? auth?.customerId;
|
|
160
|
+
const defaultOptions = getItemPriceOptions(api, itemId, effectiveCustomerId, quantity);
|
|
161
|
+
const resolvedQueryFn = options.queryFn ?? (callbacks?.getItemPrice ? () => callbacks.getItemPrice(itemId, effectiveCustomerId, quantity) : void 0);
|
|
139
162
|
return useQuery({
|
|
140
163
|
...defaultOptions,
|
|
141
|
-
...
|
|
142
|
-
enabled: options.enabled ?? (Boolean(itemId) && Boolean(
|
|
164
|
+
...resolvedQueryFn ? { queryFn: resolvedQueryFn } : {},
|
|
165
|
+
enabled: options.enabled ?? (Boolean(itemId) && Boolean(effectiveCustomerId)),
|
|
143
166
|
retry: 3
|
|
144
167
|
});
|
|
145
168
|
}
|
|
@@ -148,6 +171,7 @@ function useItemPrice(itemId, customerId, quantity = 1, options = {}) {
|
|
|
148
171
|
import { useQuery as useQuery2 } from "@tanstack/react-query";
|
|
149
172
|
function useInvMastDoc(invMastUid, itemId, options = {}) {
|
|
150
173
|
const api = useAugurApi();
|
|
174
|
+
const callbacks = useAugurCallbacks();
|
|
151
175
|
const queryOpts = getInvMastDocOptions(
|
|
152
176
|
api,
|
|
153
177
|
invMastUid,
|
|
@@ -156,7 +180,7 @@ function useInvMastDoc(invMastUid, itemId, options = {}) {
|
|
|
156
180
|
);
|
|
157
181
|
const { data, isLoading, error } = useQuery2({
|
|
158
182
|
...queryOpts,
|
|
159
|
-
...options.queryFn ? { queryFn: options.queryFn } : {},
|
|
183
|
+
...options.queryFn ?? callbacks?.getInvMastDoc ? { queryFn: options.queryFn ?? (() => callbacks.getInvMastDoc(invMastUid, itemId, options.includePricing ?? "N")) } : {},
|
|
160
184
|
enabled: options.enabled ?? true,
|
|
161
185
|
initialData: options.initialData
|
|
162
186
|
});
|
|
@@ -167,6 +191,7 @@ function useInvMastDoc(invMastUid, itemId, options = {}) {
|
|
|
167
191
|
import { useQuery as useQuery3 } from "@tanstack/react-query";
|
|
168
192
|
function useItemCategory(itemCategoryUid, options = {}) {
|
|
169
193
|
const api = useAugurApi();
|
|
194
|
+
const callbacks = useAugurCallbacks();
|
|
170
195
|
const queryOpts = getItemCategoryOptions(
|
|
171
196
|
api,
|
|
172
197
|
itemCategoryUid,
|
|
@@ -174,7 +199,7 @@ function useItemCategory(itemCategoryUid, options = {}) {
|
|
|
174
199
|
);
|
|
175
200
|
const { data, isLoading, error } = useQuery3({
|
|
176
201
|
...queryOpts,
|
|
177
|
-
...options.queryFn ? { queryFn: options.queryFn } : {},
|
|
202
|
+
...options.queryFn ?? callbacks?.getItemCategory ? { queryFn: options.queryFn ?? (() => callbacks.getItemCategory(itemCategoryUid, options.apiOptions)) } : {},
|
|
178
203
|
enabled: options.enabled ?? true
|
|
179
204
|
});
|
|
180
205
|
return { category: data, isLoading, error };
|
|
@@ -184,10 +209,11 @@ function useItemCategory(itemCategoryUid, options = {}) {
|
|
|
184
209
|
import { useQuery as useQuery4 } from "@tanstack/react-query";
|
|
185
210
|
function useInvMast(invMastUid, itemId, options = {}) {
|
|
186
211
|
const api = useAugurApi();
|
|
212
|
+
const callbacks = useAugurCallbacks();
|
|
187
213
|
const queryOpts = getInvMastOptions(api, invMastUid, itemId);
|
|
188
214
|
const { data, isLoading, error } = useQuery4({
|
|
189
215
|
...queryOpts,
|
|
190
|
-
...options.queryFn ? { queryFn: options.queryFn } : {},
|
|
216
|
+
...options.queryFn ?? callbacks?.getInvMast ? { queryFn: options.queryFn ?? (() => callbacks.getInvMast(invMastUid, itemId)) } : {},
|
|
191
217
|
enabled: options.enabled ?? true
|
|
192
218
|
});
|
|
193
219
|
return { item: data, isLoading, error };
|
|
@@ -197,10 +223,11 @@ function useInvMast(invMastUid, itemId, options = {}) {
|
|
|
197
223
|
import { useQuery as useQuery5 } from "@tanstack/react-query";
|
|
198
224
|
function useInvMastStock(invMastUid, options = {}) {
|
|
199
225
|
const api = useAugurApi();
|
|
226
|
+
const callbacks = useAugurCallbacks();
|
|
200
227
|
const queryOpts = getInvMastStockOptions(api, invMastUid);
|
|
201
228
|
const { data, isLoading, error } = useQuery5({
|
|
202
229
|
...queryOpts,
|
|
203
|
-
...options.queryFn ? { queryFn: options.queryFn } : {},
|
|
230
|
+
...options.queryFn ?? callbacks?.getInvMastStock ? { queryFn: options.queryFn ?? (() => callbacks.getInvMastStock(invMastUid)) } : {},
|
|
204
231
|
enabled: (options.enabled ?? true) && !!invMastUid,
|
|
205
232
|
retry: 3,
|
|
206
233
|
/* v8 ignore start */
|
|
@@ -216,15 +243,26 @@ function useInvMastStock(invMastUid, options = {}) {
|
|
|
216
243
|
|
|
217
244
|
// src/hooks/use-product-category.ts
|
|
218
245
|
import { useQuery as useQuery6 } from "@tanstack/react-query";
|
|
246
|
+
function resolveData(data) {
|
|
247
|
+
return {
|
|
248
|
+
childrenTotal: data?.childrenTotal ?? 0,
|
|
249
|
+
itemCategoryDesc: data?.itemCategoryDesc ?? "",
|
|
250
|
+
productCategories: data?.children ?? null,
|
|
251
|
+
productCategoryImage: data?.categoryImage ?? null
|
|
252
|
+
};
|
|
253
|
+
}
|
|
219
254
|
function useProductCategory(itemCategoryUid, options = {}) {
|
|
220
255
|
const api = useAugurApi();
|
|
256
|
+
const callbacks = useAugurCallbacks();
|
|
257
|
+
const baseOptions = itemCategoryUid ? getProductCategoryOptions(api, itemCategoryUid) : {
|
|
258
|
+
queryKey: getProductCategoryKey(null),
|
|
259
|
+
/* v8 ignore next */
|
|
260
|
+
queryFn: () => Promise.reject()
|
|
261
|
+
};
|
|
262
|
+
const resolvedQueryFn = options.queryFn ?? (callbacks?.getProductCategory ? () => callbacks.getProductCategory(itemCategoryUid) : void 0);
|
|
221
263
|
const { data, isLoading, error } = useQuery6({
|
|
222
|
-
...
|
|
223
|
-
|
|
224
|
-
/* v8 ignore next */
|
|
225
|
-
queryFn: () => Promise.reject()
|
|
226
|
-
},
|
|
227
|
-
...options.queryFn ? { queryFn: options.queryFn } : {},
|
|
264
|
+
...baseOptions,
|
|
265
|
+
...resolvedQueryFn ? { queryFn: resolvedQueryFn } : {},
|
|
228
266
|
enabled: (options.enabled ?? true) && !!itemCategoryUid,
|
|
229
267
|
retry: 3,
|
|
230
268
|
/* v8 ignore start */
|
|
@@ -232,10 +270,7 @@ function useProductCategory(itemCategoryUid, options = {}) {
|
|
|
232
270
|
/* v8 ignore stop */
|
|
233
271
|
});
|
|
234
272
|
return {
|
|
235
|
-
|
|
236
|
-
itemCategoryDesc: data?.itemCategoryDesc ?? "",
|
|
237
|
-
productCategories: data?.children ?? null,
|
|
238
|
-
productCategoryImage: data?.categoryImage ?? null,
|
|
273
|
+
...resolveData(data),
|
|
239
274
|
loading: isLoading,
|
|
240
275
|
error
|
|
241
276
|
};
|
|
@@ -245,13 +280,14 @@ function useProductCategory(itemCategoryUid, options = {}) {
|
|
|
245
280
|
import { useQuery as useQuery7 } from "@tanstack/react-query";
|
|
246
281
|
function useItemDetails(itemId, options = {}) {
|
|
247
282
|
const api = useAugurApi();
|
|
283
|
+
const callbacks = useAugurCallbacks();
|
|
248
284
|
const { data, isLoading, error } = useQuery7({
|
|
249
285
|
...itemId ? getItemDetailsOptions(api, itemId) : {
|
|
250
286
|
queryKey: getItemDetailsKey(""),
|
|
251
287
|
/* v8 ignore next */
|
|
252
288
|
queryFn: () => Promise.reject()
|
|
253
289
|
},
|
|
254
|
-
...options.queryFn ? { queryFn: options.queryFn } : {},
|
|
290
|
+
...options.queryFn ?? callbacks?.getItemDetails ? { queryFn: options.queryFn ?? (() => callbacks.getItemDetails(itemId)) } : {},
|
|
255
291
|
enabled: (options.enabled ?? true) && !!itemId,
|
|
256
292
|
retry: 3,
|
|
257
293
|
/* v8 ignore start */
|
|
@@ -271,13 +307,14 @@ function useItemDetails(itemId, options = {}) {
|
|
|
271
307
|
import { useQuery as useQuery8 } from "@tanstack/react-query";
|
|
272
308
|
function useItemAttributes(itemCategoryUid, options = {}) {
|
|
273
309
|
const api = useAugurApi();
|
|
310
|
+
const callbacks = useAugurCallbacks();
|
|
274
311
|
const { data, isLoading, error } = useQuery8({
|
|
275
312
|
...itemCategoryUid ? getItemAttributesOptions(api, itemCategoryUid) : {
|
|
276
313
|
queryKey: getItemAttributesKey(null),
|
|
277
314
|
/* v8 ignore next */
|
|
278
315
|
queryFn: () => Promise.reject()
|
|
279
316
|
},
|
|
280
|
-
...options.queryFn ? { queryFn: options.queryFn } : {},
|
|
317
|
+
...options.queryFn ?? callbacks?.getItemAttributes ? { queryFn: options.queryFn ?? (() => callbacks.getItemAttributes(itemCategoryUid)) } : {},
|
|
281
318
|
enabled: (options.enabled ?? true) && !!itemCategoryUid,
|
|
282
319
|
retry: 3,
|
|
283
320
|
/* v8 ignore start */
|
|
@@ -295,10 +332,11 @@ function useItemAttributes(itemCategoryUid, options = {}) {
|
|
|
295
332
|
import { useQuery as useQuery9 } from "@tanstack/react-query";
|
|
296
333
|
function useProductSearch(pageData, options = {}) {
|
|
297
334
|
const api = useAugurApi();
|
|
335
|
+
const callbacks = useAugurCallbacks();
|
|
298
336
|
const defaultOptions = getProductSearchOptions(api, pageData);
|
|
299
337
|
const { data, isLoading, error } = useQuery9({
|
|
300
338
|
...defaultOptions,
|
|
301
|
-
...options.queryFn ? { queryFn: options.queryFn } : {},
|
|
339
|
+
...options.queryFn ?? callbacks?.getProductSearch ? { queryFn: options.queryFn ?? (() => callbacks.getProductSearch(pageData)) } : {},
|
|
302
340
|
retry: 3,
|
|
303
341
|
/* v8 ignore start */
|
|
304
342
|
retryDelay: (attemptIndex) => Math.min(1e3 * 2 ** attemptIndex, 1e4)
|
|
@@ -316,13 +354,14 @@ function useProductSearch(pageData, options = {}) {
|
|
|
316
354
|
import { useQuery as useQuery10 } from "@tanstack/react-query";
|
|
317
355
|
function useSearchSuggestions(query, options = {}) {
|
|
318
356
|
const api = useAugurApi();
|
|
357
|
+
const callbacks = useAugurCallbacks();
|
|
319
358
|
const limit = options.limit ?? 10;
|
|
320
359
|
const offset = options.offset ?? 0;
|
|
321
360
|
const enabled = (options.enabled ?? true) && query.trim().length > 0;
|
|
322
361
|
const defaultOptions = getSearchSuggestionsOptions(api, query, limit, offset);
|
|
323
362
|
const { data, isLoading, error } = useQuery10({
|
|
324
363
|
...defaultOptions,
|
|
325
|
-
...options.queryFn ? { queryFn: options.queryFn } : {},
|
|
364
|
+
...options.queryFn ?? callbacks?.getSearchSuggestions ? { queryFn: options.queryFn ?? (() => callbacks.getSearchSuggestions(query, limit, offset)) } : {},
|
|
326
365
|
enabled
|
|
327
366
|
});
|
|
328
367
|
return {
|
|
@@ -517,36 +556,44 @@ function useCartActions(callbacks) {
|
|
|
517
556
|
}
|
|
518
557
|
|
|
519
558
|
// src/hooks/use-cart-initialization.ts
|
|
520
|
-
import { useEffect as useEffect2, useRef } from "react";
|
|
559
|
+
import { useEffect as useEffect2, useMemo, useRef } from "react";
|
|
521
560
|
import { useQuery as useQuery11, useQueryClient as useQueryClient2 } from "@tanstack/react-query";
|
|
522
561
|
import { CACHE_CONFIG } from "@simpleapps-com/augur-utils";
|
|
523
562
|
var MAX_RETRY_ATTEMPTS = 7;
|
|
524
563
|
var RETRY_DELAY_MS = 1e3;
|
|
525
564
|
function useCartInitialization(session, callbacks) {
|
|
565
|
+
const auth = useAugurAuth();
|
|
526
566
|
const cartHdrUid = useCartHdrUid();
|
|
527
567
|
const setCartHdrUid = useSetCartHdrUid();
|
|
528
568
|
const setCartLines = useSetCartLines();
|
|
529
569
|
const clearCart = useClearCart();
|
|
530
570
|
const queryClient = useQueryClient2();
|
|
571
|
+
const effectiveStatus = session.status;
|
|
572
|
+
const effectiveUserId = session.userId ?? auth?.userId;
|
|
573
|
+
const effectiveCartHdrUid = session.cartHdrUid ?? auth?.cartHdrUid;
|
|
574
|
+
const effectiveSession = useMemo(
|
|
575
|
+
() => ({ status: effectiveStatus, userId: effectiveUserId, cartHdrUid: effectiveCartHdrUid }),
|
|
576
|
+
[effectiveStatus, effectiveUserId, effectiveCartHdrUid]
|
|
577
|
+
);
|
|
531
578
|
const retryCountRef = useRef(0);
|
|
532
579
|
const isInitializingRef = useRef(false);
|
|
533
|
-
const prevStatusRef = useRef(
|
|
580
|
+
const prevStatusRef = useRef(effectiveSession.status);
|
|
534
581
|
useEffect2(() => {
|
|
535
582
|
const prevStatus = prevStatusRef.current;
|
|
536
|
-
prevStatusRef.current =
|
|
537
|
-
if (prevStatus === "authenticated" &&
|
|
583
|
+
prevStatusRef.current = effectiveSession.status;
|
|
584
|
+
if (prevStatus === "authenticated" && effectiveSession.status === "unauthenticated") {
|
|
538
585
|
clearCart();
|
|
539
586
|
queryClient.removeQueries({ queryKey: ["cartLines"] });
|
|
540
587
|
queryClient.removeQueries({ queryKey: ["cart-also-bought"] });
|
|
541
588
|
}
|
|
542
|
-
}, [
|
|
589
|
+
}, [effectiveSession.status, clearCart, queryClient]);
|
|
543
590
|
useEffect2(() => {
|
|
544
|
-
if (cartHdrUid ||
|
|
545
|
-
if (
|
|
546
|
-
setCartHdrUid(
|
|
591
|
+
if (cartHdrUid || effectiveSession.status === "loading") return;
|
|
592
|
+
if (effectiveSession.cartHdrUid && effectiveSession.status === "authenticated") {
|
|
593
|
+
setCartHdrUid(effectiveSession.cartHdrUid);
|
|
547
594
|
return;
|
|
548
595
|
}
|
|
549
|
-
if (
|
|
596
|
+
if (effectiveSession.status === "unauthenticated" && !isInitializingRef.current) {
|
|
550
597
|
isInitializingRef.current = true;
|
|
551
598
|
retryCountRef.current = 0;
|
|
552
599
|
const initializeGuestCart = async () => {
|
|
@@ -591,10 +638,10 @@ function useCartInitialization(session, callbacks) {
|
|
|
591
638
|
};
|
|
592
639
|
initializeGuestCart();
|
|
593
640
|
}
|
|
594
|
-
}, [
|
|
641
|
+
}, [effectiveSession, cartHdrUid, setCartHdrUid, callbacks]);
|
|
595
642
|
const { data: cartLinesData } = useQuery11({
|
|
596
643
|
queryKey: ["cartLines", cartHdrUid],
|
|
597
|
-
queryFn: () => callbacks.getCartLines(Number(cartHdrUid)),
|
|
644
|
+
queryFn: async () => await callbacks.getCartLines(Number(cartHdrUid)) ?? [],
|
|
598
645
|
enabled: !!cartHdrUid,
|
|
599
646
|
...CACHE_CONFIG.CART
|
|
600
647
|
});
|
|
@@ -611,19 +658,29 @@ function useCartInitialization(session, callbacks) {
|
|
|
611
658
|
}
|
|
612
659
|
|
|
613
660
|
// src/hooks/use-cart-pricing.ts
|
|
614
|
-
import { useMemo } from "react";
|
|
661
|
+
import { useMemo as useMemo2 } from "react";
|
|
615
662
|
import { useQueries } from "@tanstack/react-query";
|
|
616
663
|
function useCartPricing(options = {}) {
|
|
617
664
|
const api = useAugurApi();
|
|
665
|
+
const callbacks = useAugurCallbacks();
|
|
666
|
+
const auth = useAugurAuth();
|
|
618
667
|
const cartLines = useCartLines();
|
|
619
|
-
const
|
|
668
|
+
const customerId = options.customerId ?? auth?.customerId;
|
|
669
|
+
const priceFn = options.queryFn ?? callbacks?.getItemPrice;
|
|
620
670
|
const priceQueries = useQueries({
|
|
621
|
-
queries: cartLines.map((line) =>
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
671
|
+
queries: cartLines.map((line) => {
|
|
672
|
+
const base = priceFn ? {
|
|
673
|
+
queryKey: getItemPriceKey(line.itemId, customerId, line.quantity),
|
|
674
|
+
queryFn: () => priceFn(line.itemId, customerId, line.quantity),
|
|
675
|
+
...PRICE_CACHE_OPTIONS
|
|
676
|
+
} : getItemPriceOptions(api, line.itemId, customerId, line.quantity);
|
|
677
|
+
return {
|
|
678
|
+
...base,
|
|
679
|
+
enabled: !!customerId && !!line.itemId
|
|
680
|
+
};
|
|
681
|
+
})
|
|
625
682
|
});
|
|
626
|
-
const prices =
|
|
683
|
+
const prices = useMemo2(() => {
|
|
627
684
|
const map = {};
|
|
628
685
|
cartLines.forEach((line, index) => {
|
|
629
686
|
const queryResult = priceQueries[index];
|
|
@@ -636,17 +693,17 @@ function useCartPricing(options = {}) {
|
|
|
636
693
|
});
|
|
637
694
|
return map;
|
|
638
695
|
}, [cartLines, priceQueries]);
|
|
639
|
-
const getUnitPrice =
|
|
696
|
+
const getUnitPrice = useMemo2(() => {
|
|
640
697
|
return (itemId) => {
|
|
641
698
|
return prices[itemId?.toUpperCase()]?.unitPrice ?? 0;
|
|
642
699
|
};
|
|
643
700
|
}, [prices]);
|
|
644
|
-
const getItemTotal =
|
|
701
|
+
const getItemTotal = useMemo2(() => {
|
|
645
702
|
return (itemId, quantity) => {
|
|
646
703
|
return getUnitPrice(itemId) * quantity;
|
|
647
704
|
};
|
|
648
705
|
}, [getUnitPrice]);
|
|
649
|
-
const subtotal =
|
|
706
|
+
const subtotal = useMemo2(() => {
|
|
650
707
|
return cartLines.reduce((sum, line) => {
|
|
651
708
|
const unitPrice = prices[line.itemId.toUpperCase()]?.unitPrice ?? 0;
|
|
652
709
|
return sum + unitPrice * line.quantity;
|
|
@@ -710,72 +767,51 @@ var usePaginationPrefetch = ({
|
|
|
710
767
|
|
|
711
768
|
// src/hooks/use-category-items-infinite.ts
|
|
712
769
|
import { useInfiniteQuery } from "@tanstack/react-query";
|
|
713
|
-
import {
|
|
714
|
-
CACHE_CONFIG as CACHE_CONFIG2
|
|
715
|
-
} from "@simpleapps-com/augur-utils";
|
|
716
770
|
function useCategoryItemsInfinite(itemCategoryUid, itemsFilters, options = {}) {
|
|
717
771
|
const api = useAugurApi();
|
|
772
|
+
const callbacks = useAugurCallbacks();
|
|
718
773
|
const { enabled = true } = options;
|
|
774
|
+
const defaultOptions = getCategoryItemsInfiniteOptions(
|
|
775
|
+
api,
|
|
776
|
+
itemCategoryUid,
|
|
777
|
+
itemsFilters
|
|
778
|
+
);
|
|
779
|
+
const cb = callbacks?.getCategoryItemsInfinite;
|
|
780
|
+
const resolvedQueryFn = options.queryFn ?? (cb ? ({ pageParam }) => cb({
|
|
781
|
+
itemCategoryUid,
|
|
782
|
+
itemsFilters,
|
|
783
|
+
/* v8 ignore next */
|
|
784
|
+
pageParam: pageParam ?? 0
|
|
785
|
+
}) : void 0);
|
|
719
786
|
return useInfiniteQuery({
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
const response = await api.openSearch.itemSearch.list({
|
|
723
|
-
q: itemsFilters.q || "",
|
|
724
|
-
searchType: "query",
|
|
725
|
-
size: itemsFilters.limit,
|
|
726
|
-
from: pageParam,
|
|
727
|
-
classId5List: String(itemCategoryUid),
|
|
728
|
-
filters: itemsFilters.filters?.length ? JSON.stringify(itemsFilters.filters) : void 0
|
|
729
|
-
});
|
|
730
|
-
const items = response.data?.items ?? [];
|
|
731
|
-
const total = response.data?.totalResults ?? 0;
|
|
732
|
-
const nextOffset = pageParam + itemsFilters.limit;
|
|
733
|
-
return {
|
|
734
|
-
data: items,
|
|
735
|
-
total,
|
|
736
|
-
nextCursor: nextOffset < total ? nextOffset : void 0
|
|
737
|
-
};
|
|
738
|
-
},
|
|
739
|
-
initialPageParam: 0,
|
|
740
|
-
getNextPageParam: (lastPage) => lastPage.nextCursor,
|
|
741
|
-
...CACHE_CONFIG2.SEMI_STATIC,
|
|
787
|
+
...defaultOptions,
|
|
788
|
+
...resolvedQueryFn ? { queryFn: resolvedQueryFn } : {},
|
|
742
789
|
enabled: enabled && !!itemCategoryUid
|
|
743
790
|
});
|
|
744
791
|
}
|
|
745
792
|
|
|
746
793
|
// src/hooks/use-item-search-infinite.ts
|
|
747
794
|
import { useInfiniteQuery as useInfiniteQuery2 } from "@tanstack/react-query";
|
|
748
|
-
import {
|
|
749
|
-
CACHE_CONFIG as CACHE_CONFIG3
|
|
750
|
-
} from "@simpleapps-com/augur-utils";
|
|
751
795
|
function useItemSearchInfinite(itemsFilters, itemCategoryUid, options = {}) {
|
|
752
796
|
const api = useAugurApi();
|
|
797
|
+
const callbacks = useAugurCallbacks();
|
|
753
798
|
const { enabled = true } = options;
|
|
799
|
+
const defaultOptions = getItemSearchInfiniteOptions(
|
|
800
|
+
api,
|
|
801
|
+
itemsFilters,
|
|
802
|
+
itemCategoryUid
|
|
803
|
+
);
|
|
804
|
+
const cb = callbacks?.getItemSearchInfinite;
|
|
805
|
+
const resolvedQueryFn = options.queryFn ?? (cb ? ({ pageParam }) => cb({
|
|
806
|
+
itemsFilters,
|
|
807
|
+
itemCategoryUid,
|
|
808
|
+
/* v8 ignore next */
|
|
809
|
+
pageParam: pageParam ?? 0
|
|
810
|
+
}) : void 0);
|
|
754
811
|
return useInfiniteQuery2({
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
q: itemsFilters.q,
|
|
759
|
-
searchType: "query",
|
|
760
|
-
size: itemsFilters.limit,
|
|
761
|
-
from: pageParam,
|
|
762
|
-
classId5List: itemCategoryUid ? String(itemCategoryUid) : void 0,
|
|
763
|
-
filters: itemsFilters.filters?.length ? JSON.stringify(itemsFilters.filters) : void 0
|
|
764
|
-
});
|
|
765
|
-
const items = response.data?.items ?? [];
|
|
766
|
-
const total = response.data?.totalResults ?? 0;
|
|
767
|
-
const nextOffset = pageParam + itemsFilters.limit;
|
|
768
|
-
return {
|
|
769
|
-
data: items,
|
|
770
|
-
total,
|
|
771
|
-
nextCursor: nextOffset < total ? nextOffset : void 0
|
|
772
|
-
};
|
|
773
|
-
},
|
|
774
|
-
initialPageParam: 0,
|
|
775
|
-
getNextPageParam: (lastPage) => lastPage.nextCursor,
|
|
776
|
-
...CACHE_CONFIG3.SEMI_STATIC,
|
|
777
|
-
enabled: enabled && !!itemsFilters.q,
|
|
778
|
-
meta: { persist: true }
|
|
812
|
+
...defaultOptions,
|
|
813
|
+
...resolvedQueryFn ? { queryFn: resolvedQueryFn } : {},
|
|
814
|
+
enabled: enabled && !!itemsFilters.q
|
|
779
815
|
});
|
|
780
816
|
}
|
|
781
817
|
export {
|
|
@@ -787,6 +823,7 @@ export {
|
|
|
787
823
|
SEARCH_SUGGESTIONS_CACHE_OPTIONS,
|
|
788
824
|
getCartPricingQueryOptions,
|
|
789
825
|
getCategoryItemsInfiniteKey,
|
|
826
|
+
getCategoryItemsInfiniteOptions,
|
|
790
827
|
getInvMastDocKey,
|
|
791
828
|
getInvMastDocOptions,
|
|
792
829
|
getInvMastKey,
|
|
@@ -802,6 +839,7 @@ export {
|
|
|
802
839
|
getItemPriceKey,
|
|
803
840
|
getItemPriceOptions,
|
|
804
841
|
getItemSearchInfiniteKey,
|
|
842
|
+
getItemSearchInfiniteOptions,
|
|
805
843
|
getProductCategoryKey,
|
|
806
844
|
getProductCategoryOptions,
|
|
807
845
|
getProductSearchKey,
|
|
@@ -809,6 +847,7 @@ export {
|
|
|
809
847
|
getSearchSuggestionsKey,
|
|
810
848
|
getSearchSuggestionsOptions,
|
|
811
849
|
useAugurApi,
|
|
850
|
+
useAugurAuth,
|
|
812
851
|
useCartActions,
|
|
813
852
|
useCartHdrUid,
|
|
814
853
|
useCartInitialization,
|