@axos-web-dev/shared-components 2.0.0-dev.3-evo-ui.2 → 2.0.0-dev.30-toasts

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 (201) hide show
  1. package/dist/ATMLocator/ATMLocator.js +7 -5
  2. package/dist/Accordion/Accordion.js +3 -3
  3. package/dist/AlertBanner/index.js +1 -1
  4. package/dist/Article/Article.js +1 -1
  5. package/dist/Auth/ErrorAlert.js +8 -6
  6. package/dist/Button/Button.js +26 -6
  7. package/dist/Calculators/AnnualFeeCalculator/index.js +2 -2
  8. package/dist/Calculators/ApyCalculator/ApyCalculator.css.d.ts +46 -5
  9. package/dist/Calculators/ApyCalculator/ApyCalculator.css.js +72 -19
  10. package/dist/Calculators/ApyCalculator/index.js +583 -293
  11. package/dist/Calculators/ApyCalculatorUserTest/ApyCalculatorUserTest.css.d.ts +95 -0
  12. package/dist/Calculators/ApyCalculatorUserTest/ApyCalculatorUserTest.css.js +101 -0
  13. package/dist/Calculators/ApyCalculatorUserTest/index.d.ts +12 -0
  14. package/dist/Calculators/ApyCalculatorUserTest/index.js +618 -0
  15. package/dist/Calculators/AxosOneCalculator/BalanceAPYCalculator.css.js +2 -1
  16. package/dist/Calculators/BuyDownCalculator/index.js +1 -1
  17. package/dist/Calculators/Calculator.js +19 -7
  18. package/dist/Calculators/MarginTradingCalculator/index.js +8 -6
  19. package/dist/Calculators/MarineLoanMonthlyPaymentCalculator/index.js +2 -2
  20. package/dist/Calculators/MaxLoanCalculator/index.js +2 -2
  21. package/dist/Calculators/MonthlyPaymentCalculator/index.js +2 -2
  22. package/dist/Calculators/MonthlyPaymentLVFCalculator/index.js +1 -1
  23. package/dist/Calculators/calculator.css.d.ts +21 -1
  24. package/dist/Calculators/calculator.css.js +3 -3
  25. package/dist/Calculators/index.d.ts +1 -0
  26. package/dist/Calculators/index.js +2 -0
  27. package/dist/Carousel/index.js +9 -7
  28. package/dist/Chatbot/AnimatedGradientBorder.css.d.ts +5 -0
  29. package/dist/Chatbot/AnimatedGradientBorder.css.js +13 -3
  30. package/dist/Chatbot/AudioManager.d.ts +19 -0
  31. package/dist/Chatbot/AudioManager.js +61 -0
  32. package/dist/Chatbot/Bubble.css.js +1 -0
  33. package/dist/Chatbot/Bubble.d.ts +1 -0
  34. package/dist/Chatbot/Bubble.js +3 -12
  35. package/dist/Chatbot/Chat.js +17 -7
  36. package/dist/Chatbot/ChatWindow.css.d.ts +8 -0
  37. package/dist/Chatbot/ChatWindow.css.js +49 -33
  38. package/dist/Chatbot/ChatWindow.js +459 -366
  39. package/dist/Chatbot/Chatbot.css.js +0 -1
  40. package/dist/Chatbot/Chatbot.css.ts.vanilla.css.js +1 -0
  41. package/dist/Chatbot/Chatbot.d.ts +13 -2
  42. package/dist/Chatbot/Chatbot.js +200 -84
  43. package/dist/Chatbot/ChatbotMessage.d.ts +1 -0
  44. package/dist/Chatbot/ChatbotMessage.js +189 -160
  45. package/dist/Chatbot/EllipsisAnimation.js +0 -6
  46. package/dist/Chatbot/ExpandChatToggle.d.ts +8 -0
  47. package/dist/Chatbot/ExpandChatToggle.js +74 -0
  48. package/dist/Chatbot/index.js +11 -2
  49. package/dist/Chatbot/store/chat.d.ts +8 -0
  50. package/dist/Chatbot/store/chat.js +14 -2
  51. package/dist/Chatbot/useHeadlessChat.js +1 -2
  52. package/dist/Chevron/index.js +10 -5
  53. package/dist/Comparison/Comparison.css.js +3 -2
  54. package/dist/Comparison/Comparison.js +7 -5
  55. package/dist/ContentBanner/index.js +1 -1
  56. package/dist/ExecutiveBio/ExecutiveBio.js +115 -106
  57. package/dist/ExecutiveBio/ExecutiveBioSet.js +1 -1
  58. package/dist/FaqAccordion/index.js +8 -6
  59. package/dist/FooterDisclosure/FooterDisclosure.js +1 -1
  60. package/dist/FooterSiteMap/AxosBank/FooterSiteMap.js +26 -6
  61. package/dist/Forms/ApplyNow.js +8 -6
  62. package/dist/Forms/BoatMooringLocation.d.ts +6 -1
  63. package/dist/Forms/BoatMooringLocation.js +145 -8
  64. package/dist/Forms/ContactUsBusiness.js +9 -7
  65. package/dist/Forms/ContactUsBusinessNameEmail.js +9 -7
  66. package/dist/Forms/ContactUsNMLSId.js +9 -7
  67. package/dist/Forms/ContactUsSchwabAAS.d.ts +11 -0
  68. package/dist/Forms/ContactUsSchwabAAS.js +263 -0
  69. package/dist/Forms/CpraRequest.js +8 -6
  70. package/dist/Forms/CraPublicFile.js +9 -7
  71. package/dist/Forms/EmailOnly.js +10 -8
  72. package/dist/Forms/FormEnums.js +2 -2
  73. package/dist/Forms/MortgageRate/MortgageRateForm.js +9 -7
  74. package/dist/Forms/MortgageRate/MortgageRateWatch.js +8 -6
  75. package/dist/Forms/MortgageWarehouseLending.d.ts +1 -1
  76. package/dist/Forms/MortgageWarehouseLending.js +16 -14
  77. package/dist/Forms/SuccesForm.js +9 -7
  78. package/dist/Forms/index.d.ts +1 -0
  79. package/dist/Forms/index.js +2 -0
  80. package/dist/HeroBanner/HeroBanner.css.d.ts +1 -0
  81. package/dist/HeroBanner/HeroBanner.css.js +19 -16
  82. package/dist/HeroBanner/HeroBanner.d.ts +1 -1
  83. package/dist/HeroBanner/HeroBanner.interface.d.ts +6 -1
  84. package/dist/HeroBanner/HeroBanner.js +54 -183
  85. package/dist/HeroBanner/HeroVideoPoster.d.ts +5 -0
  86. package/dist/HeroBanner/HeroVideoPoster.js +24 -0
  87. package/dist/HeroBanner/LargeBanner.css.d.ts +110 -0
  88. package/dist/HeroBanner/LargeBanner.css.js +22 -8
  89. package/dist/HeroBanner/LargeHeroBanner.d.ts +5 -0
  90. package/dist/HeroBanner/LargeHeroBanner.js +228 -0
  91. package/dist/HeroBanner/index.js +3 -2
  92. package/dist/Hyperlink/index.js +9 -7
  93. package/dist/IconBillboard/IconBillboard.css.js +2 -1
  94. package/dist/IconBillboard/IconBillboard.interface.d.ts +2 -0
  95. package/dist/IconBillboard/IconBillboardSet.js +1 -1
  96. package/dist/IconBillboard/sections/CallToActionSection.js +3 -1
  97. package/dist/ImageBillboard/ImageBillboard.interface.d.ts +2 -0
  98. package/dist/ImageBillboard/ImageBillboard.js +1 -1
  99. package/dist/ImageBillboard/ImageBillboardSet.d.ts +1 -1
  100. package/dist/ImageBillboard/ImageBillboardSet.js +28 -20
  101. package/dist/ImageLink/ImageLink.js +7 -5
  102. package/dist/ImageLink/ImageLinkSet.js +6 -4
  103. package/dist/ImageLink/index.js +8 -6
  104. package/dist/ImageToast/ImageToast.css.d.ts +5 -0
  105. package/dist/ImageToast/ImageToast.css.js +13 -0
  106. package/dist/ImageToast/index.d.ts +9 -0
  107. package/dist/ImageToast/index.js +188 -0
  108. package/dist/Input/Checkbox.js +2 -2
  109. package/dist/Input/DownPaymentInput.js +1 -1
  110. package/dist/Input/Dropdown.js +1 -1
  111. package/dist/Input/Input.js +1 -1
  112. package/dist/Input/InputTextArea.js +1 -1
  113. package/dist/Insight/Featured/CategorySelector.js +8 -6
  114. package/dist/Insight/Featured/Featured.js +10 -8
  115. package/dist/Insight/Featured/Header.js +8 -6
  116. package/dist/LandingPageHeader/LandingPageHeader.js +1 -1
  117. package/dist/Modal/Modal.js +8 -6
  118. package/dist/Modal/contextApi/store.d.ts +0 -3
  119. package/dist/Modal/contextApi/store.js +88 -2
  120. package/dist/NavigationMenu/AxosALTS/index.js +7 -5
  121. package/dist/NavigationMenu/AxosAdvisorServices/index.js +0 -1
  122. package/dist/NavigationMenu/AxosBank/MobileMenu/MobileMenu.js +7 -5
  123. package/dist/NavigationMenu/AxosBank/MobileMenu/MobileMenu.module.js +27 -27
  124. package/dist/NavigationMenu/AxosBank/MobileMenu/MobileNavData.d.ts +13 -8
  125. package/dist/NavigationMenu/AxosBank/MobileMenu/MobileNavData.js +30 -25
  126. package/dist/NavigationMenu/AxosBank/NavBar.module.js +39 -39
  127. package/dist/NavigationMenu/AxosBank/SubNavBar.js +78 -41
  128. package/dist/NavigationMenu/AxosBank/index.js +50 -32
  129. package/dist/NavigationMenu/AxosFiduciary/NavBar.module.js +40 -43
  130. package/dist/NavigationMenu/AxosFiduciary/index.js +0 -1
  131. package/dist/NavigationMenu/LaVictoire/index.js +8 -6
  132. package/dist/NavigationMenu/Navbar.js +9 -7
  133. package/dist/NavigationMenu/SignInNavButton.js +10 -8
  134. package/dist/PageNavItem/PageNavItem.js +1 -1
  135. package/dist/SetContainer/SetContainer.css.d.ts +1 -0
  136. package/dist/SetContainer/SetContainer.css.js +5 -3
  137. package/dist/SetContainer/SetContainer.js +15 -7
  138. package/dist/SetContainer/index.js +2 -1
  139. package/dist/SocialMediaBar/iconsRepository.js +8 -6
  140. package/dist/StepItem/StepItem.js +1 -1
  141. package/dist/StepItemSet/StepItemSet.js +1 -1
  142. package/dist/Table/Table.css.d.ts +14 -1
  143. package/dist/Table/Table.css.js +21 -19
  144. package/dist/Table/Table.d.ts +1 -1
  145. package/dist/Table/Table.js +5 -3
  146. package/dist/Topic/Topic.js +1 -1
  147. package/dist/TopicalNavItem/TopicalNavItem.css.d.ts +0 -1
  148. package/dist/TopicalNavItem/TopicalNavItem.css.js +2 -4
  149. package/dist/TopicalNavItem/TopicalNavItem.js +11 -33
  150. package/dist/TopicalNavItem/index.js +1 -2
  151. package/dist/VideoTile/VideoTile.js +7 -5
  152. package/dist/VideoWrapper/index.js +8 -6
  153. package/dist/assets/Calculators/ApyCalculator/ApyCalculator.css +350 -64
  154. package/dist/assets/Calculators/ApyCalculatorUserTest/ApyCalculatorUserTest.css +424 -0
  155. package/dist/assets/Calculators/AxosOneCalculator/BalanceAPYCalculator.css +2 -2
  156. package/dist/assets/Calculators/calculator.css +25 -15
  157. package/dist/assets/Chatbot/AnimatedGradientBorder.css +104 -24
  158. package/dist/assets/Chatbot/Bubble.css +25 -7
  159. package/dist/assets/Chatbot/ChatWindow.css +181 -88
  160. package/dist/assets/Comparison/Comparison.css +2 -2
  161. package/dist/assets/DownloadTile/DownloadTile.css +7 -0
  162. package/dist/assets/ExecutiveBio/ExecutiveBio.css +38 -14
  163. package/dist/assets/HeroBanner/HeroBanner.css +83 -65
  164. package/dist/assets/HeroBanner/LargeBanner.css +126 -59
  165. package/dist/assets/IconBillboard/IconBillboard.css +33 -0
  166. package/dist/assets/ImageBillboard/ImageBillboard.css +1 -1
  167. package/dist/assets/ImageToast/ImageToast.css +33 -0
  168. package/dist/assets/NavigationMenu/AxosBank/MobileMenu/MobileMenu.css +49 -49
  169. package/dist/assets/NavigationMenu/AxosBank/NavBar.css +88 -88
  170. package/dist/assets/NavigationMenu/AxosFiduciary/NavBar.css +82 -82
  171. package/dist/assets/SetContainer/SetContainer.css +25 -15
  172. package/dist/assets/Table/Table.css +85 -76
  173. package/dist/assets/TextBlock/TextBlock.css +7 -0
  174. package/dist/assets/TopicalNavItem/TopicalNavItem.css +25 -52
  175. package/dist/assets/TopicalNavSet/TopicalNavSet.css +29 -4
  176. package/dist/assets/VideoTile/VideoTile.css +6 -0
  177. package/dist/assets/globals.css +9 -9
  178. package/dist/assets/notification.mp3.js +4 -0
  179. package/dist/assets/themes/axos.css +8 -7
  180. package/dist/assets/themes/premier.css +9 -8
  181. package/dist/assets/themes/ufb.css +9 -8
  182. package/dist/assets/themes/victorie.css +9 -8
  183. package/dist/main.js +24 -8
  184. package/dist/themes/axos.css.d.ts +1 -0
  185. package/dist/themes/axos.css.js +1 -1
  186. package/dist/utils/allowedAxosDomains.js +2 -1
  187. package/dist/utils/appendQueryParams.d.ts +3 -1
  188. package/dist/utils/appendQueryParams.js +66 -66
  189. package/dist/utils/getPosition.d.ts +1 -0
  190. package/dist/utils/getPosition.js +17 -0
  191. package/dist/utils/index.js +3 -1
  192. package/dist/utils/tealiumOrganicFallback.d.ts +21 -0
  193. package/dist/utils/tealiumOrganicFallback.js +26 -0
  194. package/dist/utils/useVisibility.d.ts +1 -0
  195. package/dist/utils/useVisibility.js +18 -0
  196. package/dist/utils/variant.types.d.ts +1 -0
  197. package/dist/vite-env.d.js +1 -0
  198. package/package.json +3 -3
  199. package/dist/Chatbot/authenticate.d.ts +0 -3
  200. package/dist/Chatbot/authenticate.js +0 -16
  201. package/dist/assets/Chatbot/Chatbot.css +0 -3
