@diffsome/react 1.2.0 → 1.2.1
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/index.d.mts +23 -3
- package/dist/index.d.ts +23 -3
- package/dist/index.js +473 -346
- package/dist/index.mjs +470 -345
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -46,6 +46,7 @@ __export(index_exports, {
|
|
|
46
46
|
useCreateReservation: () => useCreateReservation,
|
|
47
47
|
useCreateReview: () => useCreateReview,
|
|
48
48
|
useCreateSubscription: () => useCreateSubscription,
|
|
49
|
+
useCurrency: () => useCurrency,
|
|
49
50
|
useDiffsome: () => useDiffsome,
|
|
50
51
|
useDigitalProducts: () => useDigitalProducts,
|
|
51
52
|
useDownloads: () => useDownloads,
|
|
@@ -70,6 +71,7 @@ __export(index_exports, {
|
|
|
70
71
|
useReservationServices: () => useReservationServices,
|
|
71
72
|
useReservationSettings: () => useReservationSettings,
|
|
72
73
|
useReservationStaffs: () => useReservationStaffs,
|
|
74
|
+
useSite: () => useSite,
|
|
73
75
|
useSocialAuth: () => useSocialAuth,
|
|
74
76
|
useStripePayment: () => useStripePayment,
|
|
75
77
|
useSubscription: () => useSubscription,
|
|
@@ -147,19 +149,33 @@ function DiffsomeProvider({ children, config = {} }) {
|
|
|
147
149
|
}
|
|
148
150
|
}, [client]);
|
|
149
151
|
(0, import_react.useEffect)(() => {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
152
|
+
let mounted = true;
|
|
153
|
+
const init = async () => {
|
|
154
|
+
if (!mounted) return;
|
|
155
|
+
setIsReady(true);
|
|
156
|
+
try {
|
|
157
|
+
const cartData = await client.shop.getCart();
|
|
158
|
+
if (mounted) setCart(cartData);
|
|
159
|
+
} catch (err) {
|
|
160
|
+
if (mounted) setCart(null);
|
|
161
|
+
} finally {
|
|
162
|
+
if (mounted) setCartLoading(false);
|
|
163
|
+
}
|
|
164
|
+
if (client.isAuthenticated()) {
|
|
165
|
+
try {
|
|
166
|
+
const response = await client.shop.getWishlist({ per_page: 100 });
|
|
167
|
+
if (mounted) setWishlistItems(response.data);
|
|
168
|
+
} catch (err) {
|
|
169
|
+
if (mounted) setWishlistItems([]);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (mounted) setWishlistLoading(false);
|
|
157
173
|
};
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
}, [
|
|
174
|
+
init();
|
|
175
|
+
return () => {
|
|
176
|
+
mounted = false;
|
|
177
|
+
};
|
|
178
|
+
}, [client]);
|
|
163
179
|
const value = (0, import_react.useMemo)(() => ({
|
|
164
180
|
client,
|
|
165
181
|
isReady,
|
|
@@ -186,15 +202,104 @@ function useClient() {
|
|
|
186
202
|
return client;
|
|
187
203
|
}
|
|
188
204
|
|
|
189
|
-
// src/hooks/
|
|
205
|
+
// src/hooks/useSite.ts
|
|
190
206
|
var import_react2 = require("react");
|
|
191
|
-
|
|
207
|
+
var DEFAULT_CURRENCY = {
|
|
208
|
+
code: "KRW",
|
|
209
|
+
symbol: "\u20A9",
|
|
210
|
+
position: "before",
|
|
211
|
+
decimals: 0
|
|
212
|
+
};
|
|
213
|
+
function useSite() {
|
|
192
214
|
const client = useClient();
|
|
193
|
-
const [
|
|
215
|
+
const [site, setSite] = (0, import_react2.useState)(null);
|
|
194
216
|
const [loading, setLoading] = (0, import_react2.useState)(true);
|
|
195
217
|
const [error, setError] = (0, import_react2.useState)(null);
|
|
218
|
+
const fetchSite = (0, import_react2.useCallback)(async () => {
|
|
219
|
+
setLoading(true);
|
|
220
|
+
setError(null);
|
|
221
|
+
try {
|
|
222
|
+
const data = await client.site.getInfo();
|
|
223
|
+
setSite(data);
|
|
224
|
+
} catch (err) {
|
|
225
|
+
setError(err instanceof Error ? err : new Error("Failed to fetch site info"));
|
|
226
|
+
} finally {
|
|
227
|
+
setLoading(false);
|
|
228
|
+
}
|
|
229
|
+
}, [client]);
|
|
230
|
+
(0, import_react2.useEffect)(() => {
|
|
231
|
+
fetchSite();
|
|
232
|
+
}, [fetchSite]);
|
|
233
|
+
const currency = site?.currency ?? null;
|
|
234
|
+
const formatPrice = (0, import_react2.useCallback)((amount) => {
|
|
235
|
+
const curr = currency ?? DEFAULT_CURRENCY;
|
|
236
|
+
const formatted = amount.toLocaleString(void 0, {
|
|
237
|
+
minimumFractionDigits: curr.decimals,
|
|
238
|
+
maximumFractionDigits: curr.decimals
|
|
239
|
+
});
|
|
240
|
+
if (curr.position === "after") {
|
|
241
|
+
return `${formatted}${curr.symbol}`;
|
|
242
|
+
}
|
|
243
|
+
return `${curr.symbol}${formatted}`;
|
|
244
|
+
}, [currency]);
|
|
245
|
+
return {
|
|
246
|
+
site,
|
|
247
|
+
loading,
|
|
248
|
+
error,
|
|
249
|
+
refresh: fetchSite,
|
|
250
|
+
currency,
|
|
251
|
+
formatPrice
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
function useCurrency() {
|
|
255
|
+
const client = useClient();
|
|
256
|
+
const [currency, setCurrency] = (0, import_react2.useState)(null);
|
|
257
|
+
const [loading, setLoading] = (0, import_react2.useState)(true);
|
|
258
|
+
const [error, setError] = (0, import_react2.useState)(null);
|
|
259
|
+
const fetchCurrency = (0, import_react2.useCallback)(async () => {
|
|
260
|
+
setLoading(true);
|
|
261
|
+
setError(null);
|
|
262
|
+
try {
|
|
263
|
+
const data = await client.site.getCurrency();
|
|
264
|
+
setCurrency(data);
|
|
265
|
+
} catch (err) {
|
|
266
|
+
setError(err instanceof Error ? err : new Error("Failed to fetch currency"));
|
|
267
|
+
} finally {
|
|
268
|
+
setLoading(false);
|
|
269
|
+
}
|
|
270
|
+
}, [client]);
|
|
271
|
+
(0, import_react2.useEffect)(() => {
|
|
272
|
+
fetchCurrency();
|
|
273
|
+
}, [fetchCurrency]);
|
|
274
|
+
const formatPrice = (0, import_react2.useCallback)((amount) => {
|
|
275
|
+
const curr = currency ?? DEFAULT_CURRENCY;
|
|
276
|
+
const formatted = amount.toLocaleString(void 0, {
|
|
277
|
+
minimumFractionDigits: curr.decimals,
|
|
278
|
+
maximumFractionDigits: curr.decimals
|
|
279
|
+
});
|
|
280
|
+
if (curr.position === "after") {
|
|
281
|
+
return `${formatted}${curr.symbol}`;
|
|
282
|
+
}
|
|
283
|
+
return `${curr.symbol}${formatted}`;
|
|
284
|
+
}, [currency]);
|
|
285
|
+
return {
|
|
286
|
+
currency,
|
|
287
|
+
loading,
|
|
288
|
+
error,
|
|
289
|
+
formatPrice,
|
|
290
|
+
refresh: fetchCurrency
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// src/hooks/useAuth.ts
|
|
295
|
+
var import_react3 = require("react");
|
|
296
|
+
function useAuth() {
|
|
297
|
+
const client = useClient();
|
|
298
|
+
const [user, setUser] = (0, import_react3.useState)(null);
|
|
299
|
+
const [loading, setLoading] = (0, import_react3.useState)(true);
|
|
300
|
+
const [error, setError] = (0, import_react3.useState)(null);
|
|
196
301
|
const isAuthenticated = !!user && client.isAuthenticated();
|
|
197
|
-
const fetchProfile = (0,
|
|
302
|
+
const fetchProfile = (0, import_react3.useCallback)(async () => {
|
|
198
303
|
if (!client.isAuthenticated()) {
|
|
199
304
|
setUser(null);
|
|
200
305
|
setLoading(false);
|
|
@@ -211,10 +316,10 @@ function useAuth() {
|
|
|
211
316
|
setLoading(false);
|
|
212
317
|
}
|
|
213
318
|
}, [client]);
|
|
214
|
-
(0,
|
|
319
|
+
(0, import_react3.useEffect)(() => {
|
|
215
320
|
fetchProfile();
|
|
216
321
|
}, [fetchProfile]);
|
|
217
|
-
const login = (0,
|
|
322
|
+
const login = (0, import_react3.useCallback)(async (credentials) => {
|
|
218
323
|
setLoading(true);
|
|
219
324
|
setError(null);
|
|
220
325
|
try {
|
|
@@ -229,7 +334,7 @@ function useAuth() {
|
|
|
229
334
|
setLoading(false);
|
|
230
335
|
}
|
|
231
336
|
}, [client]);
|
|
232
|
-
const register = (0,
|
|
337
|
+
const register = (0, import_react3.useCallback)(async (data) => {
|
|
233
338
|
setLoading(true);
|
|
234
339
|
setError(null);
|
|
235
340
|
try {
|
|
@@ -244,7 +349,7 @@ function useAuth() {
|
|
|
244
349
|
setLoading(false);
|
|
245
350
|
}
|
|
246
351
|
}, [client]);
|
|
247
|
-
const logout = (0,
|
|
352
|
+
const logout = (0, import_react3.useCallback)(async () => {
|
|
248
353
|
setLoading(true);
|
|
249
354
|
try {
|
|
250
355
|
await client.auth.logout();
|
|
@@ -253,23 +358,23 @@ function useAuth() {
|
|
|
253
358
|
setLoading(false);
|
|
254
359
|
}
|
|
255
360
|
}, [client]);
|
|
256
|
-
const getProfile = (0,
|
|
361
|
+
const getProfile = (0, import_react3.useCallback)(async () => {
|
|
257
362
|
const profile = await client.auth.me();
|
|
258
363
|
setUser(profile);
|
|
259
364
|
return profile;
|
|
260
365
|
}, [client]);
|
|
261
|
-
const updateProfile = (0,
|
|
366
|
+
const updateProfile = (0, import_react3.useCallback)(async (data) => {
|
|
262
367
|
const profile = await client.auth.updateProfile(data);
|
|
263
368
|
setUser(profile);
|
|
264
369
|
return profile;
|
|
265
370
|
}, [client]);
|
|
266
|
-
const forgotPassword = (0,
|
|
371
|
+
const forgotPassword = (0, import_react3.useCallback)(async (email) => {
|
|
267
372
|
return await client.auth.forgotPassword({ email });
|
|
268
373
|
}, [client]);
|
|
269
|
-
const resetPassword = (0,
|
|
374
|
+
const resetPassword = (0, import_react3.useCallback)(async (data) => {
|
|
270
375
|
return await client.auth.resetPassword(data);
|
|
271
376
|
}, [client]);
|
|
272
|
-
const refresh = (0,
|
|
377
|
+
const refresh = (0, import_react3.useCallback)(async () => {
|
|
273
378
|
await fetchProfile();
|
|
274
379
|
}, [fetchProfile]);
|
|
275
380
|
return {
|
|
@@ -289,13 +394,13 @@ function useAuth() {
|
|
|
289
394
|
}
|
|
290
395
|
|
|
291
396
|
// src/hooks/useSocialAuth.ts
|
|
292
|
-
var
|
|
397
|
+
var import_react4 = require("react");
|
|
293
398
|
function useSocialAuth() {
|
|
294
399
|
const client = useClient();
|
|
295
|
-
const [providers, setProviders] = (0,
|
|
296
|
-
const [loading, setLoading] = (0,
|
|
297
|
-
const [error, setError] = (0,
|
|
298
|
-
const fetchProviders = (0,
|
|
400
|
+
const [providers, setProviders] = (0, import_react4.useState)([]);
|
|
401
|
+
const [loading, setLoading] = (0, import_react4.useState)(true);
|
|
402
|
+
const [error, setError] = (0, import_react4.useState)(null);
|
|
403
|
+
const fetchProviders = (0, import_react4.useCallback)(async () => {
|
|
299
404
|
setLoading(true);
|
|
300
405
|
setError(null);
|
|
301
406
|
try {
|
|
@@ -307,14 +412,14 @@ function useSocialAuth() {
|
|
|
307
412
|
setLoading(false);
|
|
308
413
|
}
|
|
309
414
|
}, [client]);
|
|
310
|
-
(0,
|
|
415
|
+
(0, import_react4.useEffect)(() => {
|
|
311
416
|
fetchProviders();
|
|
312
417
|
}, [fetchProviders]);
|
|
313
|
-
const getAuthUrl = (0,
|
|
418
|
+
const getAuthUrl = (0, import_react4.useCallback)(async (provider) => {
|
|
314
419
|
const result = await client.auth.getSocialAuthUrl(provider);
|
|
315
420
|
return result.url;
|
|
316
421
|
}, [client]);
|
|
317
|
-
const handleCallback = (0,
|
|
422
|
+
const handleCallback = (0, import_react4.useCallback)(async (provider, code) => {
|
|
318
423
|
return await client.auth.socialCallback(provider, code);
|
|
319
424
|
}, [client]);
|
|
320
425
|
return {
|
|
@@ -328,10 +433,10 @@ function useSocialAuth() {
|
|
|
328
433
|
}
|
|
329
434
|
|
|
330
435
|
// src/hooks/useCart.ts
|
|
331
|
-
var
|
|
436
|
+
var import_react5 = require("react");
|
|
332
437
|
function useCart() {
|
|
333
438
|
const { client, cart, cartLoading, setCart, refreshCart } = useDiffsome();
|
|
334
|
-
const addToCart = (0,
|
|
439
|
+
const addToCart = (0, import_react5.useCallback)(async (productId, quantity = 1, variantId, options) => {
|
|
335
440
|
const data = {
|
|
336
441
|
product_id: productId,
|
|
337
442
|
quantity,
|
|
@@ -342,27 +447,27 @@ function useCart() {
|
|
|
342
447
|
setCart(updatedCart);
|
|
343
448
|
return updatedCart;
|
|
344
449
|
}, [client, setCart]);
|
|
345
|
-
const updateItem = (0,
|
|
450
|
+
const updateItem = (0, import_react5.useCallback)(async (itemId, quantity) => {
|
|
346
451
|
const updatedCart = await client.shop.updateCartItem(itemId, { quantity });
|
|
347
452
|
setCart(updatedCart);
|
|
348
453
|
return updatedCart;
|
|
349
454
|
}, [client, setCart]);
|
|
350
|
-
const removeItem = (0,
|
|
455
|
+
const removeItem = (0, import_react5.useCallback)(async (itemId) => {
|
|
351
456
|
const updatedCart = await client.shop.removeFromCart(itemId);
|
|
352
457
|
setCart(updatedCart);
|
|
353
458
|
return updatedCart;
|
|
354
459
|
}, [client, setCart]);
|
|
355
|
-
const clearCart = (0,
|
|
460
|
+
const clearCart = (0, import_react5.useCallback)(async () => {
|
|
356
461
|
await client.shop.clearCart();
|
|
357
462
|
setCart(null);
|
|
358
463
|
}, [client, setCart]);
|
|
359
|
-
const isInCart = (0,
|
|
464
|
+
const isInCart = (0, import_react5.useCallback)((productId, variantId) => {
|
|
360
465
|
if (!cart?.items) return false;
|
|
361
466
|
return cart.items.some(
|
|
362
467
|
(item) => item.product_id === productId && (variantId === void 0 || item.variant_id === variantId)
|
|
363
468
|
);
|
|
364
469
|
}, [cart]);
|
|
365
|
-
const getItemQuantity = (0,
|
|
470
|
+
const getItemQuantity = (0, import_react5.useCallback)((productId, variantId) => {
|
|
366
471
|
if (!cart?.items) return 0;
|
|
367
472
|
const item = cart.items.find(
|
|
368
473
|
(item2) => item2.product_id === productId && (variantId === void 0 || item2.variant_id === variantId)
|
|
@@ -389,11 +494,11 @@ function useCart() {
|
|
|
389
494
|
}
|
|
390
495
|
|
|
391
496
|
// src/hooks/useWishlist.ts
|
|
392
|
-
var
|
|
497
|
+
var import_react6 = require("react");
|
|
393
498
|
function useWishlist() {
|
|
394
499
|
const { client, wishlistItems, wishlistLoading, setWishlistItems, refreshWishlist, setCart } = useDiffsome();
|
|
395
|
-
const [error, setError] = (0,
|
|
396
|
-
const wishlistMap = (0,
|
|
500
|
+
const [error, setError] = (0, import_react6.useState)(null);
|
|
501
|
+
const wishlistMap = (0, import_react6.useMemo)(() => {
|
|
397
502
|
const map = {};
|
|
398
503
|
wishlistItems.forEach((item) => {
|
|
399
504
|
const key = item.variant_id ? `${item.product_id}_${item.variant_id}` : String(item.product_id);
|
|
@@ -401,11 +506,11 @@ function useWishlist() {
|
|
|
401
506
|
});
|
|
402
507
|
return map;
|
|
403
508
|
}, [wishlistItems]);
|
|
404
|
-
const isInWishlist = (0,
|
|
509
|
+
const isInWishlist = (0, import_react6.useCallback)((productId, variantId) => {
|
|
405
510
|
const key = variantId ? `${productId}_${variantId}` : String(productId);
|
|
406
511
|
return wishlistMap[key] || false;
|
|
407
512
|
}, [wishlistMap]);
|
|
408
|
-
const toggleWishlist = (0,
|
|
513
|
+
const toggleWishlist = (0, import_react6.useCallback)(async (productId, variantId) => {
|
|
409
514
|
const result = await client.shop.toggleWishlist(productId, variantId);
|
|
410
515
|
if (result.action === "added") {
|
|
411
516
|
await refreshWishlist();
|
|
@@ -416,7 +521,7 @@ function useWishlist() {
|
|
|
416
521
|
}
|
|
417
522
|
return result;
|
|
418
523
|
}, [client, refreshWishlist, setWishlistItems, wishlistItems]);
|
|
419
|
-
const addToWishlist = (0,
|
|
524
|
+
const addToWishlist = (0, import_react6.useCallback)(async (productId, variantId, note) => {
|
|
420
525
|
const item = await client.shop.addToWishlist({
|
|
421
526
|
product_id: productId,
|
|
422
527
|
variant_id: variantId,
|
|
@@ -425,23 +530,23 @@ function useWishlist() {
|
|
|
425
530
|
await refreshWishlist();
|
|
426
531
|
return item;
|
|
427
532
|
}, [client, refreshWishlist]);
|
|
428
|
-
const removeFromWishlist = (0,
|
|
533
|
+
const removeFromWishlist = (0, import_react6.useCallback)(async (wishlistId) => {
|
|
429
534
|
await client.shop.removeFromWishlist(wishlistId);
|
|
430
535
|
setWishlistItems(wishlistItems.filter((i) => i.id !== wishlistId));
|
|
431
536
|
}, [client, setWishlistItems, wishlistItems]);
|
|
432
|
-
const moveToCart = (0,
|
|
537
|
+
const moveToCart = (0, import_react6.useCallback)(async (wishlistIds) => {
|
|
433
538
|
const result = await client.shop.moveWishlistToCart(wishlistIds);
|
|
434
539
|
await refreshWishlist();
|
|
435
540
|
const cartData = await client.shop.getCart();
|
|
436
541
|
setCart(cartData);
|
|
437
542
|
return result;
|
|
438
543
|
}, [client, refreshWishlist, setCart]);
|
|
439
|
-
const updateNote = (0,
|
|
544
|
+
const updateNote = (0, import_react6.useCallback)(async (wishlistId, note) => {
|
|
440
545
|
const item = await client.shop.updateWishlistNote(wishlistId, note);
|
|
441
546
|
setWishlistItems(wishlistItems.map((i) => i.id === wishlistId ? item : i));
|
|
442
547
|
return item;
|
|
443
548
|
}, [client, setWishlistItems, wishlistItems]);
|
|
444
|
-
const getProductWishlistCount = (0,
|
|
549
|
+
const getProductWishlistCount = (0, import_react6.useCallback)(async (productSlug) => {
|
|
445
550
|
return await client.shop.getProductWishlistCount(productSlug);
|
|
446
551
|
}, [client]);
|
|
447
552
|
return {
|
|
@@ -461,16 +566,16 @@ function useWishlist() {
|
|
|
461
566
|
}
|
|
462
567
|
|
|
463
568
|
// src/hooks/useProducts.ts
|
|
464
|
-
var
|
|
569
|
+
var import_react7 = require("react");
|
|
465
570
|
function useProducts(options = {}) {
|
|
466
571
|
const { autoFetch = true, ...params } = options;
|
|
467
572
|
const client = useClient();
|
|
468
|
-
const [products, setProducts] = (0,
|
|
469
|
-
const [meta, setMeta] = (0,
|
|
470
|
-
const [loading, setLoading] = (0,
|
|
471
|
-
const [error, setError] = (0,
|
|
472
|
-
const [currentParams, setCurrentParams] = (0,
|
|
473
|
-
const fetchProducts = (0,
|
|
573
|
+
const [products, setProducts] = (0, import_react7.useState)([]);
|
|
574
|
+
const [meta, setMeta] = (0, import_react7.useState)(null);
|
|
575
|
+
const [loading, setLoading] = (0, import_react7.useState)(autoFetch);
|
|
576
|
+
const [error, setError] = (0, import_react7.useState)(null);
|
|
577
|
+
const [currentParams, setCurrentParams] = (0, import_react7.useState)(params);
|
|
578
|
+
const fetchProducts = (0, import_react7.useCallback)(async (fetchParams, append = false) => {
|
|
474
579
|
setLoading(true);
|
|
475
580
|
setError(null);
|
|
476
581
|
try {
|
|
@@ -487,22 +592,22 @@ function useProducts(options = {}) {
|
|
|
487
592
|
setLoading(false);
|
|
488
593
|
}
|
|
489
594
|
}, [client]);
|
|
490
|
-
(0,
|
|
595
|
+
(0, import_react7.useEffect)(() => {
|
|
491
596
|
if (autoFetch) {
|
|
492
597
|
fetchProducts(params);
|
|
493
598
|
}
|
|
494
599
|
}, []);
|
|
495
600
|
const hasMore = meta ? meta.current_page < meta.last_page : false;
|
|
496
|
-
const loadMore = (0,
|
|
601
|
+
const loadMore = (0, import_react7.useCallback)(async () => {
|
|
497
602
|
if (!hasMore || loading) return;
|
|
498
603
|
const nextPage = (meta?.current_page ?? 0) + 1;
|
|
499
604
|
await fetchProducts({ ...currentParams, page: nextPage }, true);
|
|
500
605
|
}, [hasMore, loading, meta, currentParams, fetchProducts]);
|
|
501
|
-
const refresh = (0,
|
|
606
|
+
const refresh = (0, import_react7.useCallback)(async () => {
|
|
502
607
|
setCurrentParams(params);
|
|
503
608
|
await fetchProducts(params);
|
|
504
609
|
}, [params, fetchProducts]);
|
|
505
|
-
const search = (0,
|
|
610
|
+
const search = (0, import_react7.useCallback)(async (query) => {
|
|
506
611
|
const searchParams = { ...params, search: query, page: 1 };
|
|
507
612
|
setCurrentParams(searchParams);
|
|
508
613
|
await fetchProducts(searchParams);
|
|
@@ -520,10 +625,10 @@ function useProducts(options = {}) {
|
|
|
520
625
|
}
|
|
521
626
|
function useProduct(idOrSlug) {
|
|
522
627
|
const client = useClient();
|
|
523
|
-
const [product, setProduct] = (0,
|
|
524
|
-
const [loading, setLoading] = (0,
|
|
525
|
-
const [error, setError] = (0,
|
|
526
|
-
const fetchProduct = (0,
|
|
628
|
+
const [product, setProduct] = (0, import_react7.useState)(null);
|
|
629
|
+
const [loading, setLoading] = (0, import_react7.useState)(true);
|
|
630
|
+
const [error, setError] = (0, import_react7.useState)(null);
|
|
631
|
+
const fetchProduct = (0, import_react7.useCallback)(async () => {
|
|
527
632
|
setLoading(true);
|
|
528
633
|
setError(null);
|
|
529
634
|
try {
|
|
@@ -535,7 +640,7 @@ function useProduct(idOrSlug) {
|
|
|
535
640
|
setLoading(false);
|
|
536
641
|
}
|
|
537
642
|
}, [client, idOrSlug]);
|
|
538
|
-
(0,
|
|
643
|
+
(0, import_react7.useEffect)(() => {
|
|
539
644
|
fetchProduct();
|
|
540
645
|
}, [fetchProduct]);
|
|
541
646
|
return {
|
|
@@ -547,10 +652,10 @@ function useProduct(idOrSlug) {
|
|
|
547
652
|
}
|
|
548
653
|
function useCategories() {
|
|
549
654
|
const client = useClient();
|
|
550
|
-
const [categories, setCategories] = (0,
|
|
551
|
-
const [loading, setLoading] = (0,
|
|
552
|
-
const [error, setError] = (0,
|
|
553
|
-
const fetchCategories = (0,
|
|
655
|
+
const [categories, setCategories] = (0, import_react7.useState)([]);
|
|
656
|
+
const [loading, setLoading] = (0, import_react7.useState)(true);
|
|
657
|
+
const [error, setError] = (0, import_react7.useState)(null);
|
|
658
|
+
const fetchCategories = (0, import_react7.useCallback)(async () => {
|
|
554
659
|
setLoading(true);
|
|
555
660
|
setError(null);
|
|
556
661
|
try {
|
|
@@ -562,7 +667,7 @@ function useCategories() {
|
|
|
562
667
|
setLoading(false);
|
|
563
668
|
}
|
|
564
669
|
}, [client]);
|
|
565
|
-
(0,
|
|
670
|
+
(0, import_react7.useEffect)(() => {
|
|
566
671
|
fetchCategories();
|
|
567
672
|
}, [fetchCategories]);
|
|
568
673
|
return {
|
|
@@ -574,10 +679,10 @@ function useCategories() {
|
|
|
574
679
|
}
|
|
575
680
|
function useFeaturedProducts(limit = 8) {
|
|
576
681
|
const client = useClient();
|
|
577
|
-
const [products, setProducts] = (0,
|
|
578
|
-
const [loading, setLoading] = (0,
|
|
579
|
-
const [error, setError] = (0,
|
|
580
|
-
const fetchProducts = (0,
|
|
682
|
+
const [products, setProducts] = (0, import_react7.useState)([]);
|
|
683
|
+
const [loading, setLoading] = (0, import_react7.useState)(true);
|
|
684
|
+
const [error, setError] = (0, import_react7.useState)(null);
|
|
685
|
+
const fetchProducts = (0, import_react7.useCallback)(async () => {
|
|
581
686
|
setLoading(true);
|
|
582
687
|
setError(null);
|
|
583
688
|
try {
|
|
@@ -589,7 +694,7 @@ function useFeaturedProducts(limit = 8) {
|
|
|
589
694
|
setLoading(false);
|
|
590
695
|
}
|
|
591
696
|
}, [client, limit]);
|
|
592
|
-
(0,
|
|
697
|
+
(0, import_react7.useEffect)(() => {
|
|
593
698
|
fetchProducts();
|
|
594
699
|
}, [fetchProducts]);
|
|
595
700
|
return {
|
|
@@ -601,11 +706,11 @@ function useFeaturedProducts(limit = 8) {
|
|
|
601
706
|
}
|
|
602
707
|
function useProductsByType(type, params) {
|
|
603
708
|
const client = useClient();
|
|
604
|
-
const [products, setProducts] = (0,
|
|
605
|
-
const [meta, setMeta] = (0,
|
|
606
|
-
const [loading, setLoading] = (0,
|
|
607
|
-
const [error, setError] = (0,
|
|
608
|
-
const fetchProducts = (0,
|
|
709
|
+
const [products, setProducts] = (0, import_react7.useState)([]);
|
|
710
|
+
const [meta, setMeta] = (0, import_react7.useState)(null);
|
|
711
|
+
const [loading, setLoading] = (0, import_react7.useState)(true);
|
|
712
|
+
const [error, setError] = (0, import_react7.useState)(null);
|
|
713
|
+
const fetchProducts = (0, import_react7.useCallback)(async () => {
|
|
609
714
|
setLoading(true);
|
|
610
715
|
setError(null);
|
|
611
716
|
try {
|
|
@@ -618,7 +723,7 @@ function useProductsByType(type, params) {
|
|
|
618
723
|
setLoading(false);
|
|
619
724
|
}
|
|
620
725
|
}, [client, type, params]);
|
|
621
|
-
(0,
|
|
726
|
+
(0, import_react7.useEffect)(() => {
|
|
622
727
|
fetchProducts();
|
|
623
728
|
}, [fetchProducts]);
|
|
624
729
|
return {
|
|
@@ -640,10 +745,10 @@ function useBundleProducts(params) {
|
|
|
640
745
|
}
|
|
641
746
|
function useBundleItems(productSlug) {
|
|
642
747
|
const client = useClient();
|
|
643
|
-
const [bundle, setBundle] = (0,
|
|
644
|
-
const [loading, setLoading] = (0,
|
|
645
|
-
const [error, setError] = (0,
|
|
646
|
-
const fetchBundle = (0,
|
|
748
|
+
const [bundle, setBundle] = (0, import_react7.useState)(null);
|
|
749
|
+
const [loading, setLoading] = (0, import_react7.useState)(true);
|
|
750
|
+
const [error, setError] = (0, import_react7.useState)(null);
|
|
751
|
+
const fetchBundle = (0, import_react7.useCallback)(async () => {
|
|
647
752
|
setLoading(true);
|
|
648
753
|
setError(null);
|
|
649
754
|
try {
|
|
@@ -655,7 +760,7 @@ function useBundleItems(productSlug) {
|
|
|
655
760
|
setLoading(false);
|
|
656
761
|
}
|
|
657
762
|
}, [client, productSlug]);
|
|
658
|
-
(0,
|
|
763
|
+
(0, import_react7.useEffect)(() => {
|
|
659
764
|
fetchBundle();
|
|
660
765
|
}, [fetchBundle]);
|
|
661
766
|
return {
|
|
@@ -667,14 +772,14 @@ function useBundleItems(productSlug) {
|
|
|
667
772
|
}
|
|
668
773
|
|
|
669
774
|
// src/hooks/useOrders.ts
|
|
670
|
-
var
|
|
775
|
+
var import_react8 = require("react");
|
|
671
776
|
function useOrders(params) {
|
|
672
777
|
const client = useClient();
|
|
673
|
-
const [orders, setOrders] = (0,
|
|
674
|
-
const [meta, setMeta] = (0,
|
|
675
|
-
const [loading, setLoading] = (0,
|
|
676
|
-
const [error, setError] = (0,
|
|
677
|
-
const fetchOrders = (0,
|
|
778
|
+
const [orders, setOrders] = (0, import_react8.useState)([]);
|
|
779
|
+
const [meta, setMeta] = (0, import_react8.useState)(null);
|
|
780
|
+
const [loading, setLoading] = (0, import_react8.useState)(true);
|
|
781
|
+
const [error, setError] = (0, import_react8.useState)(null);
|
|
782
|
+
const fetchOrders = (0, import_react8.useCallback)(async (fetchParams, append = false) => {
|
|
678
783
|
if (!client.isAuthenticated()) {
|
|
679
784
|
setOrders([]);
|
|
680
785
|
setLoading(false);
|
|
@@ -696,16 +801,16 @@ function useOrders(params) {
|
|
|
696
801
|
setLoading(false);
|
|
697
802
|
}
|
|
698
803
|
}, [client]);
|
|
699
|
-
(0,
|
|
804
|
+
(0, import_react8.useEffect)(() => {
|
|
700
805
|
fetchOrders(params);
|
|
701
806
|
}, []);
|
|
702
807
|
const hasMore = meta ? meta.current_page < meta.last_page : false;
|
|
703
|
-
const loadMore = (0,
|
|
808
|
+
const loadMore = (0, import_react8.useCallback)(async () => {
|
|
704
809
|
if (!hasMore || loading) return;
|
|
705
810
|
const nextPage = (meta?.current_page ?? 0) + 1;
|
|
706
811
|
await fetchOrders({ ...params, page: nextPage }, true);
|
|
707
812
|
}, [hasMore, loading, meta, params, fetchOrders]);
|
|
708
|
-
const refresh = (0,
|
|
813
|
+
const refresh = (0, import_react8.useCallback)(async () => {
|
|
709
814
|
await fetchOrders(params);
|
|
710
815
|
}, [params, fetchOrders]);
|
|
711
816
|
return {
|
|
@@ -720,10 +825,10 @@ function useOrders(params) {
|
|
|
720
825
|
}
|
|
721
826
|
function useOrder(idOrNumber) {
|
|
722
827
|
const client = useClient();
|
|
723
|
-
const [order, setOrder] = (0,
|
|
724
|
-
const [loading, setLoading] = (0,
|
|
725
|
-
const [error, setError] = (0,
|
|
726
|
-
const fetchOrder = (0,
|
|
828
|
+
const [order, setOrder] = (0, import_react8.useState)(null);
|
|
829
|
+
const [loading, setLoading] = (0, import_react8.useState)(true);
|
|
830
|
+
const [error, setError] = (0, import_react8.useState)(null);
|
|
831
|
+
const fetchOrder = (0, import_react8.useCallback)(async () => {
|
|
727
832
|
setLoading(true);
|
|
728
833
|
setError(null);
|
|
729
834
|
try {
|
|
@@ -735,10 +840,10 @@ function useOrder(idOrNumber) {
|
|
|
735
840
|
setLoading(false);
|
|
736
841
|
}
|
|
737
842
|
}, [client, idOrNumber]);
|
|
738
|
-
(0,
|
|
843
|
+
(0, import_react8.useEffect)(() => {
|
|
739
844
|
fetchOrder();
|
|
740
845
|
}, [fetchOrder]);
|
|
741
|
-
const cancel = (0,
|
|
846
|
+
const cancel = (0, import_react8.useCallback)(async () => {
|
|
742
847
|
if (!order) throw new Error("Order not loaded");
|
|
743
848
|
const cancelled = await client.shop.cancelOrder(order.id);
|
|
744
849
|
setOrder(cancelled);
|
|
@@ -754,9 +859,9 @@ function useOrder(idOrNumber) {
|
|
|
754
859
|
}
|
|
755
860
|
function useCreateOrder() {
|
|
756
861
|
const client = useClient();
|
|
757
|
-
const [loading, setLoading] = (0,
|
|
758
|
-
const [error, setError] = (0,
|
|
759
|
-
const createOrder = (0,
|
|
862
|
+
const [loading, setLoading] = (0, import_react8.useState)(false);
|
|
863
|
+
const [error, setError] = (0, import_react8.useState)(null);
|
|
864
|
+
const createOrder = (0, import_react8.useCallback)(async (data) => {
|
|
760
865
|
setLoading(true);
|
|
761
866
|
setError(null);
|
|
762
867
|
try {
|
|
@@ -777,13 +882,19 @@ function useCreateOrder() {
|
|
|
777
882
|
}
|
|
778
883
|
|
|
779
884
|
// src/hooks/usePayment.ts
|
|
780
|
-
var
|
|
885
|
+
var import_react9 = require("react");
|
|
886
|
+
var DEFAULT_CURRENCY2 = {
|
|
887
|
+
code: "KRW",
|
|
888
|
+
symbol: "\u20A9",
|
|
889
|
+
position: "before",
|
|
890
|
+
decimals: 0
|
|
891
|
+
};
|
|
781
892
|
function usePaymentStatus() {
|
|
782
893
|
const client = useClient();
|
|
783
|
-
const [status, setStatus] = (0,
|
|
784
|
-
const [loading, setLoading] = (0,
|
|
785
|
-
const [error, setError] = (0,
|
|
786
|
-
const fetchStatus = (0,
|
|
894
|
+
const [status, setStatus] = (0, import_react9.useState)(null);
|
|
895
|
+
const [loading, setLoading] = (0, import_react9.useState)(true);
|
|
896
|
+
const [error, setError] = (0, import_react9.useState)(null);
|
|
897
|
+
const fetchStatus = (0, import_react9.useCallback)(async () => {
|
|
787
898
|
setLoading(true);
|
|
788
899
|
setError(null);
|
|
789
900
|
try {
|
|
@@ -795,11 +906,25 @@ function usePaymentStatus() {
|
|
|
795
906
|
setLoading(false);
|
|
796
907
|
}
|
|
797
908
|
}, [client]);
|
|
909
|
+
const currency = status?.currency ?? null;
|
|
910
|
+
const formatPrice = (0, import_react9.useCallback)((amount) => {
|
|
911
|
+
const curr = currency ?? DEFAULT_CURRENCY2;
|
|
912
|
+
const formatted = amount.toLocaleString(void 0, {
|
|
913
|
+
minimumFractionDigits: curr.decimals,
|
|
914
|
+
maximumFractionDigits: curr.decimals
|
|
915
|
+
});
|
|
916
|
+
if (curr.position === "after") {
|
|
917
|
+
return `${formatted}${curr.symbol}`;
|
|
918
|
+
}
|
|
919
|
+
return `${curr.symbol}${formatted}`;
|
|
920
|
+
}, [currency]);
|
|
798
921
|
return {
|
|
799
922
|
status,
|
|
800
923
|
loading,
|
|
801
924
|
error,
|
|
802
925
|
refresh: fetchStatus,
|
|
926
|
+
currency,
|
|
927
|
+
formatPrice,
|
|
803
928
|
isTossAvailable: status?.toss?.available ?? false,
|
|
804
929
|
isStripeAvailable: status?.stripe?.available ?? false,
|
|
805
930
|
stripePublishableKey: status?.stripe?.publishable_key ?? null
|
|
@@ -807,9 +932,9 @@ function usePaymentStatus() {
|
|
|
807
932
|
}
|
|
808
933
|
function useTossPayment() {
|
|
809
934
|
const client = useClient();
|
|
810
|
-
const [loading, setLoading] = (0,
|
|
811
|
-
const [error, setError] = (0,
|
|
812
|
-
const preparePayment = (0,
|
|
935
|
+
const [loading, setLoading] = (0, import_react9.useState)(false);
|
|
936
|
+
const [error, setError] = (0, import_react9.useState)(null);
|
|
937
|
+
const preparePayment = (0, import_react9.useCallback)(async (orderNumber, successUrl, failUrl) => {
|
|
813
938
|
setLoading(true);
|
|
814
939
|
setError(null);
|
|
815
940
|
try {
|
|
@@ -826,7 +951,7 @@ function useTossPayment() {
|
|
|
826
951
|
setLoading(false);
|
|
827
952
|
}
|
|
828
953
|
}, [client]);
|
|
829
|
-
const confirmPayment = (0,
|
|
954
|
+
const confirmPayment = (0, import_react9.useCallback)(async (paymentKey, orderId, amount) => {
|
|
830
955
|
setLoading(true);
|
|
831
956
|
setError(null);
|
|
832
957
|
try {
|
|
@@ -843,7 +968,7 @@ function useTossPayment() {
|
|
|
843
968
|
setLoading(false);
|
|
844
969
|
}
|
|
845
970
|
}, [client]);
|
|
846
|
-
const cancelPayment = (0,
|
|
971
|
+
const cancelPayment = (0, import_react9.useCallback)(async (orderNumber, reason, amount) => {
|
|
847
972
|
setLoading(true);
|
|
848
973
|
setError(null);
|
|
849
974
|
try {
|
|
@@ -866,9 +991,9 @@ function useTossPayment() {
|
|
|
866
991
|
}
|
|
867
992
|
function useStripePayment() {
|
|
868
993
|
const client = useClient();
|
|
869
|
-
const [loading, setLoading] = (0,
|
|
870
|
-
const [error, setError] = (0,
|
|
871
|
-
const createCheckout = (0,
|
|
994
|
+
const [loading, setLoading] = (0, import_react9.useState)(false);
|
|
995
|
+
const [error, setError] = (0, import_react9.useState)(null);
|
|
996
|
+
const createCheckout = (0, import_react9.useCallback)(async (orderNumber, successUrl, cancelUrl) => {
|
|
872
997
|
setLoading(true);
|
|
873
998
|
setError(null);
|
|
874
999
|
try {
|
|
@@ -885,7 +1010,7 @@ function useStripePayment() {
|
|
|
885
1010
|
setLoading(false);
|
|
886
1011
|
}
|
|
887
1012
|
}, [client]);
|
|
888
|
-
const verifyPayment = (0,
|
|
1013
|
+
const verifyPayment = (0, import_react9.useCallback)(async (sessionId) => {
|
|
889
1014
|
setLoading(true);
|
|
890
1015
|
setError(null);
|
|
891
1016
|
try {
|
|
@@ -898,7 +1023,7 @@ function useStripePayment() {
|
|
|
898
1023
|
setLoading(false);
|
|
899
1024
|
}
|
|
900
1025
|
}, [client]);
|
|
901
|
-
const refund = (0,
|
|
1026
|
+
const refund = (0, import_react9.useCallback)(async (orderNumber, reason, amount) => {
|
|
902
1027
|
setLoading(true);
|
|
903
1028
|
setError(null);
|
|
904
1029
|
try {
|
|
@@ -921,13 +1046,13 @@ function useStripePayment() {
|
|
|
921
1046
|
}
|
|
922
1047
|
|
|
923
1048
|
// src/hooks/useCoupons.ts
|
|
924
|
-
var
|
|
1049
|
+
var import_react10 = require("react");
|
|
925
1050
|
function useCoupons() {
|
|
926
1051
|
const client = useClient();
|
|
927
|
-
const [coupons, setCoupons] = (0,
|
|
928
|
-
const [loading, setLoading] = (0,
|
|
929
|
-
const [error, setError] = (0,
|
|
930
|
-
const fetchCoupons = (0,
|
|
1052
|
+
const [coupons, setCoupons] = (0, import_react10.useState)([]);
|
|
1053
|
+
const [loading, setLoading] = (0, import_react10.useState)(true);
|
|
1054
|
+
const [error, setError] = (0, import_react10.useState)(null);
|
|
1055
|
+
const fetchCoupons = (0, import_react10.useCallback)(async () => {
|
|
931
1056
|
if (!client.isAuthenticated()) {
|
|
932
1057
|
setCoupons([]);
|
|
933
1058
|
setLoading(false);
|
|
@@ -944,7 +1069,7 @@ function useCoupons() {
|
|
|
944
1069
|
setLoading(false);
|
|
945
1070
|
}
|
|
946
1071
|
}, [client]);
|
|
947
|
-
(0,
|
|
1072
|
+
(0, import_react10.useEffect)(() => {
|
|
948
1073
|
fetchCoupons();
|
|
949
1074
|
}, [fetchCoupons]);
|
|
950
1075
|
return {
|
|
@@ -956,10 +1081,10 @@ function useCoupons() {
|
|
|
956
1081
|
}
|
|
957
1082
|
function useValidateCoupon() {
|
|
958
1083
|
const client = useClient();
|
|
959
|
-
const [validation, setValidation] = (0,
|
|
960
|
-
const [loading, setLoading] = (0,
|
|
961
|
-
const [error, setError] = (0,
|
|
962
|
-
const validate = (0,
|
|
1084
|
+
const [validation, setValidation] = (0, import_react10.useState)(null);
|
|
1085
|
+
const [loading, setLoading] = (0, import_react10.useState)(false);
|
|
1086
|
+
const [error, setError] = (0, import_react10.useState)(null);
|
|
1087
|
+
const validate = (0, import_react10.useCallback)(async (code, orderAmount) => {
|
|
963
1088
|
setLoading(true);
|
|
964
1089
|
setError(null);
|
|
965
1090
|
try {
|
|
@@ -975,7 +1100,7 @@ function useValidateCoupon() {
|
|
|
975
1100
|
setLoading(false);
|
|
976
1101
|
}
|
|
977
1102
|
}, [client]);
|
|
978
|
-
const reset = (0,
|
|
1103
|
+
const reset = (0, import_react10.useCallback)(() => {
|
|
979
1104
|
setValidation(null);
|
|
980
1105
|
setError(null);
|
|
981
1106
|
}, []);
|
|
@@ -989,13 +1114,13 @@ function useValidateCoupon() {
|
|
|
989
1114
|
}
|
|
990
1115
|
|
|
991
1116
|
// src/hooks/useSubscriptions.ts
|
|
992
|
-
var
|
|
1117
|
+
var import_react11 = require("react");
|
|
993
1118
|
function useSubscriptions() {
|
|
994
1119
|
const client = useClient();
|
|
995
|
-
const [subscriptions, setSubscriptions] = (0,
|
|
996
|
-
const [loading, setLoading] = (0,
|
|
997
|
-
const [error, setError] = (0,
|
|
998
|
-
const fetchSubscriptions = (0,
|
|
1120
|
+
const [subscriptions, setSubscriptions] = (0, import_react11.useState)([]);
|
|
1121
|
+
const [loading, setLoading] = (0, import_react11.useState)(true);
|
|
1122
|
+
const [error, setError] = (0, import_react11.useState)(null);
|
|
1123
|
+
const fetchSubscriptions = (0, import_react11.useCallback)(async () => {
|
|
999
1124
|
if (!client.isAuthenticated()) {
|
|
1000
1125
|
setSubscriptions([]);
|
|
1001
1126
|
setLoading(false);
|
|
@@ -1012,7 +1137,7 @@ function useSubscriptions() {
|
|
|
1012
1137
|
setLoading(false);
|
|
1013
1138
|
}
|
|
1014
1139
|
}, [client]);
|
|
1015
|
-
(0,
|
|
1140
|
+
(0, import_react11.useEffect)(() => {
|
|
1016
1141
|
fetchSubscriptions();
|
|
1017
1142
|
}, [fetchSubscriptions]);
|
|
1018
1143
|
const activeSubscription = subscriptions.find((s) => s.is_active) ?? null;
|
|
@@ -1028,10 +1153,10 @@ function useSubscriptions() {
|
|
|
1028
1153
|
}
|
|
1029
1154
|
function useSubscription(id) {
|
|
1030
1155
|
const client = useClient();
|
|
1031
|
-
const [subscription, setSubscription] = (0,
|
|
1032
|
-
const [loading, setLoading] = (0,
|
|
1033
|
-
const [error, setError] = (0,
|
|
1034
|
-
const fetchSubscription = (0,
|
|
1156
|
+
const [subscription, setSubscription] = (0, import_react11.useState)(null);
|
|
1157
|
+
const [loading, setLoading] = (0, import_react11.useState)(true);
|
|
1158
|
+
const [error, setError] = (0, import_react11.useState)(null);
|
|
1159
|
+
const fetchSubscription = (0, import_react11.useCallback)(async () => {
|
|
1035
1160
|
setLoading(true);
|
|
1036
1161
|
setError(null);
|
|
1037
1162
|
try {
|
|
@@ -1043,20 +1168,20 @@ function useSubscription(id) {
|
|
|
1043
1168
|
setLoading(false);
|
|
1044
1169
|
}
|
|
1045
1170
|
}, [client, id]);
|
|
1046
|
-
(0,
|
|
1171
|
+
(0, import_react11.useEffect)(() => {
|
|
1047
1172
|
fetchSubscription();
|
|
1048
1173
|
}, [fetchSubscription]);
|
|
1049
|
-
const cancel = (0,
|
|
1174
|
+
const cancel = (0, import_react11.useCallback)(async (immediately = false) => {
|
|
1050
1175
|
const updated = await client.shop.cancelSubscription(id, immediately);
|
|
1051
1176
|
setSubscription(updated);
|
|
1052
1177
|
return updated;
|
|
1053
1178
|
}, [client, id]);
|
|
1054
|
-
const pause = (0,
|
|
1179
|
+
const pause = (0, import_react11.useCallback)(async () => {
|
|
1055
1180
|
const updated = await client.shop.pauseSubscription(id);
|
|
1056
1181
|
setSubscription(updated);
|
|
1057
1182
|
return updated;
|
|
1058
1183
|
}, [client, id]);
|
|
1059
|
-
const resume = (0,
|
|
1184
|
+
const resume = (0, import_react11.useCallback)(async () => {
|
|
1060
1185
|
const updated = await client.shop.resumeSubscription(id);
|
|
1061
1186
|
setSubscription(updated);
|
|
1062
1187
|
return updated;
|
|
@@ -1073,9 +1198,9 @@ function useSubscription(id) {
|
|
|
1073
1198
|
}
|
|
1074
1199
|
function useCreateSubscription() {
|
|
1075
1200
|
const client = useClient();
|
|
1076
|
-
const [loading, setLoading] = (0,
|
|
1077
|
-
const [error, setError] = (0,
|
|
1078
|
-
const createCheckout = (0,
|
|
1201
|
+
const [loading, setLoading] = (0, import_react11.useState)(false);
|
|
1202
|
+
const [error, setError] = (0, import_react11.useState)(null);
|
|
1203
|
+
const createCheckout = (0, import_react11.useCallback)(async (planId, successUrl, cancelUrl) => {
|
|
1079
1204
|
setLoading(true);
|
|
1080
1205
|
setError(null);
|
|
1081
1206
|
try {
|
|
@@ -1092,7 +1217,7 @@ function useCreateSubscription() {
|
|
|
1092
1217
|
setLoading(false);
|
|
1093
1218
|
}
|
|
1094
1219
|
}, [client]);
|
|
1095
|
-
const verifyCheckout = (0,
|
|
1220
|
+
const verifyCheckout = (0, import_react11.useCallback)(async (sessionId) => {
|
|
1096
1221
|
setLoading(true);
|
|
1097
1222
|
setError(null);
|
|
1098
1223
|
try {
|
|
@@ -1106,7 +1231,7 @@ function useCreateSubscription() {
|
|
|
1106
1231
|
setLoading(false);
|
|
1107
1232
|
}
|
|
1108
1233
|
}, [client]);
|
|
1109
|
-
const createSetupIntent = (0,
|
|
1234
|
+
const createSetupIntent = (0, import_react11.useCallback)(async () => {
|
|
1110
1235
|
setLoading(true);
|
|
1111
1236
|
setError(null);
|
|
1112
1237
|
try {
|
|
@@ -1130,13 +1255,13 @@ function useCreateSubscription() {
|
|
|
1130
1255
|
}
|
|
1131
1256
|
|
|
1132
1257
|
// src/hooks/useDownloads.ts
|
|
1133
|
-
var
|
|
1258
|
+
var import_react12 = require("react");
|
|
1134
1259
|
function useDownloads() {
|
|
1135
1260
|
const client = useClient();
|
|
1136
|
-
const [downloads, setDownloads] = (0,
|
|
1137
|
-
const [loading, setLoading] = (0,
|
|
1138
|
-
const [error, setError] = (0,
|
|
1139
|
-
const fetchDownloads = (0,
|
|
1261
|
+
const [downloads, setDownloads] = (0, import_react12.useState)([]);
|
|
1262
|
+
const [loading, setLoading] = (0, import_react12.useState)(true);
|
|
1263
|
+
const [error, setError] = (0, import_react12.useState)(null);
|
|
1264
|
+
const fetchDownloads = (0, import_react12.useCallback)(async () => {
|
|
1140
1265
|
if (!client.isAuthenticated()) {
|
|
1141
1266
|
setDownloads([]);
|
|
1142
1267
|
setLoading(false);
|
|
@@ -1153,13 +1278,13 @@ function useDownloads() {
|
|
|
1153
1278
|
setLoading(false);
|
|
1154
1279
|
}
|
|
1155
1280
|
}, [client]);
|
|
1156
|
-
(0,
|
|
1281
|
+
(0, import_react12.useEffect)(() => {
|
|
1157
1282
|
fetchDownloads();
|
|
1158
1283
|
}, [fetchDownloads]);
|
|
1159
|
-
const getDownloadUrl = (0,
|
|
1284
|
+
const getDownloadUrl = (0, import_react12.useCallback)((token) => {
|
|
1160
1285
|
return client.shop.getDownloadUrl(token);
|
|
1161
1286
|
}, [client]);
|
|
1162
|
-
const getDownloadInfo = (0,
|
|
1287
|
+
const getDownloadInfo = (0, import_react12.useCallback)(async (token) => {
|
|
1163
1288
|
return await client.shop.getDownloadInfo(token);
|
|
1164
1289
|
}, [client]);
|
|
1165
1290
|
return {
|
|
@@ -1173,10 +1298,10 @@ function useDownloads() {
|
|
|
1173
1298
|
}
|
|
1174
1299
|
function useOrderDownloads(orderNumber) {
|
|
1175
1300
|
const client = useClient();
|
|
1176
|
-
const [downloads, setDownloads] = (0,
|
|
1177
|
-
const [loading, setLoading] = (0,
|
|
1178
|
-
const [error, setError] = (0,
|
|
1179
|
-
const fetchDownloads = (0,
|
|
1301
|
+
const [downloads, setDownloads] = (0, import_react12.useState)([]);
|
|
1302
|
+
const [loading, setLoading] = (0, import_react12.useState)(true);
|
|
1303
|
+
const [error, setError] = (0, import_react12.useState)(null);
|
|
1304
|
+
const fetchDownloads = (0, import_react12.useCallback)(async () => {
|
|
1180
1305
|
if (!client.isAuthenticated()) {
|
|
1181
1306
|
setDownloads([]);
|
|
1182
1307
|
setLoading(false);
|
|
@@ -1193,13 +1318,13 @@ function useOrderDownloads(orderNumber) {
|
|
|
1193
1318
|
setLoading(false);
|
|
1194
1319
|
}
|
|
1195
1320
|
}, [client, orderNumber]);
|
|
1196
|
-
(0,
|
|
1321
|
+
(0, import_react12.useEffect)(() => {
|
|
1197
1322
|
fetchDownloads();
|
|
1198
1323
|
}, [fetchDownloads]);
|
|
1199
|
-
const getDownloadUrl = (0,
|
|
1324
|
+
const getDownloadUrl = (0, import_react12.useCallback)((token) => {
|
|
1200
1325
|
return client.shop.getDownloadUrl(token);
|
|
1201
1326
|
}, [client]);
|
|
1202
|
-
const getDownloadInfo = (0,
|
|
1327
|
+
const getDownloadInfo = (0, import_react12.useCallback)(async (token) => {
|
|
1203
1328
|
return await client.shop.getDownloadInfo(token);
|
|
1204
1329
|
}, [client]);
|
|
1205
1330
|
return {
|
|
@@ -1213,15 +1338,15 @@ function useOrderDownloads(orderNumber) {
|
|
|
1213
1338
|
}
|
|
1214
1339
|
|
|
1215
1340
|
// src/hooks/useReviews.ts
|
|
1216
|
-
var
|
|
1341
|
+
var import_react13 = require("react");
|
|
1217
1342
|
function useProductReviews(productSlug, params) {
|
|
1218
1343
|
const client = useClient();
|
|
1219
|
-
const [reviews, setReviews] = (0,
|
|
1220
|
-
const [stats, setStats] = (0,
|
|
1221
|
-
const [meta, setMeta] = (0,
|
|
1222
|
-
const [loading, setLoading] = (0,
|
|
1223
|
-
const [error, setError] = (0,
|
|
1224
|
-
const fetchReviews = (0,
|
|
1344
|
+
const [reviews, setReviews] = (0, import_react13.useState)([]);
|
|
1345
|
+
const [stats, setStats] = (0, import_react13.useState)(null);
|
|
1346
|
+
const [meta, setMeta] = (0, import_react13.useState)(null);
|
|
1347
|
+
const [loading, setLoading] = (0, import_react13.useState)(true);
|
|
1348
|
+
const [error, setError] = (0, import_react13.useState)(null);
|
|
1349
|
+
const fetchReviews = (0, import_react13.useCallback)(async () => {
|
|
1225
1350
|
setLoading(true);
|
|
1226
1351
|
setError(null);
|
|
1227
1352
|
try {
|
|
@@ -1235,7 +1360,7 @@ function useProductReviews(productSlug, params) {
|
|
|
1235
1360
|
setLoading(false);
|
|
1236
1361
|
}
|
|
1237
1362
|
}, [client, productSlug, params]);
|
|
1238
|
-
(0,
|
|
1363
|
+
(0, import_react13.useEffect)(() => {
|
|
1239
1364
|
fetchReviews();
|
|
1240
1365
|
}, [fetchReviews]);
|
|
1241
1366
|
return {
|
|
@@ -1249,11 +1374,11 @@ function useProductReviews(productSlug, params) {
|
|
|
1249
1374
|
}
|
|
1250
1375
|
function useCanReview(productSlug) {
|
|
1251
1376
|
const client = useClient();
|
|
1252
|
-
const [canReview, setCanReview] = (0,
|
|
1253
|
-
const [reason, setReason] = (0,
|
|
1254
|
-
const [loading, setLoading] = (0,
|
|
1255
|
-
const [error, setError] = (0,
|
|
1256
|
-
const check = (0,
|
|
1377
|
+
const [canReview, setCanReview] = (0, import_react13.useState)(false);
|
|
1378
|
+
const [reason, setReason] = (0, import_react13.useState)(null);
|
|
1379
|
+
const [loading, setLoading] = (0, import_react13.useState)(true);
|
|
1380
|
+
const [error, setError] = (0, import_react13.useState)(null);
|
|
1381
|
+
const check = (0, import_react13.useCallback)(async () => {
|
|
1257
1382
|
setLoading(true);
|
|
1258
1383
|
setError(null);
|
|
1259
1384
|
try {
|
|
@@ -1268,7 +1393,7 @@ function useCanReview(productSlug) {
|
|
|
1268
1393
|
setLoading(false);
|
|
1269
1394
|
}
|
|
1270
1395
|
}, [client, productSlug]);
|
|
1271
|
-
(0,
|
|
1396
|
+
(0, import_react13.useEffect)(() => {
|
|
1272
1397
|
if (client.isAuthenticated()) {
|
|
1273
1398
|
check();
|
|
1274
1399
|
} else {
|
|
@@ -1287,9 +1412,9 @@ function useCanReview(productSlug) {
|
|
|
1287
1412
|
}
|
|
1288
1413
|
function useCreateReview() {
|
|
1289
1414
|
const client = useClient();
|
|
1290
|
-
const [loading, setLoading] = (0,
|
|
1291
|
-
const [error, setError] = (0,
|
|
1292
|
-
const createReview = (0,
|
|
1415
|
+
const [loading, setLoading] = (0, import_react13.useState)(false);
|
|
1416
|
+
const [error, setError] = (0, import_react13.useState)(null);
|
|
1417
|
+
const createReview = (0, import_react13.useCallback)(async (productSlug, data) => {
|
|
1293
1418
|
setLoading(true);
|
|
1294
1419
|
setError(null);
|
|
1295
1420
|
try {
|
|
@@ -1310,11 +1435,11 @@ function useCreateReview() {
|
|
|
1310
1435
|
}
|
|
1311
1436
|
function useMyReviews(params) {
|
|
1312
1437
|
const client = useClient();
|
|
1313
|
-
const [reviews, setReviews] = (0,
|
|
1314
|
-
const [meta, setMeta] = (0,
|
|
1315
|
-
const [loading, setLoading] = (0,
|
|
1316
|
-
const [error, setError] = (0,
|
|
1317
|
-
const fetchReviews = (0,
|
|
1438
|
+
const [reviews, setReviews] = (0, import_react13.useState)([]);
|
|
1439
|
+
const [meta, setMeta] = (0, import_react13.useState)(null);
|
|
1440
|
+
const [loading, setLoading] = (0, import_react13.useState)(true);
|
|
1441
|
+
const [error, setError] = (0, import_react13.useState)(null);
|
|
1442
|
+
const fetchReviews = (0, import_react13.useCallback)(async () => {
|
|
1318
1443
|
if (!client.isAuthenticated()) {
|
|
1319
1444
|
setReviews([]);
|
|
1320
1445
|
setLoading(false);
|
|
@@ -1332,14 +1457,14 @@ function useMyReviews(params) {
|
|
|
1332
1457
|
setLoading(false);
|
|
1333
1458
|
}
|
|
1334
1459
|
}, [client, params]);
|
|
1335
|
-
(0,
|
|
1460
|
+
(0, import_react13.useEffect)(() => {
|
|
1336
1461
|
fetchReviews();
|
|
1337
1462
|
}, [fetchReviews]);
|
|
1338
|
-
const deleteReview = (0,
|
|
1463
|
+
const deleteReview = (0, import_react13.useCallback)(async (reviewId) => {
|
|
1339
1464
|
await client.shop.deleteReview(reviewId);
|
|
1340
1465
|
setReviews((prev) => prev.filter((r) => r.id !== reviewId));
|
|
1341
1466
|
}, [client]);
|
|
1342
|
-
const updateReview = (0,
|
|
1467
|
+
const updateReview = (0, import_react13.useCallback)(async (reviewId, data) => {
|
|
1343
1468
|
const updated = await client.shop.updateReview(reviewId, data);
|
|
1344
1469
|
setReviews((prev) => prev.map((r) => r.id === reviewId ? updated : r));
|
|
1345
1470
|
return updated;
|
|
@@ -1356,16 +1481,16 @@ function useMyReviews(params) {
|
|
|
1356
1481
|
}
|
|
1357
1482
|
|
|
1358
1483
|
// src/hooks/useBlog.ts
|
|
1359
|
-
var
|
|
1484
|
+
var import_react14 = require("react");
|
|
1360
1485
|
function useBlog(options = {}) {
|
|
1361
1486
|
const { autoFetch = true, ...params } = options;
|
|
1362
1487
|
const client = useClient();
|
|
1363
|
-
const [posts, setPosts] = (0,
|
|
1364
|
-
const [meta, setMeta] = (0,
|
|
1365
|
-
const [loading, setLoading] = (0,
|
|
1366
|
-
const [error, setError] = (0,
|
|
1367
|
-
const [currentParams, setCurrentParams] = (0,
|
|
1368
|
-
const fetchPosts = (0,
|
|
1488
|
+
const [posts, setPosts] = (0, import_react14.useState)([]);
|
|
1489
|
+
const [meta, setMeta] = (0, import_react14.useState)(null);
|
|
1490
|
+
const [loading, setLoading] = (0, import_react14.useState)(autoFetch);
|
|
1491
|
+
const [error, setError] = (0, import_react14.useState)(null);
|
|
1492
|
+
const [currentParams, setCurrentParams] = (0, import_react14.useState)(params);
|
|
1493
|
+
const fetchPosts = (0, import_react14.useCallback)(async (fetchParams, append = false) => {
|
|
1369
1494
|
setLoading(true);
|
|
1370
1495
|
setError(null);
|
|
1371
1496
|
try {
|
|
@@ -1382,18 +1507,18 @@ function useBlog(options = {}) {
|
|
|
1382
1507
|
setLoading(false);
|
|
1383
1508
|
}
|
|
1384
1509
|
}, [client]);
|
|
1385
|
-
(0,
|
|
1510
|
+
(0, import_react14.useEffect)(() => {
|
|
1386
1511
|
if (autoFetch) {
|
|
1387
1512
|
fetchPosts(params);
|
|
1388
1513
|
}
|
|
1389
1514
|
}, []);
|
|
1390
1515
|
const hasMore = meta ? meta.current_page < meta.last_page : false;
|
|
1391
|
-
const loadMore = (0,
|
|
1516
|
+
const loadMore = (0, import_react14.useCallback)(async () => {
|
|
1392
1517
|
if (!hasMore || loading) return;
|
|
1393
1518
|
const nextPage = (meta?.current_page ?? 0) + 1;
|
|
1394
1519
|
await fetchPosts({ ...currentParams, page: nextPage }, true);
|
|
1395
1520
|
}, [hasMore, loading, meta, currentParams, fetchPosts]);
|
|
1396
|
-
const refresh = (0,
|
|
1521
|
+
const refresh = (0, import_react14.useCallback)(async () => {
|
|
1397
1522
|
setCurrentParams(params);
|
|
1398
1523
|
await fetchPosts(params);
|
|
1399
1524
|
}, [params, fetchPosts]);
|
|
@@ -1409,10 +1534,10 @@ function useBlog(options = {}) {
|
|
|
1409
1534
|
}
|
|
1410
1535
|
function useBlogPost(slug) {
|
|
1411
1536
|
const client = useClient();
|
|
1412
|
-
const [post, setPost] = (0,
|
|
1413
|
-
const [loading, setLoading] = (0,
|
|
1414
|
-
const [error, setError] = (0,
|
|
1415
|
-
const fetchPost = (0,
|
|
1537
|
+
const [post, setPost] = (0, import_react14.useState)(null);
|
|
1538
|
+
const [loading, setLoading] = (0, import_react14.useState)(true);
|
|
1539
|
+
const [error, setError] = (0, import_react14.useState)(null);
|
|
1540
|
+
const fetchPost = (0, import_react14.useCallback)(async () => {
|
|
1416
1541
|
setLoading(true);
|
|
1417
1542
|
setError(null);
|
|
1418
1543
|
try {
|
|
@@ -1424,7 +1549,7 @@ function useBlogPost(slug) {
|
|
|
1424
1549
|
setLoading(false);
|
|
1425
1550
|
}
|
|
1426
1551
|
}, [client, slug]);
|
|
1427
|
-
(0,
|
|
1552
|
+
(0, import_react14.useEffect)(() => {
|
|
1428
1553
|
fetchPost();
|
|
1429
1554
|
}, [fetchPost]);
|
|
1430
1555
|
return {
|
|
@@ -1436,10 +1561,10 @@ function useBlogPost(slug) {
|
|
|
1436
1561
|
}
|
|
1437
1562
|
function useBlogCategories() {
|
|
1438
1563
|
const client = useClient();
|
|
1439
|
-
const [categories, setCategories] = (0,
|
|
1440
|
-
const [loading, setLoading] = (0,
|
|
1441
|
-
const [error, setError] = (0,
|
|
1442
|
-
const fetchCategories = (0,
|
|
1564
|
+
const [categories, setCategories] = (0, import_react14.useState)([]);
|
|
1565
|
+
const [loading, setLoading] = (0, import_react14.useState)(true);
|
|
1566
|
+
const [error, setError] = (0, import_react14.useState)(null);
|
|
1567
|
+
const fetchCategories = (0, import_react14.useCallback)(async () => {
|
|
1443
1568
|
setLoading(true);
|
|
1444
1569
|
setError(null);
|
|
1445
1570
|
try {
|
|
@@ -1451,7 +1576,7 @@ function useBlogCategories() {
|
|
|
1451
1576
|
setLoading(false);
|
|
1452
1577
|
}
|
|
1453
1578
|
}, [client]);
|
|
1454
|
-
(0,
|
|
1579
|
+
(0, import_react14.useEffect)(() => {
|
|
1455
1580
|
fetchCategories();
|
|
1456
1581
|
}, [fetchCategories]);
|
|
1457
1582
|
return {
|
|
@@ -1463,10 +1588,10 @@ function useBlogCategories() {
|
|
|
1463
1588
|
}
|
|
1464
1589
|
function useBlogTags() {
|
|
1465
1590
|
const client = useClient();
|
|
1466
|
-
const [tags, setTags] = (0,
|
|
1467
|
-
const [loading, setLoading] = (0,
|
|
1468
|
-
const [error, setError] = (0,
|
|
1469
|
-
const fetchTags = (0,
|
|
1591
|
+
const [tags, setTags] = (0, import_react14.useState)([]);
|
|
1592
|
+
const [loading, setLoading] = (0, import_react14.useState)(true);
|
|
1593
|
+
const [error, setError] = (0, import_react14.useState)(null);
|
|
1594
|
+
const fetchTags = (0, import_react14.useCallback)(async () => {
|
|
1470
1595
|
setLoading(true);
|
|
1471
1596
|
setError(null);
|
|
1472
1597
|
try {
|
|
@@ -1478,7 +1603,7 @@ function useBlogTags() {
|
|
|
1478
1603
|
setLoading(false);
|
|
1479
1604
|
}
|
|
1480
1605
|
}, [client]);
|
|
1481
|
-
(0,
|
|
1606
|
+
(0, import_react14.useEffect)(() => {
|
|
1482
1607
|
fetchTags();
|
|
1483
1608
|
}, [fetchTags]);
|
|
1484
1609
|
return {
|
|
@@ -1490,10 +1615,10 @@ function useBlogTags() {
|
|
|
1490
1615
|
}
|
|
1491
1616
|
function useFeaturedBlog(limit = 5) {
|
|
1492
1617
|
const client = useClient();
|
|
1493
|
-
const [posts, setPosts] = (0,
|
|
1494
|
-
const [loading, setLoading] = (0,
|
|
1495
|
-
const [error, setError] = (0,
|
|
1496
|
-
const fetchPosts = (0,
|
|
1618
|
+
const [posts, setPosts] = (0, import_react14.useState)([]);
|
|
1619
|
+
const [loading, setLoading] = (0, import_react14.useState)(true);
|
|
1620
|
+
const [error, setError] = (0, import_react14.useState)(null);
|
|
1621
|
+
const fetchPosts = (0, import_react14.useCallback)(async () => {
|
|
1497
1622
|
setLoading(true);
|
|
1498
1623
|
setError(null);
|
|
1499
1624
|
try {
|
|
@@ -1505,7 +1630,7 @@ function useFeaturedBlog(limit = 5) {
|
|
|
1505
1630
|
setLoading(false);
|
|
1506
1631
|
}
|
|
1507
1632
|
}, [client, limit]);
|
|
1508
|
-
(0,
|
|
1633
|
+
(0, import_react14.useEffect)(() => {
|
|
1509
1634
|
fetchPosts();
|
|
1510
1635
|
}, [fetchPosts]);
|
|
1511
1636
|
return {
|
|
@@ -1517,11 +1642,11 @@ function useFeaturedBlog(limit = 5) {
|
|
|
1517
1642
|
}
|
|
1518
1643
|
function useBlogSearch() {
|
|
1519
1644
|
const client = useClient();
|
|
1520
|
-
const [posts, setPosts] = (0,
|
|
1521
|
-
const [meta, setMeta] = (0,
|
|
1522
|
-
const [loading, setLoading] = (0,
|
|
1523
|
-
const [error, setError] = (0,
|
|
1524
|
-
const search = (0,
|
|
1645
|
+
const [posts, setPosts] = (0, import_react14.useState)([]);
|
|
1646
|
+
const [meta, setMeta] = (0, import_react14.useState)(null);
|
|
1647
|
+
const [loading, setLoading] = (0, import_react14.useState)(false);
|
|
1648
|
+
const [error, setError] = (0, import_react14.useState)(null);
|
|
1649
|
+
const search = (0, import_react14.useCallback)(async (query) => {
|
|
1525
1650
|
setLoading(true);
|
|
1526
1651
|
setError(null);
|
|
1527
1652
|
try {
|
|
@@ -1544,13 +1669,13 @@ function useBlogSearch() {
|
|
|
1544
1669
|
}
|
|
1545
1670
|
|
|
1546
1671
|
// src/hooks/useBoards.ts
|
|
1547
|
-
var
|
|
1672
|
+
var import_react15 = require("react");
|
|
1548
1673
|
function useBoards(params) {
|
|
1549
1674
|
const client = useClient();
|
|
1550
|
-
const [boards, setBoards] = (0,
|
|
1551
|
-
const [loading, setLoading] = (0,
|
|
1552
|
-
const [error, setError] = (0,
|
|
1553
|
-
const fetchBoards = (0,
|
|
1675
|
+
const [boards, setBoards] = (0, import_react15.useState)([]);
|
|
1676
|
+
const [loading, setLoading] = (0, import_react15.useState)(true);
|
|
1677
|
+
const [error, setError] = (0, import_react15.useState)(null);
|
|
1678
|
+
const fetchBoards = (0, import_react15.useCallback)(async () => {
|
|
1554
1679
|
setLoading(true);
|
|
1555
1680
|
setError(null);
|
|
1556
1681
|
try {
|
|
@@ -1562,7 +1687,7 @@ function useBoards(params) {
|
|
|
1562
1687
|
setLoading(false);
|
|
1563
1688
|
}
|
|
1564
1689
|
}, [client, params]);
|
|
1565
|
-
(0,
|
|
1690
|
+
(0, import_react15.useEffect)(() => {
|
|
1566
1691
|
fetchBoards();
|
|
1567
1692
|
}, [fetchBoards]);
|
|
1568
1693
|
return {
|
|
@@ -1574,10 +1699,10 @@ function useBoards(params) {
|
|
|
1574
1699
|
}
|
|
1575
1700
|
function useBoard(slug) {
|
|
1576
1701
|
const client = useClient();
|
|
1577
|
-
const [board, setBoard] = (0,
|
|
1578
|
-
const [loading, setLoading] = (0,
|
|
1579
|
-
const [error, setError] = (0,
|
|
1580
|
-
const fetchBoard = (0,
|
|
1702
|
+
const [board, setBoard] = (0, import_react15.useState)(null);
|
|
1703
|
+
const [loading, setLoading] = (0, import_react15.useState)(true);
|
|
1704
|
+
const [error, setError] = (0, import_react15.useState)(null);
|
|
1705
|
+
const fetchBoard = (0, import_react15.useCallback)(async () => {
|
|
1581
1706
|
setLoading(true);
|
|
1582
1707
|
setError(null);
|
|
1583
1708
|
try {
|
|
@@ -1589,7 +1714,7 @@ function useBoard(slug) {
|
|
|
1589
1714
|
setLoading(false);
|
|
1590
1715
|
}
|
|
1591
1716
|
}, [client, slug]);
|
|
1592
|
-
(0,
|
|
1717
|
+
(0, import_react15.useEffect)(() => {
|
|
1593
1718
|
fetchBoard();
|
|
1594
1719
|
}, [fetchBoard]);
|
|
1595
1720
|
return {
|
|
@@ -1601,12 +1726,12 @@ function useBoard(slug) {
|
|
|
1601
1726
|
}
|
|
1602
1727
|
function useBoardPosts(boardSlug, params) {
|
|
1603
1728
|
const client = useClient();
|
|
1604
|
-
const [posts, setPosts] = (0,
|
|
1605
|
-
const [meta, setMeta] = (0,
|
|
1606
|
-
const [loading, setLoading] = (0,
|
|
1607
|
-
const [error, setError] = (0,
|
|
1608
|
-
const [currentParams, setCurrentParams] = (0,
|
|
1609
|
-
const fetchPosts = (0,
|
|
1729
|
+
const [posts, setPosts] = (0, import_react15.useState)([]);
|
|
1730
|
+
const [meta, setMeta] = (0, import_react15.useState)(null);
|
|
1731
|
+
const [loading, setLoading] = (0, import_react15.useState)(true);
|
|
1732
|
+
const [error, setError] = (0, import_react15.useState)(null);
|
|
1733
|
+
const [currentParams, setCurrentParams] = (0, import_react15.useState)(params);
|
|
1734
|
+
const fetchPosts = (0, import_react15.useCallback)(async (fetchParams, append = false) => {
|
|
1610
1735
|
setLoading(true);
|
|
1611
1736
|
setError(null);
|
|
1612
1737
|
try {
|
|
@@ -1623,16 +1748,16 @@ function useBoardPosts(boardSlug, params) {
|
|
|
1623
1748
|
setLoading(false);
|
|
1624
1749
|
}
|
|
1625
1750
|
}, [client, boardSlug]);
|
|
1626
|
-
(0,
|
|
1751
|
+
(0, import_react15.useEffect)(() => {
|
|
1627
1752
|
fetchPosts(params);
|
|
1628
1753
|
}, []);
|
|
1629
1754
|
const hasMore = meta ? meta.current_page < meta.last_page : false;
|
|
1630
|
-
const loadMore = (0,
|
|
1755
|
+
const loadMore = (0, import_react15.useCallback)(async () => {
|
|
1631
1756
|
if (!hasMore || loading) return;
|
|
1632
1757
|
const nextPage = (meta?.current_page ?? 0) + 1;
|
|
1633
1758
|
await fetchPosts({ ...currentParams, page: nextPage }, true);
|
|
1634
1759
|
}, [hasMore, loading, meta, currentParams, fetchPosts]);
|
|
1635
|
-
const refresh = (0,
|
|
1760
|
+
const refresh = (0, import_react15.useCallback)(async () => {
|
|
1636
1761
|
setCurrentParams(params);
|
|
1637
1762
|
await fetchPosts(params);
|
|
1638
1763
|
}, [params, fetchPosts]);
|
|
@@ -1648,10 +1773,10 @@ function useBoardPosts(boardSlug, params) {
|
|
|
1648
1773
|
}
|
|
1649
1774
|
function useBoardPost(postId) {
|
|
1650
1775
|
const client = useClient();
|
|
1651
|
-
const [post, setPost] = (0,
|
|
1652
|
-
const [loading, setLoading] = (0,
|
|
1653
|
-
const [error, setError] = (0,
|
|
1654
|
-
const fetchPost = (0,
|
|
1776
|
+
const [post, setPost] = (0, import_react15.useState)(null);
|
|
1777
|
+
const [loading, setLoading] = (0, import_react15.useState)(true);
|
|
1778
|
+
const [error, setError] = (0, import_react15.useState)(null);
|
|
1779
|
+
const fetchPost = (0, import_react15.useCallback)(async () => {
|
|
1655
1780
|
setLoading(true);
|
|
1656
1781
|
setError(null);
|
|
1657
1782
|
try {
|
|
@@ -1663,7 +1788,7 @@ function useBoardPost(postId) {
|
|
|
1663
1788
|
setLoading(false);
|
|
1664
1789
|
}
|
|
1665
1790
|
}, [client, postId]);
|
|
1666
|
-
(0,
|
|
1791
|
+
(0, import_react15.useEffect)(() => {
|
|
1667
1792
|
fetchPost();
|
|
1668
1793
|
}, [fetchPost]);
|
|
1669
1794
|
return {
|
|
@@ -1675,9 +1800,9 @@ function useBoardPost(postId) {
|
|
|
1675
1800
|
}
|
|
1676
1801
|
function useCreateBoardPost() {
|
|
1677
1802
|
const client = useClient();
|
|
1678
|
-
const [loading, setLoading] = (0,
|
|
1679
|
-
const [error, setError] = (0,
|
|
1680
|
-
const createPost = (0,
|
|
1803
|
+
const [loading, setLoading] = (0, import_react15.useState)(false);
|
|
1804
|
+
const [error, setError] = (0, import_react15.useState)(null);
|
|
1805
|
+
const createPost = (0, import_react15.useCallback)(async (data) => {
|
|
1681
1806
|
setLoading(true);
|
|
1682
1807
|
setError(null);
|
|
1683
1808
|
try {
|
|
@@ -1698,15 +1823,15 @@ function useCreateBoardPost() {
|
|
|
1698
1823
|
}
|
|
1699
1824
|
|
|
1700
1825
|
// src/hooks/useComments.ts
|
|
1701
|
-
var
|
|
1826
|
+
var import_react16 = require("react");
|
|
1702
1827
|
function useComments(options) {
|
|
1703
1828
|
const { type, target, page, per_page } = options;
|
|
1704
1829
|
const client = useClient();
|
|
1705
|
-
const [comments, setComments] = (0,
|
|
1706
|
-
const [meta, setMeta] = (0,
|
|
1707
|
-
const [loading, setLoading] = (0,
|
|
1708
|
-
const [error, setError] = (0,
|
|
1709
|
-
const fetchComments = (0,
|
|
1830
|
+
const [comments, setComments] = (0, import_react16.useState)([]);
|
|
1831
|
+
const [meta, setMeta] = (0, import_react16.useState)(null);
|
|
1832
|
+
const [loading, setLoading] = (0, import_react16.useState)(true);
|
|
1833
|
+
const [error, setError] = (0, import_react16.useState)(null);
|
|
1834
|
+
const fetchComments = (0, import_react16.useCallback)(async () => {
|
|
1710
1835
|
setLoading(true);
|
|
1711
1836
|
setError(null);
|
|
1712
1837
|
try {
|
|
@@ -1731,10 +1856,10 @@ function useComments(options) {
|
|
|
1731
1856
|
setLoading(false);
|
|
1732
1857
|
}
|
|
1733
1858
|
}, [client, type, target, page, per_page]);
|
|
1734
|
-
(0,
|
|
1859
|
+
(0, import_react16.useEffect)(() => {
|
|
1735
1860
|
fetchComments();
|
|
1736
1861
|
}, [fetchComments]);
|
|
1737
|
-
const createComment = (0,
|
|
1862
|
+
const createComment = (0, import_react16.useCallback)(async (data) => {
|
|
1738
1863
|
let response;
|
|
1739
1864
|
switch (type) {
|
|
1740
1865
|
case "board":
|
|
@@ -1750,16 +1875,16 @@ function useComments(options) {
|
|
|
1750
1875
|
await fetchComments();
|
|
1751
1876
|
return response.data;
|
|
1752
1877
|
}, [client, type, target, fetchComments]);
|
|
1753
|
-
const updateComment = (0,
|
|
1878
|
+
const updateComment = (0, import_react16.useCallback)(async (commentId, content) => {
|
|
1754
1879
|
const response = await client.comments.update(commentId, { content });
|
|
1755
1880
|
setComments((prev) => prev.map((c) => c.id === commentId ? response.data : c));
|
|
1756
1881
|
return response.data;
|
|
1757
1882
|
}, [client]);
|
|
1758
|
-
const deleteComment = (0,
|
|
1883
|
+
const deleteComment = (0, import_react16.useCallback)(async (commentId, password) => {
|
|
1759
1884
|
await client.comments.delete(commentId, password ? { password } : void 0);
|
|
1760
1885
|
setComments((prev) => prev.filter((c) => c.id !== commentId));
|
|
1761
1886
|
}, [client]);
|
|
1762
|
-
const likeComment = (0,
|
|
1887
|
+
const likeComment = (0, import_react16.useCallback)(async (commentId) => {
|
|
1763
1888
|
const response = await client.comments.like(commentId);
|
|
1764
1889
|
setComments((prev) => prev.map(
|
|
1765
1890
|
(c) => c.id === commentId ? { ...c, likes: response.data.likes } : c
|
|
@@ -1780,15 +1905,15 @@ function useComments(options) {
|
|
|
1780
1905
|
}
|
|
1781
1906
|
|
|
1782
1907
|
// src/hooks/useForms.ts
|
|
1783
|
-
var
|
|
1908
|
+
var import_react17 = require("react");
|
|
1784
1909
|
function useForm(formSlug) {
|
|
1785
1910
|
const client = useClient();
|
|
1786
|
-
const [form, setForm] = (0,
|
|
1787
|
-
const [loading, setLoading] = (0,
|
|
1788
|
-
const [error, setError] = (0,
|
|
1789
|
-
const [submitting, setSubmitting] = (0,
|
|
1790
|
-
const [submitted, setSubmitted] = (0,
|
|
1791
|
-
const fetchForm = (0,
|
|
1911
|
+
const [form, setForm] = (0, import_react17.useState)(null);
|
|
1912
|
+
const [loading, setLoading] = (0, import_react17.useState)(true);
|
|
1913
|
+
const [error, setError] = (0, import_react17.useState)(null);
|
|
1914
|
+
const [submitting, setSubmitting] = (0, import_react17.useState)(false);
|
|
1915
|
+
const [submitted, setSubmitted] = (0, import_react17.useState)(false);
|
|
1916
|
+
const fetchForm = (0, import_react17.useCallback)(async () => {
|
|
1792
1917
|
setLoading(true);
|
|
1793
1918
|
setError(null);
|
|
1794
1919
|
try {
|
|
@@ -1800,10 +1925,10 @@ function useForm(formSlug) {
|
|
|
1800
1925
|
setLoading(false);
|
|
1801
1926
|
}
|
|
1802
1927
|
}, [client, formSlug]);
|
|
1803
|
-
(0,
|
|
1928
|
+
(0, import_react17.useEffect)(() => {
|
|
1804
1929
|
fetchForm();
|
|
1805
1930
|
}, [fetchForm]);
|
|
1806
|
-
const submit = (0,
|
|
1931
|
+
const submit = (0, import_react17.useCallback)(async (data) => {
|
|
1807
1932
|
setSubmitting(true);
|
|
1808
1933
|
setError(null);
|
|
1809
1934
|
try {
|
|
@@ -1818,7 +1943,7 @@ function useForm(formSlug) {
|
|
|
1818
1943
|
setSubmitting(false);
|
|
1819
1944
|
}
|
|
1820
1945
|
}, [client, formSlug]);
|
|
1821
|
-
const reset = (0,
|
|
1946
|
+
const reset = (0, import_react17.useCallback)(() => {
|
|
1822
1947
|
setSubmitted(false);
|
|
1823
1948
|
setError(null);
|
|
1824
1949
|
}, []);
|
|
@@ -1834,13 +1959,13 @@ function useForm(formSlug) {
|
|
|
1834
1959
|
}
|
|
1835
1960
|
|
|
1836
1961
|
// src/hooks/useReservation.ts
|
|
1837
|
-
var
|
|
1962
|
+
var import_react18 = require("react");
|
|
1838
1963
|
function useReservationServices() {
|
|
1839
1964
|
const client = useClient();
|
|
1840
|
-
const [services, setServices] = (0,
|
|
1841
|
-
const [loading, setLoading] = (0,
|
|
1842
|
-
const [error, setError] = (0,
|
|
1843
|
-
const fetchServices = (0,
|
|
1965
|
+
const [services, setServices] = (0, import_react18.useState)([]);
|
|
1966
|
+
const [loading, setLoading] = (0, import_react18.useState)(true);
|
|
1967
|
+
const [error, setError] = (0, import_react18.useState)(null);
|
|
1968
|
+
const fetchServices = (0, import_react18.useCallback)(async () => {
|
|
1844
1969
|
setLoading(true);
|
|
1845
1970
|
setError(null);
|
|
1846
1971
|
try {
|
|
@@ -1852,7 +1977,7 @@ function useReservationServices() {
|
|
|
1852
1977
|
setLoading(false);
|
|
1853
1978
|
}
|
|
1854
1979
|
}, [client]);
|
|
1855
|
-
(0,
|
|
1980
|
+
(0, import_react18.useEffect)(() => {
|
|
1856
1981
|
fetchServices();
|
|
1857
1982
|
}, [fetchServices]);
|
|
1858
1983
|
return {
|
|
@@ -1864,10 +1989,10 @@ function useReservationServices() {
|
|
|
1864
1989
|
}
|
|
1865
1990
|
function useReservationStaffs() {
|
|
1866
1991
|
const client = useClient();
|
|
1867
|
-
const [staffs, setStaffs] = (0,
|
|
1868
|
-
const [loading, setLoading] = (0,
|
|
1869
|
-
const [error, setError] = (0,
|
|
1870
|
-
const fetchStaffs = (0,
|
|
1992
|
+
const [staffs, setStaffs] = (0, import_react18.useState)([]);
|
|
1993
|
+
const [loading, setLoading] = (0, import_react18.useState)(true);
|
|
1994
|
+
const [error, setError] = (0, import_react18.useState)(null);
|
|
1995
|
+
const fetchStaffs = (0, import_react18.useCallback)(async () => {
|
|
1871
1996
|
setLoading(true);
|
|
1872
1997
|
setError(null);
|
|
1873
1998
|
try {
|
|
@@ -1879,7 +2004,7 @@ function useReservationStaffs() {
|
|
|
1879
2004
|
setLoading(false);
|
|
1880
2005
|
}
|
|
1881
2006
|
}, [client]);
|
|
1882
|
-
(0,
|
|
2007
|
+
(0, import_react18.useEffect)(() => {
|
|
1883
2008
|
fetchStaffs();
|
|
1884
2009
|
}, [fetchStaffs]);
|
|
1885
2010
|
return {
|
|
@@ -1891,10 +2016,10 @@ function useReservationStaffs() {
|
|
|
1891
2016
|
}
|
|
1892
2017
|
function useAvailableSlots(serviceId, date, staffId) {
|
|
1893
2018
|
const client = useClient();
|
|
1894
|
-
const [slots, setSlots] = (0,
|
|
1895
|
-
const [loading, setLoading] = (0,
|
|
1896
|
-
const [error, setError] = (0,
|
|
1897
|
-
const fetchSlots = (0,
|
|
2019
|
+
const [slots, setSlots] = (0, import_react18.useState)([]);
|
|
2020
|
+
const [loading, setLoading] = (0, import_react18.useState)(true);
|
|
2021
|
+
const [error, setError] = (0, import_react18.useState)(null);
|
|
2022
|
+
const fetchSlots = (0, import_react18.useCallback)(async () => {
|
|
1898
2023
|
if (!serviceId || !date) {
|
|
1899
2024
|
setSlots([]);
|
|
1900
2025
|
setLoading(false);
|
|
@@ -1915,7 +2040,7 @@ function useAvailableSlots(serviceId, date, staffId) {
|
|
|
1915
2040
|
setLoading(false);
|
|
1916
2041
|
}
|
|
1917
2042
|
}, [client, serviceId, date, staffId]);
|
|
1918
|
-
(0,
|
|
2043
|
+
(0, import_react18.useEffect)(() => {
|
|
1919
2044
|
fetchSlots();
|
|
1920
2045
|
}, [fetchSlots]);
|
|
1921
2046
|
return {
|
|
@@ -1927,11 +2052,11 @@ function useAvailableSlots(serviceId, date, staffId) {
|
|
|
1927
2052
|
}
|
|
1928
2053
|
function useMyReservations(params) {
|
|
1929
2054
|
const client = useClient();
|
|
1930
|
-
const [reservations, setReservations] = (0,
|
|
1931
|
-
const [meta, setMeta] = (0,
|
|
1932
|
-
const [loading, setLoading] = (0,
|
|
1933
|
-
const [error, setError] = (0,
|
|
1934
|
-
const fetchReservations = (0,
|
|
2055
|
+
const [reservations, setReservations] = (0, import_react18.useState)([]);
|
|
2056
|
+
const [meta, setMeta] = (0, import_react18.useState)(null);
|
|
2057
|
+
const [loading, setLoading] = (0, import_react18.useState)(true);
|
|
2058
|
+
const [error, setError] = (0, import_react18.useState)(null);
|
|
2059
|
+
const fetchReservations = (0, import_react18.useCallback)(async () => {
|
|
1935
2060
|
if (!client.isAuthenticated()) {
|
|
1936
2061
|
setReservations([]);
|
|
1937
2062
|
setLoading(false);
|
|
@@ -1949,7 +2074,7 @@ function useMyReservations(params) {
|
|
|
1949
2074
|
setLoading(false);
|
|
1950
2075
|
}
|
|
1951
2076
|
}, [client, params]);
|
|
1952
|
-
(0,
|
|
2077
|
+
(0, import_react18.useEffect)(() => {
|
|
1953
2078
|
fetchReservations();
|
|
1954
2079
|
}, [fetchReservations]);
|
|
1955
2080
|
return {
|
|
@@ -1962,9 +2087,9 @@ function useMyReservations(params) {
|
|
|
1962
2087
|
}
|
|
1963
2088
|
function useCreateReservation() {
|
|
1964
2089
|
const client = useClient();
|
|
1965
|
-
const [loading, setLoading] = (0,
|
|
1966
|
-
const [error, setError] = (0,
|
|
1967
|
-
const createReservation = (0,
|
|
2090
|
+
const [loading, setLoading] = (0, import_react18.useState)(false);
|
|
2091
|
+
const [error, setError] = (0, import_react18.useState)(null);
|
|
2092
|
+
const createReservation = (0, import_react18.useCallback)(async (data) => {
|
|
1968
2093
|
setLoading(true);
|
|
1969
2094
|
setError(null);
|
|
1970
2095
|
try {
|
|
@@ -1986,10 +2111,10 @@ function useCreateReservation() {
|
|
|
1986
2111
|
}
|
|
1987
2112
|
function useReservationSettings() {
|
|
1988
2113
|
const client = useClient();
|
|
1989
|
-
const [settings, setSettings] = (0,
|
|
1990
|
-
const [loading, setLoading] = (0,
|
|
1991
|
-
const [error, setError] = (0,
|
|
1992
|
-
const fetchSettings = (0,
|
|
2114
|
+
const [settings, setSettings] = (0, import_react18.useState)(null);
|
|
2115
|
+
const [loading, setLoading] = (0, import_react18.useState)(true);
|
|
2116
|
+
const [error, setError] = (0, import_react18.useState)(null);
|
|
2117
|
+
const fetchSettings = (0, import_react18.useCallback)(async () => {
|
|
1993
2118
|
setLoading(true);
|
|
1994
2119
|
setError(null);
|
|
1995
2120
|
try {
|
|
@@ -2001,7 +2126,7 @@ function useReservationSettings() {
|
|
|
2001
2126
|
setLoading(false);
|
|
2002
2127
|
}
|
|
2003
2128
|
}, [client]);
|
|
2004
|
-
(0,
|
|
2129
|
+
(0, import_react18.useEffect)(() => {
|
|
2005
2130
|
fetchSettings();
|
|
2006
2131
|
}, [fetchSettings]);
|
|
2007
2132
|
return {
|
|
@@ -2013,17 +2138,17 @@ function useReservationSettings() {
|
|
|
2013
2138
|
}
|
|
2014
2139
|
|
|
2015
2140
|
// src/hooks/useMedia.ts
|
|
2016
|
-
var
|
|
2141
|
+
var import_react19 = require("react");
|
|
2017
2142
|
function useMedia(options = {}) {
|
|
2018
2143
|
const { type, page, per_page, autoFetch = true } = options;
|
|
2019
2144
|
const client = useClient();
|
|
2020
|
-
const [files, setFiles] = (0,
|
|
2021
|
-
const [meta, setMeta] = (0,
|
|
2022
|
-
const [loading, setLoading] = (0,
|
|
2023
|
-
const [error, setError] = (0,
|
|
2024
|
-
const [uploading, setUploading] = (0,
|
|
2025
|
-
const [uploadProgress, setUploadProgress] = (0,
|
|
2026
|
-
const fetchMedia = (0,
|
|
2145
|
+
const [files, setFiles] = (0, import_react19.useState)([]);
|
|
2146
|
+
const [meta, setMeta] = (0, import_react19.useState)(null);
|
|
2147
|
+
const [loading, setLoading] = (0, import_react19.useState)(autoFetch);
|
|
2148
|
+
const [error, setError] = (0, import_react19.useState)(null);
|
|
2149
|
+
const [uploading, setUploading] = (0, import_react19.useState)(false);
|
|
2150
|
+
const [uploadProgress, setUploadProgress] = (0, import_react19.useState)(0);
|
|
2151
|
+
const fetchMedia = (0, import_react19.useCallback)(async () => {
|
|
2027
2152
|
if (!client.isAuthenticated()) {
|
|
2028
2153
|
setFiles([]);
|
|
2029
2154
|
setLoading(false);
|
|
@@ -2041,12 +2166,12 @@ function useMedia(options = {}) {
|
|
|
2041
2166
|
setLoading(false);
|
|
2042
2167
|
}
|
|
2043
2168
|
}, [client, type, page, per_page]);
|
|
2044
|
-
(0,
|
|
2169
|
+
(0, import_react19.useEffect)(() => {
|
|
2045
2170
|
if (autoFetch) {
|
|
2046
2171
|
fetchMedia();
|
|
2047
2172
|
}
|
|
2048
2173
|
}, [autoFetch, fetchMedia]);
|
|
2049
|
-
const upload = (0,
|
|
2174
|
+
const upload = (0, import_react19.useCallback)(async (file) => {
|
|
2050
2175
|
setUploading(true);
|
|
2051
2176
|
setUploadProgress(0);
|
|
2052
2177
|
setError(null);
|
|
@@ -2063,7 +2188,7 @@ function useMedia(options = {}) {
|
|
|
2063
2188
|
setUploading(false);
|
|
2064
2189
|
}
|
|
2065
2190
|
}, [client]);
|
|
2066
|
-
const uploadMultiple = (0,
|
|
2191
|
+
const uploadMultiple = (0, import_react19.useCallback)(async (filesToUpload) => {
|
|
2067
2192
|
setUploading(true);
|
|
2068
2193
|
setUploadProgress(0);
|
|
2069
2194
|
setError(null);
|
|
@@ -2084,7 +2209,7 @@ function useMedia(options = {}) {
|
|
|
2084
2209
|
setUploading(false);
|
|
2085
2210
|
}
|
|
2086
2211
|
}, [client]);
|
|
2087
|
-
const deleteFile = (0,
|
|
2212
|
+
const deleteFile = (0, import_react19.useCallback)(async (mediaId) => {
|
|
2088
2213
|
await client.media.delete(mediaId);
|
|
2089
2214
|
setFiles((prev) => prev.filter((f) => f.id !== mediaId));
|
|
2090
2215
|
}, [client]);
|
|
@@ -2103,13 +2228,13 @@ function useMedia(options = {}) {
|
|
|
2103
2228
|
}
|
|
2104
2229
|
|
|
2105
2230
|
// src/hooks/useEntities.ts
|
|
2106
|
-
var
|
|
2231
|
+
var import_react20 = require("react");
|
|
2107
2232
|
function useEntities() {
|
|
2108
2233
|
const client = useClient();
|
|
2109
|
-
const [entities, setEntities] = (0,
|
|
2110
|
-
const [loading, setLoading] = (0,
|
|
2111
|
-
const [error, setError] = (0,
|
|
2112
|
-
const fetchEntities = (0,
|
|
2234
|
+
const [entities, setEntities] = (0, import_react20.useState)([]);
|
|
2235
|
+
const [loading, setLoading] = (0, import_react20.useState)(true);
|
|
2236
|
+
const [error, setError] = (0, import_react20.useState)(null);
|
|
2237
|
+
const fetchEntities = (0, import_react20.useCallback)(async () => {
|
|
2113
2238
|
setLoading(true);
|
|
2114
2239
|
setError(null);
|
|
2115
2240
|
try {
|
|
@@ -2121,7 +2246,7 @@ function useEntities() {
|
|
|
2121
2246
|
setLoading(false);
|
|
2122
2247
|
}
|
|
2123
2248
|
}, [client]);
|
|
2124
|
-
(0,
|
|
2249
|
+
(0, import_react20.useEffect)(() => {
|
|
2125
2250
|
fetchEntities();
|
|
2126
2251
|
}, [fetchEntities]);
|
|
2127
2252
|
return {
|
|
@@ -2133,10 +2258,10 @@ function useEntities() {
|
|
|
2133
2258
|
}
|
|
2134
2259
|
function useEntity(slug) {
|
|
2135
2260
|
const client = useClient();
|
|
2136
|
-
const [entity, setEntity] = (0,
|
|
2137
|
-
const [loading, setLoading] = (0,
|
|
2138
|
-
const [error, setError] = (0,
|
|
2139
|
-
const fetchEntity = (0,
|
|
2261
|
+
const [entity, setEntity] = (0, import_react20.useState)(null);
|
|
2262
|
+
const [loading, setLoading] = (0, import_react20.useState)(true);
|
|
2263
|
+
const [error, setError] = (0, import_react20.useState)(null);
|
|
2264
|
+
const fetchEntity = (0, import_react20.useCallback)(async () => {
|
|
2140
2265
|
setLoading(true);
|
|
2141
2266
|
setError(null);
|
|
2142
2267
|
try {
|
|
@@ -2148,7 +2273,7 @@ function useEntity(slug) {
|
|
|
2148
2273
|
setLoading(false);
|
|
2149
2274
|
}
|
|
2150
2275
|
}, [client, slug]);
|
|
2151
|
-
(0,
|
|
2276
|
+
(0, import_react20.useEffect)(() => {
|
|
2152
2277
|
fetchEntity();
|
|
2153
2278
|
}, [fetchEntity]);
|
|
2154
2279
|
return {
|
|
@@ -2160,12 +2285,12 @@ function useEntity(slug) {
|
|
|
2160
2285
|
}
|
|
2161
2286
|
function useEntityRecords(slug, params) {
|
|
2162
2287
|
const client = useClient();
|
|
2163
|
-
const [records, setRecords] = (0,
|
|
2164
|
-
const [meta, setMeta] = (0,
|
|
2165
|
-
const [loading, setLoading] = (0,
|
|
2166
|
-
const [error, setError] = (0,
|
|
2167
|
-
const [currentParams, setCurrentParams] = (0,
|
|
2168
|
-
const fetchRecords = (0,
|
|
2288
|
+
const [records, setRecords] = (0, import_react20.useState)([]);
|
|
2289
|
+
const [meta, setMeta] = (0, import_react20.useState)(null);
|
|
2290
|
+
const [loading, setLoading] = (0, import_react20.useState)(true);
|
|
2291
|
+
const [error, setError] = (0, import_react20.useState)(null);
|
|
2292
|
+
const [currentParams, setCurrentParams] = (0, import_react20.useState)(params);
|
|
2293
|
+
const fetchRecords = (0, import_react20.useCallback)(async (fetchParams, append = false) => {
|
|
2169
2294
|
setLoading(true);
|
|
2170
2295
|
setError(null);
|
|
2171
2296
|
try {
|
|
@@ -2182,30 +2307,30 @@ function useEntityRecords(slug, params) {
|
|
|
2182
2307
|
setLoading(false);
|
|
2183
2308
|
}
|
|
2184
2309
|
}, [client, slug]);
|
|
2185
|
-
(0,
|
|
2310
|
+
(0, import_react20.useEffect)(() => {
|
|
2186
2311
|
fetchRecords(params);
|
|
2187
2312
|
}, []);
|
|
2188
2313
|
const hasMore = meta ? meta.current_page < meta.last_page : false;
|
|
2189
|
-
const loadMore = (0,
|
|
2314
|
+
const loadMore = (0, import_react20.useCallback)(async () => {
|
|
2190
2315
|
if (!hasMore || loading) return;
|
|
2191
2316
|
const nextPage = (meta?.current_page ?? 0) + 1;
|
|
2192
2317
|
await fetchRecords({ ...currentParams, page: nextPage }, true);
|
|
2193
2318
|
}, [hasMore, loading, meta, currentParams, fetchRecords]);
|
|
2194
|
-
const createRecord = (0,
|
|
2319
|
+
const createRecord = (0, import_react20.useCallback)(async (data) => {
|
|
2195
2320
|
const record = await client.entities.createRecord(slug, data);
|
|
2196
2321
|
setRecords((prev) => [record, ...prev]);
|
|
2197
2322
|
return record;
|
|
2198
2323
|
}, [client, slug]);
|
|
2199
|
-
const updateRecord = (0,
|
|
2324
|
+
const updateRecord = (0, import_react20.useCallback)(async (id, data) => {
|
|
2200
2325
|
const record = await client.entities.updateRecord(slug, id, data);
|
|
2201
2326
|
setRecords((prev) => prev.map((r) => r.id === id ? record : r));
|
|
2202
2327
|
return record;
|
|
2203
2328
|
}, [client, slug]);
|
|
2204
|
-
const deleteRecord = (0,
|
|
2329
|
+
const deleteRecord = (0, import_react20.useCallback)(async (id) => {
|
|
2205
2330
|
await client.entities.deleteRecord(slug, id);
|
|
2206
2331
|
setRecords((prev) => prev.filter((r) => r.id !== id));
|
|
2207
2332
|
}, [client, slug]);
|
|
2208
|
-
const refresh = (0,
|
|
2333
|
+
const refresh = (0, import_react20.useCallback)(async () => {
|
|
2209
2334
|
setCurrentParams(params);
|
|
2210
2335
|
await fetchRecords(params);
|
|
2211
2336
|
}, [params, fetchRecords]);
|
|
@@ -2224,10 +2349,10 @@ function useEntityRecords(slug, params) {
|
|
|
2224
2349
|
}
|
|
2225
2350
|
function useEntityRecord(slug, id) {
|
|
2226
2351
|
const client = useClient();
|
|
2227
|
-
const [record, setRecord] = (0,
|
|
2228
|
-
const [loading, setLoading] = (0,
|
|
2229
|
-
const [error, setError] = (0,
|
|
2230
|
-
const fetchRecord = (0,
|
|
2352
|
+
const [record, setRecord] = (0, import_react20.useState)(null);
|
|
2353
|
+
const [loading, setLoading] = (0, import_react20.useState)(true);
|
|
2354
|
+
const [error, setError] = (0, import_react20.useState)(null);
|
|
2355
|
+
const fetchRecord = (0, import_react20.useCallback)(async () => {
|
|
2231
2356
|
setLoading(true);
|
|
2232
2357
|
setError(null);
|
|
2233
2358
|
try {
|
|
@@ -2239,10 +2364,10 @@ function useEntityRecord(slug, id) {
|
|
|
2239
2364
|
setLoading(false);
|
|
2240
2365
|
}
|
|
2241
2366
|
}, [client, slug, id]);
|
|
2242
|
-
(0,
|
|
2367
|
+
(0, import_react20.useEffect)(() => {
|
|
2243
2368
|
fetchRecord();
|
|
2244
2369
|
}, [fetchRecord]);
|
|
2245
|
-
const update = (0,
|
|
2370
|
+
const update = (0, import_react20.useCallback)(async (data) => {
|
|
2246
2371
|
const updated = await client.entities.updateRecord(slug, id, data);
|
|
2247
2372
|
setRecord(updated);
|
|
2248
2373
|
return updated;
|
|
@@ -2257,7 +2382,7 @@ function useEntityRecord(slug, id) {
|
|
|
2257
2382
|
}
|
|
2258
2383
|
function useTypedEntity(slug) {
|
|
2259
2384
|
const client = useClient();
|
|
2260
|
-
return (0,
|
|
2385
|
+
return (0, import_react20.useMemo)(() => ({
|
|
2261
2386
|
useRecords: (params) => {
|
|
2262
2387
|
const result = useEntityRecords(slug, params);
|
|
2263
2388
|
return {
|
|
@@ -2311,6 +2436,7 @@ function useTypedEntity(slug) {
|
|
|
2311
2436
|
useCreateReservation,
|
|
2312
2437
|
useCreateReview,
|
|
2313
2438
|
useCreateSubscription,
|
|
2439
|
+
useCurrency,
|
|
2314
2440
|
useDiffsome,
|
|
2315
2441
|
useDigitalProducts,
|
|
2316
2442
|
useDownloads,
|
|
@@ -2335,6 +2461,7 @@ function useTypedEntity(slug) {
|
|
|
2335
2461
|
useReservationServices,
|
|
2336
2462
|
useReservationSettings,
|
|
2337
2463
|
useReservationStaffs,
|
|
2464
|
+
useSite,
|
|
2338
2465
|
useSocialAuth,
|
|
2339
2466
|
useStripePayment,
|
|
2340
2467
|
useSubscription,
|