@diffsome/react 1.1.3 → 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 +33 -6
- package/dist/index.d.ts +33 -6
- package/dist/index.js +547 -432
- package/dist/index.mjs +390 -277
- 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,
|
|
@@ -98,6 +100,10 @@ var getEnvVar = (key) => {
|
|
|
98
100
|
};
|
|
99
101
|
function DiffsomeProvider({ children, config = {} }) {
|
|
100
102
|
const [isReady, setIsReady] = (0, import_react.useState)(false);
|
|
103
|
+
const [cart, setCart] = (0, import_react.useState)(null);
|
|
104
|
+
const [cartLoading, setCartLoading] = (0, import_react.useState)(true);
|
|
105
|
+
const [wishlistItems, setWishlistItems] = (0, import_react.useState)([]);
|
|
106
|
+
const [wishlistLoading, setWishlistLoading] = (0, import_react.useState)(true);
|
|
101
107
|
const tenantId = config.tenantId || getEnvVar("DIFFSOME_TENANT_ID");
|
|
102
108
|
const apiKey = config.apiKey || getEnvVar("DIFFSOME_API_KEY");
|
|
103
109
|
const baseUrl = config.baseUrl || getEnvVar("DIFFSOME_BASE_URL");
|
|
@@ -115,13 +121,73 @@ function DiffsomeProvider({ children, config = {} }) {
|
|
|
115
121
|
storageType: config.storageType ?? "localStorage"
|
|
116
122
|
});
|
|
117
123
|
}, [tenantId, baseUrl, apiKey, config.persistToken, config.storageType]);
|
|
124
|
+
const refreshCart = (0, import_react.useCallback)(async () => {
|
|
125
|
+
setCartLoading(true);
|
|
126
|
+
try {
|
|
127
|
+
const cartData = await client.shop.getCart();
|
|
128
|
+
setCart(cartData);
|
|
129
|
+
} catch (err) {
|
|
130
|
+
setCart(null);
|
|
131
|
+
} finally {
|
|
132
|
+
setCartLoading(false);
|
|
133
|
+
}
|
|
134
|
+
}, [client]);
|
|
135
|
+
const refreshWishlist = (0, import_react.useCallback)(async () => {
|
|
136
|
+
if (!client.isAuthenticated()) {
|
|
137
|
+
setWishlistItems([]);
|
|
138
|
+
setWishlistLoading(false);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
setWishlistLoading(true);
|
|
142
|
+
try {
|
|
143
|
+
const response = await client.shop.getWishlist({ per_page: 100 });
|
|
144
|
+
setWishlistItems(response.data);
|
|
145
|
+
} catch (err) {
|
|
146
|
+
setWishlistItems([]);
|
|
147
|
+
} finally {
|
|
148
|
+
setWishlistLoading(false);
|
|
149
|
+
}
|
|
150
|
+
}, [client]);
|
|
118
151
|
(0, import_react.useEffect)(() => {
|
|
119
|
-
|
|
120
|
-
|
|
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);
|
|
173
|
+
};
|
|
174
|
+
init();
|
|
175
|
+
return () => {
|
|
176
|
+
mounted = false;
|
|
177
|
+
};
|
|
178
|
+
}, [client]);
|
|
121
179
|
const value = (0, import_react.useMemo)(() => ({
|
|
122
180
|
client,
|
|
123
|
-
isReady
|
|
124
|
-
|
|
181
|
+
isReady,
|
|
182
|
+
cart,
|
|
183
|
+
cartLoading,
|
|
184
|
+
setCart,
|
|
185
|
+
refreshCart,
|
|
186
|
+
wishlistItems,
|
|
187
|
+
wishlistLoading,
|
|
188
|
+
setWishlistItems,
|
|
189
|
+
refreshWishlist
|
|
190
|
+
}), [client, isReady, cart, cartLoading, refreshCart, wishlistItems, wishlistLoading, refreshWishlist]);
|
|
125
191
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DiffsomeContext.Provider, { value, children });
|
|
126
192
|
}
|
|
127
193
|
function useDiffsome() {
|
|
@@ -136,15 +202,104 @@ function useClient() {
|
|
|
136
202
|
return client;
|
|
137
203
|
}
|
|
138
204
|
|
|
139
|
-
// src/hooks/
|
|
205
|
+
// src/hooks/useSite.ts
|
|
140
206
|
var import_react2 = require("react");
|
|
141
|
-
|
|
207
|
+
var DEFAULT_CURRENCY = {
|
|
208
|
+
code: "KRW",
|
|
209
|
+
symbol: "\u20A9",
|
|
210
|
+
position: "before",
|
|
211
|
+
decimals: 0
|
|
212
|
+
};
|
|
213
|
+
function useSite() {
|
|
214
|
+
const client = useClient();
|
|
215
|
+
const [site, setSite] = (0, import_react2.useState)(null);
|
|
216
|
+
const [loading, setLoading] = (0, import_react2.useState)(true);
|
|
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() {
|
|
142
255
|
const client = useClient();
|
|
143
|
-
const [
|
|
256
|
+
const [currency, setCurrency] = (0, import_react2.useState)(null);
|
|
144
257
|
const [loading, setLoading] = (0, import_react2.useState)(true);
|
|
145
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);
|
|
146
301
|
const isAuthenticated = !!user && client.isAuthenticated();
|
|
147
|
-
const fetchProfile = (0,
|
|
302
|
+
const fetchProfile = (0, import_react3.useCallback)(async () => {
|
|
148
303
|
if (!client.isAuthenticated()) {
|
|
149
304
|
setUser(null);
|
|
150
305
|
setLoading(false);
|
|
@@ -161,10 +316,10 @@ function useAuth() {
|
|
|
161
316
|
setLoading(false);
|
|
162
317
|
}
|
|
163
318
|
}, [client]);
|
|
164
|
-
(0,
|
|
319
|
+
(0, import_react3.useEffect)(() => {
|
|
165
320
|
fetchProfile();
|
|
166
321
|
}, [fetchProfile]);
|
|
167
|
-
const login = (0,
|
|
322
|
+
const login = (0, import_react3.useCallback)(async (credentials) => {
|
|
168
323
|
setLoading(true);
|
|
169
324
|
setError(null);
|
|
170
325
|
try {
|
|
@@ -179,7 +334,7 @@ function useAuth() {
|
|
|
179
334
|
setLoading(false);
|
|
180
335
|
}
|
|
181
336
|
}, [client]);
|
|
182
|
-
const register = (0,
|
|
337
|
+
const register = (0, import_react3.useCallback)(async (data) => {
|
|
183
338
|
setLoading(true);
|
|
184
339
|
setError(null);
|
|
185
340
|
try {
|
|
@@ -194,7 +349,7 @@ function useAuth() {
|
|
|
194
349
|
setLoading(false);
|
|
195
350
|
}
|
|
196
351
|
}, [client]);
|
|
197
|
-
const logout = (0,
|
|
352
|
+
const logout = (0, import_react3.useCallback)(async () => {
|
|
198
353
|
setLoading(true);
|
|
199
354
|
try {
|
|
200
355
|
await client.auth.logout();
|
|
@@ -203,23 +358,23 @@ function useAuth() {
|
|
|
203
358
|
setLoading(false);
|
|
204
359
|
}
|
|
205
360
|
}, [client]);
|
|
206
|
-
const getProfile = (0,
|
|
361
|
+
const getProfile = (0, import_react3.useCallback)(async () => {
|
|
207
362
|
const profile = await client.auth.me();
|
|
208
363
|
setUser(profile);
|
|
209
364
|
return profile;
|
|
210
365
|
}, [client]);
|
|
211
|
-
const updateProfile = (0,
|
|
366
|
+
const updateProfile = (0, import_react3.useCallback)(async (data) => {
|
|
212
367
|
const profile = await client.auth.updateProfile(data);
|
|
213
368
|
setUser(profile);
|
|
214
369
|
return profile;
|
|
215
370
|
}, [client]);
|
|
216
|
-
const forgotPassword = (0,
|
|
371
|
+
const forgotPassword = (0, import_react3.useCallback)(async (email) => {
|
|
217
372
|
return await client.auth.forgotPassword({ email });
|
|
218
373
|
}, [client]);
|
|
219
|
-
const resetPassword = (0,
|
|
374
|
+
const resetPassword = (0, import_react3.useCallback)(async (data) => {
|
|
220
375
|
return await client.auth.resetPassword(data);
|
|
221
376
|
}, [client]);
|
|
222
|
-
const refresh = (0,
|
|
377
|
+
const refresh = (0, import_react3.useCallback)(async () => {
|
|
223
378
|
await fetchProfile();
|
|
224
379
|
}, [fetchProfile]);
|
|
225
380
|
return {
|
|
@@ -239,13 +394,13 @@ function useAuth() {
|
|
|
239
394
|
}
|
|
240
395
|
|
|
241
396
|
// src/hooks/useSocialAuth.ts
|
|
242
|
-
var
|
|
397
|
+
var import_react4 = require("react");
|
|
243
398
|
function useSocialAuth() {
|
|
244
399
|
const client = useClient();
|
|
245
|
-
const [providers, setProviders] = (0,
|
|
246
|
-
const [loading, setLoading] = (0,
|
|
247
|
-
const [error, setError] = (0,
|
|
248
|
-
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 () => {
|
|
249
404
|
setLoading(true);
|
|
250
405
|
setError(null);
|
|
251
406
|
try {
|
|
@@ -257,14 +412,14 @@ function useSocialAuth() {
|
|
|
257
412
|
setLoading(false);
|
|
258
413
|
}
|
|
259
414
|
}, [client]);
|
|
260
|
-
(0,
|
|
415
|
+
(0, import_react4.useEffect)(() => {
|
|
261
416
|
fetchProviders();
|
|
262
417
|
}, [fetchProviders]);
|
|
263
|
-
const getAuthUrl = (0,
|
|
418
|
+
const getAuthUrl = (0, import_react4.useCallback)(async (provider) => {
|
|
264
419
|
const result = await client.auth.getSocialAuthUrl(provider);
|
|
265
420
|
return result.url;
|
|
266
421
|
}, [client]);
|
|
267
|
-
const handleCallback = (0,
|
|
422
|
+
const handleCallback = (0, import_react4.useCallback)(async (provider, code) => {
|
|
268
423
|
return await client.auth.socialCallback(provider, code);
|
|
269
424
|
}, [client]);
|
|
270
425
|
return {
|
|
@@ -278,28 +433,10 @@ function useSocialAuth() {
|
|
|
278
433
|
}
|
|
279
434
|
|
|
280
435
|
// src/hooks/useCart.ts
|
|
281
|
-
var
|
|
436
|
+
var import_react5 = require("react");
|
|
282
437
|
function useCart() {
|
|
283
|
-
const client =
|
|
284
|
-
const
|
|
285
|
-
const [loading, setLoading] = (0, import_react4.useState)(true);
|
|
286
|
-
const [error, setError] = (0, import_react4.useState)(null);
|
|
287
|
-
const fetchCart = (0, import_react4.useCallback)(async () => {
|
|
288
|
-
try {
|
|
289
|
-
const cartData = await client.shop.getCart();
|
|
290
|
-
setCart(cartData);
|
|
291
|
-
setError(null);
|
|
292
|
-
} catch (err) {
|
|
293
|
-
setCart(null);
|
|
294
|
-
setError(err instanceof Error ? err : new Error("Failed to fetch cart"));
|
|
295
|
-
} finally {
|
|
296
|
-
setLoading(false);
|
|
297
|
-
}
|
|
298
|
-
}, [client]);
|
|
299
|
-
(0, import_react4.useEffect)(() => {
|
|
300
|
-
fetchCart();
|
|
301
|
-
}, [fetchCart]);
|
|
302
|
-
const addToCart = (0, import_react4.useCallback)(async (productId, quantity = 1, variantId, options) => {
|
|
438
|
+
const { client, cart, cartLoading, setCart, refreshCart } = useDiffsome();
|
|
439
|
+
const addToCart = (0, import_react5.useCallback)(async (productId, quantity = 1, variantId, options) => {
|
|
303
440
|
const data = {
|
|
304
441
|
product_id: productId,
|
|
305
442
|
quantity,
|
|
@@ -309,32 +446,28 @@ function useCart() {
|
|
|
309
446
|
const updatedCart = await client.shop.addToCart(data);
|
|
310
447
|
setCart(updatedCart);
|
|
311
448
|
return updatedCart;
|
|
312
|
-
}, [client]);
|
|
313
|
-
const updateItem = (0,
|
|
449
|
+
}, [client, setCart]);
|
|
450
|
+
const updateItem = (0, import_react5.useCallback)(async (itemId, quantity) => {
|
|
314
451
|
const updatedCart = await client.shop.updateCartItem(itemId, { quantity });
|
|
315
452
|
setCart(updatedCart);
|
|
316
453
|
return updatedCart;
|
|
317
|
-
}, [client]);
|
|
318
|
-
const removeItem = (0,
|
|
454
|
+
}, [client, setCart]);
|
|
455
|
+
const removeItem = (0, import_react5.useCallback)(async (itemId) => {
|
|
319
456
|
const updatedCart = await client.shop.removeFromCart(itemId);
|
|
320
457
|
setCart(updatedCart);
|
|
321
458
|
return updatedCart;
|
|
322
|
-
}, [client]);
|
|
323
|
-
const clearCart = (0,
|
|
459
|
+
}, [client, setCart]);
|
|
460
|
+
const clearCart = (0, import_react5.useCallback)(async () => {
|
|
324
461
|
await client.shop.clearCart();
|
|
325
462
|
setCart(null);
|
|
326
|
-
}, [client]);
|
|
327
|
-
const
|
|
328
|
-
setLoading(true);
|
|
329
|
-
await fetchCart();
|
|
330
|
-
}, [fetchCart]);
|
|
331
|
-
const isInCart = (0, import_react4.useCallback)((productId, variantId) => {
|
|
463
|
+
}, [client, setCart]);
|
|
464
|
+
const isInCart = (0, import_react5.useCallback)((productId, variantId) => {
|
|
332
465
|
if (!cart?.items) return false;
|
|
333
466
|
return cart.items.some(
|
|
334
467
|
(item) => item.product_id === productId && (variantId === void 0 || item.variant_id === variantId)
|
|
335
468
|
);
|
|
336
469
|
}, [cart]);
|
|
337
|
-
const getItemQuantity = (0,
|
|
470
|
+
const getItemQuantity = (0, import_react5.useCallback)((productId, variantId) => {
|
|
338
471
|
if (!cart?.items) return 0;
|
|
339
472
|
const item = cart.items.find(
|
|
340
473
|
(item2) => item2.product_id === productId && (variantId === void 0 || item2.variant_id === variantId)
|
|
@@ -349,117 +482,77 @@ function useCart() {
|
|
|
349
482
|
subtotal: cart?.subtotal ?? 0,
|
|
350
483
|
shippingFee: cart?.shipping_fee ?? 0,
|
|
351
484
|
total: cart?.total ?? 0,
|
|
352
|
-
loading,
|
|
353
|
-
error,
|
|
485
|
+
loading: cartLoading,
|
|
354
486
|
addToCart,
|
|
355
487
|
updateItem,
|
|
356
488
|
removeItem,
|
|
357
489
|
clearCart,
|
|
358
|
-
refresh,
|
|
490
|
+
refresh: refreshCart,
|
|
359
491
|
isInCart,
|
|
360
492
|
getItemQuantity
|
|
361
493
|
};
|
|
362
494
|
}
|
|
363
495
|
|
|
364
496
|
// src/hooks/useWishlist.ts
|
|
365
|
-
var
|
|
497
|
+
var import_react6 = require("react");
|
|
366
498
|
function useWishlist() {
|
|
367
|
-
const client =
|
|
368
|
-
const [
|
|
369
|
-
const
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
}
|
|
379
|
-
try {
|
|
380
|
-
const response = await client.shop.getWishlist({ per_page: 100 });
|
|
381
|
-
setItems(response.data);
|
|
382
|
-
const map = {};
|
|
383
|
-
response.data.forEach((item) => {
|
|
384
|
-
const key = item.variant_id ? `${item.product_id}_${item.variant_id}` : String(item.product_id);
|
|
385
|
-
map[key] = true;
|
|
386
|
-
});
|
|
387
|
-
setWishlistMap(map);
|
|
388
|
-
setError(null);
|
|
389
|
-
} catch (err) {
|
|
390
|
-
setItems([]);
|
|
391
|
-
setWishlistMap({});
|
|
392
|
-
setError(err instanceof Error ? err : new Error("Failed to fetch wishlist"));
|
|
393
|
-
} finally {
|
|
394
|
-
setLoading(false);
|
|
395
|
-
}
|
|
396
|
-
}, [client]);
|
|
397
|
-
(0, import_react5.useEffect)(() => {
|
|
398
|
-
fetchWishlist();
|
|
399
|
-
}, [fetchWishlist]);
|
|
400
|
-
const isInWishlist = (0, import_react5.useCallback)((productId, variantId) => {
|
|
499
|
+
const { client, wishlistItems, wishlistLoading, setWishlistItems, refreshWishlist, setCart } = useDiffsome();
|
|
500
|
+
const [error, setError] = (0, import_react6.useState)(null);
|
|
501
|
+
const wishlistMap = (0, import_react6.useMemo)(() => {
|
|
502
|
+
const map = {};
|
|
503
|
+
wishlistItems.forEach((item) => {
|
|
504
|
+
const key = item.variant_id ? `${item.product_id}_${item.variant_id}` : String(item.product_id);
|
|
505
|
+
map[key] = true;
|
|
506
|
+
});
|
|
507
|
+
return map;
|
|
508
|
+
}, [wishlistItems]);
|
|
509
|
+
const isInWishlist = (0, import_react6.useCallback)((productId, variantId) => {
|
|
401
510
|
const key = variantId ? `${productId}_${variantId}` : String(productId);
|
|
402
511
|
return wishlistMap[key] || false;
|
|
403
512
|
}, [wishlistMap]);
|
|
404
|
-
const toggleWishlist = (0,
|
|
513
|
+
const toggleWishlist = (0, import_react6.useCallback)(async (productId, variantId) => {
|
|
405
514
|
const result = await client.shop.toggleWishlist(productId, variantId);
|
|
406
|
-
const key = variantId ? `${productId}_${variantId}` : String(productId);
|
|
407
|
-
setWishlistMap((prev) => ({
|
|
408
|
-
...prev,
|
|
409
|
-
[key]: result.in_wishlist
|
|
410
|
-
}));
|
|
411
515
|
if (result.action === "added") {
|
|
412
|
-
await
|
|
516
|
+
await refreshWishlist();
|
|
413
517
|
} else {
|
|
414
|
-
|
|
518
|
+
setWishlistItems(wishlistItems.filter(
|
|
415
519
|
(item) => !(item.product_id === productId && item.variant_id === variantId)
|
|
416
520
|
));
|
|
417
521
|
}
|
|
418
522
|
return result;
|
|
419
|
-
}, [client,
|
|
420
|
-
const addToWishlist = (0,
|
|
523
|
+
}, [client, refreshWishlist, setWishlistItems, wishlistItems]);
|
|
524
|
+
const addToWishlist = (0, import_react6.useCallback)(async (productId, variantId, note) => {
|
|
421
525
|
const item = await client.shop.addToWishlist({
|
|
422
526
|
product_id: productId,
|
|
423
527
|
variant_id: variantId,
|
|
424
528
|
note
|
|
425
529
|
});
|
|
426
|
-
await
|
|
530
|
+
await refreshWishlist();
|
|
427
531
|
return item;
|
|
428
|
-
}, [client,
|
|
429
|
-
const removeFromWishlist = (0,
|
|
430
|
-
const item = items.find((i) => i.id === wishlistId);
|
|
532
|
+
}, [client, refreshWishlist]);
|
|
533
|
+
const removeFromWishlist = (0, import_react6.useCallback)(async (wishlistId) => {
|
|
431
534
|
await client.shop.removeFromWishlist(wishlistId);
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
const next = { ...prev };
|
|
436
|
-
delete next[key];
|
|
437
|
-
return next;
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
setItems((prev) => prev.filter((i) => i.id !== wishlistId));
|
|
441
|
-
}, [client, items]);
|
|
442
|
-
const moveToCart = (0, import_react5.useCallback)(async (wishlistIds) => {
|
|
535
|
+
setWishlistItems(wishlistItems.filter((i) => i.id !== wishlistId));
|
|
536
|
+
}, [client, setWishlistItems, wishlistItems]);
|
|
537
|
+
const moveToCart = (0, import_react6.useCallback)(async (wishlistIds) => {
|
|
443
538
|
const result = await client.shop.moveWishlistToCart(wishlistIds);
|
|
444
|
-
await
|
|
539
|
+
await refreshWishlist();
|
|
540
|
+
const cartData = await client.shop.getCart();
|
|
541
|
+
setCart(cartData);
|
|
445
542
|
return result;
|
|
446
|
-
}, [client,
|
|
447
|
-
const updateNote = (0,
|
|
543
|
+
}, [client, refreshWishlist, setCart]);
|
|
544
|
+
const updateNote = (0, import_react6.useCallback)(async (wishlistId, note) => {
|
|
448
545
|
const item = await client.shop.updateWishlistNote(wishlistId, note);
|
|
449
|
-
|
|
546
|
+
setWishlistItems(wishlistItems.map((i) => i.id === wishlistId ? item : i));
|
|
450
547
|
return item;
|
|
451
|
-
}, [client]);
|
|
452
|
-
const getProductWishlistCount = (0,
|
|
548
|
+
}, [client, setWishlistItems, wishlistItems]);
|
|
549
|
+
const getProductWishlistCount = (0, import_react6.useCallback)(async (productSlug) => {
|
|
453
550
|
return await client.shop.getProductWishlistCount(productSlug);
|
|
454
551
|
}, [client]);
|
|
455
|
-
const refresh = (0, import_react5.useCallback)(async () => {
|
|
456
|
-
setLoading(true);
|
|
457
|
-
await fetchWishlist();
|
|
458
|
-
}, [fetchWishlist]);
|
|
459
552
|
return {
|
|
460
|
-
items,
|
|
461
|
-
count:
|
|
462
|
-
loading,
|
|
553
|
+
items: wishlistItems,
|
|
554
|
+
count: wishlistItems.length,
|
|
555
|
+
loading: wishlistLoading,
|
|
463
556
|
error,
|
|
464
557
|
isInWishlist,
|
|
465
558
|
toggleWishlist,
|
|
@@ -468,21 +561,21 @@ function useWishlist() {
|
|
|
468
561
|
moveToCart,
|
|
469
562
|
updateNote,
|
|
470
563
|
getProductWishlistCount,
|
|
471
|
-
refresh
|
|
564
|
+
refresh: refreshWishlist
|
|
472
565
|
};
|
|
473
566
|
}
|
|
474
567
|
|
|
475
568
|
// src/hooks/useProducts.ts
|
|
476
|
-
var
|
|
569
|
+
var import_react7 = require("react");
|
|
477
570
|
function useProducts(options = {}) {
|
|
478
571
|
const { autoFetch = true, ...params } = options;
|
|
479
572
|
const client = useClient();
|
|
480
|
-
const [products, setProducts] = (0,
|
|
481
|
-
const [meta, setMeta] = (0,
|
|
482
|
-
const [loading, setLoading] = (0,
|
|
483
|
-
const [error, setError] = (0,
|
|
484
|
-
const [currentParams, setCurrentParams] = (0,
|
|
485
|
-
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) => {
|
|
486
579
|
setLoading(true);
|
|
487
580
|
setError(null);
|
|
488
581
|
try {
|
|
@@ -499,22 +592,22 @@ function useProducts(options = {}) {
|
|
|
499
592
|
setLoading(false);
|
|
500
593
|
}
|
|
501
594
|
}, [client]);
|
|
502
|
-
(0,
|
|
595
|
+
(0, import_react7.useEffect)(() => {
|
|
503
596
|
if (autoFetch) {
|
|
504
597
|
fetchProducts(params);
|
|
505
598
|
}
|
|
506
599
|
}, []);
|
|
507
600
|
const hasMore = meta ? meta.current_page < meta.last_page : false;
|
|
508
|
-
const loadMore = (0,
|
|
601
|
+
const loadMore = (0, import_react7.useCallback)(async () => {
|
|
509
602
|
if (!hasMore || loading) return;
|
|
510
603
|
const nextPage = (meta?.current_page ?? 0) + 1;
|
|
511
604
|
await fetchProducts({ ...currentParams, page: nextPage }, true);
|
|
512
605
|
}, [hasMore, loading, meta, currentParams, fetchProducts]);
|
|
513
|
-
const refresh = (0,
|
|
606
|
+
const refresh = (0, import_react7.useCallback)(async () => {
|
|
514
607
|
setCurrentParams(params);
|
|
515
608
|
await fetchProducts(params);
|
|
516
609
|
}, [params, fetchProducts]);
|
|
517
|
-
const search = (0,
|
|
610
|
+
const search = (0, import_react7.useCallback)(async (query) => {
|
|
518
611
|
const searchParams = { ...params, search: query, page: 1 };
|
|
519
612
|
setCurrentParams(searchParams);
|
|
520
613
|
await fetchProducts(searchParams);
|
|
@@ -532,10 +625,10 @@ function useProducts(options = {}) {
|
|
|
532
625
|
}
|
|
533
626
|
function useProduct(idOrSlug) {
|
|
534
627
|
const client = useClient();
|
|
535
|
-
const [product, setProduct] = (0,
|
|
536
|
-
const [loading, setLoading] = (0,
|
|
537
|
-
const [error, setError] = (0,
|
|
538
|
-
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 () => {
|
|
539
632
|
setLoading(true);
|
|
540
633
|
setError(null);
|
|
541
634
|
try {
|
|
@@ -547,7 +640,7 @@ function useProduct(idOrSlug) {
|
|
|
547
640
|
setLoading(false);
|
|
548
641
|
}
|
|
549
642
|
}, [client, idOrSlug]);
|
|
550
|
-
(0,
|
|
643
|
+
(0, import_react7.useEffect)(() => {
|
|
551
644
|
fetchProduct();
|
|
552
645
|
}, [fetchProduct]);
|
|
553
646
|
return {
|
|
@@ -559,10 +652,10 @@ function useProduct(idOrSlug) {
|
|
|
559
652
|
}
|
|
560
653
|
function useCategories() {
|
|
561
654
|
const client = useClient();
|
|
562
|
-
const [categories, setCategories] = (0,
|
|
563
|
-
const [loading, setLoading] = (0,
|
|
564
|
-
const [error, setError] = (0,
|
|
565
|
-
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 () => {
|
|
566
659
|
setLoading(true);
|
|
567
660
|
setError(null);
|
|
568
661
|
try {
|
|
@@ -574,7 +667,7 @@ function useCategories() {
|
|
|
574
667
|
setLoading(false);
|
|
575
668
|
}
|
|
576
669
|
}, [client]);
|
|
577
|
-
(0,
|
|
670
|
+
(0, import_react7.useEffect)(() => {
|
|
578
671
|
fetchCategories();
|
|
579
672
|
}, [fetchCategories]);
|
|
580
673
|
return {
|
|
@@ -586,10 +679,10 @@ function useCategories() {
|
|
|
586
679
|
}
|
|
587
680
|
function useFeaturedProducts(limit = 8) {
|
|
588
681
|
const client = useClient();
|
|
589
|
-
const [products, setProducts] = (0,
|
|
590
|
-
const [loading, setLoading] = (0,
|
|
591
|
-
const [error, setError] = (0,
|
|
592
|
-
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 () => {
|
|
593
686
|
setLoading(true);
|
|
594
687
|
setError(null);
|
|
595
688
|
try {
|
|
@@ -601,7 +694,7 @@ function useFeaturedProducts(limit = 8) {
|
|
|
601
694
|
setLoading(false);
|
|
602
695
|
}
|
|
603
696
|
}, [client, limit]);
|
|
604
|
-
(0,
|
|
697
|
+
(0, import_react7.useEffect)(() => {
|
|
605
698
|
fetchProducts();
|
|
606
699
|
}, [fetchProducts]);
|
|
607
700
|
return {
|
|
@@ -613,11 +706,11 @@ function useFeaturedProducts(limit = 8) {
|
|
|
613
706
|
}
|
|
614
707
|
function useProductsByType(type, params) {
|
|
615
708
|
const client = useClient();
|
|
616
|
-
const [products, setProducts] = (0,
|
|
617
|
-
const [meta, setMeta] = (0,
|
|
618
|
-
const [loading, setLoading] = (0,
|
|
619
|
-
const [error, setError] = (0,
|
|
620
|
-
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 () => {
|
|
621
714
|
setLoading(true);
|
|
622
715
|
setError(null);
|
|
623
716
|
try {
|
|
@@ -630,7 +723,7 @@ function useProductsByType(type, params) {
|
|
|
630
723
|
setLoading(false);
|
|
631
724
|
}
|
|
632
725
|
}, [client, type, params]);
|
|
633
|
-
(0,
|
|
726
|
+
(0, import_react7.useEffect)(() => {
|
|
634
727
|
fetchProducts();
|
|
635
728
|
}, [fetchProducts]);
|
|
636
729
|
return {
|
|
@@ -652,10 +745,10 @@ function useBundleProducts(params) {
|
|
|
652
745
|
}
|
|
653
746
|
function useBundleItems(productSlug) {
|
|
654
747
|
const client = useClient();
|
|
655
|
-
const [bundle, setBundle] = (0,
|
|
656
|
-
const [loading, setLoading] = (0,
|
|
657
|
-
const [error, setError] = (0,
|
|
658
|
-
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 () => {
|
|
659
752
|
setLoading(true);
|
|
660
753
|
setError(null);
|
|
661
754
|
try {
|
|
@@ -667,7 +760,7 @@ function useBundleItems(productSlug) {
|
|
|
667
760
|
setLoading(false);
|
|
668
761
|
}
|
|
669
762
|
}, [client, productSlug]);
|
|
670
|
-
(0,
|
|
763
|
+
(0, import_react7.useEffect)(() => {
|
|
671
764
|
fetchBundle();
|
|
672
765
|
}, [fetchBundle]);
|
|
673
766
|
return {
|
|
@@ -679,14 +772,14 @@ function useBundleItems(productSlug) {
|
|
|
679
772
|
}
|
|
680
773
|
|
|
681
774
|
// src/hooks/useOrders.ts
|
|
682
|
-
var
|
|
775
|
+
var import_react8 = require("react");
|
|
683
776
|
function useOrders(params) {
|
|
684
777
|
const client = useClient();
|
|
685
|
-
const [orders, setOrders] = (0,
|
|
686
|
-
const [meta, setMeta] = (0,
|
|
687
|
-
const [loading, setLoading] = (0,
|
|
688
|
-
const [error, setError] = (0,
|
|
689
|
-
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) => {
|
|
690
783
|
if (!client.isAuthenticated()) {
|
|
691
784
|
setOrders([]);
|
|
692
785
|
setLoading(false);
|
|
@@ -708,16 +801,16 @@ function useOrders(params) {
|
|
|
708
801
|
setLoading(false);
|
|
709
802
|
}
|
|
710
803
|
}, [client]);
|
|
711
|
-
(0,
|
|
804
|
+
(0, import_react8.useEffect)(() => {
|
|
712
805
|
fetchOrders(params);
|
|
713
806
|
}, []);
|
|
714
807
|
const hasMore = meta ? meta.current_page < meta.last_page : false;
|
|
715
|
-
const loadMore = (0,
|
|
808
|
+
const loadMore = (0, import_react8.useCallback)(async () => {
|
|
716
809
|
if (!hasMore || loading) return;
|
|
717
810
|
const nextPage = (meta?.current_page ?? 0) + 1;
|
|
718
811
|
await fetchOrders({ ...params, page: nextPage }, true);
|
|
719
812
|
}, [hasMore, loading, meta, params, fetchOrders]);
|
|
720
|
-
const refresh = (0,
|
|
813
|
+
const refresh = (0, import_react8.useCallback)(async () => {
|
|
721
814
|
await fetchOrders(params);
|
|
722
815
|
}, [params, fetchOrders]);
|
|
723
816
|
return {
|
|
@@ -732,10 +825,10 @@ function useOrders(params) {
|
|
|
732
825
|
}
|
|
733
826
|
function useOrder(idOrNumber) {
|
|
734
827
|
const client = useClient();
|
|
735
|
-
const [order, setOrder] = (0,
|
|
736
|
-
const [loading, setLoading] = (0,
|
|
737
|
-
const [error, setError] = (0,
|
|
738
|
-
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 () => {
|
|
739
832
|
setLoading(true);
|
|
740
833
|
setError(null);
|
|
741
834
|
try {
|
|
@@ -747,10 +840,10 @@ function useOrder(idOrNumber) {
|
|
|
747
840
|
setLoading(false);
|
|
748
841
|
}
|
|
749
842
|
}, [client, idOrNumber]);
|
|
750
|
-
(0,
|
|
843
|
+
(0, import_react8.useEffect)(() => {
|
|
751
844
|
fetchOrder();
|
|
752
845
|
}, [fetchOrder]);
|
|
753
|
-
const cancel = (0,
|
|
846
|
+
const cancel = (0, import_react8.useCallback)(async () => {
|
|
754
847
|
if (!order) throw new Error("Order not loaded");
|
|
755
848
|
const cancelled = await client.shop.cancelOrder(order.id);
|
|
756
849
|
setOrder(cancelled);
|
|
@@ -766,9 +859,9 @@ function useOrder(idOrNumber) {
|
|
|
766
859
|
}
|
|
767
860
|
function useCreateOrder() {
|
|
768
861
|
const client = useClient();
|
|
769
|
-
const [loading, setLoading] = (0,
|
|
770
|
-
const [error, setError] = (0,
|
|
771
|
-
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) => {
|
|
772
865
|
setLoading(true);
|
|
773
866
|
setError(null);
|
|
774
867
|
try {
|
|
@@ -789,13 +882,19 @@ function useCreateOrder() {
|
|
|
789
882
|
}
|
|
790
883
|
|
|
791
884
|
// src/hooks/usePayment.ts
|
|
792
|
-
var
|
|
885
|
+
var import_react9 = require("react");
|
|
886
|
+
var DEFAULT_CURRENCY2 = {
|
|
887
|
+
code: "KRW",
|
|
888
|
+
symbol: "\u20A9",
|
|
889
|
+
position: "before",
|
|
890
|
+
decimals: 0
|
|
891
|
+
};
|
|
793
892
|
function usePaymentStatus() {
|
|
794
893
|
const client = useClient();
|
|
795
|
-
const [status, setStatus] = (0,
|
|
796
|
-
const [loading, setLoading] = (0,
|
|
797
|
-
const [error, setError] = (0,
|
|
798
|
-
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 () => {
|
|
799
898
|
setLoading(true);
|
|
800
899
|
setError(null);
|
|
801
900
|
try {
|
|
@@ -807,11 +906,25 @@ function usePaymentStatus() {
|
|
|
807
906
|
setLoading(false);
|
|
808
907
|
}
|
|
809
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]);
|
|
810
921
|
return {
|
|
811
922
|
status,
|
|
812
923
|
loading,
|
|
813
924
|
error,
|
|
814
925
|
refresh: fetchStatus,
|
|
926
|
+
currency,
|
|
927
|
+
formatPrice,
|
|
815
928
|
isTossAvailable: status?.toss?.available ?? false,
|
|
816
929
|
isStripeAvailable: status?.stripe?.available ?? false,
|
|
817
930
|
stripePublishableKey: status?.stripe?.publishable_key ?? null
|
|
@@ -819,9 +932,9 @@ function usePaymentStatus() {
|
|
|
819
932
|
}
|
|
820
933
|
function useTossPayment() {
|
|
821
934
|
const client = useClient();
|
|
822
|
-
const [loading, setLoading] = (0,
|
|
823
|
-
const [error, setError] = (0,
|
|
824
|
-
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) => {
|
|
825
938
|
setLoading(true);
|
|
826
939
|
setError(null);
|
|
827
940
|
try {
|
|
@@ -838,7 +951,7 @@ function useTossPayment() {
|
|
|
838
951
|
setLoading(false);
|
|
839
952
|
}
|
|
840
953
|
}, [client]);
|
|
841
|
-
const confirmPayment = (0,
|
|
954
|
+
const confirmPayment = (0, import_react9.useCallback)(async (paymentKey, orderId, amount) => {
|
|
842
955
|
setLoading(true);
|
|
843
956
|
setError(null);
|
|
844
957
|
try {
|
|
@@ -855,7 +968,7 @@ function useTossPayment() {
|
|
|
855
968
|
setLoading(false);
|
|
856
969
|
}
|
|
857
970
|
}, [client]);
|
|
858
|
-
const cancelPayment = (0,
|
|
971
|
+
const cancelPayment = (0, import_react9.useCallback)(async (orderNumber, reason, amount) => {
|
|
859
972
|
setLoading(true);
|
|
860
973
|
setError(null);
|
|
861
974
|
try {
|
|
@@ -878,9 +991,9 @@ function useTossPayment() {
|
|
|
878
991
|
}
|
|
879
992
|
function useStripePayment() {
|
|
880
993
|
const client = useClient();
|
|
881
|
-
const [loading, setLoading] = (0,
|
|
882
|
-
const [error, setError] = (0,
|
|
883
|
-
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) => {
|
|
884
997
|
setLoading(true);
|
|
885
998
|
setError(null);
|
|
886
999
|
try {
|
|
@@ -897,7 +1010,7 @@ function useStripePayment() {
|
|
|
897
1010
|
setLoading(false);
|
|
898
1011
|
}
|
|
899
1012
|
}, [client]);
|
|
900
|
-
const verifyPayment = (0,
|
|
1013
|
+
const verifyPayment = (0, import_react9.useCallback)(async (sessionId) => {
|
|
901
1014
|
setLoading(true);
|
|
902
1015
|
setError(null);
|
|
903
1016
|
try {
|
|
@@ -910,7 +1023,7 @@ function useStripePayment() {
|
|
|
910
1023
|
setLoading(false);
|
|
911
1024
|
}
|
|
912
1025
|
}, [client]);
|
|
913
|
-
const refund = (0,
|
|
1026
|
+
const refund = (0, import_react9.useCallback)(async (orderNumber, reason, amount) => {
|
|
914
1027
|
setLoading(true);
|
|
915
1028
|
setError(null);
|
|
916
1029
|
try {
|
|
@@ -933,13 +1046,13 @@ function useStripePayment() {
|
|
|
933
1046
|
}
|
|
934
1047
|
|
|
935
1048
|
// src/hooks/useCoupons.ts
|
|
936
|
-
var
|
|
1049
|
+
var import_react10 = require("react");
|
|
937
1050
|
function useCoupons() {
|
|
938
1051
|
const client = useClient();
|
|
939
|
-
const [coupons, setCoupons] = (0,
|
|
940
|
-
const [loading, setLoading] = (0,
|
|
941
|
-
const [error, setError] = (0,
|
|
942
|
-
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 () => {
|
|
943
1056
|
if (!client.isAuthenticated()) {
|
|
944
1057
|
setCoupons([]);
|
|
945
1058
|
setLoading(false);
|
|
@@ -956,7 +1069,7 @@ function useCoupons() {
|
|
|
956
1069
|
setLoading(false);
|
|
957
1070
|
}
|
|
958
1071
|
}, [client]);
|
|
959
|
-
(0,
|
|
1072
|
+
(0, import_react10.useEffect)(() => {
|
|
960
1073
|
fetchCoupons();
|
|
961
1074
|
}, [fetchCoupons]);
|
|
962
1075
|
return {
|
|
@@ -968,10 +1081,10 @@ function useCoupons() {
|
|
|
968
1081
|
}
|
|
969
1082
|
function useValidateCoupon() {
|
|
970
1083
|
const client = useClient();
|
|
971
|
-
const [validation, setValidation] = (0,
|
|
972
|
-
const [loading, setLoading] = (0,
|
|
973
|
-
const [error, setError] = (0,
|
|
974
|
-
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) => {
|
|
975
1088
|
setLoading(true);
|
|
976
1089
|
setError(null);
|
|
977
1090
|
try {
|
|
@@ -987,7 +1100,7 @@ function useValidateCoupon() {
|
|
|
987
1100
|
setLoading(false);
|
|
988
1101
|
}
|
|
989
1102
|
}, [client]);
|
|
990
|
-
const reset = (0,
|
|
1103
|
+
const reset = (0, import_react10.useCallback)(() => {
|
|
991
1104
|
setValidation(null);
|
|
992
1105
|
setError(null);
|
|
993
1106
|
}, []);
|
|
@@ -1001,13 +1114,13 @@ function useValidateCoupon() {
|
|
|
1001
1114
|
}
|
|
1002
1115
|
|
|
1003
1116
|
// src/hooks/useSubscriptions.ts
|
|
1004
|
-
var
|
|
1117
|
+
var import_react11 = require("react");
|
|
1005
1118
|
function useSubscriptions() {
|
|
1006
1119
|
const client = useClient();
|
|
1007
|
-
const [subscriptions, setSubscriptions] = (0,
|
|
1008
|
-
const [loading, setLoading] = (0,
|
|
1009
|
-
const [error, setError] = (0,
|
|
1010
|
-
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 () => {
|
|
1011
1124
|
if (!client.isAuthenticated()) {
|
|
1012
1125
|
setSubscriptions([]);
|
|
1013
1126
|
setLoading(false);
|
|
@@ -1024,7 +1137,7 @@ function useSubscriptions() {
|
|
|
1024
1137
|
setLoading(false);
|
|
1025
1138
|
}
|
|
1026
1139
|
}, [client]);
|
|
1027
|
-
(0,
|
|
1140
|
+
(0, import_react11.useEffect)(() => {
|
|
1028
1141
|
fetchSubscriptions();
|
|
1029
1142
|
}, [fetchSubscriptions]);
|
|
1030
1143
|
const activeSubscription = subscriptions.find((s) => s.is_active) ?? null;
|
|
@@ -1040,10 +1153,10 @@ function useSubscriptions() {
|
|
|
1040
1153
|
}
|
|
1041
1154
|
function useSubscription(id) {
|
|
1042
1155
|
const client = useClient();
|
|
1043
|
-
const [subscription, setSubscription] = (0,
|
|
1044
|
-
const [loading, setLoading] = (0,
|
|
1045
|
-
const [error, setError] = (0,
|
|
1046
|
-
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 () => {
|
|
1047
1160
|
setLoading(true);
|
|
1048
1161
|
setError(null);
|
|
1049
1162
|
try {
|
|
@@ -1055,20 +1168,20 @@ function useSubscription(id) {
|
|
|
1055
1168
|
setLoading(false);
|
|
1056
1169
|
}
|
|
1057
1170
|
}, [client, id]);
|
|
1058
|
-
(0,
|
|
1171
|
+
(0, import_react11.useEffect)(() => {
|
|
1059
1172
|
fetchSubscription();
|
|
1060
1173
|
}, [fetchSubscription]);
|
|
1061
|
-
const cancel = (0,
|
|
1174
|
+
const cancel = (0, import_react11.useCallback)(async (immediately = false) => {
|
|
1062
1175
|
const updated = await client.shop.cancelSubscription(id, immediately);
|
|
1063
1176
|
setSubscription(updated);
|
|
1064
1177
|
return updated;
|
|
1065
1178
|
}, [client, id]);
|
|
1066
|
-
const pause = (0,
|
|
1179
|
+
const pause = (0, import_react11.useCallback)(async () => {
|
|
1067
1180
|
const updated = await client.shop.pauseSubscription(id);
|
|
1068
1181
|
setSubscription(updated);
|
|
1069
1182
|
return updated;
|
|
1070
1183
|
}, [client, id]);
|
|
1071
|
-
const resume = (0,
|
|
1184
|
+
const resume = (0, import_react11.useCallback)(async () => {
|
|
1072
1185
|
const updated = await client.shop.resumeSubscription(id);
|
|
1073
1186
|
setSubscription(updated);
|
|
1074
1187
|
return updated;
|
|
@@ -1085,9 +1198,9 @@ function useSubscription(id) {
|
|
|
1085
1198
|
}
|
|
1086
1199
|
function useCreateSubscription() {
|
|
1087
1200
|
const client = useClient();
|
|
1088
|
-
const [loading, setLoading] = (0,
|
|
1089
|
-
const [error, setError] = (0,
|
|
1090
|
-
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) => {
|
|
1091
1204
|
setLoading(true);
|
|
1092
1205
|
setError(null);
|
|
1093
1206
|
try {
|
|
@@ -1104,7 +1217,7 @@ function useCreateSubscription() {
|
|
|
1104
1217
|
setLoading(false);
|
|
1105
1218
|
}
|
|
1106
1219
|
}, [client]);
|
|
1107
|
-
const verifyCheckout = (0,
|
|
1220
|
+
const verifyCheckout = (0, import_react11.useCallback)(async (sessionId) => {
|
|
1108
1221
|
setLoading(true);
|
|
1109
1222
|
setError(null);
|
|
1110
1223
|
try {
|
|
@@ -1118,7 +1231,7 @@ function useCreateSubscription() {
|
|
|
1118
1231
|
setLoading(false);
|
|
1119
1232
|
}
|
|
1120
1233
|
}, [client]);
|
|
1121
|
-
const createSetupIntent = (0,
|
|
1234
|
+
const createSetupIntent = (0, import_react11.useCallback)(async () => {
|
|
1122
1235
|
setLoading(true);
|
|
1123
1236
|
setError(null);
|
|
1124
1237
|
try {
|
|
@@ -1142,13 +1255,13 @@ function useCreateSubscription() {
|
|
|
1142
1255
|
}
|
|
1143
1256
|
|
|
1144
1257
|
// src/hooks/useDownloads.ts
|
|
1145
|
-
var
|
|
1258
|
+
var import_react12 = require("react");
|
|
1146
1259
|
function useDownloads() {
|
|
1147
1260
|
const client = useClient();
|
|
1148
|
-
const [downloads, setDownloads] = (0,
|
|
1149
|
-
const [loading, setLoading] = (0,
|
|
1150
|
-
const [error, setError] = (0,
|
|
1151
|
-
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 () => {
|
|
1152
1265
|
if (!client.isAuthenticated()) {
|
|
1153
1266
|
setDownloads([]);
|
|
1154
1267
|
setLoading(false);
|
|
@@ -1165,13 +1278,13 @@ function useDownloads() {
|
|
|
1165
1278
|
setLoading(false);
|
|
1166
1279
|
}
|
|
1167
1280
|
}, [client]);
|
|
1168
|
-
(0,
|
|
1281
|
+
(0, import_react12.useEffect)(() => {
|
|
1169
1282
|
fetchDownloads();
|
|
1170
1283
|
}, [fetchDownloads]);
|
|
1171
|
-
const getDownloadUrl = (0,
|
|
1284
|
+
const getDownloadUrl = (0, import_react12.useCallback)((token) => {
|
|
1172
1285
|
return client.shop.getDownloadUrl(token);
|
|
1173
1286
|
}, [client]);
|
|
1174
|
-
const getDownloadInfo = (0,
|
|
1287
|
+
const getDownloadInfo = (0, import_react12.useCallback)(async (token) => {
|
|
1175
1288
|
return await client.shop.getDownloadInfo(token);
|
|
1176
1289
|
}, [client]);
|
|
1177
1290
|
return {
|
|
@@ -1185,10 +1298,10 @@ function useDownloads() {
|
|
|
1185
1298
|
}
|
|
1186
1299
|
function useOrderDownloads(orderNumber) {
|
|
1187
1300
|
const client = useClient();
|
|
1188
|
-
const [downloads, setDownloads] = (0,
|
|
1189
|
-
const [loading, setLoading] = (0,
|
|
1190
|
-
const [error, setError] = (0,
|
|
1191
|
-
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 () => {
|
|
1192
1305
|
if (!client.isAuthenticated()) {
|
|
1193
1306
|
setDownloads([]);
|
|
1194
1307
|
setLoading(false);
|
|
@@ -1205,13 +1318,13 @@ function useOrderDownloads(orderNumber) {
|
|
|
1205
1318
|
setLoading(false);
|
|
1206
1319
|
}
|
|
1207
1320
|
}, [client, orderNumber]);
|
|
1208
|
-
(0,
|
|
1321
|
+
(0, import_react12.useEffect)(() => {
|
|
1209
1322
|
fetchDownloads();
|
|
1210
1323
|
}, [fetchDownloads]);
|
|
1211
|
-
const getDownloadUrl = (0,
|
|
1324
|
+
const getDownloadUrl = (0, import_react12.useCallback)((token) => {
|
|
1212
1325
|
return client.shop.getDownloadUrl(token);
|
|
1213
1326
|
}, [client]);
|
|
1214
|
-
const getDownloadInfo = (0,
|
|
1327
|
+
const getDownloadInfo = (0, import_react12.useCallback)(async (token) => {
|
|
1215
1328
|
return await client.shop.getDownloadInfo(token);
|
|
1216
1329
|
}, [client]);
|
|
1217
1330
|
return {
|
|
@@ -1225,15 +1338,15 @@ function useOrderDownloads(orderNumber) {
|
|
|
1225
1338
|
}
|
|
1226
1339
|
|
|
1227
1340
|
// src/hooks/useReviews.ts
|
|
1228
|
-
var
|
|
1341
|
+
var import_react13 = require("react");
|
|
1229
1342
|
function useProductReviews(productSlug, params) {
|
|
1230
1343
|
const client = useClient();
|
|
1231
|
-
const [reviews, setReviews] = (0,
|
|
1232
|
-
const [stats, setStats] = (0,
|
|
1233
|
-
const [meta, setMeta] = (0,
|
|
1234
|
-
const [loading, setLoading] = (0,
|
|
1235
|
-
const [error, setError] = (0,
|
|
1236
|
-
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 () => {
|
|
1237
1350
|
setLoading(true);
|
|
1238
1351
|
setError(null);
|
|
1239
1352
|
try {
|
|
@@ -1247,7 +1360,7 @@ function useProductReviews(productSlug, params) {
|
|
|
1247
1360
|
setLoading(false);
|
|
1248
1361
|
}
|
|
1249
1362
|
}, [client, productSlug, params]);
|
|
1250
|
-
(0,
|
|
1363
|
+
(0, import_react13.useEffect)(() => {
|
|
1251
1364
|
fetchReviews();
|
|
1252
1365
|
}, [fetchReviews]);
|
|
1253
1366
|
return {
|
|
@@ -1261,11 +1374,11 @@ function useProductReviews(productSlug, params) {
|
|
|
1261
1374
|
}
|
|
1262
1375
|
function useCanReview(productSlug) {
|
|
1263
1376
|
const client = useClient();
|
|
1264
|
-
const [canReview, setCanReview] = (0,
|
|
1265
|
-
const [reason, setReason] = (0,
|
|
1266
|
-
const [loading, setLoading] = (0,
|
|
1267
|
-
const [error, setError] = (0,
|
|
1268
|
-
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 () => {
|
|
1269
1382
|
setLoading(true);
|
|
1270
1383
|
setError(null);
|
|
1271
1384
|
try {
|
|
@@ -1280,7 +1393,7 @@ function useCanReview(productSlug) {
|
|
|
1280
1393
|
setLoading(false);
|
|
1281
1394
|
}
|
|
1282
1395
|
}, [client, productSlug]);
|
|
1283
|
-
(0,
|
|
1396
|
+
(0, import_react13.useEffect)(() => {
|
|
1284
1397
|
if (client.isAuthenticated()) {
|
|
1285
1398
|
check();
|
|
1286
1399
|
} else {
|
|
@@ -1299,9 +1412,9 @@ function useCanReview(productSlug) {
|
|
|
1299
1412
|
}
|
|
1300
1413
|
function useCreateReview() {
|
|
1301
1414
|
const client = useClient();
|
|
1302
|
-
const [loading, setLoading] = (0,
|
|
1303
|
-
const [error, setError] = (0,
|
|
1304
|
-
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) => {
|
|
1305
1418
|
setLoading(true);
|
|
1306
1419
|
setError(null);
|
|
1307
1420
|
try {
|
|
@@ -1322,11 +1435,11 @@ function useCreateReview() {
|
|
|
1322
1435
|
}
|
|
1323
1436
|
function useMyReviews(params) {
|
|
1324
1437
|
const client = useClient();
|
|
1325
|
-
const [reviews, setReviews] = (0,
|
|
1326
|
-
const [meta, setMeta] = (0,
|
|
1327
|
-
const [loading, setLoading] = (0,
|
|
1328
|
-
const [error, setError] = (0,
|
|
1329
|
-
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 () => {
|
|
1330
1443
|
if (!client.isAuthenticated()) {
|
|
1331
1444
|
setReviews([]);
|
|
1332
1445
|
setLoading(false);
|
|
@@ -1344,14 +1457,14 @@ function useMyReviews(params) {
|
|
|
1344
1457
|
setLoading(false);
|
|
1345
1458
|
}
|
|
1346
1459
|
}, [client, params]);
|
|
1347
|
-
(0,
|
|
1460
|
+
(0, import_react13.useEffect)(() => {
|
|
1348
1461
|
fetchReviews();
|
|
1349
1462
|
}, [fetchReviews]);
|
|
1350
|
-
const deleteReview = (0,
|
|
1463
|
+
const deleteReview = (0, import_react13.useCallback)(async (reviewId) => {
|
|
1351
1464
|
await client.shop.deleteReview(reviewId);
|
|
1352
1465
|
setReviews((prev) => prev.filter((r) => r.id !== reviewId));
|
|
1353
1466
|
}, [client]);
|
|
1354
|
-
const updateReview = (0,
|
|
1467
|
+
const updateReview = (0, import_react13.useCallback)(async (reviewId, data) => {
|
|
1355
1468
|
const updated = await client.shop.updateReview(reviewId, data);
|
|
1356
1469
|
setReviews((prev) => prev.map((r) => r.id === reviewId ? updated : r));
|
|
1357
1470
|
return updated;
|
|
@@ -1368,16 +1481,16 @@ function useMyReviews(params) {
|
|
|
1368
1481
|
}
|
|
1369
1482
|
|
|
1370
1483
|
// src/hooks/useBlog.ts
|
|
1371
|
-
var
|
|
1484
|
+
var import_react14 = require("react");
|
|
1372
1485
|
function useBlog(options = {}) {
|
|
1373
1486
|
const { autoFetch = true, ...params } = options;
|
|
1374
1487
|
const client = useClient();
|
|
1375
|
-
const [posts, setPosts] = (0,
|
|
1376
|
-
const [meta, setMeta] = (0,
|
|
1377
|
-
const [loading, setLoading] = (0,
|
|
1378
|
-
const [error, setError] = (0,
|
|
1379
|
-
const [currentParams, setCurrentParams] = (0,
|
|
1380
|
-
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) => {
|
|
1381
1494
|
setLoading(true);
|
|
1382
1495
|
setError(null);
|
|
1383
1496
|
try {
|
|
@@ -1394,18 +1507,18 @@ function useBlog(options = {}) {
|
|
|
1394
1507
|
setLoading(false);
|
|
1395
1508
|
}
|
|
1396
1509
|
}, [client]);
|
|
1397
|
-
(0,
|
|
1510
|
+
(0, import_react14.useEffect)(() => {
|
|
1398
1511
|
if (autoFetch) {
|
|
1399
1512
|
fetchPosts(params);
|
|
1400
1513
|
}
|
|
1401
1514
|
}, []);
|
|
1402
1515
|
const hasMore = meta ? meta.current_page < meta.last_page : false;
|
|
1403
|
-
const loadMore = (0,
|
|
1516
|
+
const loadMore = (0, import_react14.useCallback)(async () => {
|
|
1404
1517
|
if (!hasMore || loading) return;
|
|
1405
1518
|
const nextPage = (meta?.current_page ?? 0) + 1;
|
|
1406
1519
|
await fetchPosts({ ...currentParams, page: nextPage }, true);
|
|
1407
1520
|
}, [hasMore, loading, meta, currentParams, fetchPosts]);
|
|
1408
|
-
const refresh = (0,
|
|
1521
|
+
const refresh = (0, import_react14.useCallback)(async () => {
|
|
1409
1522
|
setCurrentParams(params);
|
|
1410
1523
|
await fetchPosts(params);
|
|
1411
1524
|
}, [params, fetchPosts]);
|
|
@@ -1421,10 +1534,10 @@ function useBlog(options = {}) {
|
|
|
1421
1534
|
}
|
|
1422
1535
|
function useBlogPost(slug) {
|
|
1423
1536
|
const client = useClient();
|
|
1424
|
-
const [post, setPost] = (0,
|
|
1425
|
-
const [loading, setLoading] = (0,
|
|
1426
|
-
const [error, setError] = (0,
|
|
1427
|
-
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 () => {
|
|
1428
1541
|
setLoading(true);
|
|
1429
1542
|
setError(null);
|
|
1430
1543
|
try {
|
|
@@ -1436,7 +1549,7 @@ function useBlogPost(slug) {
|
|
|
1436
1549
|
setLoading(false);
|
|
1437
1550
|
}
|
|
1438
1551
|
}, [client, slug]);
|
|
1439
|
-
(0,
|
|
1552
|
+
(0, import_react14.useEffect)(() => {
|
|
1440
1553
|
fetchPost();
|
|
1441
1554
|
}, [fetchPost]);
|
|
1442
1555
|
return {
|
|
@@ -1448,10 +1561,10 @@ function useBlogPost(slug) {
|
|
|
1448
1561
|
}
|
|
1449
1562
|
function useBlogCategories() {
|
|
1450
1563
|
const client = useClient();
|
|
1451
|
-
const [categories, setCategories] = (0,
|
|
1452
|
-
const [loading, setLoading] = (0,
|
|
1453
|
-
const [error, setError] = (0,
|
|
1454
|
-
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 () => {
|
|
1455
1568
|
setLoading(true);
|
|
1456
1569
|
setError(null);
|
|
1457
1570
|
try {
|
|
@@ -1463,7 +1576,7 @@ function useBlogCategories() {
|
|
|
1463
1576
|
setLoading(false);
|
|
1464
1577
|
}
|
|
1465
1578
|
}, [client]);
|
|
1466
|
-
(0,
|
|
1579
|
+
(0, import_react14.useEffect)(() => {
|
|
1467
1580
|
fetchCategories();
|
|
1468
1581
|
}, [fetchCategories]);
|
|
1469
1582
|
return {
|
|
@@ -1475,10 +1588,10 @@ function useBlogCategories() {
|
|
|
1475
1588
|
}
|
|
1476
1589
|
function useBlogTags() {
|
|
1477
1590
|
const client = useClient();
|
|
1478
|
-
const [tags, setTags] = (0,
|
|
1479
|
-
const [loading, setLoading] = (0,
|
|
1480
|
-
const [error, setError] = (0,
|
|
1481
|
-
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 () => {
|
|
1482
1595
|
setLoading(true);
|
|
1483
1596
|
setError(null);
|
|
1484
1597
|
try {
|
|
@@ -1490,7 +1603,7 @@ function useBlogTags() {
|
|
|
1490
1603
|
setLoading(false);
|
|
1491
1604
|
}
|
|
1492
1605
|
}, [client]);
|
|
1493
|
-
(0,
|
|
1606
|
+
(0, import_react14.useEffect)(() => {
|
|
1494
1607
|
fetchTags();
|
|
1495
1608
|
}, [fetchTags]);
|
|
1496
1609
|
return {
|
|
@@ -1502,10 +1615,10 @@ function useBlogTags() {
|
|
|
1502
1615
|
}
|
|
1503
1616
|
function useFeaturedBlog(limit = 5) {
|
|
1504
1617
|
const client = useClient();
|
|
1505
|
-
const [posts, setPosts] = (0,
|
|
1506
|
-
const [loading, setLoading] = (0,
|
|
1507
|
-
const [error, setError] = (0,
|
|
1508
|
-
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 () => {
|
|
1509
1622
|
setLoading(true);
|
|
1510
1623
|
setError(null);
|
|
1511
1624
|
try {
|
|
@@ -1517,7 +1630,7 @@ function useFeaturedBlog(limit = 5) {
|
|
|
1517
1630
|
setLoading(false);
|
|
1518
1631
|
}
|
|
1519
1632
|
}, [client, limit]);
|
|
1520
|
-
(0,
|
|
1633
|
+
(0, import_react14.useEffect)(() => {
|
|
1521
1634
|
fetchPosts();
|
|
1522
1635
|
}, [fetchPosts]);
|
|
1523
1636
|
return {
|
|
@@ -1529,11 +1642,11 @@ function useFeaturedBlog(limit = 5) {
|
|
|
1529
1642
|
}
|
|
1530
1643
|
function useBlogSearch() {
|
|
1531
1644
|
const client = useClient();
|
|
1532
|
-
const [posts, setPosts] = (0,
|
|
1533
|
-
const [meta, setMeta] = (0,
|
|
1534
|
-
const [loading, setLoading] = (0,
|
|
1535
|
-
const [error, setError] = (0,
|
|
1536
|
-
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) => {
|
|
1537
1650
|
setLoading(true);
|
|
1538
1651
|
setError(null);
|
|
1539
1652
|
try {
|
|
@@ -1556,13 +1669,13 @@ function useBlogSearch() {
|
|
|
1556
1669
|
}
|
|
1557
1670
|
|
|
1558
1671
|
// src/hooks/useBoards.ts
|
|
1559
|
-
var
|
|
1672
|
+
var import_react15 = require("react");
|
|
1560
1673
|
function useBoards(params) {
|
|
1561
1674
|
const client = useClient();
|
|
1562
|
-
const [boards, setBoards] = (0,
|
|
1563
|
-
const [loading, setLoading] = (0,
|
|
1564
|
-
const [error, setError] = (0,
|
|
1565
|
-
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 () => {
|
|
1566
1679
|
setLoading(true);
|
|
1567
1680
|
setError(null);
|
|
1568
1681
|
try {
|
|
@@ -1574,7 +1687,7 @@ function useBoards(params) {
|
|
|
1574
1687
|
setLoading(false);
|
|
1575
1688
|
}
|
|
1576
1689
|
}, [client, params]);
|
|
1577
|
-
(0,
|
|
1690
|
+
(0, import_react15.useEffect)(() => {
|
|
1578
1691
|
fetchBoards();
|
|
1579
1692
|
}, [fetchBoards]);
|
|
1580
1693
|
return {
|
|
@@ -1586,10 +1699,10 @@ function useBoards(params) {
|
|
|
1586
1699
|
}
|
|
1587
1700
|
function useBoard(slug) {
|
|
1588
1701
|
const client = useClient();
|
|
1589
|
-
const [board, setBoard] = (0,
|
|
1590
|
-
const [loading, setLoading] = (0,
|
|
1591
|
-
const [error, setError] = (0,
|
|
1592
|
-
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 () => {
|
|
1593
1706
|
setLoading(true);
|
|
1594
1707
|
setError(null);
|
|
1595
1708
|
try {
|
|
@@ -1601,7 +1714,7 @@ function useBoard(slug) {
|
|
|
1601
1714
|
setLoading(false);
|
|
1602
1715
|
}
|
|
1603
1716
|
}, [client, slug]);
|
|
1604
|
-
(0,
|
|
1717
|
+
(0, import_react15.useEffect)(() => {
|
|
1605
1718
|
fetchBoard();
|
|
1606
1719
|
}, [fetchBoard]);
|
|
1607
1720
|
return {
|
|
@@ -1613,12 +1726,12 @@ function useBoard(slug) {
|
|
|
1613
1726
|
}
|
|
1614
1727
|
function useBoardPosts(boardSlug, params) {
|
|
1615
1728
|
const client = useClient();
|
|
1616
|
-
const [posts, setPosts] = (0,
|
|
1617
|
-
const [meta, setMeta] = (0,
|
|
1618
|
-
const [loading, setLoading] = (0,
|
|
1619
|
-
const [error, setError] = (0,
|
|
1620
|
-
const [currentParams, setCurrentParams] = (0,
|
|
1621
|
-
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) => {
|
|
1622
1735
|
setLoading(true);
|
|
1623
1736
|
setError(null);
|
|
1624
1737
|
try {
|
|
@@ -1635,16 +1748,16 @@ function useBoardPosts(boardSlug, params) {
|
|
|
1635
1748
|
setLoading(false);
|
|
1636
1749
|
}
|
|
1637
1750
|
}, [client, boardSlug]);
|
|
1638
|
-
(0,
|
|
1751
|
+
(0, import_react15.useEffect)(() => {
|
|
1639
1752
|
fetchPosts(params);
|
|
1640
1753
|
}, []);
|
|
1641
1754
|
const hasMore = meta ? meta.current_page < meta.last_page : false;
|
|
1642
|
-
const loadMore = (0,
|
|
1755
|
+
const loadMore = (0, import_react15.useCallback)(async () => {
|
|
1643
1756
|
if (!hasMore || loading) return;
|
|
1644
1757
|
const nextPage = (meta?.current_page ?? 0) + 1;
|
|
1645
1758
|
await fetchPosts({ ...currentParams, page: nextPage }, true);
|
|
1646
1759
|
}, [hasMore, loading, meta, currentParams, fetchPosts]);
|
|
1647
|
-
const refresh = (0,
|
|
1760
|
+
const refresh = (0, import_react15.useCallback)(async () => {
|
|
1648
1761
|
setCurrentParams(params);
|
|
1649
1762
|
await fetchPosts(params);
|
|
1650
1763
|
}, [params, fetchPosts]);
|
|
@@ -1660,10 +1773,10 @@ function useBoardPosts(boardSlug, params) {
|
|
|
1660
1773
|
}
|
|
1661
1774
|
function useBoardPost(postId) {
|
|
1662
1775
|
const client = useClient();
|
|
1663
|
-
const [post, setPost] = (0,
|
|
1664
|
-
const [loading, setLoading] = (0,
|
|
1665
|
-
const [error, setError] = (0,
|
|
1666
|
-
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 () => {
|
|
1667
1780
|
setLoading(true);
|
|
1668
1781
|
setError(null);
|
|
1669
1782
|
try {
|
|
@@ -1675,7 +1788,7 @@ function useBoardPost(postId) {
|
|
|
1675
1788
|
setLoading(false);
|
|
1676
1789
|
}
|
|
1677
1790
|
}, [client, postId]);
|
|
1678
|
-
(0,
|
|
1791
|
+
(0, import_react15.useEffect)(() => {
|
|
1679
1792
|
fetchPost();
|
|
1680
1793
|
}, [fetchPost]);
|
|
1681
1794
|
return {
|
|
@@ -1687,9 +1800,9 @@ function useBoardPost(postId) {
|
|
|
1687
1800
|
}
|
|
1688
1801
|
function useCreateBoardPost() {
|
|
1689
1802
|
const client = useClient();
|
|
1690
|
-
const [loading, setLoading] = (0,
|
|
1691
|
-
const [error, setError] = (0,
|
|
1692
|
-
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) => {
|
|
1693
1806
|
setLoading(true);
|
|
1694
1807
|
setError(null);
|
|
1695
1808
|
try {
|
|
@@ -1710,15 +1823,15 @@ function useCreateBoardPost() {
|
|
|
1710
1823
|
}
|
|
1711
1824
|
|
|
1712
1825
|
// src/hooks/useComments.ts
|
|
1713
|
-
var
|
|
1826
|
+
var import_react16 = require("react");
|
|
1714
1827
|
function useComments(options) {
|
|
1715
1828
|
const { type, target, page, per_page } = options;
|
|
1716
1829
|
const client = useClient();
|
|
1717
|
-
const [comments, setComments] = (0,
|
|
1718
|
-
const [meta, setMeta] = (0,
|
|
1719
|
-
const [loading, setLoading] = (0,
|
|
1720
|
-
const [error, setError] = (0,
|
|
1721
|
-
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 () => {
|
|
1722
1835
|
setLoading(true);
|
|
1723
1836
|
setError(null);
|
|
1724
1837
|
try {
|
|
@@ -1743,10 +1856,10 @@ function useComments(options) {
|
|
|
1743
1856
|
setLoading(false);
|
|
1744
1857
|
}
|
|
1745
1858
|
}, [client, type, target, page, per_page]);
|
|
1746
|
-
(0,
|
|
1859
|
+
(0, import_react16.useEffect)(() => {
|
|
1747
1860
|
fetchComments();
|
|
1748
1861
|
}, [fetchComments]);
|
|
1749
|
-
const createComment = (0,
|
|
1862
|
+
const createComment = (0, import_react16.useCallback)(async (data) => {
|
|
1750
1863
|
let response;
|
|
1751
1864
|
switch (type) {
|
|
1752
1865
|
case "board":
|
|
@@ -1762,16 +1875,16 @@ function useComments(options) {
|
|
|
1762
1875
|
await fetchComments();
|
|
1763
1876
|
return response.data;
|
|
1764
1877
|
}, [client, type, target, fetchComments]);
|
|
1765
|
-
const updateComment = (0,
|
|
1878
|
+
const updateComment = (0, import_react16.useCallback)(async (commentId, content) => {
|
|
1766
1879
|
const response = await client.comments.update(commentId, { content });
|
|
1767
1880
|
setComments((prev) => prev.map((c) => c.id === commentId ? response.data : c));
|
|
1768
1881
|
return response.data;
|
|
1769
1882
|
}, [client]);
|
|
1770
|
-
const deleteComment = (0,
|
|
1883
|
+
const deleteComment = (0, import_react16.useCallback)(async (commentId, password) => {
|
|
1771
1884
|
await client.comments.delete(commentId, password ? { password } : void 0);
|
|
1772
1885
|
setComments((prev) => prev.filter((c) => c.id !== commentId));
|
|
1773
1886
|
}, [client]);
|
|
1774
|
-
const likeComment = (0,
|
|
1887
|
+
const likeComment = (0, import_react16.useCallback)(async (commentId) => {
|
|
1775
1888
|
const response = await client.comments.like(commentId);
|
|
1776
1889
|
setComments((prev) => prev.map(
|
|
1777
1890
|
(c) => c.id === commentId ? { ...c, likes: response.data.likes } : c
|
|
@@ -1792,15 +1905,15 @@ function useComments(options) {
|
|
|
1792
1905
|
}
|
|
1793
1906
|
|
|
1794
1907
|
// src/hooks/useForms.ts
|
|
1795
|
-
var
|
|
1908
|
+
var import_react17 = require("react");
|
|
1796
1909
|
function useForm(formSlug) {
|
|
1797
1910
|
const client = useClient();
|
|
1798
|
-
const [form, setForm] = (0,
|
|
1799
|
-
const [loading, setLoading] = (0,
|
|
1800
|
-
const [error, setError] = (0,
|
|
1801
|
-
const [submitting, setSubmitting] = (0,
|
|
1802
|
-
const [submitted, setSubmitted] = (0,
|
|
1803
|
-
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 () => {
|
|
1804
1917
|
setLoading(true);
|
|
1805
1918
|
setError(null);
|
|
1806
1919
|
try {
|
|
@@ -1812,10 +1925,10 @@ function useForm(formSlug) {
|
|
|
1812
1925
|
setLoading(false);
|
|
1813
1926
|
}
|
|
1814
1927
|
}, [client, formSlug]);
|
|
1815
|
-
(0,
|
|
1928
|
+
(0, import_react17.useEffect)(() => {
|
|
1816
1929
|
fetchForm();
|
|
1817
1930
|
}, [fetchForm]);
|
|
1818
|
-
const submit = (0,
|
|
1931
|
+
const submit = (0, import_react17.useCallback)(async (data) => {
|
|
1819
1932
|
setSubmitting(true);
|
|
1820
1933
|
setError(null);
|
|
1821
1934
|
try {
|
|
@@ -1830,7 +1943,7 @@ function useForm(formSlug) {
|
|
|
1830
1943
|
setSubmitting(false);
|
|
1831
1944
|
}
|
|
1832
1945
|
}, [client, formSlug]);
|
|
1833
|
-
const reset = (0,
|
|
1946
|
+
const reset = (0, import_react17.useCallback)(() => {
|
|
1834
1947
|
setSubmitted(false);
|
|
1835
1948
|
setError(null);
|
|
1836
1949
|
}, []);
|
|
@@ -1846,13 +1959,13 @@ function useForm(formSlug) {
|
|
|
1846
1959
|
}
|
|
1847
1960
|
|
|
1848
1961
|
// src/hooks/useReservation.ts
|
|
1849
|
-
var
|
|
1962
|
+
var import_react18 = require("react");
|
|
1850
1963
|
function useReservationServices() {
|
|
1851
1964
|
const client = useClient();
|
|
1852
|
-
const [services, setServices] = (0,
|
|
1853
|
-
const [loading, setLoading] = (0,
|
|
1854
|
-
const [error, setError] = (0,
|
|
1855
|
-
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 () => {
|
|
1856
1969
|
setLoading(true);
|
|
1857
1970
|
setError(null);
|
|
1858
1971
|
try {
|
|
@@ -1864,7 +1977,7 @@ function useReservationServices() {
|
|
|
1864
1977
|
setLoading(false);
|
|
1865
1978
|
}
|
|
1866
1979
|
}, [client]);
|
|
1867
|
-
(0,
|
|
1980
|
+
(0, import_react18.useEffect)(() => {
|
|
1868
1981
|
fetchServices();
|
|
1869
1982
|
}, [fetchServices]);
|
|
1870
1983
|
return {
|
|
@@ -1876,10 +1989,10 @@ function useReservationServices() {
|
|
|
1876
1989
|
}
|
|
1877
1990
|
function useReservationStaffs() {
|
|
1878
1991
|
const client = useClient();
|
|
1879
|
-
const [staffs, setStaffs] = (0,
|
|
1880
|
-
const [loading, setLoading] = (0,
|
|
1881
|
-
const [error, setError] = (0,
|
|
1882
|
-
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 () => {
|
|
1883
1996
|
setLoading(true);
|
|
1884
1997
|
setError(null);
|
|
1885
1998
|
try {
|
|
@@ -1891,7 +2004,7 @@ function useReservationStaffs() {
|
|
|
1891
2004
|
setLoading(false);
|
|
1892
2005
|
}
|
|
1893
2006
|
}, [client]);
|
|
1894
|
-
(0,
|
|
2007
|
+
(0, import_react18.useEffect)(() => {
|
|
1895
2008
|
fetchStaffs();
|
|
1896
2009
|
}, [fetchStaffs]);
|
|
1897
2010
|
return {
|
|
@@ -1903,10 +2016,10 @@ function useReservationStaffs() {
|
|
|
1903
2016
|
}
|
|
1904
2017
|
function useAvailableSlots(serviceId, date, staffId) {
|
|
1905
2018
|
const client = useClient();
|
|
1906
|
-
const [slots, setSlots] = (0,
|
|
1907
|
-
const [loading, setLoading] = (0,
|
|
1908
|
-
const [error, setError] = (0,
|
|
1909
|
-
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 () => {
|
|
1910
2023
|
if (!serviceId || !date) {
|
|
1911
2024
|
setSlots([]);
|
|
1912
2025
|
setLoading(false);
|
|
@@ -1927,7 +2040,7 @@ function useAvailableSlots(serviceId, date, staffId) {
|
|
|
1927
2040
|
setLoading(false);
|
|
1928
2041
|
}
|
|
1929
2042
|
}, [client, serviceId, date, staffId]);
|
|
1930
|
-
(0,
|
|
2043
|
+
(0, import_react18.useEffect)(() => {
|
|
1931
2044
|
fetchSlots();
|
|
1932
2045
|
}, [fetchSlots]);
|
|
1933
2046
|
return {
|
|
@@ -1939,11 +2052,11 @@ function useAvailableSlots(serviceId, date, staffId) {
|
|
|
1939
2052
|
}
|
|
1940
2053
|
function useMyReservations(params) {
|
|
1941
2054
|
const client = useClient();
|
|
1942
|
-
const [reservations, setReservations] = (0,
|
|
1943
|
-
const [meta, setMeta] = (0,
|
|
1944
|
-
const [loading, setLoading] = (0,
|
|
1945
|
-
const [error, setError] = (0,
|
|
1946
|
-
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 () => {
|
|
1947
2060
|
if (!client.isAuthenticated()) {
|
|
1948
2061
|
setReservations([]);
|
|
1949
2062
|
setLoading(false);
|
|
@@ -1961,7 +2074,7 @@ function useMyReservations(params) {
|
|
|
1961
2074
|
setLoading(false);
|
|
1962
2075
|
}
|
|
1963
2076
|
}, [client, params]);
|
|
1964
|
-
(0,
|
|
2077
|
+
(0, import_react18.useEffect)(() => {
|
|
1965
2078
|
fetchReservations();
|
|
1966
2079
|
}, [fetchReservations]);
|
|
1967
2080
|
return {
|
|
@@ -1974,9 +2087,9 @@ function useMyReservations(params) {
|
|
|
1974
2087
|
}
|
|
1975
2088
|
function useCreateReservation() {
|
|
1976
2089
|
const client = useClient();
|
|
1977
|
-
const [loading, setLoading] = (0,
|
|
1978
|
-
const [error, setError] = (0,
|
|
1979
|
-
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) => {
|
|
1980
2093
|
setLoading(true);
|
|
1981
2094
|
setError(null);
|
|
1982
2095
|
try {
|
|
@@ -1998,10 +2111,10 @@ function useCreateReservation() {
|
|
|
1998
2111
|
}
|
|
1999
2112
|
function useReservationSettings() {
|
|
2000
2113
|
const client = useClient();
|
|
2001
|
-
const [settings, setSettings] = (0,
|
|
2002
|
-
const [loading, setLoading] = (0,
|
|
2003
|
-
const [error, setError] = (0,
|
|
2004
|
-
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 () => {
|
|
2005
2118
|
setLoading(true);
|
|
2006
2119
|
setError(null);
|
|
2007
2120
|
try {
|
|
@@ -2013,7 +2126,7 @@ function useReservationSettings() {
|
|
|
2013
2126
|
setLoading(false);
|
|
2014
2127
|
}
|
|
2015
2128
|
}, [client]);
|
|
2016
|
-
(0,
|
|
2129
|
+
(0, import_react18.useEffect)(() => {
|
|
2017
2130
|
fetchSettings();
|
|
2018
2131
|
}, [fetchSettings]);
|
|
2019
2132
|
return {
|
|
@@ -2025,17 +2138,17 @@ function useReservationSettings() {
|
|
|
2025
2138
|
}
|
|
2026
2139
|
|
|
2027
2140
|
// src/hooks/useMedia.ts
|
|
2028
|
-
var
|
|
2141
|
+
var import_react19 = require("react");
|
|
2029
2142
|
function useMedia(options = {}) {
|
|
2030
2143
|
const { type, page, per_page, autoFetch = true } = options;
|
|
2031
2144
|
const client = useClient();
|
|
2032
|
-
const [files, setFiles] = (0,
|
|
2033
|
-
const [meta, setMeta] = (0,
|
|
2034
|
-
const [loading, setLoading] = (0,
|
|
2035
|
-
const [error, setError] = (0,
|
|
2036
|
-
const [uploading, setUploading] = (0,
|
|
2037
|
-
const [uploadProgress, setUploadProgress] = (0,
|
|
2038
|
-
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 () => {
|
|
2039
2152
|
if (!client.isAuthenticated()) {
|
|
2040
2153
|
setFiles([]);
|
|
2041
2154
|
setLoading(false);
|
|
@@ -2053,12 +2166,12 @@ function useMedia(options = {}) {
|
|
|
2053
2166
|
setLoading(false);
|
|
2054
2167
|
}
|
|
2055
2168
|
}, [client, type, page, per_page]);
|
|
2056
|
-
(0,
|
|
2169
|
+
(0, import_react19.useEffect)(() => {
|
|
2057
2170
|
if (autoFetch) {
|
|
2058
2171
|
fetchMedia();
|
|
2059
2172
|
}
|
|
2060
2173
|
}, [autoFetch, fetchMedia]);
|
|
2061
|
-
const upload = (0,
|
|
2174
|
+
const upload = (0, import_react19.useCallback)(async (file) => {
|
|
2062
2175
|
setUploading(true);
|
|
2063
2176
|
setUploadProgress(0);
|
|
2064
2177
|
setError(null);
|
|
@@ -2075,7 +2188,7 @@ function useMedia(options = {}) {
|
|
|
2075
2188
|
setUploading(false);
|
|
2076
2189
|
}
|
|
2077
2190
|
}, [client]);
|
|
2078
|
-
const uploadMultiple = (0,
|
|
2191
|
+
const uploadMultiple = (0, import_react19.useCallback)(async (filesToUpload) => {
|
|
2079
2192
|
setUploading(true);
|
|
2080
2193
|
setUploadProgress(0);
|
|
2081
2194
|
setError(null);
|
|
@@ -2096,7 +2209,7 @@ function useMedia(options = {}) {
|
|
|
2096
2209
|
setUploading(false);
|
|
2097
2210
|
}
|
|
2098
2211
|
}, [client]);
|
|
2099
|
-
const deleteFile = (0,
|
|
2212
|
+
const deleteFile = (0, import_react19.useCallback)(async (mediaId) => {
|
|
2100
2213
|
await client.media.delete(mediaId);
|
|
2101
2214
|
setFiles((prev) => prev.filter((f) => f.id !== mediaId));
|
|
2102
2215
|
}, [client]);
|
|
@@ -2115,13 +2228,13 @@ function useMedia(options = {}) {
|
|
|
2115
2228
|
}
|
|
2116
2229
|
|
|
2117
2230
|
// src/hooks/useEntities.ts
|
|
2118
|
-
var
|
|
2231
|
+
var import_react20 = require("react");
|
|
2119
2232
|
function useEntities() {
|
|
2120
2233
|
const client = useClient();
|
|
2121
|
-
const [entities, setEntities] = (0,
|
|
2122
|
-
const [loading, setLoading] = (0,
|
|
2123
|
-
const [error, setError] = (0,
|
|
2124
|
-
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 () => {
|
|
2125
2238
|
setLoading(true);
|
|
2126
2239
|
setError(null);
|
|
2127
2240
|
try {
|
|
@@ -2133,7 +2246,7 @@ function useEntities() {
|
|
|
2133
2246
|
setLoading(false);
|
|
2134
2247
|
}
|
|
2135
2248
|
}, [client]);
|
|
2136
|
-
(0,
|
|
2249
|
+
(0, import_react20.useEffect)(() => {
|
|
2137
2250
|
fetchEntities();
|
|
2138
2251
|
}, [fetchEntities]);
|
|
2139
2252
|
return {
|
|
@@ -2145,10 +2258,10 @@ function useEntities() {
|
|
|
2145
2258
|
}
|
|
2146
2259
|
function useEntity(slug) {
|
|
2147
2260
|
const client = useClient();
|
|
2148
|
-
const [entity, setEntity] = (0,
|
|
2149
|
-
const [loading, setLoading] = (0,
|
|
2150
|
-
const [error, setError] = (0,
|
|
2151
|
-
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 () => {
|
|
2152
2265
|
setLoading(true);
|
|
2153
2266
|
setError(null);
|
|
2154
2267
|
try {
|
|
@@ -2160,7 +2273,7 @@ function useEntity(slug) {
|
|
|
2160
2273
|
setLoading(false);
|
|
2161
2274
|
}
|
|
2162
2275
|
}, [client, slug]);
|
|
2163
|
-
(0,
|
|
2276
|
+
(0, import_react20.useEffect)(() => {
|
|
2164
2277
|
fetchEntity();
|
|
2165
2278
|
}, [fetchEntity]);
|
|
2166
2279
|
return {
|
|
@@ -2172,12 +2285,12 @@ function useEntity(slug) {
|
|
|
2172
2285
|
}
|
|
2173
2286
|
function useEntityRecords(slug, params) {
|
|
2174
2287
|
const client = useClient();
|
|
2175
|
-
const [records, setRecords] = (0,
|
|
2176
|
-
const [meta, setMeta] = (0,
|
|
2177
|
-
const [loading, setLoading] = (0,
|
|
2178
|
-
const [error, setError] = (0,
|
|
2179
|
-
const [currentParams, setCurrentParams] = (0,
|
|
2180
|
-
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) => {
|
|
2181
2294
|
setLoading(true);
|
|
2182
2295
|
setError(null);
|
|
2183
2296
|
try {
|
|
@@ -2194,30 +2307,30 @@ function useEntityRecords(slug, params) {
|
|
|
2194
2307
|
setLoading(false);
|
|
2195
2308
|
}
|
|
2196
2309
|
}, [client, slug]);
|
|
2197
|
-
(0,
|
|
2310
|
+
(0, import_react20.useEffect)(() => {
|
|
2198
2311
|
fetchRecords(params);
|
|
2199
2312
|
}, []);
|
|
2200
2313
|
const hasMore = meta ? meta.current_page < meta.last_page : false;
|
|
2201
|
-
const loadMore = (0,
|
|
2314
|
+
const loadMore = (0, import_react20.useCallback)(async () => {
|
|
2202
2315
|
if (!hasMore || loading) return;
|
|
2203
2316
|
const nextPage = (meta?.current_page ?? 0) + 1;
|
|
2204
2317
|
await fetchRecords({ ...currentParams, page: nextPage }, true);
|
|
2205
2318
|
}, [hasMore, loading, meta, currentParams, fetchRecords]);
|
|
2206
|
-
const createRecord = (0,
|
|
2319
|
+
const createRecord = (0, import_react20.useCallback)(async (data) => {
|
|
2207
2320
|
const record = await client.entities.createRecord(slug, data);
|
|
2208
2321
|
setRecords((prev) => [record, ...prev]);
|
|
2209
2322
|
return record;
|
|
2210
2323
|
}, [client, slug]);
|
|
2211
|
-
const updateRecord = (0,
|
|
2324
|
+
const updateRecord = (0, import_react20.useCallback)(async (id, data) => {
|
|
2212
2325
|
const record = await client.entities.updateRecord(slug, id, data);
|
|
2213
2326
|
setRecords((prev) => prev.map((r) => r.id === id ? record : r));
|
|
2214
2327
|
return record;
|
|
2215
2328
|
}, [client, slug]);
|
|
2216
|
-
const deleteRecord = (0,
|
|
2329
|
+
const deleteRecord = (0, import_react20.useCallback)(async (id) => {
|
|
2217
2330
|
await client.entities.deleteRecord(slug, id);
|
|
2218
2331
|
setRecords((prev) => prev.filter((r) => r.id !== id));
|
|
2219
2332
|
}, [client, slug]);
|
|
2220
|
-
const refresh = (0,
|
|
2333
|
+
const refresh = (0, import_react20.useCallback)(async () => {
|
|
2221
2334
|
setCurrentParams(params);
|
|
2222
2335
|
await fetchRecords(params);
|
|
2223
2336
|
}, [params, fetchRecords]);
|
|
@@ -2236,10 +2349,10 @@ function useEntityRecords(slug, params) {
|
|
|
2236
2349
|
}
|
|
2237
2350
|
function useEntityRecord(slug, id) {
|
|
2238
2351
|
const client = useClient();
|
|
2239
|
-
const [record, setRecord] = (0,
|
|
2240
|
-
const [loading, setLoading] = (0,
|
|
2241
|
-
const [error, setError] = (0,
|
|
2242
|
-
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 () => {
|
|
2243
2356
|
setLoading(true);
|
|
2244
2357
|
setError(null);
|
|
2245
2358
|
try {
|
|
@@ -2251,10 +2364,10 @@ function useEntityRecord(slug, id) {
|
|
|
2251
2364
|
setLoading(false);
|
|
2252
2365
|
}
|
|
2253
2366
|
}, [client, slug, id]);
|
|
2254
|
-
(0,
|
|
2367
|
+
(0, import_react20.useEffect)(() => {
|
|
2255
2368
|
fetchRecord();
|
|
2256
2369
|
}, [fetchRecord]);
|
|
2257
|
-
const update = (0,
|
|
2370
|
+
const update = (0, import_react20.useCallback)(async (data) => {
|
|
2258
2371
|
const updated = await client.entities.updateRecord(slug, id, data);
|
|
2259
2372
|
setRecord(updated);
|
|
2260
2373
|
return updated;
|
|
@@ -2269,7 +2382,7 @@ function useEntityRecord(slug, id) {
|
|
|
2269
2382
|
}
|
|
2270
2383
|
function useTypedEntity(slug) {
|
|
2271
2384
|
const client = useClient();
|
|
2272
|
-
return (0,
|
|
2385
|
+
return (0, import_react20.useMemo)(() => ({
|
|
2273
2386
|
useRecords: (params) => {
|
|
2274
2387
|
const result = useEntityRecords(slug, params);
|
|
2275
2388
|
return {
|
|
@@ -2323,6 +2436,7 @@ function useTypedEntity(slug) {
|
|
|
2323
2436
|
useCreateReservation,
|
|
2324
2437
|
useCreateReview,
|
|
2325
2438
|
useCreateSubscription,
|
|
2439
|
+
useCurrency,
|
|
2326
2440
|
useDiffsome,
|
|
2327
2441
|
useDigitalProducts,
|
|
2328
2442
|
useDownloads,
|
|
@@ -2347,6 +2461,7 @@ function useTypedEntity(slug) {
|
|
|
2347
2461
|
useReservationServices,
|
|
2348
2462
|
useReservationSettings,
|
|
2349
2463
|
useReservationStaffs,
|
|
2464
|
+
useSite,
|
|
2350
2465
|
useSocialAuth,
|
|
2351
2466
|
useStripePayment,
|
|
2352
2467
|
useSubscription,
|