@axos-web-dev/shared-components 1.0.77-patch.39 → 1.0.77-patch.40

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.
Files changed (98) hide show
  1. package/dist/ATMLocator/ATMLocator.js +7 -1
  2. package/dist/Auth/ErrorAlert.js +7 -1
  3. package/dist/Avatar/Avatar.module.js +7 -7
  4. package/dist/Blockquote/Blockquote.module.js +3 -3
  5. package/dist/Button/Button.js +7 -1
  6. package/dist/Calculators/BuyDownCalculator/index.js +1 -1
  7. package/dist/Calculators/Calculator.js +8 -2
  8. package/dist/Carousel/index.js +7 -1
  9. package/dist/Chatbot/Bubble.css.d.ts +2 -0
  10. package/dist/Chatbot/Bubble.css.js +7 -0
  11. package/dist/Chatbot/Bubble.d.ts +5 -0
  12. package/dist/Chatbot/Bubble.js +103 -0
  13. package/dist/Chatbot/Chat.d.ts +1 -0
  14. package/dist/Chatbot/Chat.js +165 -0
  15. package/dist/Chatbot/ChatWindow.css.d.ts +18 -0
  16. package/dist/Chatbot/ChatWindow.css.js +39 -0
  17. package/dist/Chatbot/ChatWindow.d.ts +26 -0
  18. package/dist/Chatbot/ChatWindow.js +446 -0
  19. package/dist/Chatbot/Chatbot.css.d.ts +2 -0
  20. package/dist/Chatbot/Chatbot.css.js +7 -0
  21. package/dist/Chatbot/Chatbot.css.ts.vanilla.css.js +1 -0
  22. package/dist/Chatbot/Chatbot.d.ts +10 -0
  23. package/dist/Chatbot/Chatbot.js +222 -0
  24. package/dist/Chatbot/EllipsisAnimation.d.ts +2 -0
  25. package/dist/Chatbot/EllipsisAnimation.js +85 -0
  26. package/dist/Chatbot/EllipsisIcon.d.ts +4 -0
  27. package/dist/Chatbot/EllipsisIcon.js +19 -0
  28. package/dist/Chatbot/authenticate.d.ts +3 -0
  29. package/dist/Chatbot/authenticate.js +16 -0
  30. package/dist/Chatbot/index.d.ts +8 -0
  31. package/dist/Chatbot/index.js +38 -0
  32. package/dist/Chatbot/store/chat.d.ts +10 -0
  33. package/dist/Chatbot/store/chat.js +18 -0
  34. package/dist/Chatbot/store/messages.d.ts +15 -0
  35. package/dist/Chatbot/store/messages.js +13 -0
  36. package/dist/Chatbot/useHeadlessChat.d.ts +27 -0
  37. package/dist/Chatbot/useHeadlessChat.js +240 -0
  38. package/dist/Chevron/index.js +7 -1
  39. package/dist/Comparison/Comparison.js +7 -1
  40. package/dist/ExecutiveBio/ExecutiveBio.js +7 -1
  41. package/dist/FaqAccordion/index.js +7 -1
  42. package/dist/FooterSiteMap/AxosBank/FooterSiteMap.js +7 -1
  43. package/dist/Forms/ApplyNow.js +7 -1
  44. package/dist/Forms/ContactUsBusiness.js +7 -1
  45. package/dist/Forms/ContactUsBusinessNameEmail.js +7 -1
  46. package/dist/Forms/ContactUsNMLSId.js +7 -1
  47. package/dist/Forms/CraPublicFile.js +7 -1
  48. package/dist/Forms/EmailOnly.js +7 -1
  49. package/dist/Forms/MortgageRate/MortgageRateForm.js +7 -1
  50. package/dist/Forms/MortgageRate/MortgageRateWatch.js +7 -1
  51. package/dist/Forms/MortgageWarehouseLending.js +7 -1
  52. package/dist/Forms/SuccesForm.js +8 -2
  53. package/dist/Hyperlink/index.js +7 -1
  54. package/dist/ImageLink/ImageLink.js +7 -1
  55. package/dist/ImageLink/ImageLinkSet.js +7 -1
  56. package/dist/ImageLink/index.js +7 -1
  57. package/dist/Insight/Featured/CategorySelector.js +7 -1
  58. package/dist/Insight/Featured/Featured.js +7 -1
  59. package/dist/Insight/Featured/Header.js +7 -1
  60. package/dist/Modal/Modal.js +7 -1
  61. package/dist/NavigationMenu/AxosALTS/NavData.js +7 -1
  62. package/dist/NavigationMenu/AxosALTS/index.js +7 -1
  63. package/dist/NavigationMenu/AxosAdvisor/NavBar.module.js +52 -52
  64. package/dist/NavigationMenu/AxosAdvisorServices/NavBar.module.js +53 -53
  65. package/dist/NavigationMenu/AxosBank/MobileMenu/MobileMenu.module.js +16 -16
  66. package/dist/NavigationMenu/AxosBank/MobileMenu/MobileNavData.js +7 -1
  67. package/dist/NavigationMenu/AxosBank/NavBar.module.js +39 -39
  68. package/dist/NavigationMenu/AxosBank/NavData.js +7 -1
  69. package/dist/NavigationMenu/AxosBank/SubNavBar.js +7 -1
  70. package/dist/NavigationMenu/AxosBank/index.js +7 -1
  71. package/dist/NavigationMenu/AxosClearing/NavBar.module.js +37 -37
  72. package/dist/NavigationMenu/AxosFiduciary/NavBar.module.js +41 -41
  73. package/dist/NavigationMenu/LaVictoire/NavData.js +7 -1
  74. package/dist/NavigationMenu/LaVictoire/index.js +7 -1
  75. package/dist/SetContainer/SetContainer.js +7 -1
  76. package/dist/SocialMediaBar/iconsRepository.js +7 -1
  77. package/dist/Table/Table.d.ts +1 -1
  78. package/dist/VideoTile/VideoTile.js +7 -1
  79. package/dist/VideoWrapper/index.js +7 -1
  80. package/dist/WalnutIframe/wrapper.module.js +3 -3
  81. package/dist/assets/Avatar/Avatar.css.css +59 -59
  82. package/dist/assets/Blockquote/Blockquote.css.css +68 -68
  83. package/dist/assets/Chatbot/Bubble.css +51 -0
  84. package/dist/assets/Chatbot/ChatWindow.css +213 -0
  85. package/dist/assets/NavigationMenu/AxosAdvisor/NavBar.css.css +597 -597
  86. package/dist/assets/NavigationMenu/AxosAdvisorServices/NavBar.css.css +618 -618
  87. package/dist/assets/NavigationMenu/AxosBank/MobileMenu/MobileMenu.css.css +191 -191
  88. package/dist/assets/NavigationMenu/AxosBank/NavBar.css.css +473 -473
  89. package/dist/assets/NavigationMenu/AxosClearing/NavBar.css.css +458 -458
  90. package/dist/assets/NavigationMenu/AxosFiduciary/NavBar.css.css +426 -426
  91. package/dist/assets/WalnutIframe/wrapper.css.css +48 -48
  92. package/dist/main.d.ts +1 -0
  93. package/dist/main.js +35 -0
  94. package/package.json +135 -133
  95. package/dist/utils/emailValidation.d.ts +0 -1
  96. package/dist/utils/emailValidation.js +0 -31
  97. package/dist/utils/nmlsValidation.d.ts +0 -1
  98. package/dist/utils/nmlsValidation.js +0 -31