@@ -1,4 +1,3 @@
1
- import '../assets/Chatbot/Chatbot.css';/* empty css */
2
1
  var chatbotAXB = "_1hpv6vm0";
3
2
  var chatbotUFB = "_1hpv6vm1";
4
3
  export {
@@ -1,10 +1,21 @@
1
+ import { default as AudioManager } from './AudioManager';
2
+
3
+ export declare const audioManager: AudioManager;
1
4
  export type ChatbotProps = {
2
5
  project?: "axos" | "ufb";
3
6
  debug?: boolean;
4
7
  };
5
- export declare const Chatbot: ({ project, projectEnv, menuOption, debug, }: {
6
- project?: "axos" | "ufb";
8
+ type InitalizeChatbot = {
9
+ companyId: string;
10
+ tenantName: string;
11
+ host: string;
12
+ authUrl: string;
13
+ };
14
+ export declare const Chatbot: ({ project, projectEnv, menuOption, config, }: {
15
+ project?: "axos" | "ufb" | "Axos" | "Ufb";
7
16
  projectEnv?: "dev" | "qa" | "uat" | "stg" | "prod";
8
17
  menuOption?: "Support Virtual Agent" | string;
9
18
  debug?: boolean;
19
+ config: InitalizeChatbot;
10
20
  }) => false | import("react/jsx-runtime").JSX.Element;
21
+ export {};
@@ -1,20 +1,29 @@
1
1
  "use client";
2
2
  import { jsxs, jsx } from "react/jsx-runtime";
3
- import { authenticate } from "./authenticate.js";
3
+ import { usePageVisibility } from "../utils/useVisibility.js";
4
+ import { useRef, useState, useEffect } from "react";
5
+ import { useMount, useUnmount } from "react-use";
6
+ import notificationSound from "../assets/notification.mp3.js";
7
+ import AudioManager from "./AudioManager.js";
4
8
  import { Bubble } from "./Bubble.js";
5
- import { chatbotUFB, chatbotAXB } from "./Chatbot.css.js";
9
+ import { chatbotAXB, chatbotUFB } from "./Chatbot.css.js";
6
10
  import { ChatWindow } from "./ChatWindow.js";
7
11
  import { useOpenChat } from "./store/chat.js";
8
12
  import { useMessages } from "./store/messages.js";
9
- import { useRef, useState, useEffect } from "react";
10
- import { useMount, useUnmount } from "react-use";
13
+ const audioManager = new AudioManager();
14
+ audioManager.installUjetAudioOverride(notificationSound);
15
+ audioManager.setSoundEnabled(false);
16
+ function isChat(obj) {
17
+ return obj !== null && typeof obj === "object" && "id" in obj && "agent" in obj && typeof obj.connect === "function";
18
+ }
11
19
  const Chatbot = ({
12
20
  project = "axos",
13
21
  projectEnv = "dev",
14
22
  menuOption = "Support Virtual Agent",
15
- debug = false
23
+ config
16
24
  }) => {
17
25
  const {
26
+ isOpen,
18
27
  hasOpenedOnce,
19
28
  toggle,
20
29
  reset,
@@ -22,19 +31,24 @@ const Chatbot = ({
22
31
  hasEscalated,
23
32
  endEscalation,
24
33
  unblockInput,
25
- blockInput
34
+ blockInput,
35
+ hasStarted,
36
+ setChatStarted,
37
+ resetChatStarted,
38
+ setChatStatus,
39
+ displayThankyouMessage,
40
+ hideDisplayThankyouMessage
26
41
  } = useOpenChat();
42
+ const isVisible = usePageVisibility();
27
43
  const { addMessage, addMessages, clearMessages, messages } = useMessages();
28
44
  const clientRef = useRef(null);
29
45
  const menuRef = useRef(null);
30
46
  const isMountedRef = useRef(false);
31
- const hasLoadedBefore = useRef(true);
32
47
  const chatRef = useRef(null);
48
+ const chatLoading = useRef(false);
33
49
  const agent_virtual = useRef(null);
34
50
  const [status, setStatus] = useState("idle");
35
- const [hasStarted, setHasStarted] = useState(false);
36
51
  const [menusLoaded, setMenusLoaded] = useState(false);
37
- const [pendingStart, setPendingStart] = useState(false);
38
52
  const [isTyping, setIsTyping] = useState(false);
39
53
  const [scalationStarted, setScalationStarted] = useState(false);
40
54
  useEffect(() => {
@@ -63,7 +77,7 @@ const Chatbot = ({
63
77
  $index: -10,
64
78
  $userId: 0
65
79
  };
66
- const custom_data = {
80
+ const custom_data = () => ({
67
81
  unsigned: {
68
82
  facingBrandId: {
69
83
  label: "facingBrandId",
@@ -80,15 +94,22 @@ const Chatbot = ({
80
94
  env: {
81
95
  label: "env",
82
96
  value: projectEnv === "uat" ? "dev" : projectEnv
97
+ },
98
+ url: {
99
+ label: "url",
100
+ value: window.location.href
83
101
  }
84
102
  }
85
- };
103
+ });
86
104
  const onReadyHandler = async () => {
87
105
  console.log("Chat client is ready");
88
106
  if (clientRef.current) {
89
107
  menuRef.current = await clientRef.current.getMenus();
90
108
  setMenusLoaded(true);
91
109
  console.log("menus:", menuRef.current);
110
+ if (menuRef.current !== null) {
111
+ await startChat("onReady");
112
+ }
92
113
  }
93
114
  };
94
115
  const onAuthenticatedHandler = async () => {
@@ -219,20 +240,24 @@ const Chatbot = ({
219
240
  clientRef.current?.off("chat.connected", onChatConnectedHandler);
220
241
  };
221
242
  const createClient = async () => {
222
- const { Client, Logger, consoleLoggerHandler } = await import("@ujet/websdk-headless");
223
- if (projectEnv !== "prod" || debug) {
224
- Logger.addHandler(consoleLoggerHandler);
225
- }
243
+ const { Client } = await import("@ujet/websdk-headless");
226
244
  if (clientRef.current) return;
227
245
  const client = new Client({
228
- companyId: process.env.CCAI_COMPANY_ID || "",
229
- tenant: process.env.CCAI_TENANT_NAME || "",
230
- host: process.env.CCAI_HOST || "",
231
- // or your region
232
- // companyId: import.meta.env.VITE_COMPANY_ID || "",
233
- // tenant: import.meta.env.VITE_TENANT_NAME || "",
234
- // host: import.meta.env.VITE_HOST || "", // or your region
235
- authenticate
246
+ companyId: config.companyId,
247
+ tenant: config.tenantName,
248
+ host: config.host,
249
+ authenticate: async () => {
250
+ const res = await fetch(config.authUrl, {
251
+ method: "GET",
252
+ headers: {
253
+ "Content-Type": "application/json"
254
+ }
255
+ });
256
+ const data = await res.json();
257
+ return {
258
+ token: data.token
259
+ };
260
+ }
236
261
  });
237
262
  client?.on("ready", onReadyHandler);
238
263
  client?.on("authenticated", onAuthenticatedHandler);
@@ -241,59 +266,91 @@ const Chatbot = ({
241
266
  registerEventHandlers();
242
267
  return;
243
268
  };
244
- const startChat = async () => {
245
- console.log("Starting chat");
269
+ const startChat = async (source) => {
246
270
  const client = clientRef.current;
247
- if (!client) return;
248
- if (!menuRef.current || !menuRef.current.menus) {
249
- let waited = 0;
250
- while ((!menuRef.current || !menuRef.current.menus) && waited < 5e3) {
251
- await new Promise((res) => setTimeout(res, 100));
252
- waited += 100;
253
- }
254
- if (!menuRef.current || !menuRef.current.menus) {
255
- console.error("Menu not loaded, cannot start chat");
256
- return;
257
- }
271
+ if (!client) {
272
+ console.log(`no client detected`);
273
+ return;
274
+ }
275
+ if (hasStarted) {
276
+ console.log(`has started is ${hasStarted}`);
277
+ return;
278
+ }
279
+ hideDisplayThankyouMessage();
280
+ if (chatLoading.current) {
281
+ console.log(`startChat skipped [${source}] — already in progress`);
282
+ return;
258
283
  }
284
+ setChatStatus("connected");
259
285
  try {
286
+ console.log(`Starting chat [${source}]`, chatRef.current);
287
+ chatLoading.current = true;
288
+ if (!menuRef.current || !menuRef.current.menus) {
289
+ let waited = 0;
290
+ while ((!menuRef.current || !menuRef.current.menus) && waited < 5e3) {
291
+ await new Promise((res) => setTimeout(res, 100));
292
+ waited += 100;
293
+ }
294
+ if (!menuRef.current || !menuRef.current.menus) {
295
+ console.error("Menu not loaded, cannot start chat");
296
+ return;
297
+ }
298
+ }
299
+ console.log("menus: ->", menuRef.current);
260
300
  const ongoingChat = await client.loadOngoingChat();
301
+ console.log("theres a ongoing chat?: -->", ongoingChat);
261
302
  if (ongoingChat) {
262
303
  console.log("Ongoing chat found:", ongoingChat);
263
304
  console.log("Resuming chat:", ongoingChat.id);
264
- chatRef.current = await client.resumeChat(ongoingChat.id);
305
+ chatRef.current = ongoingChat;
265
306
  agent_virtual.current = ongoingChat.agent;
266
307
  return;
267
308
  }
309
+ console.log("not ongoing chat ");
310
+ console.log(!!ongoingChat);
268
311
  const foundMenu = menuRef.current.menus.find(
269
312
  (menu) => menu.name === menuOption
270
313
  );
271
314
  const menuId = foundMenu && foundMenu.id;
272
315
  console.log("Creating new chat with menu ID:", menuId);
273
- const newChat = await client.createChat(menuId, { custom_data });
274
- if (newChat !== null) {
316
+ if (!foundMenu) {
317
+ throw new Error("Menu not found: " + menuOption);
318
+ }
319
+ const newChat = await client.createChat(menuId, {
320
+ custom_data: custom_data()
321
+ });
322
+ if (newChat && typeof newChat === "object" && isChat(newChat)) {
275
323
  chatRef.current = newChat;
276
324
  agent_virtual.current = newChat.agent;
277
325
  console.log("Chat created id:", newChat.id);
278
326
  }
279
327
  } catch (err) {
280
328
  console.error("Error creating chat:", err);
329
+ } finally {
330
+ chatLoading.current = false;
331
+ setChatStarted();
281
332
  }
282
333
  };
283
334
  const handleClick = async () => {
335
+ audioManager.setSoundEnabled(true);
284
336
  toggle();
285
337
  if (hasStarted) return;
286
- if (!menusLoaded) {
287
- setPendingStart(true);
288
- return;
289
- }
290
338
  if (!hasOpenedOnce) {
291
- await startChat();
292
- setHasStarted(true);
339
+ await startChat("bubbleClick");
340
+ setChatStarted();
293
341
  }
294
342
  };
295
343
  const onSendMessage = async (msg) => {
296
- console.log("Sending message:", msg);
344
+ const clientChatId = clientRef.current?.chat?.id;
345
+ const refChatId = chatRef.current?.id;
346
+ console.log(
347
+ "Sending message:",
348
+ msg,
349
+ "| client.chat.id:",
350
+ clientChatId,
351
+ "| chatRef.id:",
352
+ refChatId
353
+ );
297
354
  try {
298
355
  await clientRef.current?.sendTextMessage(msg);
299
356
  } catch (error) {
@@ -305,21 +362,33 @@ const Chatbot = ({
305
362
  }
306
363
  };
307
364
  const onEndChat = async () => {
308
- console.log("Ending chat");
365
+ console.log(`Ending chat [end chat]`);
309
366
  if (chatRef.current) {
310
- await clientRef.current?.finishChat();
311
- await chatRef.current?.destroy();
312
- clearMessages();
313
- chatRef.current = null;
314
- console.log("Chat ended");
315
- setHasStarted(false);
316
- endEscalation?.();
367
+ try {
368
+ clientRef.current?.finishChat().then(() => {
369
+ console.log(`Chat finished`);
370
+ chatRef.current?.destroy().then(() => {
371
+ console.log(`Chat destroyed`);
372
+ clearMessages();
373
+ chatRef.current = null;
374
+ resetChatStarted();
375
+ console.log("Chat ended");
376
+ endEscalation?.();
377
+ }).finally(() => {
378
+ setChatStatus("ending");
379
+ displayThankyouMessage();
380
+ });
381
+ });
382
+ } catch (error) {
383
+ console.log(error, "from onEndChat");
384
+ }
385
+ return;
317
386
  }
318
387
  };
319
388
  const onEndAndStartNewChat = async () => {
320
389
  console.log("Ending current chat and starting a new one");
321
390
  await onEndChat();
322
- await startChat();
391
+ await startChat("endAndStartNew");
323
392
  };
324
393
  useMount(async () => {
325
394
  console.log("Chatbot mounted");
@@ -327,19 +396,12 @@ const Chatbot = ({
327
396
  isMountedRef.current = true;
328
397
  await createClient();
329
398
  });
330
- useEffect(() => {
331
- if (menusLoaded && pendingStart && !hasStarted) {
332
- startChat();
333
- setPendingStart(false);
334
- }
335
- }, [menusLoaded, pendingStart, hasStarted]);
336
399
  useUnmount(() => {
337
400
  console.log("Chatbot unmounted");
338
401
  deregisterEventHandlers();
339
- isMountedRef.current = false;
340
- hasLoadedBefore.current = true;
402
+ chatLoading.current = false;
341
403
  reset();
342
- setHasStarted(false);
404
+ resetChatStarted();
343
405
  setStatus("idle");
344
406
  clearMessages();
345
407
  endEscalation?.();
@@ -350,9 +412,13 @@ const Chatbot = ({
350
412
  const onClose = () => {
351
413
  toggle();
352
414
  };
353
- const onCloseAfterThankYou = () => {
415
+ const newChatSession = async () => {
416
+ console.log("create new session");
417
+ };
418
+ const onCloseAfterThankYou = async () => {
354
419
  reset();
355
- setHasStarted(false);
420
+ resetChatStarted();
421
+ newChatSession();
356
422
  };
357
423
  const onPreviewTyping = async (msg) => {
358
424
  console.log("Preview typing message:", msg);
@@ -365,25 +431,75 @@ const Chatbot = ({
365
431
  console.error("Error sending preview message:", error);
366
432
  }
367
433
  };
368
- return menusLoaded && /* @__PURE__ */ jsxs("div", { className: project === "ufb" ? chatbotUFB : chatbotAXB, children: [
369
- /* @__PURE__ */ jsx(Bubble, { onClick: handleClick }),
370
- /* @__PURE__ */ jsx(
371
- ChatWindow,
372
- {
373
- status,
374
- virtualAgent: agent_virtual.current,
375
- messages,
376
- onSend: onSendMessage,
377
- endChat: onEndChat,
378
- onClose,
379
- onNewChat: onEndAndStartNewChat,
380
- onCloseAfterThankYou,
381
- previewTyping: onPreviewTyping,
382
- isTyping
434
+ useEffect(() => {
435
+ if (chatRef.current) {
436
+ if (isVisible && isOpen) {
437
+ audioManager.setSoundEnabled(false);
438
+ }
439
+ if (isVisible && !isOpen) {
440
+ audioManager.setSoundEnabled(true);
441
+ }
442
+ if (!isVisible) {
443
+ audioManager.setSoundEnabled(true);
383
444
  }
384
- )
385
- ] });
445
+ }
446
+ }, [isOpen, isVisible]);
447
+ useMount(() => {
448
+ const hasParams = () => {
449
+ return window.location.search.includes("utm_");
450
+ };
451
+ const tryStart = () => {
452
+ if (hasParams()) {
453
+ startChat("utm-ready");
454
+ return true;
455
+ }
456
+ return false;
457
+ };
458
+ if (tryStart()) return;
459
+ const original = history.replaceState;
460
+ history.replaceState = function(...args) {
461
+ original.apply(this, args);
462
+ if (tryStart()) {
463
+ history.replaceState = original;
464
+ }
465
+ };
466
+ const interval = setInterval(() => {
467
+ if (tryStart()) {
468
+ clearInterval(interval);
469
+ history.replaceState = original;
470
+ }
471
+ }, 100);
472
+ return () => {
473
+ clearInterval(interval);
474
+ history.replaceState = original;
475
+ };
476
+ });
477
+ return menusLoaded && /* @__PURE__ */ jsxs(
478
+ "div",
479
+ {
480
+ className: ["axos", "Axos"].includes(project) ? chatbotAXB : chatbotUFB,
481
+ children: [
482
+ /* @__PURE__ */ jsx(Bubble, { onClick: handleClick, project }),
483
+ /* @__PURE__ */ jsx(
484
+ ChatWindow,
485
+ {
486
+ status,
487
+ virtualAgent: agent_virtual.current,
488
+ messages,
489
+ onSend: onSendMessage,
490
+ endChat: onEndChat,
491
+ onClose,
492
+ onNewChat: onEndAndStartNewChat,
493
+ onCloseAfterThankYou,
494
+ previewTyping: onPreviewTyping,
495
+ isTyping
496
+ }
497
+ )
498
+ ]
499
+ }
500
+ );
386
501
  };
387
502
  export {
388
- Chatbot
503
+ Chatbot,
504
+ audioManager
389
505
  };
@@ -12,6 +12,7 @@ interface ChatbotMessageProps {
12
12
  onCancelEndChat?: () => void;
13
13
  onSend?: (content: string) => void;
14
14
  onEndChat?: () => void;
15
+ inputRef: React.RefObject<HTMLTextAreaElement | null>;
15
16
  }
16
17
  export declare const ChatbotMessage: FC<ChatbotMessageProps>;
17
18
  export {};