ajaxter-chat 1.0.3 → 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 +124 -241
- 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 +19 -0
- package/dist/components/ChatScreen/index.js +168 -0
- package/dist/components/ChatWidget.d.ts +0 -24
- package/dist/components/ChatWidget.js +228 -43
- package/dist/components/EmojiPicker/index.d.ts +8 -0
- package/dist/components/EmojiPicker/index.js +18 -0
- package/dist/components/HomeScreen/index.d.ts +8 -0
- package/dist/components/HomeScreen/index.js +55 -0
- package/dist/components/MaintenanceView/index.d.ts +0 -1
- package/dist/components/MaintenanceView/index.js +13 -52
- package/dist/components/RecentChatsScreen/index.d.ts +17 -0
- package/dist/components/RecentChatsScreen/index.js +8 -0
- package/dist/components/Tabs/BottomTabs.d.ts +10 -0
- package/dist/components/Tabs/BottomTabs.js +34 -0
- package/dist/components/TicketScreen/index.d.ts +9 -0
- package/dist/components/TicketScreen/index.js +54 -0
- package/dist/components/UserListScreen/index.d.ts +11 -0
- package/dist/components/UserListScreen/index.js +35 -0
- package/dist/config/index.d.ts +3 -16
- package/dist/config/index.js +20 -103
- package/dist/hooks/useChat.d.ts +10 -9
- package/dist/hooks/useChat.js +22 -40
- 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 +16 -11
- package/dist/index.js +15 -16
- package/dist/types/index.d.ts +66 -38
- package/dist/utils/chat.d.ts +13 -0
- package/dist/utils/chat.js +62 -0
- package/dist/utils/theme.d.ts +3 -2
- package/dist/utils/theme.js +13 -21
- package/package.json +10 -20
- 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 +469 -0
- package/src/components/ChatWidget.tsx +471 -0
- package/src/components/EmojiPicker/index.tsx +48 -0
- package/src/components/HomeScreen/index.tsx +106 -0
- package/src/components/MaintenanceView/index.tsx +38 -0
- package/src/components/RecentChatsScreen/index.tsx +63 -0
- package/src/components/Tabs/BottomTabs.tsx +90 -0
- package/src/components/TicketScreen/index.tsx +124 -0
- package/src/components/UserListScreen/index.tsx +103 -0
- package/src/config/index.ts +40 -0
- package/src/hooks/useChat.ts +48 -0
- package/src/hooks/useRemoteConfig.ts +20 -0
- package/src/hooks/useWebRTC.ts +130 -0
- package/src/index.ts +29 -0
- package/src/types/index.ts +127 -0
- package/src/utils/chat.ts +70 -0
- package/src/utils/theme.ts +27 -0
- package/dist/components/BottomNav/index.d.ts +0 -10
- package/dist/components/BottomNav/index.js +0 -32
- package/dist/components/ChatBox/index.d.ts +0 -15
- package/dist/components/ChatBox/index.js +0 -228
- package/dist/components/ChatButton/index.d.ts +0 -9
- package/dist/components/ChatButton/index.js +0 -17
- package/dist/components/ChatWindow/index.d.ts +0 -10
- package/dist/components/ChatWindow/index.js +0 -286
- package/dist/components/HomeView/index.d.ts +0 -12
- package/dist/components/HomeView/index.js +0 -51
- package/dist/components/UserList/index.d.ts +0 -13
- package/dist/components/UserList/index.js +0 -136
- package/dist/hooks/useUsers.d.ts +0 -14
- package/dist/hooks/useUsers.js +0 -32
- package/dist/services/userService.d.ts +0 -7
- package/dist/services/userService.js +0 -18
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { useState, useMemo, useCallback } from 'react';
|
|
3
|
-
import { UserList } from '../UserList';
|
|
4
|
-
import { ChatBox } from '../ChatBox';
|
|
5
|
-
import { MaintenanceView } from '../MaintenanceView';
|
|
6
|
-
import { HomeView } from '../HomeView';
|
|
7
|
-
import { BottomNav } from '../BottomNav';
|
|
8
|
-
import { useUsers } from '../../hooks/useUsers';
|
|
9
|
-
import { useChat } from '../../hooks/useChat';
|
|
10
|
-
import { buildUserListUrl } from '../../config';
|
|
11
|
-
import { mergeTheme } from '../../utils/theme';
|
|
12
|
-
export const ChatWindow = ({ config, theme, buttonPosition, onClose, }) => {
|
|
13
|
-
var _a, _b, _c, _d, _e, _f;
|
|
14
|
-
const t = mergeTheme(Object.assign(Object.assign({}, theme), { widgetMinWidth: (_a = theme === null || theme === void 0 ? void 0 : theme.widgetMinWidth) !== null && _a !== void 0 ? _a : config.widgetMinWidth, widgetMaxWidth: (_b = theme === null || theme === void 0 ? void 0 : theme.widgetMaxWidth) !== null && _b !== void 0 ? _b : config.widgetMaxWidth, widgetMinHeight: (_c = theme === null || theme === void 0 ? void 0 : theme.widgetMinHeight) !== null && _c !== void 0 ? _c : config.widgetMinHeight, widgetMaxHeight: (_d = theme === null || theme === void 0 ? void 0 : theme.widgetMaxHeight) !== null && _d !== void 0 ? _d : config.widgetMaxHeight, widgetDefaultSize: (_e = theme === null || theme === void 0 ? void 0 : theme.widgetDefaultSize) !== null && _e !== void 0 ? _e : config.widgetDefaultSize }));
|
|
15
|
-
const minW = Math.min(t.widgetMinWidth, t.widgetMaxWidth);
|
|
16
|
-
const maxW = Math.max(t.widgetMinWidth, t.widgetMaxWidth);
|
|
17
|
-
const minH = Math.min(t.widgetMinHeight, t.widgetMaxHeight);
|
|
18
|
-
const maxH = Math.max(t.widgetMinHeight, t.widgetMaxHeight);
|
|
19
|
-
const [sizeRatio, setSizeRatio] = useState(t.widgetDefaultSize);
|
|
20
|
-
const widthPx = minW + (maxW - minW) * sizeRatio;
|
|
21
|
-
const heightPx = minH + (maxH - minH) * sizeRatio;
|
|
22
|
-
const [bottomTab, setBottomTab] = useState('home');
|
|
23
|
-
const [homeFlow, setHomeFlow] = useState('home');
|
|
24
|
-
const [pickUserMode, setPickUserMode] = useState(null);
|
|
25
|
-
const [tickets, setTickets] = useState([]);
|
|
26
|
-
const [ticketSubject, setTicketSubject] = useState('');
|
|
27
|
-
const [ticketBody, setTicketBody] = useState('');
|
|
28
|
-
const userListUrl = buildUserListUrl(config);
|
|
29
|
-
const filterType = pickUserMode === 'support'
|
|
30
|
-
? 'developer'
|
|
31
|
-
: pickUserMode === 'conversation'
|
|
32
|
-
? 'user'
|
|
33
|
-
: config.chatType === 'SUPPORT'
|
|
34
|
-
? 'developer'
|
|
35
|
-
: config.chatType === 'CHAT'
|
|
36
|
-
? 'user'
|
|
37
|
-
: 'developer';
|
|
38
|
-
const { users, loading, error } = useUsers({
|
|
39
|
-
url: userListUrl,
|
|
40
|
-
filterType,
|
|
41
|
-
enabled: config.status === 'ACTIVE' && homeFlow === 'pickUser',
|
|
42
|
-
});
|
|
43
|
-
const { messages, activeUser, recentChats, selectUser, sendMessage, openRecent, } = useChat();
|
|
44
|
-
const positionStyle = buttonPosition === 'bottom-left'
|
|
45
|
-
? { left: '24px', right: 'auto' }
|
|
46
|
-
: { right: '24px', left: 'auto' };
|
|
47
|
-
const goHomeCards = useCallback(() => {
|
|
48
|
-
setHomeFlow('home');
|
|
49
|
-
setPickUserMode(null);
|
|
50
|
-
}, []);
|
|
51
|
-
const handleBackFromChat = useCallback(() => {
|
|
52
|
-
if (pickUserMode) {
|
|
53
|
-
setHomeFlow('pickUser');
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
setBottomTab('chats');
|
|
57
|
-
setHomeFlow('home');
|
|
58
|
-
}, [pickUserMode]);
|
|
59
|
-
const handleBottomTab = useCallback((tab) => {
|
|
60
|
-
setBottomTab(tab);
|
|
61
|
-
goHomeCards();
|
|
62
|
-
}, [goHomeCards]);
|
|
63
|
-
const startSupport = useCallback(() => {
|
|
64
|
-
setPickUserMode('support');
|
|
65
|
-
setHomeFlow('pickUser');
|
|
66
|
-
}, []);
|
|
67
|
-
const startConversation = useCallback(() => {
|
|
68
|
-
setPickUserMode('conversation');
|
|
69
|
-
setHomeFlow('pickUser');
|
|
70
|
-
}, []);
|
|
71
|
-
const startRaiseTicket = useCallback(() => {
|
|
72
|
-
setHomeFlow('raiseTicket');
|
|
73
|
-
setTicketSubject('');
|
|
74
|
-
setTicketBody('');
|
|
75
|
-
}, []);
|
|
76
|
-
const submitTicket = useCallback(() => {
|
|
77
|
-
if (!ticketSubject.trim())
|
|
78
|
-
return;
|
|
79
|
-
const id = `tkt_${Date.now()}`;
|
|
80
|
-
setTickets((prev) => [
|
|
81
|
-
{
|
|
82
|
-
id,
|
|
83
|
-
subject: ticketSubject.trim(),
|
|
84
|
-
body: ticketBody.trim(),
|
|
85
|
-
createdAt: new Date(),
|
|
86
|
-
status: 'open',
|
|
87
|
-
},
|
|
88
|
-
...prev,
|
|
89
|
-
]);
|
|
90
|
-
setHomeFlow('home');
|
|
91
|
-
setBottomTab('tickets');
|
|
92
|
-
}, [ticketSubject, ticketBody]);
|
|
93
|
-
const pickUserHeader = useMemo(() => {
|
|
94
|
-
if (pickUserMode === 'support')
|
|
95
|
-
return 'Support';
|
|
96
|
-
if (pickUserMode === 'conversation')
|
|
97
|
-
return 'New conversation';
|
|
98
|
-
return 'People';
|
|
99
|
-
}, [pickUserMode]);
|
|
100
|
-
return (_jsxs("div", { style: Object.assign(Object.assign({ position: 'fixed', bottom: '90px' }, positionStyle), { zIndex: 9998, width: `${widthPx}px`, maxWidth: 'calc(100vw - 32px)', height: `${heightPx}px`, maxHeight: 'calc(100vh - 120px)', backgroundColor: t.backgroundColor, borderRadius: t.borderRadius, boxShadow: '0 24px 80px rgba(0,0,0,0.18), 0 8px 24px rgba(0,0,0,0.08)', display: 'flex', flexDirection: 'column', overflow: 'hidden', fontFamily: t.fontFamily, animation: 'cw-slideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1)' }), children: [_jsx("style", { children: `
|
|
101
|
-
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&display=swap');
|
|
102
|
-
@keyframes cw-slideUp {
|
|
103
|
-
from { opacity: 0; transform: translateY(20px) scale(0.97); }
|
|
104
|
-
to { opacity: 1; transform: translateY(0) scale(1); }
|
|
105
|
-
}
|
|
106
|
-
@keyframes cw-slideFromRight {
|
|
107
|
-
from { opacity: 0; transform: translateX(24px); }
|
|
108
|
-
to { opacity: 1; transform: translateX(0); }
|
|
109
|
-
}
|
|
110
|
-
@keyframes shimmer {
|
|
111
|
-
0% { background-position: 200% 0; }
|
|
112
|
-
100% { background-position: -200% 0; }
|
|
113
|
-
}
|
|
114
|
-
::-webkit-scrollbar { width: 4px; }
|
|
115
|
-
::-webkit-scrollbar-track { background: transparent; }
|
|
116
|
-
::-webkit-scrollbar-thumb { background: #e0e0e0; border-radius: 4px; }
|
|
117
|
-
` }), config.status === 'MAINTENANCE' ? (_jsx(MaintenanceView, { fontFamily: t.fontFamily, primaryColor: t.primaryColor })) : (_jsxs(_Fragment, { children: [_jsxs("div", { style: { flex: 1, display: 'flex', flexDirection: 'column', minHeight: 0, overflow: 'hidden' }, children: [bottomTab === 'home' && homeFlow === 'home' && (_jsx(HomeView, { primaryColor: t.primaryColor, fontFamily: t.fontFamily, showNeedSupport: config.showNeedSupport, showNewConversation: config.showNewConversation, onNeedSupport: startSupport, onNewConversation: startConversation, onRaiseTicket: startRaiseTicket, onClose: onClose })), bottomTab === 'home' && homeFlow === 'pickUser' && (_jsxs("div", { style: {
|
|
118
|
-
flex: 1,
|
|
119
|
-
display: 'flex',
|
|
120
|
-
flexDirection: 'column',
|
|
121
|
-
minHeight: 0,
|
|
122
|
-
backgroundColor: '#fff',
|
|
123
|
-
animation: 'cw-slideFromRight 0.28s ease-out',
|
|
124
|
-
}, children: [_jsxs("div", { style: {
|
|
125
|
-
flexShrink: 0,
|
|
126
|
-
padding: '14px 16px',
|
|
127
|
-
backgroundColor: t.primaryColor,
|
|
128
|
-
color: '#fff',
|
|
129
|
-
display: 'flex',
|
|
130
|
-
alignItems: 'center',
|
|
131
|
-
gap: '12px',
|
|
132
|
-
}, children: [_jsx("button", { type: "button", onClick: goHomeCards, "aria-label": "Back", style: {
|
|
133
|
-
background: 'transparent',
|
|
134
|
-
border: 'none',
|
|
135
|
-
color: '#fff',
|
|
136
|
-
cursor: 'pointer',
|
|
137
|
-
padding: '4px',
|
|
138
|
-
}, children: _jsx("svg", { width: "22", height: "22", viewBox: "0 0 24 24", fill: "none", children: _jsx("path", { d: "M15 18L9 12L15 6", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) }) }), _jsx("div", { style: { fontWeight: 700, fontSize: '16px' }, children: pickUserHeader })] }), _jsxs("div", { style: { flex: 1, overflow: 'hidden', display: 'flex', flexDirection: 'column' }, children: [_jsx("div", { style: {
|
|
139
|
-
padding: '10px 16px',
|
|
140
|
-
fontSize: '11px',
|
|
141
|
-
fontWeight: 700,
|
|
142
|
-
color: '#bbb',
|
|
143
|
-
textTransform: 'uppercase',
|
|
144
|
-
letterSpacing: '0.08em',
|
|
145
|
-
borderBottom: '1px solid #f0f0f0',
|
|
146
|
-
}, children: "Select a contact" }), _jsx(UserList, { users: users, loading: loading, error: error, activeUserId: (_f = activeUser === null || activeUser === void 0 ? void 0 : activeUser.uid) !== null && _f !== void 0 ? _f : null, onSelectUser: (u) => {
|
|
147
|
-
selectUser(u);
|
|
148
|
-
setHomeFlow('chat');
|
|
149
|
-
}, primaryColor: t.primaryColor, fontFamily: t.fontFamily })] })] })), bottomTab === 'home' && homeFlow === 'chat' && (_jsx("div", { style: {
|
|
150
|
-
flex: 1,
|
|
151
|
-
display: 'flex',
|
|
152
|
-
flexDirection: 'column',
|
|
153
|
-
minHeight: 0,
|
|
154
|
-
animation: 'cw-slideFromRight 0.28s ease-out',
|
|
155
|
-
}, children: _jsx(ChatBox, { activeUser: activeUser, messages: messages, onSendMessage: sendMessage, primaryColor: t.primaryColor, fontFamily: t.fontFamily, variant: "minimal", onBack: handleBackFromChat, onClose: onClose, headerTitle: activeUser === null || activeUser === void 0 ? void 0 : activeUser.name }) })), bottomTab === 'home' && homeFlow === 'raiseTicket' && (_jsxs("div", { style: {
|
|
156
|
-
flex: 1,
|
|
157
|
-
display: 'flex',
|
|
158
|
-
flexDirection: 'column',
|
|
159
|
-
minHeight: 0,
|
|
160
|
-
backgroundColor: '#fff',
|
|
161
|
-
animation: 'cw-slideFromRight 0.28s ease-out',
|
|
162
|
-
}, children: [_jsxs("div", { style: {
|
|
163
|
-
flexShrink: 0,
|
|
164
|
-
padding: '14px 16px',
|
|
165
|
-
backgroundColor: t.primaryColor,
|
|
166
|
-
color: '#fff',
|
|
167
|
-
display: 'flex',
|
|
168
|
-
alignItems: 'center',
|
|
169
|
-
justifyContent: 'space-between',
|
|
170
|
-
}, children: [_jsx("button", { type: "button", onClick: goHomeCards, "aria-label": "Back", style: {
|
|
171
|
-
background: 'transparent',
|
|
172
|
-
border: 'none',
|
|
173
|
-
color: '#fff',
|
|
174
|
-
cursor: 'pointer',
|
|
175
|
-
padding: '4px',
|
|
176
|
-
}, children: _jsx("svg", { width: "22", height: "22", viewBox: "0 0 24 24", fill: "none", children: _jsx("path", { d: "M15 18L9 12L15 6", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) }) }), _jsx("span", { style: { fontWeight: 700, fontSize: '16px' }, children: "Raise ticket" }), _jsx("button", { type: "button", onClick: onClose, "aria-label": "Close", style: {
|
|
177
|
-
background: 'transparent',
|
|
178
|
-
border: 'none',
|
|
179
|
-
color: '#fff',
|
|
180
|
-
cursor: 'pointer',
|
|
181
|
-
padding: '4px',
|
|
182
|
-
}, children: _jsxs("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", children: [_jsx("line", { x1: "18", y1: "6", x2: "6", y2: "18", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }), _jsx("line", { x1: "6", y1: "6", x2: "18", y2: "18", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" })] }) })] }), _jsxs("div", { style: { padding: '20px', flex: 1, overflowY: 'auto' }, children: [_jsx("label", { style: { display: 'block', fontSize: '12px', fontWeight: 600, color: '#666', marginBottom: '6px' }, children: "Subject" }), _jsx("input", { value: ticketSubject, onChange: (e) => setTicketSubject(e.target.value), placeholder: "Brief summary", style: {
|
|
183
|
-
width: '100%',
|
|
184
|
-
boxSizing: 'border-box',
|
|
185
|
-
padding: '10px 12px',
|
|
186
|
-
borderRadius: '10px',
|
|
187
|
-
border: '1px solid #e5e5e5',
|
|
188
|
-
fontFamily: t.fontFamily,
|
|
189
|
-
fontSize: '14px',
|
|
190
|
-
marginBottom: '16px',
|
|
191
|
-
} }), _jsx("label", { style: { display: 'block', fontSize: '12px', fontWeight: 600, color: '#666', marginBottom: '6px' }, children: "Description" }), _jsx("textarea", { value: ticketBody, onChange: (e) => setTicketBody(e.target.value), placeholder: "Describe the issue or change\u2026", rows: 5, style: {
|
|
192
|
-
width: '100%',
|
|
193
|
-
boxSizing: 'border-box',
|
|
194
|
-
padding: '10px 12px',
|
|
195
|
-
borderRadius: '10px',
|
|
196
|
-
border: '1px solid #e5e5e5',
|
|
197
|
-
fontFamily: t.fontFamily,
|
|
198
|
-
fontSize: '14px',
|
|
199
|
-
resize: 'vertical',
|
|
200
|
-
} }), _jsx("button", { type: "button", onClick: submitTicket, style: {
|
|
201
|
-
marginTop: '18px',
|
|
202
|
-
width: '100%',
|
|
203
|
-
padding: '12px',
|
|
204
|
-
borderRadius: '10px',
|
|
205
|
-
border: 'none',
|
|
206
|
-
backgroundColor: t.primaryColor,
|
|
207
|
-
color: '#fff',
|
|
208
|
-
fontWeight: 700,
|
|
209
|
-
fontFamily: t.fontFamily,
|
|
210
|
-
cursor: 'pointer',
|
|
211
|
-
fontSize: '15px',
|
|
212
|
-
}, children: "Submit ticket" })] })] })), bottomTab === 'chats' && (_jsxs("div", { style: {
|
|
213
|
-
flex: 1,
|
|
214
|
-
display: 'flex',
|
|
215
|
-
flexDirection: 'column',
|
|
216
|
-
minHeight: 0,
|
|
217
|
-
backgroundColor: '#fff',
|
|
218
|
-
}, children: [_jsxs("div", { style: {
|
|
219
|
-
padding: '16px 20px',
|
|
220
|
-
backgroundColor: t.primaryColor,
|
|
221
|
-
color: '#fff',
|
|
222
|
-
fontWeight: 700,
|
|
223
|
-
fontSize: '17px',
|
|
224
|
-
display: 'flex',
|
|
225
|
-
alignItems: 'center',
|
|
226
|
-
justifyContent: 'space-between',
|
|
227
|
-
}, children: ["Recent chats", _jsx("button", { type: "button", onClick: onClose, "aria-label": "Close", style: {
|
|
228
|
-
background: 'transparent',
|
|
229
|
-
border: 'none',
|
|
230
|
-
color: '#fff',
|
|
231
|
-
cursor: 'pointer',
|
|
232
|
-
}, children: _jsxs("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", children: [_jsx("line", { x1: "18", y1: "6", x2: "6", y2: "18", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }), _jsx("line", { x1: "6", y1: "6", x2: "18", y2: "18", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" })] }) })] }), _jsx("div", { style: { flex: 1, overflowY: 'auto' }, children: recentChats.length === 0 ? (_jsx("p", { style: { padding: '24px', textAlign: 'center', color: '#aaa', fontSize: '14px', margin: 0 }, children: "No recent chats yet" })) : (recentChats.map((r) => (_jsxs("button", { type: "button", onClick: () => {
|
|
233
|
-
openRecent(r.user);
|
|
234
|
-
setBottomTab('home');
|
|
235
|
-
setHomeFlow('chat');
|
|
236
|
-
setPickUserMode(null);
|
|
237
|
-
}, style: {
|
|
238
|
-
width: '100%',
|
|
239
|
-
padding: '14px 18px',
|
|
240
|
-
border: 'none',
|
|
241
|
-
borderBottom: '1px solid #f0f0f0',
|
|
242
|
-
background: '#fff',
|
|
243
|
-
textAlign: 'left',
|
|
244
|
-
cursor: 'pointer',
|
|
245
|
-
fontFamily: t.fontFamily,
|
|
246
|
-
}, children: [_jsx("div", { style: { fontWeight: 600, color: '#1a1a2e' }, children: r.user.name }), _jsx("div", { style: { fontSize: '13px', color: '#888', marginTop: '4px' }, children: r.lastMessage }), _jsx("div", { style: { fontSize: '11px', color: '#bbb', marginTop: '6px' }, children: r.updatedAt.toLocaleString() })] }, r.user.uid)))) })] })), bottomTab === 'tickets' && (_jsxs("div", { style: {
|
|
247
|
-
flex: 1,
|
|
248
|
-
display: 'flex',
|
|
249
|
-
flexDirection: 'column',
|
|
250
|
-
minHeight: 0,
|
|
251
|
-
backgroundColor: '#fff',
|
|
252
|
-
}, children: [_jsxs("div", { style: {
|
|
253
|
-
padding: '16px 20px',
|
|
254
|
-
backgroundColor: t.primaryColor,
|
|
255
|
-
color: '#fff',
|
|
256
|
-
fontWeight: 700,
|
|
257
|
-
fontSize: '17px',
|
|
258
|
-
display: 'flex',
|
|
259
|
-
alignItems: 'center',
|
|
260
|
-
justifyContent: 'space-between',
|
|
261
|
-
}, children: ["Tickets", _jsx("button", { type: "button", onClick: onClose, "aria-label": "Close", style: {
|
|
262
|
-
background: 'transparent',
|
|
263
|
-
border: 'none',
|
|
264
|
-
color: '#fff',
|
|
265
|
-
cursor: 'pointer',
|
|
266
|
-
}, children: _jsxs("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", children: [_jsx("line", { x1: "18", y1: "6", x2: "6", y2: "18", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }), _jsx("line", { x1: "6", y1: "6", x2: "18", y2: "18", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" })] }) })] }), _jsx("div", { style: { flex: 1, overflowY: 'auto' }, children: tickets.length === 0 ? (_jsx("p", { style: { padding: '24px', textAlign: 'center', color: '#aaa', fontSize: '14px', margin: 0 }, children: "No tickets yet. Use Home \u2192 Raise Ticket." })) : (tickets.map((tk) => (_jsxs("div", { style: {
|
|
267
|
-
padding: '14px 18px',
|
|
268
|
-
borderBottom: '1px solid #f0f0f0',
|
|
269
|
-
fontFamily: t.fontFamily,
|
|
270
|
-
}, children: [_jsx("div", { style: { fontWeight: 600, color: '#1a1a2e' }, children: tk.subject }), tk.body ? (_jsx("div", { style: { fontSize: '13px', color: '#666', marginTop: '6px', lineHeight: 1.45 }, children: tk.body })) : null, _jsxs("div", { style: { fontSize: '11px', color: '#bbb', marginTop: '8px' }, children: [tk.createdAt.toLocaleString(), " \u00B7 ", tk.status] })] }, tk.id)))) })] }))] }), _jsx("div", { style: {
|
|
271
|
-
padding: '8px 14px 6px',
|
|
272
|
-
borderTop: '1px solid #eee',
|
|
273
|
-
backgroundColor: '#fafafa',
|
|
274
|
-
flexShrink: 0,
|
|
275
|
-
}, children: _jsxs("div", { style: {
|
|
276
|
-
display: 'flex',
|
|
277
|
-
alignItems: 'center',
|
|
278
|
-
gap: '10px',
|
|
279
|
-
fontSize: '11px',
|
|
280
|
-
color: '#888',
|
|
281
|
-
fontFamily: t.fontFamily,
|
|
282
|
-
}, children: [_jsx("span", { style: { flexShrink: 0 }, children: "Size" }), _jsx("input", { type: "range", min: 0, max: 1, step: 0.02, value: sizeRatio, onChange: (e) => setSizeRatio(parseFloat(e.target.value)), "aria-label": "Widget size", style: {
|
|
283
|
-
flex: 1,
|
|
284
|
-
accentColor: t.primaryColor,
|
|
285
|
-
} })] }) }), _jsx(BottomNav, { active: bottomTab, onChange: handleBottomTab, primaryColor: t.primaryColor, fontFamily: t.fontFamily })] }))] }));
|
|
286
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
export interface HomeViewProps {
|
|
3
|
-
primaryColor: string;
|
|
4
|
-
fontFamily: string;
|
|
5
|
-
showNeedSupport: boolean;
|
|
6
|
-
showNewConversation: boolean;
|
|
7
|
-
onNeedSupport: () => void;
|
|
8
|
-
onNewConversation: () => void;
|
|
9
|
-
onRaiseTicket: () => void;
|
|
10
|
-
onClose: () => void;
|
|
11
|
-
}
|
|
12
|
-
export declare const HomeView: React.FC<HomeViewProps>;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
const SendIcon = ({ color }) => (_jsx("svg", { width: "22", height: "22", viewBox: "0 0 24 24", fill: "none", "aria-hidden": true, children: _jsx("path", { d: "M22 2L11 13M22 2L15 22L11 13L2 9L22 2Z", stroke: color, strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
3
|
-
export const HomeView = ({ primaryColor, fontFamily, showNeedSupport, showNewConversation, onNeedSupport, onNewConversation, onRaiseTicket, onClose, }) => {
|
|
4
|
-
const cardStyle = {
|
|
5
|
-
width: '100%',
|
|
6
|
-
backgroundColor: '#fff',
|
|
7
|
-
borderRadius: '12px',
|
|
8
|
-
padding: '16px 18px',
|
|
9
|
-
display: 'flex',
|
|
10
|
-
alignItems: 'center',
|
|
11
|
-
justifyContent: 'space-between',
|
|
12
|
-
gap: '12px',
|
|
13
|
-
border: 'none',
|
|
14
|
-
cursor: 'pointer',
|
|
15
|
-
textAlign: 'left',
|
|
16
|
-
fontFamily,
|
|
17
|
-
boxShadow: '0 2px 12px rgba(0,0,0,0.06)',
|
|
18
|
-
transition: 'transform 0.15s ease, box-shadow 0.15s ease',
|
|
19
|
-
};
|
|
20
|
-
return (_jsxs("div", { style: {
|
|
21
|
-
flex: 1,
|
|
22
|
-
display: 'flex',
|
|
23
|
-
flexDirection: 'column',
|
|
24
|
-
backgroundColor: primaryColor,
|
|
25
|
-
fontFamily,
|
|
26
|
-
minHeight: 0,
|
|
27
|
-
}, children: [_jsx("div", { style: {
|
|
28
|
-
padding: '20px 20px 8px',
|
|
29
|
-
display: 'flex',
|
|
30
|
-
justifyContent: 'flex-end',
|
|
31
|
-
}, children: _jsx("button", { type: "button", onClick: onClose, "aria-label": "Close", style: {
|
|
32
|
-
background: 'transparent',
|
|
33
|
-
border: 'none',
|
|
34
|
-
color: '#fff',
|
|
35
|
-
cursor: 'pointer',
|
|
36
|
-
padding: '4px',
|
|
37
|
-
}, children: _jsxs("svg", { width: "22", height: "22", viewBox: "0 0 24 24", fill: "none", children: [_jsx("line", { x1: "18", y1: "6", x2: "6", y2: "18", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }), _jsx("line", { x1: "6", y1: "6", x2: "18", y2: "18", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" })] }) }) }), _jsxs("div", { style: { padding: '0 24px 20px', flexShrink: 0 }, children: [_jsx("h1", { style: {
|
|
38
|
-
margin: 0,
|
|
39
|
-
color: '#fff',
|
|
40
|
-
fontSize: '26px',
|
|
41
|
-
fontWeight: 700,
|
|
42
|
-
letterSpacing: '-0.02em',
|
|
43
|
-
}, children: "Hi there \uD83D\uDC4B" }), _jsx("p", { style: { margin: '10px 0 0', color: 'rgba(255,255,255,0.92)', fontSize: '14px', lineHeight: 1.5 }, children: "Need help? start a conversation:" })] }), _jsxs("div", { style: {
|
|
44
|
-
flex: 1,
|
|
45
|
-
padding: '0 20px 16px',
|
|
46
|
-
display: 'flex',
|
|
47
|
-
flexDirection: 'column',
|
|
48
|
-
gap: '12px',
|
|
49
|
-
overflowY: 'auto',
|
|
50
|
-
}, children: [showNeedSupport && (_jsxs("button", { type: "button", onClick: onNeedSupport, style: cardStyle, children: [_jsxs("div", { children: [_jsx("div", { style: { fontWeight: 700, fontSize: '15px', color: '#1a1a2e' }, children: "Need Support" }), _jsx("div", { style: { fontSize: '13px', color: '#888', marginTop: '4px' }, children: "We typically reply in a few minutes" })] }), _jsx(SendIcon, { color: primaryColor })] })), showNewConversation && (_jsxs("button", { type: "button", onClick: onNewConversation, style: cardStyle, children: [_jsxs("div", { children: [_jsx("div", { style: { fontWeight: 700, fontSize: '15px', color: '#1a1a2e' }, children: "New Conversation" }), _jsx("div", { style: { fontSize: '13px', color: '#888', marginTop: '4px' }, children: "With your colleague" })] }), _jsx(SendIcon, { color: primaryColor })] })), _jsxs("button", { type: "button", onClick: onRaiseTicket, style: cardStyle, children: [_jsxs("div", { children: [_jsx("div", { style: { fontWeight: 700, fontSize: '15px', color: '#1a1a2e' }, children: "Raise Ticket" }), _jsx("div", { style: { fontSize: '13px', color: '#888', marginTop: '4px' }, children: "For major changes" })] }), _jsx(SendIcon, { color: primaryColor })] })] })] }));
|
|
51
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { ChatUser } from '../../types';
|
|
3
|
-
interface UserListProps {
|
|
4
|
-
users: ChatUser[];
|
|
5
|
-
loading: boolean;
|
|
6
|
-
error: string | null;
|
|
7
|
-
activeUserId: string | null;
|
|
8
|
-
onSelectUser: (user: ChatUser) => void;
|
|
9
|
-
primaryColor: string;
|
|
10
|
-
fontFamily: string;
|
|
11
|
-
}
|
|
12
|
-
export declare const UserList: React.FC<UserListProps>;
|
|
13
|
-
export {};
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
export const UserList = ({ users, loading, error, activeUserId, onSelectUser, primaryColor, fontFamily, }) => {
|
|
3
|
-
if (loading) {
|
|
4
|
-
return (_jsx("div", { style: { padding: '16px', fontFamily }, children: [1, 2, 3, 4].map((i) => (_jsx(SkeletonUser, {}, i))) }));
|
|
5
|
-
}
|
|
6
|
-
if (error) {
|
|
7
|
-
return (_jsxs("div", { style: {
|
|
8
|
-
padding: '32px 20px',
|
|
9
|
-
textAlign: 'center',
|
|
10
|
-
fontFamily,
|
|
11
|
-
display: 'flex',
|
|
12
|
-
flexDirection: 'column',
|
|
13
|
-
alignItems: 'center',
|
|
14
|
-
gap: '10px',
|
|
15
|
-
}, children: [_jsxs("svg", { width: "36", height: "36", viewBox: "0 0 24 24", fill: "none", children: [_jsx("circle", { cx: "12", cy: "12", r: "10", stroke: "#ff6b6b", strokeWidth: "2" }), _jsx("line", { x1: "12", y1: "8", x2: "12", y2: "12", stroke: "#ff6b6b", strokeWidth: "2", strokeLinecap: "round" }), _jsx("line", { x1: "12", y1: "16", x2: "12.01", y2: "16", stroke: "#ff6b6b", strokeWidth: "2", strokeLinecap: "round" })] }), _jsx("p", { style: { margin: 0, fontSize: '13px', color: '#ff6b6b', fontWeight: 600 }, children: "Failed to load users" }), _jsx("p", { style: { margin: 0, fontSize: '12px', color: '#999', lineHeight: 1.5 }, children: error })] }));
|
|
16
|
-
}
|
|
17
|
-
if (users.length === 0) {
|
|
18
|
-
return (_jsxs("div", { style: {
|
|
19
|
-
padding: '40px 20px',
|
|
20
|
-
textAlign: 'center',
|
|
21
|
-
fontFamily,
|
|
22
|
-
display: 'flex',
|
|
23
|
-
flexDirection: 'column',
|
|
24
|
-
alignItems: 'center',
|
|
25
|
-
gap: '10px',
|
|
26
|
-
}, children: [_jsxs("svg", { width: "40", height: "40", viewBox: "0 0 24 24", fill: "none", children: [_jsx("path", { d: "M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2", stroke: "#ccc", strokeWidth: "2", strokeLinecap: "round" }), _jsx("circle", { cx: "9", cy: "7", r: "4", stroke: "#ccc", strokeWidth: "2" }), _jsx("path", { d: "M23 21v-2a4 4 0 0 0-3-3.87M16 3.13a4 4 0 0 1 0 7.75", stroke: "#ccc", strokeWidth: "2", strokeLinecap: "round" })] }), _jsx("p", { style: { margin: 0, fontSize: '13px', color: '#bbb', fontWeight: 600 }, children: "No users available" }), _jsx("p", { style: { margin: 0, fontSize: '12px', color: '#ccc' }, children: "Check back later" })] }));
|
|
27
|
-
}
|
|
28
|
-
return (_jsx("div", { style: { overflowY: 'auto', flex: 1, fontFamily }, children: users.map((user) => {
|
|
29
|
-
const isActive = user.uid === activeUserId;
|
|
30
|
-
const initials = user.name
|
|
31
|
-
.split(' ')
|
|
32
|
-
.map((n) => n[0])
|
|
33
|
-
.join('')
|
|
34
|
-
.toUpperCase()
|
|
35
|
-
.slice(0, 2);
|
|
36
|
-
return (_jsxs("button", { onClick: () => onSelectUser(user), style: {
|
|
37
|
-
width: '100%',
|
|
38
|
-
padding: '12px 16px',
|
|
39
|
-
display: 'flex',
|
|
40
|
-
alignItems: 'center',
|
|
41
|
-
gap: '12px',
|
|
42
|
-
background: isActive ? `${primaryColor}12` : 'transparent',
|
|
43
|
-
border: 'none',
|
|
44
|
-
borderLeft: isActive ? `3px solid ${primaryColor}` : '3px solid transparent',
|
|
45
|
-
cursor: 'pointer',
|
|
46
|
-
textAlign: 'left',
|
|
47
|
-
transition: 'all 0.18s ease',
|
|
48
|
-
borderRadius: '0',
|
|
49
|
-
}, onMouseEnter: (e) => {
|
|
50
|
-
if (!isActive) {
|
|
51
|
-
e.currentTarget.style.backgroundColor = '#f8f8ff';
|
|
52
|
-
}
|
|
53
|
-
}, onMouseLeave: (e) => {
|
|
54
|
-
if (!isActive) {
|
|
55
|
-
e.currentTarget.style.backgroundColor = 'transparent';
|
|
56
|
-
}
|
|
57
|
-
}, children: [_jsx("div", { style: {
|
|
58
|
-
width: '40px',
|
|
59
|
-
height: '40px',
|
|
60
|
-
borderRadius: '50%',
|
|
61
|
-
backgroundColor: isActive ? primaryColor : stringToColor(user.name),
|
|
62
|
-
display: 'flex',
|
|
63
|
-
alignItems: 'center',
|
|
64
|
-
justifyContent: 'center',
|
|
65
|
-
color: '#fff',
|
|
66
|
-
fontSize: '13px',
|
|
67
|
-
fontWeight: 700,
|
|
68
|
-
flexShrink: 0,
|
|
69
|
-
transition: 'background 0.2s',
|
|
70
|
-
}, children: initials }), _jsxs("div", { style: { flex: 1, minWidth: 0 }, children: [_jsx("div", { style: {
|
|
71
|
-
fontSize: '14px',
|
|
72
|
-
fontWeight: 600,
|
|
73
|
-
color: isActive ? primaryColor : '#1a1a2e',
|
|
74
|
-
whiteSpace: 'nowrap',
|
|
75
|
-
overflow: 'hidden',
|
|
76
|
-
textOverflow: 'ellipsis',
|
|
77
|
-
}, children: user.name }), _jsx("div", { style: {
|
|
78
|
-
fontSize: '12px',
|
|
79
|
-
color: '#999',
|
|
80
|
-
whiteSpace: 'nowrap',
|
|
81
|
-
overflow: 'hidden',
|
|
82
|
-
textOverflow: 'ellipsis',
|
|
83
|
-
}, children: user.project || user.email })] }), _jsx("span", { style: {
|
|
84
|
-
fontSize: '10px',
|
|
85
|
-
fontWeight: 700,
|
|
86
|
-
padding: '3px 8px',
|
|
87
|
-
borderRadius: '20px',
|
|
88
|
-
textTransform: 'uppercase',
|
|
89
|
-
letterSpacing: '0.05em',
|
|
90
|
-
flexShrink: 0,
|
|
91
|
-
backgroundColor: user.type === 'developer' ? '#e8f5e9' : '#e3f2fd',
|
|
92
|
-
color: user.type === 'developer' ? '#2e7d32' : '#1565c0',
|
|
93
|
-
}, children: user.type === 'developer' ? 'Dev' : 'User' })] }, user.uid));
|
|
94
|
-
}) }));
|
|
95
|
-
};
|
|
96
|
-
const SkeletonUser = () => (_jsxs("div", { style: {
|
|
97
|
-
display: 'flex',
|
|
98
|
-
alignItems: 'center',
|
|
99
|
-
gap: '12px',
|
|
100
|
-
padding: '12px 16px',
|
|
101
|
-
}, children: [_jsx("div", { style: {
|
|
102
|
-
width: '40px',
|
|
103
|
-
height: '40px',
|
|
104
|
-
borderRadius: '50%',
|
|
105
|
-
background: 'linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%)',
|
|
106
|
-
backgroundSize: '200% 100%',
|
|
107
|
-
animation: 'shimmer 1.5s infinite',
|
|
108
|
-
flexShrink: 0,
|
|
109
|
-
} }), _jsxs("div", { style: { flex: 1 }, children: [_jsx("div", { style: {
|
|
110
|
-
height: '12px',
|
|
111
|
-
width: '60%',
|
|
112
|
-
borderRadius: '6px',
|
|
113
|
-
background: 'linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%)',
|
|
114
|
-
backgroundSize: '200% 100%',
|
|
115
|
-
animation: 'shimmer 1.5s infinite',
|
|
116
|
-
marginBottom: '8px',
|
|
117
|
-
} }), _jsx("div", { style: {
|
|
118
|
-
height: '10px',
|
|
119
|
-
width: '40%',
|
|
120
|
-
borderRadius: '6px',
|
|
121
|
-
background: 'linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%)',
|
|
122
|
-
backgroundSize: '200% 100%',
|
|
123
|
-
animation: 'shimmer 1.5s infinite',
|
|
124
|
-
} })] })] }));
|
|
125
|
-
// Generate consistent color from name string
|
|
126
|
-
function stringToColor(str) {
|
|
127
|
-
let hash = 0;
|
|
128
|
-
for (let i = 0; i < str.length; i++) {
|
|
129
|
-
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
130
|
-
}
|
|
131
|
-
const colors = [
|
|
132
|
-
'#7C3AED', '#2563EB', '#059669', '#D97706',
|
|
133
|
-
'#DC2626', '#7C2D12', '#0E7490', '#4F46E5',
|
|
134
|
-
];
|
|
135
|
-
return colors[Math.abs(hash) % colors.length];
|
|
136
|
-
}
|
package/dist/hooks/useUsers.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ChatUser, UserType } from '../types';
|
|
2
|
-
interface UseUsersOptions {
|
|
3
|
-
url: string;
|
|
4
|
-
filterType?: UserType;
|
|
5
|
-
enabled?: boolean;
|
|
6
|
-
}
|
|
7
|
-
interface UseUsersReturn {
|
|
8
|
-
users: ChatUser[];
|
|
9
|
-
loading: boolean;
|
|
10
|
-
error: string | null;
|
|
11
|
-
refetch: () => void;
|
|
12
|
-
}
|
|
13
|
-
export declare function useUsers({ url, filterType, enabled, }: UseUsersOptions): UseUsersReturn;
|
|
14
|
-
export {};
|
package/dist/hooks/useUsers.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect, useCallback } from 'react';
|
|
2
|
-
import { fetchUsers } from '../services/userService';
|
|
3
|
-
export function useUsers({ url, filterType, enabled = true, }) {
|
|
4
|
-
const [users, setUsers] = useState([]);
|
|
5
|
-
const [loading, setLoading] = useState(false);
|
|
6
|
-
const [error, setError] = useState(null);
|
|
7
|
-
const load = useCallback(async () => {
|
|
8
|
-
if (!enabled)
|
|
9
|
-
return;
|
|
10
|
-
setLoading(true);
|
|
11
|
-
setError(null);
|
|
12
|
-
try {
|
|
13
|
-
const data = await fetchUsers(url);
|
|
14
|
-
const filtered = filterType
|
|
15
|
-
? data.filter((u) => u.type === filterType)
|
|
16
|
-
: data;
|
|
17
|
-
setUsers(filtered);
|
|
18
|
-
}
|
|
19
|
-
catch (err) {
|
|
20
|
-
const message = err instanceof Error ? err.message : 'Unknown error occurred.';
|
|
21
|
-
setError(message);
|
|
22
|
-
setUsers([]);
|
|
23
|
-
}
|
|
24
|
-
finally {
|
|
25
|
-
setLoading(false);
|
|
26
|
-
}
|
|
27
|
-
}, [url, filterType, enabled]);
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
load();
|
|
30
|
-
}, [load]);
|
|
31
|
-
return { users, loading, error, refetch: load };
|
|
32
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export async function fetchUsers(url) {
|
|
2
|
-
const sameOriginPath = url.startsWith('/');
|
|
3
|
-
const response = await fetch(url, {
|
|
4
|
-
method: 'GET',
|
|
5
|
-
headers: {
|
|
6
|
-
'Content-Type': 'application/json',
|
|
7
|
-
},
|
|
8
|
-
credentials: sameOriginPath ? 'same-origin' : 'omit',
|
|
9
|
-
});
|
|
10
|
-
if (!response.ok) {
|
|
11
|
-
throw new Error(`[ChatWidget] Failed to fetch users: ${response.status} ${response.statusText}`);
|
|
12
|
-
}
|
|
13
|
-
const data = await response.json();
|
|
14
|
-
if (!Array.isArray(data)) {
|
|
15
|
-
throw new Error('[ChatWidget] User list API did not return an array.');
|
|
16
|
-
}
|
|
17
|
-
return data;
|
|
18
|
-
}
|