@@ -0,0 +1,446 @@
1
+ "use client";
2
+ import { jsxs, jsx, Fragment } from "react/jsx-runtime";
3
+ import clsx from "clsx";
4
+ import React, { useRef, useEffect, Fragment as Fragment$1 } from "react";
5
+ import ReactMarkdown from "react-markdown";
6
+ import { useNetworkState, useMount } from "react-use";
7
+ import remarkGfm from "remark-gfm";
8
+ import { windowBarStyle, chat_title, chatbotMenuItem, chatbotMenu, chatFinishDialog, endChatButtonStyle, button_reset, arrowFill, chatNetworkStatus, notificationStyle, messageStyle, inline_button_wrapper, inline_button, messagesContainerStyle, inputStyle, sendButtonStyle, windowStyle, windowOpenStyle } from "./ChatWindow.css.js";
9
+ import EllipsisLoader from "./EllipsisAnimation.js";
10
+ import { EllipsisIcon } from "./EllipsisIcon.js";
11
+ import { useOpenChat } from "./store/chat.js";
12
+ const ChatWindow = ({
13
+ messages,
14
+ status = "connected",
15
+ onSend,
16
+ inputDisabled = false,
17
+ onClose,
18
+ endChat = () => {
19
+ console.log("End chat");
20
+ },
21
+ showReconnect = false,
22
+ virtualAgent,
23
+ showAvatar = false
24
+ }) => {
25
+ const [mounted, setMounted] = React.useState(false);
26
+ const [menuOpen, setMenuOpen] = React.useState(false);
27
+ const [showEndChatDialog, setShowEndChatDialog] = React.useState(false);
28
+ const state = useNetworkState();
29
+ const [input, setInput] = React.useState("");
30
+ const messagesEndRef = useRef(null);
31
+ const isOpen = useOpenChat((state2) => state2.isOpen);
32
+ useEffect(() => {
33
+ messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
34
+ }, [messages]);
35
+ const handleSend = (e) => {
36
+ e.preventDefault();
37
+ if (input.trim()) {
38
+ onSend(input);
39
+ setInput("");
40
+ }
41
+ };
42
+ useMount(() => {
43
+ setMounted(true);
44
+ });
45
+ const project = process.env.CCAI_PROJECT_ID;
46
+ const isAxos = project === "axos";
47
+ const endUserBg = isAxos ? "#14263d" : "#323339";
48
+ const chatbotBg = isAxos ? "#E9F8FF" : "#EAE8E8";
49
+ const escalationDeflected = messages?.filter(
50
+ (item) => item.type == "noti" && item.event == "escalationDeflected"
51
+ ).length > 0;
52
+ return /* @__PURE__ */ jsxs("div", { className: clsx(windowStyle, isOpen && windowOpenStyle), children: [
53
+ /* @__PURE__ */ jsxs("div", { className: windowBarStyle, children: [
54
+ /* @__PURE__ */ jsxs("div", { className: "flex middle", style: { paddingBlock: "6px" }, children: [
55
+ /* @__PURE__ */ jsx(
56
+ "img",
57
+ {
58
+ src: "https://www.axos.com/images/2xmVfQm5l0HWOKjgxQO1Iw/axb-assistant.svg",
59
+ style: { marginRight: 12 },
60
+ height: 18,
61
+ width: 18
62
+ }
63
+ ),
64
+ /* @__PURE__ */ jsx("h2", { className: chat_title, children: "Evo Virtual Assistant" })
65
+ ] }),
66
+ /* @__PURE__ */ jsx(
67
+ "button",
68
+ {
69
+ onClick: () => {
70
+ setMenuOpen(!menuOpen);
71
+ },
72
+ style: {
73
+ border: "none",
74
+ background: "transparent",
75
+ marginLeft: "auto",
76
+ cursor: "pointer",
77
+ padding: 0,
78
+ display: "flex",
79
+ alignContent: "center"
80
+ },
81
+ children: /* @__PURE__ */ jsx(EllipsisIcon, { color: "#fff" })
82
+ }
83
+ ),
84
+ menuOpen && /* @__PURE__ */ jsx("ul", { className: clsx(chatbotMenu), children: /* @__PURE__ */ jsx("li", { className: chatbotMenuItem, children: /* @__PURE__ */ jsx(
85
+ "button",
86
+ {
87
+ type: "button",
88
+ onClick: () => {
89
+ setShowEndChatDialog(true);
90
+ setMenuOpen(false);
91
+ },
92
+ style: { width: "100%" },
93
+ children: "Finish chat"
94
+ }
95
+ ) }) }),
96
+ showEndChatDialog && /* @__PURE__ */ jsxs(Fragment, { children: [
97
+ /* @__PURE__ */ jsx(
98
+ "div",
99
+ {
100
+ style: {
101
+ background: "#00000080",
102
+ position: "fixed",
103
+ top: 0,
104
+ left: 0,
105
+ right: 0,
106
+ bottom: 0,
107
+ zIndex: 999,
108
+ opacity: 0.75
109
+ }
110
+ }
111
+ ),
112
+ /* @__PURE__ */ jsx(
113
+ "dialog",
114
+ {
115
+ open: showEndChatDialog,
116
+ style: {
117
+ padding: "1rem",
118
+ borderRadius: 8,
119
+ background: "#fff",
120
+ color: "#000",
121
+ border: `1px solid ${endUserBg}`,
122
+ outline: "none",
123
+ maxWidth: "90%",
124
+ top: "25%",
125
+ marginInline: "auto",
126
+ zIndex: 1e3
127
+ },
128
+ children: /* @__PURE__ */ jsxs("form", { method: "dialog", className: chatFinishDialog, children: [
129
+ /* @__PURE__ */ jsx("p", { children: "Are you sure you want to end this chat?" }),
130
+ /* @__PURE__ */ jsxs(
131
+ "div",
132
+ {
133
+ style: { display: "flex", gap: "1rem", marginTop: "1rem" },
134
+ children: [
135
+ /* @__PURE__ */ jsx(
136
+ "button",
137
+ {
138
+ className: endChatButtonStyle,
139
+ type: "submit",
140
+ onClick: () => {
141
+ endChat();
142
+ setShowEndChatDialog(false);
143
+ },
144
+ children: "Yes"
145
+ }
146
+ ),
147
+ /* @__PURE__ */ jsx(
148
+ "button",
149
+ {
150
+ className: endChatButtonStyle,
151
+ type: "button",
152
+ onClick: () => {
153
+ setShowEndChatDialog(false);
154
+ },
155
+ children: "No"
156
+ }
157
+ )
158
+ ]
159
+ }
160
+ )
161
+ ] })
162
+ }
163
+ )
164
+ ] }),
165
+ onClose && /* @__PURE__ */ jsx(
166
+ "button",
167
+ {
168
+ onClick: onClose,
169
+ className: button_reset,
170
+ "aria-label": "Close chat",
171
+ title: "Close",
172
+ children: /* @__PURE__ */ jsx(
173
+ "svg",
174
+ {
175
+ xmlns: "http://www.w3.org/2000/svg",
176
+ width: "24",
177
+ height: "24",
178
+ viewBox: "0 0 24 24",
179
+ fill: "none",
180
+ children: /* @__PURE__ */ jsx(
181
+ "path",
182
+ {
183
+ className: arrowFill,
184
+ d: "M2.46875 7.76574L11.9991 17.2961L21.5294 7.76574L20.4687 6.70508L11.9991 15.1749L3.52941 6.70508L2.46875 7.76574Z",
185
+ fill: "#98DDFF"
186
+ }
187
+ )
188
+ }
189
+ )
190
+ }
191
+ )
192
+ ] }),
193
+ mounted && !state.online ? /* @__PURE__ */ jsx("div", { className: clsx(chatNetworkStatus), children: /* @__PURE__ */ jsxs(
194
+ "div",
195
+ {
196
+ style: {
197
+ color: "#d32f2f",
198
+ textAlign: "center",
199
+ padding: "8px 0",
200
+ fontWeight: 500
201
+ },
202
+ children: [
203
+ /* @__PURE__ */ jsx(
204
+ "span",
205
+ {
206
+ role: "img",
207
+ "aria-label": "disconnected",
208
+ style: { marginRight: 6 },
209
+ children: "⚠️"
210
+ }
211
+ ),
212
+ "You are currently disconnected. Please check your connection."
213
+ ]
214
+ }
215
+ ) }) : null,
216
+ /* @__PURE__ */ jsxs("div", { className: clsx(messagesContainerStyle), children: [
217
+ (status === "idle" || messages.length == 0) && /* @__PURE__ */ jsx(
218
+ "div",
219
+ {
220
+ className: clsx(),
221
+ style: {
222
+ textAlign: "left",
223
+ alignSelf: "flex-start",
224
+ background: "#eee",
225
+ color: "#1e3860",
226
+ borderRadius: 16,
227
+ padding: "8px 8px",
228
+ maxWidth: "80%",
229
+ marginBottom: 2
230
+ },
231
+ children: /* @__PURE__ */ jsx(
232
+ "div",
233
+ {
234
+ style: {
235
+ fontSize: 13,
236
+ display: "flex",
237
+ flexDirection: "column",
238
+ gap: 4
239
+ },
240
+ children: /* @__PURE__ */ jsx(EllipsisLoader, {})
241
+ }
242
+ )
243
+ }
244
+ ),
245
+ messages?.map((msg) => /* @__PURE__ */ jsxs(Fragment$1, { children: [
246
+ msg.type == "noti" && msg.$userType == "system" && msg.event == "escalationStarted" && /* @__PURE__ */ jsx("div", { className: notificationStyle, children: "We are connecting you with a human agent..." }, msg.$index),
247
+ msg.type == "noti" && msg.$userType == "system" && msg.event == "memberLeft" && /* @__PURE__ */ jsxs("div", { className: notificationStyle, children: [
248
+ /* @__PURE__ */ jsx("strong", { children: "Virtual Agent" }),
249
+ " just left the conversation."
250
+ ] }, msg.$index),
251
+ msg.type == "noti" && msg.$userType == "system" && msg.event == "escalationAccepted" && /* @__PURE__ */ jsxs("div", { className: notificationStyle, children: [
252
+ "You are now connected with a",
253
+ " ",
254
+ msg.to_agent ? /* @__PURE__ */ jsx("strong", { children: msg?.to_agent?.name }) : "an agent"
255
+ ] }, msg.$index),
256
+ msg.type == "noti" && msg.$userType == "virtual_agent" && msg.event == "escalationDeflected" && /* @__PURE__ */ jsxs(Fragment, { children: [
257
+ /* @__PURE__ */ jsxs(
258
+ "div",
259
+ {
260
+ className: notificationStyle,
261
+ style: { fontSize: 12 },
262
+ children: [
263
+ "Our chat team is available weekdays, 8am-5pm, except federal bank holidays. For immediate assistance you can reach out to us at ",
264
+ /* @__PURE__ */ jsx("a", { href: "tel:1-888-502-2967", children: "1-888-502-2967" }),
265
+ "."
266
+ ]
267
+ },
268
+ msg.$index
269
+ ),
270
+ /* @__PURE__ */ jsx("div", { style: { textAlign: "center", marginBottom: 12 }, children: /* @__PURE__ */ jsx("button", { className: endChatButtonStyle, onClick: endChat, children: "End Chat" }) })
271
+ ] }),
272
+ ["text", "markdown_template", "markdown"].includes(msg.type) && /* @__PURE__ */ jsxs(
273
+ "div",
274
+ {
275
+ className: messageStyle,
276
+ style: {
277
+ textAlign: msg.$userType == "end_user" ? "right" : "left",
278
+ alignSelf: msg.$userType == "end_user" ? "flex-end" : "flex-start",
279
+ background: msg.$userType == "end_user" ? endUserBg : chatbotBg,
280
+ color: msg.$userType == "end_user" ? "#fff" : "#1F1F1F",
281
+ boxShadow: msg.$userType == "end_user" ? "0 1px 4px #b3e0ff55" : void 0
282
+ },
283
+ children: [
284
+ /* @__PURE__ */ jsxs(
285
+ "div",
286
+ {
287
+ style: {
288
+ fontSize: 13,
289
+ display: "flex",
290
+ flexDirection: "column",
291
+ gap: 4
292
+ },
293
+ children: [
294
+ msg.$userType == "virtual_agent" && /* @__PURE__ */ jsxs(
295
+ "div",
296
+ {
297
+ style: {
298
+ display: "flex",
299
+ // justifyContent: "center",
300
+ alignItems: "center",
301
+ gap: "8px"
302
+ },
303
+ children: [
304
+ showAvatar && /* @__PURE__ */ jsx(
305
+ "img",
306
+ {
307
+ width: 24,
308
+ height: 24,
309
+ src: virtualAgent?.avatar_url,
310
+ alt: "agent avatar"
311
+ }
312
+ ),
313
+ /* @__PURE__ */ jsx("strong", { children: virtualAgent?.name })
314
+ ]
315
+ }
316
+ ),
317
+ /* @__PURE__ */ jsx(
318
+ ReactMarkdown,
319
+ {
320
+ remarkPlugins: [[remarkGfm, { singleTilde: false }]],
321
+ components: {
322
+ p: ({ ...props }) => /* @__PURE__ */ jsx(
323
+ "p",
324
+ {
325
+ style: { margin: 0, fontSize: "inherit" },
326
+ title: new Date(msg.$timestamp).toLocaleString(),
327
+ ...props
328
+ }
329
+ )
330
+ },
331
+ children: msg.content
332
+ }
333
+ )
334
+ ]
335
+ }
336
+ ),
337
+ /* @__PURE__ */ jsx("div", { style: { fontSize: 10, color: "#888", marginTop: 2 } })
338
+ ]
339
+ },
340
+ msg.$index
341
+ ),
342
+ msg.type == "inline_button" && Array.isArray(msg.buttons) && msg.buttons.length > 0 && /* @__PURE__ */ jsx("div", { className: inline_button_wrapper, children: msg.buttons.length !== 0 && Array.isArray(msg.buttons) && msg.buttons.map((button, index) => {
343
+ const lastItem = msg.buttons && msg.buttons?.length - 1;
344
+ return /* @__PURE__ */ jsx(
345
+ "button",
346
+ {
347
+ className: inline_button,
348
+ style: {
349
+ borderRadius: "0px",
350
+ borderTopLeftRadius: [0].includes(index) ? 8 : 0,
351
+ borderTopRightRadius: [0].includes(index) ? 8 : 0,
352
+ borderBottomLeftRadius: [lastItem].includes(index) ? 8 : 0,
353
+ borderBottomRightRadius: [lastItem].includes(index) ? 8 : 0
354
+ },
355
+ onClick: () => {
356
+ onSend(button?.title);
357
+ },
358
+ children: button.title
359
+ },
360
+ index
361
+ );
362
+ }) }),
363
+ msg.event == "chatEnded" && /* @__PURE__ */ jsxs(Fragment, { children: [
364
+ /* @__PURE__ */ jsxs(
365
+ "div",
366
+ {
367
+ title: (/* @__PURE__ */ new Date()).toLocaleString(),
368
+ style: {
369
+ fontSize: 12,
370
+ color: "#888",
371
+ marginBottom: 4,
372
+ textAlign: "center"
373
+ },
374
+ children: [
375
+ "Thank you for chatting!",
376
+ /* @__PURE__ */ jsx("br", {}),
377
+ " This conversation has ended."
378
+ ]
379
+ }
380
+ ),
381
+ /* @__PURE__ */ jsx("div", { style: { textAlign: "center", marginBottom: 12 }, children: /* @__PURE__ */ jsx("button", { className: endChatButtonStyle, onClick: endChat, children: "End Chat" }) })
382
+ ] })
383
+ ] }, msg.$index)),
384
+ showReconnect && /* @__PURE__ */ jsx(
385
+ "button",
386
+ {
387
+ style: { margin: "12px auto", display: "block" },
388
+ onClick: () => {
389
+ },
390
+ children: "Reconnect Chat"
391
+ }
392
+ ),
393
+ /* @__PURE__ */ jsx("div", { ref: messagesEndRef })
394
+ ] }),
395
+ /* @__PURE__ */ jsxs(
396
+ "form",
397
+ {
398
+ onSubmit: handleSend,
399
+ style: {
400
+ borderTop: "1px solid #eee",
401
+ display: "flex",
402
+ gap: 8
403
+ },
404
+ children: [
405
+ /* @__PURE__ */ jsx(
406
+ "input",
407
+ {
408
+ type: "text",
409
+ value: input,
410
+ onChange: (e) => setInput(e.target.value),
411
+ placeholder: "Ask something...",
412
+ className: inputStyle,
413
+ autoFocus: true,
414
+ disabled: inputDisabled || status !== "connected" || messages.length == 0 || escalationDeflected
415
+ }
416
+ ),
417
+ /* @__PURE__ */ jsx(
418
+ "button",
419
+ {
420
+ className: clsx(sendButtonStyle, input.trim().length > 0 && "active"),
421
+ type: "submit",
422
+ title: "Send message",
423
+ disabled: inputDisabled || status !== "connected" || !input.trim() || messages.length == 0 || escalationDeflected,
424
+ children: /* @__PURE__ */ jsxs(
425
+ "svg",
426
+ {
427
+ xmlns: "http://www.w3.org/2000/svg",
428
+ id: "send-icon",
429
+ width: 24,
430
+ height: 24,
431
+ children: [
432
+ /* @__PURE__ */ jsx("path", { d: "M2.01 21L23 12 2.01 3 2 10l15 2-15 2z" }),
433
+ /* @__PURE__ */ jsx("path", { d: "M0 0h24v24H0z", fill: "none" })
434
+ ]
435
+ }
436
+ )
437
+ }
438
+ )
439
+ ]
440
+ }
441
+ )
442
+ ] });
443
+ };
444
+ export {
445
+ ChatWindow
446
+ };
@@ -0,0 +1,2 @@
1
+ export declare const chatbotAXB: string;
2
+ export declare const chatbotUFB: string;
@@ -0,0 +1,7 @@
1
+ import "./Chatbot.css.ts.vanilla.css.js";
2
+ var chatbotAXB = "_1hpv6vm0";
3
+ var chatbotUFB = "_1hpv6vm1";
4
+ export {
5
+ chatbotAXB,
6
+ chatbotUFB
7
+ };
@@ -0,0 +1,10 @@
1
+ export type ChatbotProps = {
2
+ project?: "axos" | "ufb";
3
+ debug?: boolean;
4
+ };
5
+ export declare const Chatbot: ({ project, projectEnv, menuOption, debug, }: {
6
+ project?: "axos" | "ufb";
7
+ projectEnv?: "dev" | "qa" | "uat" | "stg" | "prod";
8
+ menuOption?: "Support Virtual Agent" | string;
9
+ debug?: boolean;
10
+ }) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,222 @@
1
+ "use client";
2
+ import { jsxs, jsx } from "react/jsx-runtime";
3
+ import { authenticate } from "./authenticate.js";
4
+ import { Bubble } from "./Bubble.js";
5
+ import { chatbotUFB, chatbotAXB } from "./Chatbot.css.js";
6
+ import { ChatWindow } from "./ChatWindow.js";
7
+ import { useOpenChat } from "./store/chat.js";
8
+ import { useMessages } from "./store/messages.js";
9
+ import { useRef, useState } from "react";
10
+ import { useMount, useUnmount } from "react-use";
11
+ const Chatbot = ({
12
+ project = "axos",
13
+ projectEnv = "dev",
14
+ menuOption = "Support Virtual Agent",
15
+ debug = false
16
+ }) => {
17
+ const { hasOpenedOnce, toggle, reset } = useOpenChat();
18
+ const { addMessage, addMessages, clearMessages, messages } = useMessages();
19
+ const clientRef = useRef(null);
20
+ const menuRef = useRef(null);
21
+ const isMountedRef = useRef(false);
22
+ const hasLoadedBefore = useRef(true);
23
+ const chatRef = useRef(null);
24
+ const agent_virtual = useRef(null);
25
+ const [status, setStatus] = useState("idle");
26
+ const [hasStarted, setHasStarted] = useState(false);
27
+ const brandMap = /* @__PURE__ */ new Map([
28
+ ["axos", 1],
29
+ ["ufb", 3]
30
+ ]);
31
+ const custom_data = {
32
+ unsigned: {
33
+ facingBrandId: {
34
+ label: "facingBrandId",
35
+ value: `${brandMap.get(project) || 1}`
36
+ },
37
+ channel: {
38
+ label: "channel",
39
+ value: "in_web"
40
+ },
41
+ user_auth: {
42
+ label: "user_auth",
43
+ value: "false"
44
+ },
45
+ env: {
46
+ label: "env",
47
+ value: projectEnv === "dev" ? "uat" : projectEnv
48
+ }
49
+ }
50
+ };
51
+ const onReadyHandler = async () => {
52
+ console.log("Chat client is ready");
53
+ };
54
+ const onAuthenticatedHandler = async () => {
55
+ console.log("Chat client is authenticated");
56
+ };
57
+ const onChatOngoingHandler = async (chat) => {
58
+ console.log("Ongoing chat:", chat);
59
+ };
60
+ const onChatMessageHandler = async (message) => {
61
+ console.log("Received message:", message);
62
+ addMessage(message);
63
+ };
64
+ const onChatTypingStartedHandler = async (identity) => {
65
+ console.log("Typing started by:", identity);
66
+ };
67
+ const onChatDisconnectedHandler = async () => {
68
+ console.log("Chat disconnected");
69
+ setStatus("idle");
70
+ };
71
+ const onDismissedHandler = async () => {
72
+ console.log("Chat dismissed");
73
+ };
74
+ const onTimeoutHandler = async () => {
75
+ console.log("Chat timeout");
76
+ };
77
+ const onEndedHandler = async () => {
78
+ console.log("Chat ended");
79
+ setStatus("finished");
80
+ };
81
+ const onDestroyedHandler = async () => {
82
+ console.log("Chat destroyed");
83
+ };
84
+ const onChatMemberLeftHandler = async (identity) => {
85
+ console.log("Chat member left:", identity);
86
+ };
87
+ const onChatConnectedHandler = async () => {
88
+ setStatus("connected");
89
+ console.log("connected");
90
+ const messages2 = await clientRef.current?.fetchMessages();
91
+ if (messages2) {
92
+ addMessages(messages2);
93
+ }
94
+ };
95
+ const registerEventHandlers = () => {
96
+ clientRef.current?.on("ready", onReadyHandler);
97
+ clientRef.current?.on("authenticated", onAuthenticatedHandler);
98
+ clientRef.current?.on("chat.ongoing", onChatOngoingHandler);
99
+ clientRef.current?.on("chat.message", onChatMessageHandler);
100
+ clientRef.current?.on("chat.typingStarted", onChatTypingStartedHandler);
101
+ clientRef.current?.on("chat.disconnected", onChatDisconnectedHandler);
102
+ clientRef.current?.on("chat.dismissed", onDismissedHandler);
103
+ clientRef.current?.on("chat.timeout", onTimeoutHandler);
104
+ clientRef.current?.on("chat.ended", onEndedHandler);
105
+ clientRef.current?.on("chat.destroyed", onDestroyedHandler);
106
+ clientRef.current?.on("chat.memberLeft", onChatMemberLeftHandler);
107
+ clientRef?.current?.on("chat.connected", onChatConnectedHandler);
108
+ };
109
+ const deregisterEventHandlers = () => {
110
+ clientRef.current?.off("ready", onReadyHandler);
111
+ clientRef.current?.off("authenticated", onAuthenticatedHandler);
112
+ clientRef.current?.off("chat.ongoing", onDismissedHandler);
113
+ clientRef.current?.off("chat.message", onChatMessageHandler);
114
+ clientRef.current?.off("chat.typingStarted", onChatTypingStartedHandler);
115
+ clientRef.current?.off("chat.disconnected", onChatDisconnectedHandler);
116
+ clientRef.current?.off("chat.dismissed", onDismissedHandler);
117
+ clientRef.current?.off("chat.timeout", onTimeoutHandler);
118
+ clientRef.current?.off("chat.ended", onEndedHandler);
119
+ clientRef.current?.off("chat.destroyed", onDestroyedHandler);
120
+ clientRef.current?.off("chat.memberLeft", onChatMemberLeftHandler);
121
+ clientRef.current?.off("chat.connected", onChatConnectedHandler);
122
+ };
123
+ const createClient = async () => {
124
+ const { Client, Logger, consoleLoggerHandler } = await import("@ujet/websdk-headless");
125
+ if (projectEnv !== "prod" || debug) {
126
+ Logger.addHandler(consoleLoggerHandler);
127
+ }
128
+ if (clientRef.current) return;
129
+ const client = new Client({
130
+ companyId: process.env.CCAI_COMPANY_ID || "",
131
+ tenant: process.env.CCAI_TENANT_NAME || "",
132
+ host: process.env.CCAI_HOST || "",
133
+ // or your region
134
+ authenticate
135
+ });
136
+ isMountedRef.current = true;
137
+ clientRef.current = client;
138
+ menuRef.current = await client.getMenus();
139
+ console.log("menus:", menuRef.current);
140
+ registerEventHandlers();
141
+ return;
142
+ };
143
+ const startChat = async () => {
144
+ console.log("Starting chat");
145
+ const client = clientRef.current;
146
+ if (!client) return;
147
+ try {
148
+ const ongoingChat = await client.loadOngoingChat();
149
+ if (ongoingChat) {
150
+ console.log("Ongoing chat found:", ongoingChat);
151
+ console.log("Resuming chat:", ongoingChat.id);
152
+ chatRef.current = await client.resumeChat(ongoingChat.id);
153
+ agent_virtual.current = ongoingChat.agent;
154
+ return;
155
+ }
156
+ const foundMenu = menuRef.current.menus.find(
157
+ (menu) => menu.name === menuOption
158
+ );
159
+ const menuId = foundMenu && foundMenu.id;
160
+ console.log("Creating new chat with menu ID:", menuId);
161
+ const newChat = await client.createChat(menuId, { custom_data });
162
+ if (newChat !== null) {
163
+ chatRef.current = newChat;
164
+ console.log("Chat created id:", newChat.id);
165
+ }
166
+ } catch (err) {
167
+ console.error("Error creating chat:", err);
168
+ }
169
+ };
170
+ const handleClick = async () => {
171
+ toggle();
172
+ if (hasStarted) return;
173
+ if (!hasOpenedOnce) {
174
+ await startChat();
175
+ setHasStarted(true);
176
+ }
177
+ };
178
+ const onSendMessage = (msg) => {
179
+ console.log("Sending message:", msg);
180
+ clientRef.current?.sendTextMessage(msg);
181
+ };
182
+ const onEndChat = async () => {
183
+ console.log("Ending chat");
184
+ if (chatRef.current) {
185
+ await clientRef.current?.finishChat();
186
+ await chatRef.current.destroy();
187
+ clearMessages();
188
+ chatRef.current = null;
189
+ console.log("Chat ended");
190
+ setHasStarted(false);
191
+ reset();
192
+ }
193
+ };
194
+ useMount(async () => {
195
+ console.log("Chatbot mounted");
196
+ if (isMountedRef.current) return;
197
+ isMountedRef.current = true;
198
+ await createClient();
199
+ });
200
+ useUnmount(() => {
201
+ console.log("Chatbot unmounted");
202
+ deregisterEventHandlers();
203
+ isMountedRef.current = false;
204
+ hasLoadedBefore.current = true;
205
+ });
206
+ return /* @__PURE__ */ jsxs("div", { className: project === "ufb" ? chatbotUFB : chatbotAXB, children: [
207
+ /* @__PURE__ */ jsx(Bubble, { onClick: handleClick }),
208
+ /* @__PURE__ */ jsx(
209
+ ChatWindow,
210
+ {
211
+ status,
212
+ virtualAgent: agent_virtual.current,
213
+ messages,
214
+ onSend: onSendMessage,
215
+ endChat: onEndChat
216
+ }
217
+ )
218
+ ] });
219
+ };
220
+ export {
221
+ Chatbot
222
+ };