ajaxter-chat 2.0.1 → 3.0.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/README.md +119 -128
- package/dist/components/BlockList/index.d.ts +10 -0
- package/dist/components/BlockList/index.js +33 -0
- package/dist/components/CallScreen/index.d.ts +13 -0
- package/dist/components/CallScreen/index.js +48 -0
- package/dist/components/ChatScreen/index.d.ts +10 -3
- package/dist/components/ChatScreen/index.js +142 -57
- package/dist/components/ChatWidget.js +192 -98
- package/dist/components/EmojiPicker/index.d.ts +8 -0
- package/dist/components/EmojiPicker/index.js +18 -0
- package/dist/components/HomeScreen/index.d.ts +2 -3
- package/dist/components/HomeScreen/index.js +25 -41
- package/dist/components/MaintenanceView/index.d.ts +0 -1
- package/dist/components/MaintenanceView/index.js +4 -6
- package/dist/components/RecentChatsScreen/index.d.ts +4 -3
- package/dist/components/RecentChatsScreen/index.js +7 -37
- package/dist/components/Tabs/BottomTabs.d.ts +1 -1
- package/dist/components/Tabs/BottomTabs.js +25 -20
- package/dist/components/TicketScreen/index.d.ts +3 -3
- package/dist/components/TicketScreen/index.js +39 -56
- package/dist/components/UserListScreen/index.d.ts +2 -4
- package/dist/components/UserListScreen/index.js +33 -62
- package/dist/config/index.d.ts +3 -3
- package/dist/config/index.js +18 -26
- package/dist/hooks/useChat.d.ts +8 -3
- package/dist/hooks/useChat.js +22 -18
- package/dist/hooks/useRemoteConfig.d.ts +6 -0
- package/dist/hooks/useRemoteConfig.js +22 -0
- package/dist/hooks/useWebRTC.d.ts +11 -0
- package/dist/hooks/useWebRTC.js +112 -0
- package/dist/index.d.ts +9 -5
- package/dist/index.js +8 -4
- package/dist/types/index.d.ts +62 -21
- package/dist/utils/chat.d.ts +13 -0
- package/dist/utils/chat.js +62 -0
- package/dist/utils/theme.d.ts +3 -1
- package/dist/utils/theme.js +14 -7
- package/package.json +4 -4
- package/public/chatData.json +162 -0
- package/src/components/BlockList/index.tsx +94 -0
- package/src/components/CallScreen/index.tsx +144 -0
- package/src/components/ChatScreen/index.tsx +403 -139
- package/src/components/ChatWidget.tsx +394 -250
- package/src/components/EmojiPicker/index.tsx +48 -0
- package/src/components/HomeScreen/index.tsx +58 -82
- package/src/components/MaintenanceView/index.tsx +6 -9
- package/src/components/RecentChatsScreen/index.tsx +51 -96
- package/src/components/Tabs/BottomTabs.tsx +45 -37
- package/src/components/TicketScreen/index.tsx +87 -133
- package/src/components/UserListScreen/index.tsx +75 -153
- package/src/config/index.ts +22 -28
- package/src/hooks/useChat.ts +31 -14
- package/src/hooks/useRemoteConfig.ts +20 -0
- package/src/hooks/useWebRTC.ts +130 -0
- package/src/index.ts +26 -15
- package/src/types/index.ts +85 -40
- package/src/utils/chat.ts +70 -0
- package/src/utils/theme.ts +18 -7
- package/dist/hooks/useUsers.d.ts +0 -7
- package/dist/hooks/useUsers.js +0 -26
- package/dist/services/userService.d.ts +0 -2
- package/dist/services/userService.js +0 -9
- package/dist/src/components/ChatScreen/index.d.ts +0 -12
- package/dist/src/components/ChatScreen/index.js +0 -83
- package/dist/src/components/ChatWidget.d.ts +0 -4
- package/dist/src/components/ChatWidget.js +0 -141
- package/dist/src/components/HomeScreen/index.d.ts +0 -9
- package/dist/src/components/HomeScreen/index.js +0 -71
- package/dist/src/components/MaintenanceView/index.d.ts +0 -7
- package/dist/src/components/MaintenanceView/index.js +0 -16
- package/dist/src/components/RecentChatsScreen/index.d.ts +0 -16
- package/dist/src/components/RecentChatsScreen/index.js +0 -38
- package/dist/src/components/Tabs/BottomTabs.d.ts +0 -10
- package/dist/src/components/Tabs/BottomTabs.js +0 -29
- package/dist/src/components/TicketScreen/index.d.ts +0 -9
- package/dist/src/components/TicketScreen/index.js +0 -71
- package/dist/src/components/UserListScreen/index.d.ts +0 -13
- package/dist/src/components/UserListScreen/index.js +0 -64
- package/dist/src/config/index.d.ts +0 -3
- package/dist/src/config/index.js +0 -38
- package/dist/src/hooks/useChat.d.ts +0 -8
- package/dist/src/hooks/useChat.js +0 -26
- package/dist/src/hooks/useUsers.d.ts +0 -7
- package/dist/src/hooks/useUsers.js +0 -26
- package/dist/src/index.d.ts +0 -14
- package/dist/src/index.js +0 -13
- package/dist/src/services/userService.d.ts +0 -2
- package/dist/src/services/userService.js +0 -9
- package/dist/src/types/index.d.ts +0 -59
- package/dist/src/types/index.js +0 -1
- package/dist/src/utils/theme.d.ts +0 -3
- package/dist/src/utils/theme.js +0 -13
- package/src/hooks/useUsers.ts +0 -27
- package/src/services/userService.ts +0 -9
|
@@ -1,57 +1,110 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import React, { useState, useEffect, useCallback } from 'react';
|
|
4
|
-
import { ChatWidgetProps, BottomTab, Screen, UserListContext, ChatUser, Ticket } from '../types';
|
|
5
|
-
import {
|
|
3
|
+
import React, { useState, useEffect, useCallback, useRef } from 'react';
|
|
4
|
+
import { ChatWidgetProps, BottomTab, Screen, UserListContext, ChatUser, Ticket, RecentChat } from '../types';
|
|
5
|
+
import { loadLocalConfig } from '../config';
|
|
6
6
|
import { mergeTheme } from '../utils/theme';
|
|
7
|
-
import {
|
|
7
|
+
import { useRemoteConfig } from '../hooks/useRemoteConfig';
|
|
8
8
|
import { useChat } from '../hooks/useChat';
|
|
9
|
+
import { useWebRTC } from '../hooks/useWebRTC';
|
|
9
10
|
|
|
10
|
-
// Screens
|
|
11
11
|
import { HomeScreen } from './HomeScreen';
|
|
12
12
|
import { UserListScreen } from './UserListScreen';
|
|
13
13
|
import { ChatScreen } from './ChatScreen';
|
|
14
14
|
import { RecentChatsScreen } from './RecentChatsScreen';
|
|
15
15
|
import { TicketScreen } from './TicketScreen';
|
|
16
|
+
import { BlockListScreen } from './BlockList';
|
|
17
|
+
import { CallScreen } from './CallScreen';
|
|
16
18
|
import { MaintenanceView } from './MaintenanceView';
|
|
17
19
|
import { BottomTabs } from './Tabs/BottomTabs';
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const [isMaximized, setIsMaximized] = useState(false);
|
|
23
|
-
const [activeTab, setActiveTab] = useState<BottomTab>('home');
|
|
24
|
-
const [screen, setScreen] = useState<Screen>('home');
|
|
25
|
-
const [userListCtx, setUserListCtx] = useState<UserListContext>('support');
|
|
26
|
-
const [tickets, setTickets] = useState<Ticket[]>([]);
|
|
27
|
-
|
|
28
|
-
// SSR guard
|
|
29
|
-
useEffect(() => { setIsMounted(true); }, []);
|
|
30
|
-
|
|
31
|
-
const config = loadChatConfig();
|
|
32
|
-
const t = mergeTheme(theme);
|
|
33
|
-
const apiUrl = buildUserListUrl(config);
|
|
34
|
-
|
|
35
|
-
// Determine filter based on context
|
|
36
|
-
const filterType = userListCtx === 'support' ? 'developer' : 'user';
|
|
37
|
-
const { users, loading, error } = useUsers(
|
|
38
|
-
apiUrl,
|
|
39
|
-
filterType,
|
|
40
|
-
config.status === 'ACTIVE' && screen === 'user-list'
|
|
41
|
-
);
|
|
21
|
+
/* ─── Drawer width ─────────────────────────────────────────────────────────── */
|
|
22
|
+
const DRAWER_W_NORMAL = 380;
|
|
23
|
+
const DRAWER_W_MAX = 480;
|
|
42
24
|
|
|
43
|
-
|
|
25
|
+
export const ChatWidget: React.FC<ChatWidgetProps> = ({ theme: localTheme }) => {
|
|
26
|
+
/* SSR guard */
|
|
27
|
+
const [mounted, setMounted] = useState(false);
|
|
28
|
+
useEffect(() => { setMounted(true); }, []);
|
|
44
29
|
|
|
45
|
-
|
|
46
|
-
const
|
|
30
|
+
/* Env config */
|
|
31
|
+
const { apiKey, widgetId } = loadLocalConfig();
|
|
47
32
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
33
|
+
/* Remote config */
|
|
34
|
+
const { data, loading: cfgLoading, error: cfgError } = useRemoteConfig(apiKey, widgetId);
|
|
35
|
+
|
|
36
|
+
/* Merged theme — remote config overrides defaults, local prop overrides both */
|
|
37
|
+
const theme = mergeTheme(
|
|
38
|
+
data?.widget ? { primaryColor: data.widget.primaryColor, buttonLabel: data.widget.buttonLabel, buttonPosition: data.widget.buttonPosition } : undefined,
|
|
39
|
+
localTheme
|
|
40
|
+
);
|
|
54
41
|
|
|
42
|
+
/* Drawer open state */
|
|
43
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
44
|
+
const [isMaximized, setIsMaximized] = useState(false);
|
|
45
|
+
const [closing, setClosing] = useState(false); // for slide-out animation
|
|
46
|
+
|
|
47
|
+
/* Navigation */
|
|
48
|
+
const [activeTab, setActiveTab] = useState<BottomTab>('home');
|
|
49
|
+
const [screen, setScreen] = useState<Screen>('home');
|
|
50
|
+
const [userListCtx, setUserListCtx] = useState<UserListContext>('support');
|
|
51
|
+
|
|
52
|
+
/* App state */
|
|
53
|
+
const [tickets, setTickets] = useState<Ticket[]>(data?.sampleTickets ?? []);
|
|
54
|
+
const [recentChats, setRecentChats] = useState<RecentChat[]>([]);
|
|
55
|
+
const [blockedUids, setBlockedUids] = useState<string[]>(data?.blockedUsers ?? []);
|
|
56
|
+
|
|
57
|
+
/* Sync remote data into local state once loaded */
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (data) {
|
|
60
|
+
setTickets(data.sampleTickets);
|
|
61
|
+
setBlockedUids(data.blockedUsers);
|
|
62
|
+
// Seed recent chats from sample chats
|
|
63
|
+
const all = [...(data.developers ?? []), ...(data.users ?? [])];
|
|
64
|
+
const recents: RecentChat[] = Object.entries(data.sampleChats).map(([uid, msgs]) => {
|
|
65
|
+
const user = all.find(u => u.uid === uid);
|
|
66
|
+
if (!user || msgs.length === 0) return null;
|
|
67
|
+
const last = msgs[msgs.length - 1];
|
|
68
|
+
return {
|
|
69
|
+
id: `rc_${uid}`,
|
|
70
|
+
user,
|
|
71
|
+
lastMessage: last.text,
|
|
72
|
+
lastTime: last.timestamp,
|
|
73
|
+
unread: Math.floor(Math.random() * 3),
|
|
74
|
+
isPaused: false,
|
|
75
|
+
};
|
|
76
|
+
}).filter(Boolean) as RecentChat[];
|
|
77
|
+
setRecentChats(recents);
|
|
78
|
+
}
|
|
79
|
+
}, [data]);
|
|
80
|
+
|
|
81
|
+
/* Chat hook */
|
|
82
|
+
const {
|
|
83
|
+
messages, activeUser, isPaused, isReported,
|
|
84
|
+
selectUser, sendMessage, togglePause, reportChat, clearChat, setMessages,
|
|
85
|
+
} = useChat();
|
|
86
|
+
|
|
87
|
+
/* WebRTC hook */
|
|
88
|
+
const { session: callSession, localVideoRef, remoteVideoRef, startCall, endCall, toggleMute, toggleCamera } = useWebRTC();
|
|
89
|
+
|
|
90
|
+
/* ── Drawer open/close with slide animation ───────────────────────────── */
|
|
91
|
+
const openDrawer = () => {
|
|
92
|
+
setClosing(false);
|
|
93
|
+
setIsOpen(true);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const closeDrawer = useCallback(() => {
|
|
97
|
+
setClosing(true);
|
|
98
|
+
setTimeout(() => {
|
|
99
|
+
setIsOpen(false);
|
|
100
|
+
setClosing(false);
|
|
101
|
+
setScreen('home');
|
|
102
|
+
setActiveTab('home');
|
|
103
|
+
clearChat();
|
|
104
|
+
}, 300);
|
|
105
|
+
}, [clearChat]);
|
|
106
|
+
|
|
107
|
+
/* ── Navigation ──────────────────────────────────────────────────────── */
|
|
55
108
|
const handleCardClick = useCallback((ctx: UserListContext | 'ticket') => {
|
|
56
109
|
if (ctx === 'ticket') {
|
|
57
110
|
setActiveTab('tickets');
|
|
@@ -63,235 +116,340 @@ export const ChatWidget: React.FC<ChatWidgetProps> = ({ theme }) => {
|
|
|
63
116
|
}, []);
|
|
64
117
|
|
|
65
118
|
const handleSelectUser = useCallback((user: ChatUser) => {
|
|
66
|
-
|
|
119
|
+
// Load history from sample chats if available
|
|
120
|
+
const history = data?.sampleChats[user.uid] ?? [];
|
|
121
|
+
selectUser(user, history);
|
|
67
122
|
setScreen('chat');
|
|
68
|
-
|
|
123
|
+
// Update recent chats
|
|
124
|
+
setRecentChats(prev => {
|
|
125
|
+
const exists = prev.find(r => r.user.uid === user.uid);
|
|
126
|
+
if (exists) return prev;
|
|
127
|
+
return [{ id: `rc_${user.uid}`, user, lastMessage: '', lastTime: new Date().toISOString(), unread: 0, isPaused: false }, ...prev];
|
|
128
|
+
});
|
|
129
|
+
}, [data, selectUser]);
|
|
69
130
|
|
|
70
|
-
const
|
|
71
|
-
|
|
131
|
+
const handleTabChange = useCallback((tab: BottomTab) => {
|
|
132
|
+
setActiveTab(tab);
|
|
133
|
+
setScreen(tab === 'home' ? 'home' : tab === 'chats' ? 'recent-chats' : 'tickets');
|
|
72
134
|
}, []);
|
|
73
135
|
|
|
74
|
-
|
|
136
|
+
/* ── Block/Unblock ───────────────────────────────────────────────────── */
|
|
137
|
+
const handleBlock = useCallback(() => {
|
|
138
|
+
if (!activeUser) return;
|
|
139
|
+
setBlockedUids(prev => [...prev, activeUser.uid]);
|
|
75
140
|
clearChat();
|
|
76
|
-
setScreen('
|
|
77
|
-
|
|
141
|
+
setScreen('home');
|
|
142
|
+
setActiveTab('home');
|
|
143
|
+
}, [activeUser, clearChat]);
|
|
144
|
+
|
|
145
|
+
const handleUnblock = useCallback((uid: string) => {
|
|
146
|
+
setBlockedUids(prev => prev.filter(id => id !== uid));
|
|
147
|
+
}, []);
|
|
78
148
|
|
|
79
|
-
|
|
149
|
+
/* ── Tickets ─────────────────────────────────────────────────────────── */
|
|
150
|
+
const handleRaiseTicket = useCallback((title: string, desc: string, priority: Ticket['priority']) => {
|
|
80
151
|
const t: Ticket = {
|
|
81
|
-
id: `
|
|
82
|
-
title,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
createdAt: new Date(),
|
|
87
|
-
updatedAt: new Date(),
|
|
152
|
+
id: `TKT-${String(Date.now()).slice(-4)}`,
|
|
153
|
+
title, description: desc, status: 'open', priority,
|
|
154
|
+
createdAt: new Date().toISOString(),
|
|
155
|
+
updatedAt: new Date().toISOString(),
|
|
156
|
+
assignedTo: null,
|
|
88
157
|
};
|
|
89
158
|
setTickets(prev => [t, ...prev]);
|
|
90
159
|
}, []);
|
|
91
160
|
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
161
|
+
/* ── Pause sync back into recent chats ──────────────────────────────── */
|
|
162
|
+
const handleTogglePause = useCallback(() => {
|
|
163
|
+
togglePause();
|
|
164
|
+
if (activeUser) {
|
|
165
|
+
setRecentChats(prev => prev.map(r => r.user.uid === activeUser.uid ? { ...r, isPaused: !isPaused } : r));
|
|
166
|
+
}
|
|
167
|
+
}, [togglePause, activeUser, isPaused]);
|
|
97
168
|
|
|
98
|
-
|
|
99
|
-
const
|
|
169
|
+
/* ── Call ────────────────────────────────────────────────────────────── */
|
|
170
|
+
const handleStartCall = useCallback((withVideo: boolean) => {
|
|
171
|
+
if (!activeUser) return;
|
|
172
|
+
startCall(activeUser, withVideo);
|
|
173
|
+
setScreen('call');
|
|
174
|
+
}, [activeUser, startCall]);
|
|
100
175
|
|
|
101
|
-
const
|
|
176
|
+
const handleEndCall = useCallback(() => {
|
|
177
|
+
endCall();
|
|
178
|
+
setScreen('chat');
|
|
179
|
+
}, [endCall]);
|
|
180
|
+
|
|
181
|
+
/* ── Derived ─────────────────────────────────────────────────────────── */
|
|
182
|
+
const isBlocked = activeUser ? blockedUids.includes(activeUser.uid) : false;
|
|
183
|
+
const drawerW = isMaximized ? DRAWER_W_MAX : DRAWER_W_NORMAL;
|
|
184
|
+
const widgetConfig = data?.widget;
|
|
185
|
+
const primaryColor = theme.primaryColor;
|
|
186
|
+
|
|
187
|
+
const allUsers = data ? [...data.developers, ...data.users] : [];
|
|
188
|
+
const filteredUsers = screen === 'user-list'
|
|
189
|
+
? allUsers.filter(u => userListCtx === 'support' ? u.type === 'developer' : u.type === 'user')
|
|
190
|
+
: [];
|
|
191
|
+
const blockedUsers = allUsers.filter(u => blockedUids.includes(u.uid));
|
|
192
|
+
|
|
193
|
+
/* Position */
|
|
194
|
+
const posStyle: React.CSSProperties = theme.buttonPosition === 'bottom-left'
|
|
102
195
|
? { left: 24, right: 'auto' }
|
|
103
196
|
: { right: 24, left: 'auto' };
|
|
104
197
|
|
|
105
|
-
|
|
106
|
-
|
|
198
|
+
const drawerPosStyle: React.CSSProperties = theme.buttonPosition === 'bottom-left'
|
|
199
|
+
? { left: 0, borderRadius: '0 16px 16px 0' }
|
|
200
|
+
: { right: 0, borderRadius: '16px 0 0 16px' };
|
|
201
|
+
|
|
202
|
+
/* ── Don't render until mounted (SSR safe) ──────────────────────────── */
|
|
203
|
+
if (!mounted) return null;
|
|
107
204
|
|
|
108
205
|
return (
|
|
109
206
|
<>
|
|
110
|
-
{/* ── Global
|
|
207
|
+
{/* ── Global styles ── */}
|
|
111
208
|
<style>{`
|
|
112
209
|
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700;800&display=swap');
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
@keyframes cw-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
@keyframes cw-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
.cw-
|
|
126
|
-
.cw-
|
|
127
|
-
.cw-
|
|
210
|
+
|
|
211
|
+
.cw-root * { box-sizing: border-box; font-family: 'DM Sans', 'Segoe UI', sans-serif; }
|
|
212
|
+
|
|
213
|
+
@keyframes cw-slideInRight { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
|
|
214
|
+
@keyframes cw-slideOutRight { from { transform: translateX(0); opacity: 1; } to { transform: translateX(100%); opacity: 0; } }
|
|
215
|
+
@keyframes cw-slideInLeft { from { transform: translateX(-100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
|
|
216
|
+
@keyframes cw-slideOutLeft { from { transform: translateX(0); opacity: 1; } to { transform: translateX(-100%); opacity: 0; } }
|
|
217
|
+
@keyframes cw-fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
|
|
218
|
+
@keyframes cw-slideIn { from { opacity: 0; transform: translateX(18px); } to { opacity: 1; transform: translateX(0); } }
|
|
219
|
+
@keyframes cw-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
|
|
220
|
+
@keyframes cw-btnPop { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
|
|
221
|
+
|
|
222
|
+
.cw-scroll::-webkit-scrollbar { width: 4px; }
|
|
223
|
+
.cw-scroll::-webkit-scrollbar-track { background: transparent; }
|
|
224
|
+
.cw-scroll::-webkit-scrollbar-thumb { background: #e0e0e0; border-radius: 4px; }
|
|
225
|
+
|
|
226
|
+
.cw-drawer-enter { animation: ${theme.buttonPosition === 'bottom-left' ? 'cw-slideInLeft' : 'cw-slideInRight'} 0.32s cubic-bezier(0.22,1,0.36,1) both; }
|
|
227
|
+
.cw-drawer-exit { animation: ${theme.buttonPosition === 'bottom-left' ? 'cw-slideOutLeft' : 'cw-slideOutRight'} 0.28s cubic-bezier(0.55,0,1,0.45) both; }
|
|
128
228
|
`}</style>
|
|
129
229
|
|
|
130
230
|
{/* ── Floating Button ── */}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
(e.currentTarget as HTMLElement).style.
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
</button>
|
|
169
|
-
|
|
170
|
-
{/* ── Chat Window ── */}
|
|
231
|
+
{!isOpen && (
|
|
232
|
+
<button
|
|
233
|
+
className="cw-root"
|
|
234
|
+
onClick={openDrawer}
|
|
235
|
+
aria-label={theme.buttonLabel}
|
|
236
|
+
style={{
|
|
237
|
+
position: 'fixed', bottom: 24, zIndex: 9999,
|
|
238
|
+
...posStyle,
|
|
239
|
+
display: 'flex', alignItems: 'center', gap: 10,
|
|
240
|
+
padding: '13px 22px',
|
|
241
|
+
backgroundColor: theme.buttonColor,
|
|
242
|
+
color: theme.buttonTextColor,
|
|
243
|
+
border: 'none', borderRadius: 50,
|
|
244
|
+
cursor: 'pointer', fontSize: 15, fontWeight: 700,
|
|
245
|
+
boxShadow: `0 8px 28px ${theme.buttonColor}55`,
|
|
246
|
+
animation: 'cw-btnPop 0.4s cubic-bezier(0.34,1.56,0.64,1)',
|
|
247
|
+
transition: 'transform 0.2s, box-shadow 0.2s',
|
|
248
|
+
}}
|
|
249
|
+
onMouseEnter={e => {
|
|
250
|
+
(e.currentTarget as HTMLElement).style.transform = 'scale(1.06) translateY(-2px)';
|
|
251
|
+
(e.currentTarget as HTMLElement).style.boxShadow = `0 14px 36px ${theme.buttonColor}66`;
|
|
252
|
+
}}
|
|
253
|
+
onMouseLeave={e => {
|
|
254
|
+
(e.currentTarget as HTMLElement).style.transform = 'scale(1)';
|
|
255
|
+
(e.currentTarget as HTMLElement).style.boxShadow = `0 8px 28px ${theme.buttonColor}55`;
|
|
256
|
+
}}
|
|
257
|
+
>
|
|
258
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="none">
|
|
259
|
+
<path d="M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"
|
|
260
|
+
stroke={theme.buttonTextColor} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
|
|
261
|
+
</svg>
|
|
262
|
+
<span>{theme.buttonLabel}</span>
|
|
263
|
+
</button>
|
|
264
|
+
)}
|
|
265
|
+
|
|
266
|
+
{/* ── Backdrop (mobile) ── */}
|
|
171
267
|
{isOpen && (
|
|
172
268
|
<div
|
|
269
|
+
onClick={closeDrawer}
|
|
270
|
+
style={{
|
|
271
|
+
position: 'fixed', inset: 0, zIndex: 9997,
|
|
272
|
+
backgroundColor: 'rgba(0,0,0,0.35)',
|
|
273
|
+
opacity: closing ? 0 : 1,
|
|
274
|
+
transition: 'opacity 0.3s',
|
|
275
|
+
}}
|
|
276
|
+
/>
|
|
277
|
+
)}
|
|
278
|
+
|
|
279
|
+
{/* ── Drawer / Slider ── */}
|
|
280
|
+
{isOpen && (
|
|
281
|
+
<div
|
|
282
|
+
className={`cw-root ${closing ? 'cw-drawer-exit' : 'cw-drawer-enter'}`}
|
|
173
283
|
style={{
|
|
174
284
|
position: 'fixed',
|
|
175
|
-
|
|
176
|
-
|
|
285
|
+
top: 0,
|
|
286
|
+
bottom: 0,
|
|
287
|
+
...drawerPosStyle,
|
|
177
288
|
zIndex: 9998,
|
|
178
|
-
width,
|
|
179
|
-
|
|
180
|
-
maxWidth: 'calc(100vw - 32px)',
|
|
181
|
-
maxHeight: 'calc(100vh - 110px)',
|
|
289
|
+
width: drawerW,
|
|
290
|
+
maxWidth: '100vw',
|
|
182
291
|
backgroundColor: '#fff',
|
|
183
|
-
|
|
184
|
-
|
|
292
|
+
boxShadow: theme.buttonPosition === 'bottom-left'
|
|
293
|
+
? '4px 0 40px rgba(0,0,0,0.18)'
|
|
294
|
+
: '-4px 0 40px rgba(0,0,0,0.18)',
|
|
185
295
|
display: 'flex',
|
|
186
296
|
flexDirection: 'column',
|
|
187
297
|
overflow: 'hidden',
|
|
188
|
-
|
|
189
|
-
animation: 'cw-popIn 0.3s cubic-bezier(0.34,1.56,0.64,1)',
|
|
190
|
-
transition: 'width 0.3s ease, height 0.3s ease',
|
|
298
|
+
transition: 'width 0.28s ease',
|
|
191
299
|
}}
|
|
192
300
|
>
|
|
193
|
-
{/*
|
|
194
|
-
{
|
|
195
|
-
<
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}}
|
|
204
|
-
|
|
205
|
-
onMouseLeave={e => (e.currentTarget as HTMLElement).style.background = 'rgba(255,255,255,0.22)'}
|
|
206
|
-
>
|
|
207
|
-
{isMaximized
|
|
208
|
-
? <MinimizeIcon />
|
|
209
|
-
: <MaximizeIcon />
|
|
210
|
-
}
|
|
211
|
-
</button>
|
|
301
|
+
{/* ── Loading state ── */}
|
|
302
|
+
{cfgLoading && (
|
|
303
|
+
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', height: '100%', gap: 16 }}>
|
|
304
|
+
<div style={{
|
|
305
|
+
width: 40, height: 40, borderRadius: '50%',
|
|
306
|
+
border: `3px solid ${primaryColor}30`,
|
|
307
|
+
borderTopColor: primaryColor,
|
|
308
|
+
animation: 'spin 0.8s linear infinite',
|
|
309
|
+
}} />
|
|
310
|
+
<style>{`@keyframes spin { to { transform: rotate(360deg); } }`}</style>
|
|
311
|
+
<p style={{ fontSize: 14, color: '#7b8fa1' }}>Loading chat…</p>
|
|
312
|
+
</div>
|
|
212
313
|
)}
|
|
213
314
|
|
|
214
|
-
{/*
|
|
215
|
-
{
|
|
216
|
-
<
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
style={{
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
width: 28, height: 28, display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
223
|
-
cursor: 'pointer',
|
|
224
|
-
}}
|
|
225
|
-
>
|
|
226
|
-
<svg width="14" height="14" viewBox="0 0 24 24" fill="none">
|
|
227
|
-
<path d="M18 6L6 18M6 6l12 12" stroke="#fff" strokeWidth="2.5" strokeLinecap="round"/>
|
|
228
|
-
</svg>
|
|
229
|
-
</button>
|
|
315
|
+
{/* ── Error state ── */}
|
|
316
|
+
{cfgError && !cfgLoading && (
|
|
317
|
+
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', height: '100%', gap: 12, padding: 32, textAlign: 'center' }}>
|
|
318
|
+
<div style={{ fontSize: 40 }}>⚠️</div>
|
|
319
|
+
<p style={{ fontWeight: 700, color: '#1a2332' }}>Could not load chat configuration</p>
|
|
320
|
+
<p style={{ fontSize: 13, color: '#7b8fa1', lineHeight: 1.6 }}>{cfgError}</p>
|
|
321
|
+
<button onClick={closeDrawer} style={{ padding: '9px 20px', borderRadius: 10, border: 'none', background: primaryColor, color: '#fff', cursor: 'pointer', fontWeight: 700 }}>Close</button>
|
|
322
|
+
</div>
|
|
230
323
|
)}
|
|
231
324
|
|
|
232
|
-
{/* ──
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
325
|
+
{/* ── Main content ── */}
|
|
326
|
+
{!cfgLoading && !cfgError && widgetConfig && (
|
|
327
|
+
<>
|
|
328
|
+
{/* Resize + Close controls — shown outside chat/call screens */}
|
|
329
|
+
{screen !== 'chat' && screen !== 'call' && (
|
|
330
|
+
<div style={{
|
|
331
|
+
position: 'absolute', top: 12,
|
|
332
|
+
right: theme.buttonPosition === 'bottom-left' ? 'auto' : 12,
|
|
333
|
+
left: theme.buttonPosition === 'bottom-left' ? 12 : 'auto',
|
|
334
|
+
zIndex: 20, display: 'flex', gap: 6,
|
|
335
|
+
}}>
|
|
336
|
+
<CornerBtn onClick={() => setIsMaximized(m => !m)} title={isMaximized ? 'Minimize' : 'Maximize'}>
|
|
337
|
+
{isMaximized
|
|
338
|
+
? <svg width="12" height="12" viewBox="0 0 24 24" fill="none"><path d="M8 3v5H3M21 8h-5V3M3 16h5v5M16 21v-5h5" stroke="#fff" strokeWidth="2.2" strokeLinecap="round"/></svg>
|
|
339
|
+
: <svg width="12" height="12" viewBox="0 0 24 24" fill="none"><path d="M8 3H5a2 2 0 00-2 2v3M21 8V5a2 2 0 00-2-2h-3M3 16v3a2 2 0 002 2h3M16 21h3a2 2 0 002-2v-3" stroke="#fff" strokeWidth="2.2" strokeLinecap="round"/></svg>
|
|
340
|
+
}
|
|
341
|
+
</CornerBtn>
|
|
342
|
+
<CornerBtn onClick={closeDrawer} title="Close">
|
|
343
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none">
|
|
344
|
+
<path d="M18 6L6 18M6 6l12 12" stroke="#fff" strokeWidth="2.5" strokeLinecap="round"/>
|
|
345
|
+
</svg>
|
|
346
|
+
</CornerBtn>
|
|
347
|
+
</div>
|
|
348
|
+
)}
|
|
349
|
+
|
|
350
|
+
{/* ── MAINTENANCE ── */}
|
|
351
|
+
{widgetConfig.status === 'MAINTENANCE' && (
|
|
352
|
+
<MaintenanceView primaryColor={primaryColor} />
|
|
353
|
+
)}
|
|
354
|
+
|
|
355
|
+
{/* ── DISABLED ── */}
|
|
356
|
+
{widgetConfig.status === 'DISABLE' && (
|
|
357
|
+
<div style={{ display:'flex',flexDirection:'column',alignItems:'center',justifyContent:'center',height:'100%',padding:32,textAlign:'center',gap:12 }}>
|
|
358
|
+
<div style={{ fontSize:40 }}>🔒</div>
|
|
359
|
+
<p style={{ fontWeight:700,color:'#1a2332' }}>Chat is disabled</p>
|
|
360
|
+
<button onClick={closeDrawer} style={{ padding:'9px 20px',borderRadius:10,border:'none',background:primaryColor,color:'#fff',cursor:'pointer',fontWeight:700 }}>Close</button>
|
|
361
|
+
</div>
|
|
362
|
+
)}
|
|
363
|
+
|
|
364
|
+
{/* ── ACTIVE ── */}
|
|
365
|
+
{widgetConfig.status === 'ACTIVE' && (
|
|
366
|
+
<div className="cw-scroll" style={{ flex: 1, display: 'flex', flexDirection: 'column', overflow: 'hidden' }}>
|
|
367
|
+
|
|
368
|
+
{screen === 'home' && (
|
|
369
|
+
<HomeScreen config={widgetConfig} onNavigate={handleCardClick} />
|
|
370
|
+
)}
|
|
371
|
+
|
|
372
|
+
{screen === 'user-list' && (
|
|
373
|
+
<UserListScreen
|
|
374
|
+
context={userListCtx}
|
|
375
|
+
users={filteredUsers}
|
|
376
|
+
primaryColor={primaryColor}
|
|
377
|
+
onBack={() => setScreen('home')}
|
|
378
|
+
onSelectUser={handleSelectUser}
|
|
379
|
+
/>
|
|
380
|
+
)}
|
|
381
|
+
|
|
382
|
+
{screen === 'chat' && activeUser && (
|
|
383
|
+
<ChatScreen
|
|
384
|
+
activeUser={activeUser}
|
|
385
|
+
messages={messages}
|
|
386
|
+
config={widgetConfig}
|
|
387
|
+
isPaused={isPaused}
|
|
388
|
+
isReported={isReported}
|
|
389
|
+
isBlocked={isBlocked}
|
|
390
|
+
onSend={sendMessage}
|
|
391
|
+
onBack={() => { clearChat(); setScreen('home'); setActiveTab('home'); }}
|
|
392
|
+
onClose={closeDrawer}
|
|
393
|
+
onTogglePause={handleTogglePause}
|
|
394
|
+
onReport={reportChat}
|
|
395
|
+
onBlock={handleBlock}
|
|
396
|
+
onStartCall={handleStartCall}
|
|
397
|
+
/>
|
|
398
|
+
)}
|
|
399
|
+
|
|
400
|
+
{screen === 'call' && callSession.peer && (
|
|
401
|
+
<CallScreen
|
|
402
|
+
session={callSession}
|
|
403
|
+
localVideoRef={localVideoRef}
|
|
404
|
+
remoteVideoRef={remoteVideoRef}
|
|
405
|
+
onEnd={handleEndCall}
|
|
406
|
+
onToggleMute={toggleMute}
|
|
407
|
+
onToggleCamera={toggleCamera}
|
|
408
|
+
primaryColor={primaryColor}
|
|
409
|
+
/>
|
|
410
|
+
)}
|
|
411
|
+
|
|
412
|
+
{screen === 'recent-chats' && (
|
|
413
|
+
<RecentChatsScreen
|
|
414
|
+
chats={recentChats}
|
|
415
|
+
config={widgetConfig}
|
|
416
|
+
onSelectChat={handleSelectUser}
|
|
417
|
+
/>
|
|
418
|
+
)}
|
|
419
|
+
|
|
420
|
+
{screen === 'tickets' && (
|
|
421
|
+
<TicketScreen
|
|
422
|
+
tickets={tickets}
|
|
423
|
+
config={widgetConfig}
|
|
424
|
+
onRaiseTicket={handleRaiseTicket}
|
|
425
|
+
/>
|
|
426
|
+
)}
|
|
427
|
+
|
|
428
|
+
{screen === 'block-list' && (
|
|
429
|
+
<BlockListScreen
|
|
430
|
+
blockedUsers={blockedUsers}
|
|
431
|
+
config={widgetConfig}
|
|
432
|
+
onUnblock={handleUnblock}
|
|
433
|
+
onBack={() => { setScreen('home'); setActiveTab('home'); }}
|
|
434
|
+
/>
|
|
435
|
+
)}
|
|
436
|
+
</div>
|
|
437
|
+
)}
|
|
438
|
+
|
|
439
|
+
{/* ── Bottom Tabs (hidden during chat/call/user-list/block-list) ── */}
|
|
440
|
+
{widgetConfig.status === 'ACTIVE' &&
|
|
441
|
+
screen !== 'chat' &&
|
|
442
|
+
screen !== 'call' &&
|
|
443
|
+
screen !== 'user-list' &&
|
|
444
|
+
screen !== 'block-list' && (
|
|
445
|
+
<BottomTabs
|
|
446
|
+
active={activeTab}
|
|
447
|
+
onChange={handleTabChange}
|
|
448
|
+
primaryColor={primaryColor}
|
|
449
|
+
onBlockList={() => setScreen('block-list')}
|
|
450
|
+
/>
|
|
451
|
+
)}
|
|
452
|
+
</>
|
|
295
453
|
)}
|
|
296
454
|
</div>
|
|
297
455
|
)}
|
|
@@ -301,27 +459,13 @@ export const ChatWidget: React.FC<ChatWidgetProps> = ({ theme }) => {
|
|
|
301
459
|
|
|
302
460
|
export default ChatWidget;
|
|
303
461
|
|
|
304
|
-
|
|
305
|
-
const
|
|
306
|
-
<
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
<path d="M18 6L6 18M6 6l12 12" stroke={color} strokeWidth="2.5" strokeLinecap="round"/>
|
|
314
|
-
</svg>
|
|
315
|
-
);
|
|
316
|
-
const MaximizeIcon = () => (
|
|
317
|
-
<svg width="13" height="13" viewBox="0 0 24 24" fill="none">
|
|
318
|
-
<path d="M8 3H5a2 2 0 00-2 2v3M21 8V5a2 2 0 00-2-2h-3M3 16v3a2 2 0 002 2h3M16 21h3a2 2 0 002-2v-3"
|
|
319
|
-
stroke="#fff" strokeWidth="2.2" strokeLinecap="round"/>
|
|
320
|
-
</svg>
|
|
321
|
-
);
|
|
322
|
-
const MinimizeIcon = () => (
|
|
323
|
-
<svg width="13" height="13" viewBox="0 0 24 24" fill="none">
|
|
324
|
-
<path d="M8 3v5H3M21 8h-5V3M3 16h5v5M16 21v-5h5"
|
|
325
|
-
stroke="#fff" strokeWidth="2.2" strokeLinecap="round"/>
|
|
326
|
-
</svg>
|
|
462
|
+
/* ── Tiny corner button ────────────────────────────────────────────────────── */
|
|
463
|
+
const CornerBtn: React.FC<{ onClick: () => void; title: string; children: React.ReactNode }> = ({ onClick, title, children }) => (
|
|
464
|
+
<button onClick={onClick} title={title} style={{
|
|
465
|
+
width: 26, height: 26, borderRadius: '50%',
|
|
466
|
+
background: 'rgba(0,0,0,0.25)', border: 'none',
|
|
467
|
+
display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer',
|
|
468
|
+
}}>
|
|
469
|
+
{children}
|
|
470
|
+
</button>
|
|
327
471
|
);
|