@diffsome/react 1.2.14 → 1.2.16
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/chat.css +29 -0
- package/dist/index.d.mts +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.js +66 -40
- package/dist/index.mjs +128 -102
- package/package.json +1 -1
package/dist/chat.css
CHANGED
|
@@ -316,6 +316,35 @@
|
|
|
316
316
|
background: var(--diffsome-chat-primary-dark);
|
|
317
317
|
}
|
|
318
318
|
|
|
319
|
+
/* Login Prompt */
|
|
320
|
+
.diffsome-chat-login-prompt {
|
|
321
|
+
display: flex;
|
|
322
|
+
align-items: center;
|
|
323
|
+
justify-content: space-between;
|
|
324
|
+
gap: 12px;
|
|
325
|
+
padding: 10px 16px;
|
|
326
|
+
background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
|
|
327
|
+
border-top: 1px solid #bae6fd;
|
|
328
|
+
font-size: 13px;
|
|
329
|
+
color: #0369a1;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
.diffsome-chat-login-btn {
|
|
333
|
+
background: var(--diffsome-chat-primary);
|
|
334
|
+
color: white;
|
|
335
|
+
text-decoration: none;
|
|
336
|
+
padding: 6px 14px;
|
|
337
|
+
border-radius: 16px;
|
|
338
|
+
font-size: 12px;
|
|
339
|
+
font-weight: 500;
|
|
340
|
+
white-space: nowrap;
|
|
341
|
+
transition: background-color 0.2s ease;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
.diffsome-chat-login-btn:hover {
|
|
345
|
+
background: var(--diffsome-chat-primary-dark);
|
|
346
|
+
}
|
|
347
|
+
|
|
319
348
|
/* System Message */
|
|
320
349
|
.diffsome-chat-message-system {
|
|
321
350
|
align-self: center;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import React__default, { ReactNode } from 'react';
|
|
4
|
-
import { Diffsome, Cart, WishlistItem, DiffsomeConfig, CurrencyInfo, SiteInfo,
|
|
4
|
+
import { Diffsome, Member, Cart, WishlistItem, DiffsomeConfig, CurrencyInfo, SiteInfo, LoginCredentials, AuthResponse, RegisterData, UpdateProfileData, ResetPasswordData, SocialProvider, WishlistToggleResult, WishlistMoveToCartResult, BundlePricing, ProductCategory, Product, PaginationMeta, ProductListParams, ProductType, CreateOrderData, Order, OrderListParams, PaymentStatusResponse, StripeCheckoutResponse, StripeVerifyResponse, TossPaymentReadyResponse, TossPaymentConfirmResponse, Coupon, CouponValidation, MemberSubscription, DigitalDownloadLink, CanReviewResponse, CreateProductReviewData, ProductReview, UpdateProductReviewData, ProductReviewStats, ProductReviewListParams, BlogCategory, BlogListParams, BlogPost, BoardPost, Board, CreateBoardPostData, BoardPostListParams, BoardListParams, Comment, CreateCommentData, Form, FormSubmissionData, FormSubmission, ReservationSlot, CreateReservationData, Reservation, ReservationService, ReservationSettings, ReservationStaff, ReservationListParams, Media, CustomEntity, EntityRecord, EntityListParams, ChatConversation, ChatMessage as ChatMessage$1 } from '@diffsome/sdk';
|
|
5
5
|
export { AddToCartData, AuthResponse, BlogCategory, BlogListParams, BlogPost, Board, BoardListParams, BoardPost, BoardPostListParams, CanReviewResponse, Cart, CartItem, Comment, Coupon, CouponType, CouponValidation, CreateBoardPostData, CreateCommentData, CreateOrderData, CreateProductReviewData, CreateReservationData, CustomEntity, DiffsomeConfig, DigitalDownloadLink, DigitalFile, EntityField, EntityListParams, EntityRecord, EntitySchema, Form, FormSubmission, FormSubmissionData, ListResponse, LoginCredentials, Media, Member, MemberSubscription, Order, OrderItem, OrderListParams, OrderStatus, PaginatedResponse, PaginationMeta, Payment, PaymentMethod, PaymentStatus, PaymentStatusResponse, Product, ProductCategory, ProductListParams, ProductReview, ProductReviewStats, ProductType, ProductVariant, RegisterData, Reservation, ReservationService, ReservationSettings, ReservationSlot, ReservationStaff, ResetPasswordData, SiteInfo, SocialAuthUrl, SocialProvider, StripeCheckoutResponse, StripeVerifyResponse, SubscriptionInterval, SubscriptionPlan, SubscriptionStatus, TossPaymentConfirmResponse, TossPaymentReadyResponse, UpdateProfileData, WishlistItem, WishlistMoveToCartResult, WishlistToggleResult } from '@diffsome/sdk';
|
|
6
6
|
|
|
7
7
|
interface DiffsomeContextValue {
|
|
8
8
|
client: Diffsome;
|
|
9
9
|
isReady: boolean;
|
|
10
|
+
user: Member | null;
|
|
11
|
+
authLoading: boolean;
|
|
12
|
+
setUser: (user: Member | null) => void;
|
|
13
|
+
refreshAuth: () => Promise<void>;
|
|
10
14
|
cart: Cart | null;
|
|
11
15
|
cartLoading: boolean;
|
|
12
16
|
setCart: (cart: Cart | null) => void;
|
|
@@ -868,6 +872,12 @@ interface ChatBubbleProps {
|
|
|
868
872
|
onClose?: () => void;
|
|
869
873
|
/** Member auth token for logged-in users (optional) */
|
|
870
874
|
memberToken?: string;
|
|
875
|
+
/** Show login prompt for non-logged-in users */
|
|
876
|
+
showLoginPrompt?: boolean;
|
|
877
|
+
/** Login page URL (used when showLoginPrompt is true) */
|
|
878
|
+
loginUrl?: string;
|
|
879
|
+
/** Custom login prompt message */
|
|
880
|
+
loginPromptMessage?: string;
|
|
871
881
|
}
|
|
872
882
|
declare const ChatBubble: React__default.FC<ChatBubbleProps>;
|
|
873
883
|
|
|
@@ -895,6 +905,14 @@ interface ChatWidgetProps {
|
|
|
895
905
|
typing?: boolean;
|
|
896
906
|
ended?: boolean;
|
|
897
907
|
className?: string;
|
|
908
|
+
/** Whether user is logged in */
|
|
909
|
+
isLoggedIn?: boolean;
|
|
910
|
+
/** Show login prompt for non-logged-in users */
|
|
911
|
+
showLoginPrompt?: boolean;
|
|
912
|
+
/** Login page URL */
|
|
913
|
+
loginUrl?: string;
|
|
914
|
+
/** Custom login prompt message */
|
|
915
|
+
loginPromptMessage?: string;
|
|
898
916
|
}
|
|
899
917
|
declare const ChatWidget: React__default.FC<ChatWidgetProps>;
|
|
900
918
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import React__default, { ReactNode } from 'react';
|
|
4
|
-
import { Diffsome, Cart, WishlistItem, DiffsomeConfig, CurrencyInfo, SiteInfo,
|
|
4
|
+
import { Diffsome, Member, Cart, WishlistItem, DiffsomeConfig, CurrencyInfo, SiteInfo, LoginCredentials, AuthResponse, RegisterData, UpdateProfileData, ResetPasswordData, SocialProvider, WishlistToggleResult, WishlistMoveToCartResult, BundlePricing, ProductCategory, Product, PaginationMeta, ProductListParams, ProductType, CreateOrderData, Order, OrderListParams, PaymentStatusResponse, StripeCheckoutResponse, StripeVerifyResponse, TossPaymentReadyResponse, TossPaymentConfirmResponse, Coupon, CouponValidation, MemberSubscription, DigitalDownloadLink, CanReviewResponse, CreateProductReviewData, ProductReview, UpdateProductReviewData, ProductReviewStats, ProductReviewListParams, BlogCategory, BlogListParams, BlogPost, BoardPost, Board, CreateBoardPostData, BoardPostListParams, BoardListParams, Comment, CreateCommentData, Form, FormSubmissionData, FormSubmission, ReservationSlot, CreateReservationData, Reservation, ReservationService, ReservationSettings, ReservationStaff, ReservationListParams, Media, CustomEntity, EntityRecord, EntityListParams, ChatConversation, ChatMessage as ChatMessage$1 } from '@diffsome/sdk';
|
|
5
5
|
export { AddToCartData, AuthResponse, BlogCategory, BlogListParams, BlogPost, Board, BoardListParams, BoardPost, BoardPostListParams, CanReviewResponse, Cart, CartItem, Comment, Coupon, CouponType, CouponValidation, CreateBoardPostData, CreateCommentData, CreateOrderData, CreateProductReviewData, CreateReservationData, CustomEntity, DiffsomeConfig, DigitalDownloadLink, DigitalFile, EntityField, EntityListParams, EntityRecord, EntitySchema, Form, FormSubmission, FormSubmissionData, ListResponse, LoginCredentials, Media, Member, MemberSubscription, Order, OrderItem, OrderListParams, OrderStatus, PaginatedResponse, PaginationMeta, Payment, PaymentMethod, PaymentStatus, PaymentStatusResponse, Product, ProductCategory, ProductListParams, ProductReview, ProductReviewStats, ProductType, ProductVariant, RegisterData, Reservation, ReservationService, ReservationSettings, ReservationSlot, ReservationStaff, ResetPasswordData, SiteInfo, SocialAuthUrl, SocialProvider, StripeCheckoutResponse, StripeVerifyResponse, SubscriptionInterval, SubscriptionPlan, SubscriptionStatus, TossPaymentConfirmResponse, TossPaymentReadyResponse, UpdateProfileData, WishlistItem, WishlistMoveToCartResult, WishlistToggleResult } from '@diffsome/sdk';
|
|
6
6
|
|
|
7
7
|
interface DiffsomeContextValue {
|
|
8
8
|
client: Diffsome;
|
|
9
9
|
isReady: boolean;
|
|
10
|
+
user: Member | null;
|
|
11
|
+
authLoading: boolean;
|
|
12
|
+
setUser: (user: Member | null) => void;
|
|
13
|
+
refreshAuth: () => Promise<void>;
|
|
10
14
|
cart: Cart | null;
|
|
11
15
|
cartLoading: boolean;
|
|
12
16
|
setCart: (cart: Cart | null) => void;
|
|
@@ -868,6 +872,12 @@ interface ChatBubbleProps {
|
|
|
868
872
|
onClose?: () => void;
|
|
869
873
|
/** Member auth token for logged-in users (optional) */
|
|
870
874
|
memberToken?: string;
|
|
875
|
+
/** Show login prompt for non-logged-in users */
|
|
876
|
+
showLoginPrompt?: boolean;
|
|
877
|
+
/** Login page URL (used when showLoginPrompt is true) */
|
|
878
|
+
loginUrl?: string;
|
|
879
|
+
/** Custom login prompt message */
|
|
880
|
+
loginPromptMessage?: string;
|
|
871
881
|
}
|
|
872
882
|
declare const ChatBubble: React__default.FC<ChatBubbleProps>;
|
|
873
883
|
|
|
@@ -895,6 +905,14 @@ interface ChatWidgetProps {
|
|
|
895
905
|
typing?: boolean;
|
|
896
906
|
ended?: boolean;
|
|
897
907
|
className?: string;
|
|
908
|
+
/** Whether user is logged in */
|
|
909
|
+
isLoggedIn?: boolean;
|
|
910
|
+
/** Show login prompt for non-logged-in users */
|
|
911
|
+
showLoginPrompt?: boolean;
|
|
912
|
+
/** Login page URL */
|
|
913
|
+
loginUrl?: string;
|
|
914
|
+
/** Custom login prompt message */
|
|
915
|
+
loginPromptMessage?: string;
|
|
898
916
|
}
|
|
899
917
|
declare const ChatWidget: React__default.FC<ChatWidgetProps>;
|
|
900
918
|
|
package/dist/index.js
CHANGED
|
@@ -106,6 +106,8 @@ var getEnvVar = (key) => {
|
|
|
106
106
|
};
|
|
107
107
|
function DiffsomeProvider({ children, config = {} }) {
|
|
108
108
|
const [isReady, setIsReady] = (0, import_react.useState)(false);
|
|
109
|
+
const [user, setUser] = (0, import_react.useState)(null);
|
|
110
|
+
const [authLoading, setAuthLoading] = (0, import_react.useState)(true);
|
|
109
111
|
const [cart, setCart] = (0, import_react.useState)(null);
|
|
110
112
|
const [cartLoading, setCartLoading] = (0, import_react.useState)(true);
|
|
111
113
|
const [wishlistItems, setWishlistItems] = (0, import_react.useState)([]);
|
|
@@ -127,6 +129,22 @@ function DiffsomeProvider({ children, config = {} }) {
|
|
|
127
129
|
storageType: config.storageType ?? "localStorage"
|
|
128
130
|
});
|
|
129
131
|
}, [tenantId, baseUrl, apiKey, config.persistToken, config.storageType]);
|
|
132
|
+
const refreshAuth = (0, import_react.useCallback)(async () => {
|
|
133
|
+
if (!client.isAuthenticated()) {
|
|
134
|
+
setUser(null);
|
|
135
|
+
setAuthLoading(false);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
setAuthLoading(true);
|
|
139
|
+
try {
|
|
140
|
+
const profile = await client.auth.me();
|
|
141
|
+
setUser(profile);
|
|
142
|
+
} catch (err) {
|
|
143
|
+
setUser(null);
|
|
144
|
+
} finally {
|
|
145
|
+
setAuthLoading(false);
|
|
146
|
+
}
|
|
147
|
+
}, [client]);
|
|
130
148
|
const refreshCart = (0, import_react.useCallback)(async () => {
|
|
131
149
|
setCartLoading(true);
|
|
132
150
|
try {
|
|
@@ -159,6 +177,15 @@ function DiffsomeProvider({ children, config = {} }) {
|
|
|
159
177
|
const init = async () => {
|
|
160
178
|
if (!mounted) return;
|
|
161
179
|
setIsReady(true);
|
|
180
|
+
if (client.isAuthenticated()) {
|
|
181
|
+
try {
|
|
182
|
+
const profile = await client.auth.me();
|
|
183
|
+
if (mounted) setUser(profile);
|
|
184
|
+
} catch (err) {
|
|
185
|
+
if (mounted) setUser(null);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (mounted) setAuthLoading(false);
|
|
162
189
|
try {
|
|
163
190
|
const cartData = await client.shop.getCart();
|
|
164
191
|
if (mounted) setCart(cartData);
|
|
@@ -185,6 +212,10 @@ function DiffsomeProvider({ children, config = {} }) {
|
|
|
185
212
|
const value = (0, import_react.useMemo)(() => ({
|
|
186
213
|
client,
|
|
187
214
|
isReady,
|
|
215
|
+
user,
|
|
216
|
+
authLoading,
|
|
217
|
+
setUser,
|
|
218
|
+
refreshAuth,
|
|
188
219
|
cart,
|
|
189
220
|
cartLoading,
|
|
190
221
|
setCart,
|
|
@@ -193,7 +224,7 @@ function DiffsomeProvider({ children, config = {} }) {
|
|
|
193
224
|
wishlistLoading,
|
|
194
225
|
setWishlistItems,
|
|
195
226
|
refreshWishlist
|
|
196
|
-
}), [client, isReady, cart, cartLoading, refreshCart, wishlistItems, wishlistLoading, refreshWishlist]);
|
|
227
|
+
}), [client, isReady, user, authLoading, refreshAuth, cart, cartLoading, refreshCart, wishlistItems, wishlistLoading, refreshWishlist]);
|
|
197
228
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DiffsomeContext.Provider, { value, children });
|
|
198
229
|
}
|
|
199
230
|
function useDiffsome() {
|
|
@@ -300,33 +331,13 @@ function useCurrency() {
|
|
|
300
331
|
// src/hooks/useAuth.ts
|
|
301
332
|
var import_react3 = require("react");
|
|
302
333
|
function useAuth() {
|
|
303
|
-
const client =
|
|
304
|
-
const [
|
|
305
|
-
const [loading, setLoading] = (0, import_react3.useState)(true);
|
|
334
|
+
const { client, user, authLoading, setUser, refreshAuth } = useDiffsome();
|
|
335
|
+
const [actionLoading, setActionLoading] = (0, import_react3.useState)(false);
|
|
306
336
|
const [error, setError] = (0, import_react3.useState)(null);
|
|
307
337
|
const isAuthenticated = !!user && client.isAuthenticated();
|
|
308
|
-
const
|
|
309
|
-
if (!client.isAuthenticated()) {
|
|
310
|
-
setUser(null);
|
|
311
|
-
setLoading(false);
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
try {
|
|
315
|
-
const profile = await client.auth.me();
|
|
316
|
-
setUser(profile);
|
|
317
|
-
setError(null);
|
|
318
|
-
} catch (err) {
|
|
319
|
-
setUser(null);
|
|
320
|
-
setError(err instanceof Error ? err : new Error("Failed to fetch profile"));
|
|
321
|
-
} finally {
|
|
322
|
-
setLoading(false);
|
|
323
|
-
}
|
|
324
|
-
}, [client]);
|
|
325
|
-
(0, import_react3.useEffect)(() => {
|
|
326
|
-
fetchProfile();
|
|
327
|
-
}, [fetchProfile]);
|
|
338
|
+
const loading = authLoading || actionLoading;
|
|
328
339
|
const login = (0, import_react3.useCallback)(async (credentials) => {
|
|
329
|
-
|
|
340
|
+
setActionLoading(true);
|
|
330
341
|
setError(null);
|
|
331
342
|
try {
|
|
332
343
|
const response = await client.auth.login(credentials);
|
|
@@ -337,11 +348,11 @@ function useAuth() {
|
|
|
337
348
|
setError(error2);
|
|
338
349
|
throw error2;
|
|
339
350
|
} finally {
|
|
340
|
-
|
|
351
|
+
setActionLoading(false);
|
|
341
352
|
}
|
|
342
|
-
}, [client]);
|
|
353
|
+
}, [client, setUser]);
|
|
343
354
|
const register = (0, import_react3.useCallback)(async (data) => {
|
|
344
|
-
|
|
355
|
+
setActionLoading(true);
|
|
345
356
|
setError(null);
|
|
346
357
|
try {
|
|
347
358
|
const response = await client.auth.register(data);
|
|
@@ -352,28 +363,28 @@ function useAuth() {
|
|
|
352
363
|
setError(error2);
|
|
353
364
|
throw error2;
|
|
354
365
|
} finally {
|
|
355
|
-
|
|
366
|
+
setActionLoading(false);
|
|
356
367
|
}
|
|
357
|
-
}, [client]);
|
|
368
|
+
}, [client, setUser]);
|
|
358
369
|
const logout = (0, import_react3.useCallback)(async () => {
|
|
359
|
-
|
|
370
|
+
setActionLoading(true);
|
|
360
371
|
try {
|
|
361
372
|
await client.auth.logout();
|
|
362
373
|
} finally {
|
|
363
374
|
setUser(null);
|
|
364
|
-
|
|
375
|
+
setActionLoading(false);
|
|
365
376
|
}
|
|
366
|
-
}, [client]);
|
|
377
|
+
}, [client, setUser]);
|
|
367
378
|
const getProfile = (0, import_react3.useCallback)(async () => {
|
|
368
379
|
const profile = await client.auth.me();
|
|
369
380
|
setUser(profile);
|
|
370
381
|
return profile;
|
|
371
|
-
}, [client]);
|
|
382
|
+
}, [client, setUser]);
|
|
372
383
|
const updateProfile = (0, import_react3.useCallback)(async (data) => {
|
|
373
384
|
const profile = await client.auth.updateProfile(data);
|
|
374
385
|
setUser(profile);
|
|
375
386
|
return profile;
|
|
376
|
-
}, [client]);
|
|
387
|
+
}, [client, setUser]);
|
|
377
388
|
const forgotPassword = (0, import_react3.useCallback)(async (email) => {
|
|
378
389
|
return await client.auth.forgotPassword({ email });
|
|
379
390
|
}, [client]);
|
|
@@ -381,8 +392,8 @@ function useAuth() {
|
|
|
381
392
|
return await client.auth.resetPassword(data);
|
|
382
393
|
}, [client]);
|
|
383
394
|
const refresh = (0, import_react3.useCallback)(async () => {
|
|
384
|
-
await
|
|
385
|
-
}, [
|
|
395
|
+
await refreshAuth();
|
|
396
|
+
}, [refreshAuth]);
|
|
386
397
|
return {
|
|
387
398
|
user,
|
|
388
399
|
isAuthenticated,
|
|
@@ -2727,7 +2738,11 @@ var ChatWidget = ({
|
|
|
2727
2738
|
loading = false,
|
|
2728
2739
|
typing = false,
|
|
2729
2740
|
ended = false,
|
|
2730
|
-
className = ""
|
|
2741
|
+
className = "",
|
|
2742
|
+
isLoggedIn = false,
|
|
2743
|
+
showLoginPrompt = false,
|
|
2744
|
+
loginUrl = "/auth/login",
|
|
2745
|
+
loginPromptMessage = "Login to save your chat history across devices"
|
|
2731
2746
|
}) => {
|
|
2732
2747
|
const messagesEndRef = (0, import_react23.useRef)(null);
|
|
2733
2748
|
const scrollToBottom = () => {
|
|
@@ -2805,6 +2820,10 @@ var ChatWidget = ({
|
|
|
2805
2820
|
}
|
|
2806
2821
|
)
|
|
2807
2822
|
] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
2823
|
+
showLoginPrompt && !isLoggedIn && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "diffsome-chat-login-prompt", children: [
|
|
2824
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: loginPromptMessage }),
|
|
2825
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("a", { href: loginUrl, className: "diffsome-chat-login-btn", children: "Login" })
|
|
2826
|
+
] }),
|
|
2808
2827
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2809
2828
|
ChatInput,
|
|
2810
2829
|
{
|
|
@@ -2845,7 +2864,10 @@ var ChatBubble = ({
|
|
|
2845
2864
|
className = "",
|
|
2846
2865
|
onOpen,
|
|
2847
2866
|
onClose,
|
|
2848
|
-
memberToken
|
|
2867
|
+
memberToken,
|
|
2868
|
+
showLoginPrompt = false,
|
|
2869
|
+
loginUrl = "/auth/login",
|
|
2870
|
+
loginPromptMessage = "Login to save your chat history across devices"
|
|
2849
2871
|
}) => {
|
|
2850
2872
|
(0, import_react24.useEffect)(() => {
|
|
2851
2873
|
if (memberToken) {
|
|
@@ -3043,7 +3065,11 @@ var ChatBubble = ({
|
|
|
3043
3065
|
placeholder,
|
|
3044
3066
|
loading,
|
|
3045
3067
|
typing,
|
|
3046
|
-
ended
|
|
3068
|
+
ended,
|
|
3069
|
+
isLoggedIn: !!memberToken,
|
|
3070
|
+
showLoginPrompt,
|
|
3071
|
+
loginUrl,
|
|
3072
|
+
loginPromptMessage
|
|
3047
3073
|
}
|
|
3048
3074
|
),
|
|
3049
3075
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
package/dist/index.mjs
CHANGED
|
@@ -14,6 +14,8 @@ var getEnvVar = (key) => {
|
|
|
14
14
|
};
|
|
15
15
|
function DiffsomeProvider({ children, config = {} }) {
|
|
16
16
|
const [isReady, setIsReady] = useState(false);
|
|
17
|
+
const [user, setUser] = useState(null);
|
|
18
|
+
const [authLoading, setAuthLoading] = useState(true);
|
|
17
19
|
const [cart, setCart] = useState(null);
|
|
18
20
|
const [cartLoading, setCartLoading] = useState(true);
|
|
19
21
|
const [wishlistItems, setWishlistItems] = useState([]);
|
|
@@ -35,6 +37,22 @@ function DiffsomeProvider({ children, config = {} }) {
|
|
|
35
37
|
storageType: config.storageType ?? "localStorage"
|
|
36
38
|
});
|
|
37
39
|
}, [tenantId, baseUrl, apiKey, config.persistToken, config.storageType]);
|
|
40
|
+
const refreshAuth = useCallback(async () => {
|
|
41
|
+
if (!client.isAuthenticated()) {
|
|
42
|
+
setUser(null);
|
|
43
|
+
setAuthLoading(false);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
setAuthLoading(true);
|
|
47
|
+
try {
|
|
48
|
+
const profile = await client.auth.me();
|
|
49
|
+
setUser(profile);
|
|
50
|
+
} catch (err) {
|
|
51
|
+
setUser(null);
|
|
52
|
+
} finally {
|
|
53
|
+
setAuthLoading(false);
|
|
54
|
+
}
|
|
55
|
+
}, [client]);
|
|
38
56
|
const refreshCart = useCallback(async () => {
|
|
39
57
|
setCartLoading(true);
|
|
40
58
|
try {
|
|
@@ -67,6 +85,15 @@ function DiffsomeProvider({ children, config = {} }) {
|
|
|
67
85
|
const init = async () => {
|
|
68
86
|
if (!mounted) return;
|
|
69
87
|
setIsReady(true);
|
|
88
|
+
if (client.isAuthenticated()) {
|
|
89
|
+
try {
|
|
90
|
+
const profile = await client.auth.me();
|
|
91
|
+
if (mounted) setUser(profile);
|
|
92
|
+
} catch (err) {
|
|
93
|
+
if (mounted) setUser(null);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (mounted) setAuthLoading(false);
|
|
70
97
|
try {
|
|
71
98
|
const cartData = await client.shop.getCart();
|
|
72
99
|
if (mounted) setCart(cartData);
|
|
@@ -93,6 +120,10 @@ function DiffsomeProvider({ children, config = {} }) {
|
|
|
93
120
|
const value = useMemo(() => ({
|
|
94
121
|
client,
|
|
95
122
|
isReady,
|
|
123
|
+
user,
|
|
124
|
+
authLoading,
|
|
125
|
+
setUser,
|
|
126
|
+
refreshAuth,
|
|
96
127
|
cart,
|
|
97
128
|
cartLoading,
|
|
98
129
|
setCart,
|
|
@@ -101,7 +132,7 @@ function DiffsomeProvider({ children, config = {} }) {
|
|
|
101
132
|
wishlistLoading,
|
|
102
133
|
setWishlistItems,
|
|
103
134
|
refreshWishlist
|
|
104
|
-
}), [client, isReady, cart, cartLoading, refreshCart, wishlistItems, wishlistLoading, refreshWishlist]);
|
|
135
|
+
}), [client, isReady, user, authLoading, refreshAuth, cart, cartLoading, refreshCart, wishlistItems, wishlistLoading, refreshWishlist]);
|
|
105
136
|
return /* @__PURE__ */ jsx(DiffsomeContext.Provider, { value, children });
|
|
106
137
|
}
|
|
107
138
|
function useDiffsome() {
|
|
@@ -206,35 +237,15 @@ function useCurrency() {
|
|
|
206
237
|
}
|
|
207
238
|
|
|
208
239
|
// src/hooks/useAuth.ts
|
|
209
|
-
import { useState as useState3,
|
|
240
|
+
import { useState as useState3, useCallback as useCallback3 } from "react";
|
|
210
241
|
function useAuth() {
|
|
211
|
-
const client =
|
|
212
|
-
const [
|
|
213
|
-
const [loading, setLoading] = useState3(true);
|
|
242
|
+
const { client, user, authLoading, setUser, refreshAuth } = useDiffsome();
|
|
243
|
+
const [actionLoading, setActionLoading] = useState3(false);
|
|
214
244
|
const [error, setError] = useState3(null);
|
|
215
245
|
const isAuthenticated = !!user && client.isAuthenticated();
|
|
216
|
-
const
|
|
217
|
-
if (!client.isAuthenticated()) {
|
|
218
|
-
setUser(null);
|
|
219
|
-
setLoading(false);
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
try {
|
|
223
|
-
const profile = await client.auth.me();
|
|
224
|
-
setUser(profile);
|
|
225
|
-
setError(null);
|
|
226
|
-
} catch (err) {
|
|
227
|
-
setUser(null);
|
|
228
|
-
setError(err instanceof Error ? err : new Error("Failed to fetch profile"));
|
|
229
|
-
} finally {
|
|
230
|
-
setLoading(false);
|
|
231
|
-
}
|
|
232
|
-
}, [client]);
|
|
233
|
-
useEffect3(() => {
|
|
234
|
-
fetchProfile();
|
|
235
|
-
}, [fetchProfile]);
|
|
246
|
+
const loading = authLoading || actionLoading;
|
|
236
247
|
const login = useCallback3(async (credentials) => {
|
|
237
|
-
|
|
248
|
+
setActionLoading(true);
|
|
238
249
|
setError(null);
|
|
239
250
|
try {
|
|
240
251
|
const response = await client.auth.login(credentials);
|
|
@@ -245,11 +256,11 @@ function useAuth() {
|
|
|
245
256
|
setError(error2);
|
|
246
257
|
throw error2;
|
|
247
258
|
} finally {
|
|
248
|
-
|
|
259
|
+
setActionLoading(false);
|
|
249
260
|
}
|
|
250
|
-
}, [client]);
|
|
261
|
+
}, [client, setUser]);
|
|
251
262
|
const register = useCallback3(async (data) => {
|
|
252
|
-
|
|
263
|
+
setActionLoading(true);
|
|
253
264
|
setError(null);
|
|
254
265
|
try {
|
|
255
266
|
const response = await client.auth.register(data);
|
|
@@ -260,28 +271,28 @@ function useAuth() {
|
|
|
260
271
|
setError(error2);
|
|
261
272
|
throw error2;
|
|
262
273
|
} finally {
|
|
263
|
-
|
|
274
|
+
setActionLoading(false);
|
|
264
275
|
}
|
|
265
|
-
}, [client]);
|
|
276
|
+
}, [client, setUser]);
|
|
266
277
|
const logout = useCallback3(async () => {
|
|
267
|
-
|
|
278
|
+
setActionLoading(true);
|
|
268
279
|
try {
|
|
269
280
|
await client.auth.logout();
|
|
270
281
|
} finally {
|
|
271
282
|
setUser(null);
|
|
272
|
-
|
|
283
|
+
setActionLoading(false);
|
|
273
284
|
}
|
|
274
|
-
}, [client]);
|
|
285
|
+
}, [client, setUser]);
|
|
275
286
|
const getProfile = useCallback3(async () => {
|
|
276
287
|
const profile = await client.auth.me();
|
|
277
288
|
setUser(profile);
|
|
278
289
|
return profile;
|
|
279
|
-
}, [client]);
|
|
290
|
+
}, [client, setUser]);
|
|
280
291
|
const updateProfile = useCallback3(async (data) => {
|
|
281
292
|
const profile = await client.auth.updateProfile(data);
|
|
282
293
|
setUser(profile);
|
|
283
294
|
return profile;
|
|
284
|
-
}, [client]);
|
|
295
|
+
}, [client, setUser]);
|
|
285
296
|
const forgotPassword = useCallback3(async (email) => {
|
|
286
297
|
return await client.auth.forgotPassword({ email });
|
|
287
298
|
}, [client]);
|
|
@@ -289,8 +300,8 @@ function useAuth() {
|
|
|
289
300
|
return await client.auth.resetPassword(data);
|
|
290
301
|
}, [client]);
|
|
291
302
|
const refresh = useCallback3(async () => {
|
|
292
|
-
await
|
|
293
|
-
}, [
|
|
303
|
+
await refreshAuth();
|
|
304
|
+
}, [refreshAuth]);
|
|
294
305
|
return {
|
|
295
306
|
user,
|
|
296
307
|
isAuthenticated,
|
|
@@ -308,7 +319,7 @@ function useAuth() {
|
|
|
308
319
|
}
|
|
309
320
|
|
|
310
321
|
// src/hooks/useSocialAuth.ts
|
|
311
|
-
import { useState as useState4, useEffect as
|
|
322
|
+
import { useState as useState4, useEffect as useEffect3, useCallback as useCallback4 } from "react";
|
|
312
323
|
function useSocialAuth() {
|
|
313
324
|
const client = useClient();
|
|
314
325
|
const [providers, setProviders] = useState4([]);
|
|
@@ -326,7 +337,7 @@ function useSocialAuth() {
|
|
|
326
337
|
setLoading(false);
|
|
327
338
|
}
|
|
328
339
|
}, [client]);
|
|
329
|
-
|
|
340
|
+
useEffect3(() => {
|
|
330
341
|
fetchProviders();
|
|
331
342
|
}, [fetchProviders]);
|
|
332
343
|
const getAuthUrl = useCallback4(async (provider) => {
|
|
@@ -480,7 +491,7 @@ function useWishlist() {
|
|
|
480
491
|
}
|
|
481
492
|
|
|
482
493
|
// src/hooks/useProducts.ts
|
|
483
|
-
import { useState as useState6, useEffect as
|
|
494
|
+
import { useState as useState6, useEffect as useEffect4, useCallback as useCallback7 } from "react";
|
|
484
495
|
function useProducts(options = {}) {
|
|
485
496
|
const { autoFetch = true, ...params } = options;
|
|
486
497
|
const client = useClient();
|
|
@@ -506,7 +517,7 @@ function useProducts(options = {}) {
|
|
|
506
517
|
setLoading(false);
|
|
507
518
|
}
|
|
508
519
|
}, [client]);
|
|
509
|
-
|
|
520
|
+
useEffect4(() => {
|
|
510
521
|
if (autoFetch) {
|
|
511
522
|
fetchProducts(params);
|
|
512
523
|
}
|
|
@@ -554,7 +565,7 @@ function useProduct(idOrSlug) {
|
|
|
554
565
|
setLoading(false);
|
|
555
566
|
}
|
|
556
567
|
}, [client, idOrSlug]);
|
|
557
|
-
|
|
568
|
+
useEffect4(() => {
|
|
558
569
|
fetchProduct();
|
|
559
570
|
}, [fetchProduct]);
|
|
560
571
|
return {
|
|
@@ -581,7 +592,7 @@ function useCategories() {
|
|
|
581
592
|
setLoading(false);
|
|
582
593
|
}
|
|
583
594
|
}, [client]);
|
|
584
|
-
|
|
595
|
+
useEffect4(() => {
|
|
585
596
|
fetchCategories();
|
|
586
597
|
}, [fetchCategories]);
|
|
587
598
|
return {
|
|
@@ -608,7 +619,7 @@ function useFeaturedProducts(limit = 8) {
|
|
|
608
619
|
setLoading(false);
|
|
609
620
|
}
|
|
610
621
|
}, [client, limit]);
|
|
611
|
-
|
|
622
|
+
useEffect4(() => {
|
|
612
623
|
fetchProducts();
|
|
613
624
|
}, [fetchProducts]);
|
|
614
625
|
return {
|
|
@@ -637,7 +648,7 @@ function useProductsByType(type, params) {
|
|
|
637
648
|
setLoading(false);
|
|
638
649
|
}
|
|
639
650
|
}, [client, type, params]);
|
|
640
|
-
|
|
651
|
+
useEffect4(() => {
|
|
641
652
|
fetchProducts();
|
|
642
653
|
}, [fetchProducts]);
|
|
643
654
|
return {
|
|
@@ -674,7 +685,7 @@ function useBundleItems(productSlug) {
|
|
|
674
685
|
setLoading(false);
|
|
675
686
|
}
|
|
676
687
|
}, [client, productSlug]);
|
|
677
|
-
|
|
688
|
+
useEffect4(() => {
|
|
678
689
|
fetchBundle();
|
|
679
690
|
}, [fetchBundle]);
|
|
680
691
|
return {
|
|
@@ -686,7 +697,7 @@ function useBundleItems(productSlug) {
|
|
|
686
697
|
}
|
|
687
698
|
|
|
688
699
|
// src/hooks/useOrders.ts
|
|
689
|
-
import { useState as useState7, useEffect as
|
|
700
|
+
import { useState as useState7, useEffect as useEffect5, useCallback as useCallback8 } from "react";
|
|
690
701
|
function useOrders(params) {
|
|
691
702
|
const client = useClient();
|
|
692
703
|
const [orders, setOrders] = useState7([]);
|
|
@@ -715,7 +726,7 @@ function useOrders(params) {
|
|
|
715
726
|
setLoading(false);
|
|
716
727
|
}
|
|
717
728
|
}, [client]);
|
|
718
|
-
|
|
729
|
+
useEffect5(() => {
|
|
719
730
|
fetchOrders(params);
|
|
720
731
|
}, []);
|
|
721
732
|
const hasMore = meta ? meta.current_page < meta.last_page : false;
|
|
@@ -754,7 +765,7 @@ function useOrder(idOrNumber) {
|
|
|
754
765
|
setLoading(false);
|
|
755
766
|
}
|
|
756
767
|
}, [client, idOrNumber]);
|
|
757
|
-
|
|
768
|
+
useEffect5(() => {
|
|
758
769
|
fetchOrder();
|
|
759
770
|
}, [fetchOrder]);
|
|
760
771
|
const cancel = useCallback8(async () => {
|
|
@@ -960,7 +971,7 @@ function useStripePayment() {
|
|
|
960
971
|
}
|
|
961
972
|
|
|
962
973
|
// src/hooks/useCoupons.ts
|
|
963
|
-
import { useState as useState9, useEffect as
|
|
974
|
+
import { useState as useState9, useEffect as useEffect6, useCallback as useCallback10 } from "react";
|
|
964
975
|
function useCoupons() {
|
|
965
976
|
const client = useClient();
|
|
966
977
|
const [coupons, setCoupons] = useState9([]);
|
|
@@ -983,7 +994,7 @@ function useCoupons() {
|
|
|
983
994
|
setLoading(false);
|
|
984
995
|
}
|
|
985
996
|
}, [client]);
|
|
986
|
-
|
|
997
|
+
useEffect6(() => {
|
|
987
998
|
fetchCoupons();
|
|
988
999
|
}, [fetchCoupons]);
|
|
989
1000
|
return {
|
|
@@ -1028,7 +1039,7 @@ function useValidateCoupon() {
|
|
|
1028
1039
|
}
|
|
1029
1040
|
|
|
1030
1041
|
// src/hooks/useSubscriptions.ts
|
|
1031
|
-
import { useState as useState10, useEffect as
|
|
1042
|
+
import { useState as useState10, useEffect as useEffect7, useCallback as useCallback11 } from "react";
|
|
1032
1043
|
function useSubscriptions() {
|
|
1033
1044
|
const client = useClient();
|
|
1034
1045
|
const [subscriptions, setSubscriptions] = useState10([]);
|
|
@@ -1051,7 +1062,7 @@ function useSubscriptions() {
|
|
|
1051
1062
|
setLoading(false);
|
|
1052
1063
|
}
|
|
1053
1064
|
}, [client]);
|
|
1054
|
-
|
|
1065
|
+
useEffect7(() => {
|
|
1055
1066
|
fetchSubscriptions();
|
|
1056
1067
|
}, [fetchSubscriptions]);
|
|
1057
1068
|
const activeSubscription = subscriptions.find((s) => s.is_active) ?? null;
|
|
@@ -1082,7 +1093,7 @@ function useSubscription(id) {
|
|
|
1082
1093
|
setLoading(false);
|
|
1083
1094
|
}
|
|
1084
1095
|
}, [client, id]);
|
|
1085
|
-
|
|
1096
|
+
useEffect7(() => {
|
|
1086
1097
|
fetchSubscription();
|
|
1087
1098
|
}, [fetchSubscription]);
|
|
1088
1099
|
const cancel = useCallback11(async (immediately = false) => {
|
|
@@ -1169,7 +1180,7 @@ function useCreateSubscription() {
|
|
|
1169
1180
|
}
|
|
1170
1181
|
|
|
1171
1182
|
// src/hooks/useDownloads.ts
|
|
1172
|
-
import { useState as useState11, useEffect as
|
|
1183
|
+
import { useState as useState11, useEffect as useEffect8, useCallback as useCallback12 } from "react";
|
|
1173
1184
|
function useDownloads() {
|
|
1174
1185
|
const client = useClient();
|
|
1175
1186
|
const [downloads, setDownloads] = useState11([]);
|
|
@@ -1192,7 +1203,7 @@ function useDownloads() {
|
|
|
1192
1203
|
setLoading(false);
|
|
1193
1204
|
}
|
|
1194
1205
|
}, [client]);
|
|
1195
|
-
|
|
1206
|
+
useEffect8(() => {
|
|
1196
1207
|
fetchDownloads();
|
|
1197
1208
|
}, [fetchDownloads]);
|
|
1198
1209
|
const getDownloadUrl = useCallback12((token) => {
|
|
@@ -1232,7 +1243,7 @@ function useOrderDownloads(orderNumber) {
|
|
|
1232
1243
|
setLoading(false);
|
|
1233
1244
|
}
|
|
1234
1245
|
}, [client, orderNumber]);
|
|
1235
|
-
|
|
1246
|
+
useEffect8(() => {
|
|
1236
1247
|
fetchDownloads();
|
|
1237
1248
|
}, [fetchDownloads]);
|
|
1238
1249
|
const getDownloadUrl = useCallback12((token) => {
|
|
@@ -1252,7 +1263,7 @@ function useOrderDownloads(orderNumber) {
|
|
|
1252
1263
|
}
|
|
1253
1264
|
|
|
1254
1265
|
// src/hooks/useReviews.ts
|
|
1255
|
-
import { useState as useState12, useEffect as
|
|
1266
|
+
import { useState as useState12, useEffect as useEffect9, useCallback as useCallback13 } from "react";
|
|
1256
1267
|
function useProductReviews(productSlug, params) {
|
|
1257
1268
|
const client = useClient();
|
|
1258
1269
|
const [reviews, setReviews] = useState12([]);
|
|
@@ -1274,7 +1285,7 @@ function useProductReviews(productSlug, params) {
|
|
|
1274
1285
|
setLoading(false);
|
|
1275
1286
|
}
|
|
1276
1287
|
}, [client, productSlug, params]);
|
|
1277
|
-
|
|
1288
|
+
useEffect9(() => {
|
|
1278
1289
|
fetchReviews();
|
|
1279
1290
|
}, [fetchReviews]);
|
|
1280
1291
|
return {
|
|
@@ -1307,7 +1318,7 @@ function useCanReview(productSlug) {
|
|
|
1307
1318
|
setLoading(false);
|
|
1308
1319
|
}
|
|
1309
1320
|
}, [client, productSlug]);
|
|
1310
|
-
|
|
1321
|
+
useEffect9(() => {
|
|
1311
1322
|
if (client.isAuthenticated()) {
|
|
1312
1323
|
check();
|
|
1313
1324
|
} else {
|
|
@@ -1371,7 +1382,7 @@ function useMyReviews(params) {
|
|
|
1371
1382
|
setLoading(false);
|
|
1372
1383
|
}
|
|
1373
1384
|
}, [client, params]);
|
|
1374
|
-
|
|
1385
|
+
useEffect9(() => {
|
|
1375
1386
|
fetchReviews();
|
|
1376
1387
|
}, [fetchReviews]);
|
|
1377
1388
|
const deleteReview = useCallback13(async (reviewId) => {
|
|
@@ -1395,7 +1406,7 @@ function useMyReviews(params) {
|
|
|
1395
1406
|
}
|
|
1396
1407
|
|
|
1397
1408
|
// src/hooks/useBlog.ts
|
|
1398
|
-
import { useState as useState13, useEffect as
|
|
1409
|
+
import { useState as useState13, useEffect as useEffect10, useCallback as useCallback14 } from "react";
|
|
1399
1410
|
function useBlog(options = {}) {
|
|
1400
1411
|
const { autoFetch = true, ...params } = options;
|
|
1401
1412
|
const client = useClient();
|
|
@@ -1421,7 +1432,7 @@ function useBlog(options = {}) {
|
|
|
1421
1432
|
setLoading(false);
|
|
1422
1433
|
}
|
|
1423
1434
|
}, [client]);
|
|
1424
|
-
|
|
1435
|
+
useEffect10(() => {
|
|
1425
1436
|
if (autoFetch) {
|
|
1426
1437
|
fetchPosts(params);
|
|
1427
1438
|
}
|
|
@@ -1463,7 +1474,7 @@ function useBlogPost(slug) {
|
|
|
1463
1474
|
setLoading(false);
|
|
1464
1475
|
}
|
|
1465
1476
|
}, [client, slug]);
|
|
1466
|
-
|
|
1477
|
+
useEffect10(() => {
|
|
1467
1478
|
fetchPost();
|
|
1468
1479
|
}, [fetchPost]);
|
|
1469
1480
|
return {
|
|
@@ -1490,7 +1501,7 @@ function useBlogCategories() {
|
|
|
1490
1501
|
setLoading(false);
|
|
1491
1502
|
}
|
|
1492
1503
|
}, [client]);
|
|
1493
|
-
|
|
1504
|
+
useEffect10(() => {
|
|
1494
1505
|
fetchCategories();
|
|
1495
1506
|
}, [fetchCategories]);
|
|
1496
1507
|
return {
|
|
@@ -1517,7 +1528,7 @@ function useBlogTags() {
|
|
|
1517
1528
|
setLoading(false);
|
|
1518
1529
|
}
|
|
1519
1530
|
}, [client]);
|
|
1520
|
-
|
|
1531
|
+
useEffect10(() => {
|
|
1521
1532
|
fetchTags();
|
|
1522
1533
|
}, [fetchTags]);
|
|
1523
1534
|
return {
|
|
@@ -1544,7 +1555,7 @@ function useFeaturedBlog(limit = 5) {
|
|
|
1544
1555
|
setLoading(false);
|
|
1545
1556
|
}
|
|
1546
1557
|
}, [client, limit]);
|
|
1547
|
-
|
|
1558
|
+
useEffect10(() => {
|
|
1548
1559
|
fetchPosts();
|
|
1549
1560
|
}, [fetchPosts]);
|
|
1550
1561
|
return {
|
|
@@ -1583,7 +1594,7 @@ function useBlogSearch() {
|
|
|
1583
1594
|
}
|
|
1584
1595
|
|
|
1585
1596
|
// src/hooks/useBoards.ts
|
|
1586
|
-
import { useState as useState14, useEffect as
|
|
1597
|
+
import { useState as useState14, useEffect as useEffect11, useCallback as useCallback15 } from "react";
|
|
1587
1598
|
function useBoards(params) {
|
|
1588
1599
|
const client = useClient();
|
|
1589
1600
|
const [boards, setBoards] = useState14([]);
|
|
@@ -1601,7 +1612,7 @@ function useBoards(params) {
|
|
|
1601
1612
|
setLoading(false);
|
|
1602
1613
|
}
|
|
1603
1614
|
}, [client, params]);
|
|
1604
|
-
|
|
1615
|
+
useEffect11(() => {
|
|
1605
1616
|
fetchBoards();
|
|
1606
1617
|
}, [fetchBoards]);
|
|
1607
1618
|
return {
|
|
@@ -1628,7 +1639,7 @@ function useBoard(slug) {
|
|
|
1628
1639
|
setLoading(false);
|
|
1629
1640
|
}
|
|
1630
1641
|
}, [client, slug]);
|
|
1631
|
-
|
|
1642
|
+
useEffect11(() => {
|
|
1632
1643
|
fetchBoard();
|
|
1633
1644
|
}, [fetchBoard]);
|
|
1634
1645
|
return {
|
|
@@ -1662,7 +1673,7 @@ function useBoardPosts(boardSlug, params) {
|
|
|
1662
1673
|
setLoading(false);
|
|
1663
1674
|
}
|
|
1664
1675
|
}, [client, boardSlug]);
|
|
1665
|
-
|
|
1676
|
+
useEffect11(() => {
|
|
1666
1677
|
fetchPosts(params);
|
|
1667
1678
|
}, []);
|
|
1668
1679
|
const hasMore = meta ? meta.current_page < meta.last_page : false;
|
|
@@ -1702,7 +1713,7 @@ function useBoardPost(postId) {
|
|
|
1702
1713
|
setLoading(false);
|
|
1703
1714
|
}
|
|
1704
1715
|
}, [client, postId]);
|
|
1705
|
-
|
|
1716
|
+
useEffect11(() => {
|
|
1706
1717
|
fetchPost();
|
|
1707
1718
|
}, [fetchPost]);
|
|
1708
1719
|
return {
|
|
@@ -1737,7 +1748,7 @@ function useCreateBoardPost() {
|
|
|
1737
1748
|
}
|
|
1738
1749
|
|
|
1739
1750
|
// src/hooks/useComments.ts
|
|
1740
|
-
import { useState as useState15, useEffect as
|
|
1751
|
+
import { useState as useState15, useEffect as useEffect12, useCallback as useCallback16 } from "react";
|
|
1741
1752
|
function useComments(options) {
|
|
1742
1753
|
const { type, target, page, per_page } = options;
|
|
1743
1754
|
const client = useClient();
|
|
@@ -1770,7 +1781,7 @@ function useComments(options) {
|
|
|
1770
1781
|
setLoading(false);
|
|
1771
1782
|
}
|
|
1772
1783
|
}, [client, type, target, page, per_page]);
|
|
1773
|
-
|
|
1784
|
+
useEffect12(() => {
|
|
1774
1785
|
fetchComments();
|
|
1775
1786
|
}, [fetchComments]);
|
|
1776
1787
|
const createComment = useCallback16(async (data) => {
|
|
@@ -1819,7 +1830,7 @@ function useComments(options) {
|
|
|
1819
1830
|
}
|
|
1820
1831
|
|
|
1821
1832
|
// src/hooks/useForms.ts
|
|
1822
|
-
import { useState as useState16, useEffect as
|
|
1833
|
+
import { useState as useState16, useEffect as useEffect13, useCallback as useCallback17 } from "react";
|
|
1823
1834
|
function useForm(formSlug) {
|
|
1824
1835
|
const client = useClient();
|
|
1825
1836
|
const [form, setForm] = useState16(null);
|
|
@@ -1839,7 +1850,7 @@ function useForm(formSlug) {
|
|
|
1839
1850
|
setLoading(false);
|
|
1840
1851
|
}
|
|
1841
1852
|
}, [client, formSlug]);
|
|
1842
|
-
|
|
1853
|
+
useEffect13(() => {
|
|
1843
1854
|
fetchForm();
|
|
1844
1855
|
}, [fetchForm]);
|
|
1845
1856
|
const submit = useCallback17(async (data) => {
|
|
@@ -1873,7 +1884,7 @@ function useForm(formSlug) {
|
|
|
1873
1884
|
}
|
|
1874
1885
|
|
|
1875
1886
|
// src/hooks/useReservation.ts
|
|
1876
|
-
import { useState as useState17, useEffect as
|
|
1887
|
+
import { useState as useState17, useEffect as useEffect14, useCallback as useCallback18 } from "react";
|
|
1877
1888
|
function useReservationServices() {
|
|
1878
1889
|
const client = useClient();
|
|
1879
1890
|
const [services, setServices] = useState17([]);
|
|
@@ -1891,7 +1902,7 @@ function useReservationServices() {
|
|
|
1891
1902
|
setLoading(false);
|
|
1892
1903
|
}
|
|
1893
1904
|
}, [client]);
|
|
1894
|
-
|
|
1905
|
+
useEffect14(() => {
|
|
1895
1906
|
fetchServices();
|
|
1896
1907
|
}, [fetchServices]);
|
|
1897
1908
|
return {
|
|
@@ -1918,7 +1929,7 @@ function useReservationStaffs() {
|
|
|
1918
1929
|
setLoading(false);
|
|
1919
1930
|
}
|
|
1920
1931
|
}, [client]);
|
|
1921
|
-
|
|
1932
|
+
useEffect14(() => {
|
|
1922
1933
|
fetchStaffs();
|
|
1923
1934
|
}, [fetchStaffs]);
|
|
1924
1935
|
return {
|
|
@@ -1954,7 +1965,7 @@ function useAvailableSlots(serviceId, date, staffId) {
|
|
|
1954
1965
|
setLoading(false);
|
|
1955
1966
|
}
|
|
1956
1967
|
}, [client, serviceId, date, staffId]);
|
|
1957
|
-
|
|
1968
|
+
useEffect14(() => {
|
|
1958
1969
|
fetchSlots();
|
|
1959
1970
|
}, [fetchSlots]);
|
|
1960
1971
|
return {
|
|
@@ -1988,7 +1999,7 @@ function useMyReservations(params) {
|
|
|
1988
1999
|
setLoading(false);
|
|
1989
2000
|
}
|
|
1990
2001
|
}, [client, params]);
|
|
1991
|
-
|
|
2002
|
+
useEffect14(() => {
|
|
1992
2003
|
fetchReservations();
|
|
1993
2004
|
}, [fetchReservations]);
|
|
1994
2005
|
return {
|
|
@@ -2040,7 +2051,7 @@ function useReservationSettings() {
|
|
|
2040
2051
|
setLoading(false);
|
|
2041
2052
|
}
|
|
2042
2053
|
}, [client]);
|
|
2043
|
-
|
|
2054
|
+
useEffect14(() => {
|
|
2044
2055
|
fetchSettings();
|
|
2045
2056
|
}, [fetchSettings]);
|
|
2046
2057
|
return {
|
|
@@ -2052,7 +2063,7 @@ function useReservationSettings() {
|
|
|
2052
2063
|
}
|
|
2053
2064
|
|
|
2054
2065
|
// src/hooks/useMedia.ts
|
|
2055
|
-
import { useState as useState18, useEffect as
|
|
2066
|
+
import { useState as useState18, useEffect as useEffect15, useCallback as useCallback19 } from "react";
|
|
2056
2067
|
function useMedia(options = {}) {
|
|
2057
2068
|
const { type, page, per_page, autoFetch = true } = options;
|
|
2058
2069
|
const client = useClient();
|
|
@@ -2080,7 +2091,7 @@ function useMedia(options = {}) {
|
|
|
2080
2091
|
setLoading(false);
|
|
2081
2092
|
}
|
|
2082
2093
|
}, [client, type, page, per_page]);
|
|
2083
|
-
|
|
2094
|
+
useEffect15(() => {
|
|
2084
2095
|
if (autoFetch) {
|
|
2085
2096
|
fetchMedia();
|
|
2086
2097
|
}
|
|
@@ -2142,7 +2153,7 @@ function useMedia(options = {}) {
|
|
|
2142
2153
|
}
|
|
2143
2154
|
|
|
2144
2155
|
// src/hooks/useEntities.ts
|
|
2145
|
-
import { useState as useState19, useEffect as
|
|
2156
|
+
import { useState as useState19, useEffect as useEffect16, useCallback as useCallback20, useMemo as useMemo3 } from "react";
|
|
2146
2157
|
function useEntities() {
|
|
2147
2158
|
const client = useClient();
|
|
2148
2159
|
const [entities, setEntities] = useState19([]);
|
|
@@ -2160,7 +2171,7 @@ function useEntities() {
|
|
|
2160
2171
|
setLoading(false);
|
|
2161
2172
|
}
|
|
2162
2173
|
}, [client]);
|
|
2163
|
-
|
|
2174
|
+
useEffect16(() => {
|
|
2164
2175
|
fetchEntities();
|
|
2165
2176
|
}, [fetchEntities]);
|
|
2166
2177
|
return {
|
|
@@ -2187,7 +2198,7 @@ function useEntity(slug) {
|
|
|
2187
2198
|
setLoading(false);
|
|
2188
2199
|
}
|
|
2189
2200
|
}, [client, slug]);
|
|
2190
|
-
|
|
2201
|
+
useEffect16(() => {
|
|
2191
2202
|
fetchEntity();
|
|
2192
2203
|
}, [fetchEntity]);
|
|
2193
2204
|
return {
|
|
@@ -2221,7 +2232,7 @@ function useEntityRecords(slug, params) {
|
|
|
2221
2232
|
setLoading(false);
|
|
2222
2233
|
}
|
|
2223
2234
|
}, [client, slug]);
|
|
2224
|
-
|
|
2235
|
+
useEffect16(() => {
|
|
2225
2236
|
fetchRecords(params);
|
|
2226
2237
|
}, []);
|
|
2227
2238
|
const hasMore = meta ? meta.current_page < meta.last_page : false;
|
|
@@ -2278,7 +2289,7 @@ function useEntityRecord(slug, id) {
|
|
|
2278
2289
|
setLoading(false);
|
|
2279
2290
|
}
|
|
2280
2291
|
}, [client, slug, id]);
|
|
2281
|
-
|
|
2292
|
+
useEffect16(() => {
|
|
2282
2293
|
fetchRecord();
|
|
2283
2294
|
}, [fetchRecord]);
|
|
2284
2295
|
const update = useCallback20(async (data) => {
|
|
@@ -2324,7 +2335,7 @@ function useTypedEntity(slug) {
|
|
|
2324
2335
|
}
|
|
2325
2336
|
|
|
2326
2337
|
// src/hooks/useChat.ts
|
|
2327
|
-
import { useState as useState20, useEffect as
|
|
2338
|
+
import { useState as useState20, useEffect as useEffect17, useCallback as useCallback21 } from "react";
|
|
2328
2339
|
function useChat(options = {}) {
|
|
2329
2340
|
const client = useClient();
|
|
2330
2341
|
const [conversation, setConversation] = useState20(null);
|
|
@@ -2399,7 +2410,7 @@ function useChat(options = {}) {
|
|
|
2399
2410
|
setConnected(false);
|
|
2400
2411
|
setConnection(null);
|
|
2401
2412
|
}, [connection]);
|
|
2402
|
-
|
|
2413
|
+
useEffect17(() => {
|
|
2403
2414
|
if (options.autoConnect) {
|
|
2404
2415
|
start();
|
|
2405
2416
|
}
|
|
@@ -2490,10 +2501,10 @@ function RichContent({
|
|
|
2490
2501
|
}
|
|
2491
2502
|
|
|
2492
2503
|
// src/components/chat/ChatBubble.tsx
|
|
2493
|
-
import { useState as useState22, useEffect as
|
|
2504
|
+
import { useState as useState22, useEffect as useEffect20, useCallback as useCallback22, useRef as useRef3 } from "react";
|
|
2494
2505
|
|
|
2495
2506
|
// src/components/chat/ChatWidget.tsx
|
|
2496
|
-
import { useRef as useRef2, useEffect as
|
|
2507
|
+
import { useRef as useRef2, useEffect as useEffect19 } from "react";
|
|
2497
2508
|
|
|
2498
2509
|
// src/components/chat/ChatMessage.tsx
|
|
2499
2510
|
import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
@@ -2531,7 +2542,7 @@ var ChatMessage = ({
|
|
|
2531
2542
|
};
|
|
2532
2543
|
|
|
2533
2544
|
// src/components/chat/ChatInput.tsx
|
|
2534
|
-
import { useState as useState21, useRef, useEffect as
|
|
2545
|
+
import { useState as useState21, useRef, useEffect as useEffect18 } from "react";
|
|
2535
2546
|
import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
2536
2547
|
var ChatInput = ({
|
|
2537
2548
|
onSend,
|
|
@@ -2569,7 +2580,7 @@ var ChatInput = ({
|
|
|
2569
2580
|
}, 2e3);
|
|
2570
2581
|
}
|
|
2571
2582
|
};
|
|
2572
|
-
|
|
2583
|
+
useEffect18(() => {
|
|
2573
2584
|
return () => {
|
|
2574
2585
|
if (typingTimeoutRef.current) {
|
|
2575
2586
|
clearTimeout(typingTimeoutRef.current);
|
|
@@ -2635,13 +2646,17 @@ var ChatWidget = ({
|
|
|
2635
2646
|
loading = false,
|
|
2636
2647
|
typing = false,
|
|
2637
2648
|
ended = false,
|
|
2638
|
-
className = ""
|
|
2649
|
+
className = "",
|
|
2650
|
+
isLoggedIn = false,
|
|
2651
|
+
showLoginPrompt = false,
|
|
2652
|
+
loginUrl = "/auth/login",
|
|
2653
|
+
loginPromptMessage = "Login to save your chat history across devices"
|
|
2639
2654
|
}) => {
|
|
2640
2655
|
const messagesEndRef = useRef2(null);
|
|
2641
2656
|
const scrollToBottom = () => {
|
|
2642
2657
|
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
2643
2658
|
};
|
|
2644
|
-
|
|
2659
|
+
useEffect19(() => {
|
|
2645
2660
|
scrollToBottom();
|
|
2646
2661
|
}, [messages, typing]);
|
|
2647
2662
|
const formatTime = (timestamp) => {
|
|
@@ -2713,6 +2728,10 @@ var ChatWidget = ({
|
|
|
2713
2728
|
}
|
|
2714
2729
|
)
|
|
2715
2730
|
] }) : /* @__PURE__ */ jsxs4(Fragment3, { children: [
|
|
2731
|
+
showLoginPrompt && !isLoggedIn && /* @__PURE__ */ jsxs4("div", { className: "diffsome-chat-login-prompt", children: [
|
|
2732
|
+
/* @__PURE__ */ jsx5("span", { children: loginPromptMessage }),
|
|
2733
|
+
/* @__PURE__ */ jsx5("a", { href: loginUrl, className: "diffsome-chat-login-btn", children: "Login" })
|
|
2734
|
+
] }),
|
|
2716
2735
|
/* @__PURE__ */ jsx5(
|
|
2717
2736
|
ChatInput,
|
|
2718
2737
|
{
|
|
@@ -2753,9 +2772,12 @@ var ChatBubble = ({
|
|
|
2753
2772
|
className = "",
|
|
2754
2773
|
onOpen,
|
|
2755
2774
|
onClose,
|
|
2756
|
-
memberToken
|
|
2775
|
+
memberToken,
|
|
2776
|
+
showLoginPrompt = false,
|
|
2777
|
+
loginUrl = "/auth/login",
|
|
2778
|
+
loginPromptMessage = "Login to save your chat history across devices"
|
|
2757
2779
|
}) => {
|
|
2758
|
-
|
|
2780
|
+
useEffect20(() => {
|
|
2759
2781
|
if (memberToken) {
|
|
2760
2782
|
client.setToken(memberToken);
|
|
2761
2783
|
} else {
|
|
@@ -2925,7 +2947,7 @@ var ChatBubble = ({
|
|
|
2925
2947
|
seenMessageIds.current.clear();
|
|
2926
2948
|
initChat();
|
|
2927
2949
|
};
|
|
2928
|
-
|
|
2950
|
+
useEffect20(() => {
|
|
2929
2951
|
return () => {
|
|
2930
2952
|
connectionRef.current?.disconnect();
|
|
2931
2953
|
};
|
|
@@ -2951,7 +2973,11 @@ var ChatBubble = ({
|
|
|
2951
2973
|
placeholder,
|
|
2952
2974
|
loading,
|
|
2953
2975
|
typing,
|
|
2954
|
-
ended
|
|
2976
|
+
ended,
|
|
2977
|
+
isLoggedIn: !!memberToken,
|
|
2978
|
+
showLoginPrompt,
|
|
2979
|
+
loginUrl,
|
|
2980
|
+
loginPromptMessage
|
|
2955
2981
|
}
|
|
2956
2982
|
),
|
|
2957
2983
|
/* @__PURE__ */ jsxs5(
|