@baseportal/chat-widget 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -202,6 +202,7 @@ var pt = {
202
202
  placeholder: "Digite uma mensagem...",
203
203
  closed: "Esta conversa foi encerrada.",
204
204
  reopen: "Reabrir conversa",
205
+ newConversation: "Nova conversa",
205
206
  attachFile: "Anexar arquivo",
206
207
  uploading: "Enviando...",
207
208
  fileTooLarge: "Arquivo muito grande (m\xE1x. 25MB)",
@@ -233,6 +234,7 @@ var en = {
233
234
  placeholder: "Type a message...",
234
235
  closed: "This conversation has been closed.",
235
236
  reopen: "Reopen conversation",
237
+ newConversation: "New conversation",
236
238
  attachFile: "Attach file",
237
239
  uploading: "Uploading...",
238
240
  fileTooLarge: "File too large (max 25MB)",
@@ -264,6 +266,7 @@ var es = {
264
266
  placeholder: "Escribe un mensaje...",
265
267
  closed: "Esta conversaci\xF3n ha sido cerrada.",
266
268
  reopen: "Reabrir conversaci\xF3n",
269
+ newConversation: "Nueva conversaci\xF3n",
267
270
  attachFile: "Adjuntar archivo",
268
271
  uploading: "Subiendo...",
269
272
  fileTooLarge: "Archivo demasiado grande (m\xE1x. 25MB)",
@@ -779,18 +782,11 @@ function ChatWindow({
779
782
  if (storedId) {
780
783
  try {
781
784
  const conv = await apiClient.getConversation(storedId);
782
- if (!conv.open) {
783
- storage.clear();
784
- if (needsPreChat()) {
785
- setView("prechat");
786
- } else {
787
- await startNewConversation();
788
- }
789
- } else {
790
- const msgs = await apiClient.getMessages(storedId, { limit: 50 });
791
- setMessages(Array.isArray(msgs) ? msgs.reverse() : []);
792
- setConversation(conv);
793
- setView("chat");
785
+ const msgs = await apiClient.getMessages(storedId, { limit: 50 });
786
+ setMessages(Array.isArray(msgs) ? msgs.reverse() : []);
787
+ setConversation(conv);
788
+ setView("chat");
789
+ if (conv.open) {
794
790
  connectRealtime(storedId);
795
791
  }
796
792
  } catch {
@@ -847,21 +843,6 @@ function ChatWindow({
847
843
  );
848
844
  if (!conv.open) {
849
845
  events.emit("conversation:closed", conv);
850
- setTimeout(() => {
851
- realtimeClient.unsubscribe();
852
- storage.clear();
853
- setConversation(null);
854
- setMessages([]);
855
- if (allowViewHistory) {
856
- apiClient.getVisitorConversations().then(setConversations).catch(() => {
857
- });
858
- setView("conversations");
859
- } else if (needsPreChat()) {
860
- setView("prechat");
861
- } else {
862
- startNewConversationRef.current();
863
- }
864
- }, 2e3);
865
846
  }
866
847
  }
867
848
  });
@@ -997,6 +978,21 @@ function ChatWindow({
997
978
  setSending(false);
998
979
  }
999
980
  }, [inputValue, uploadedFileId, conversation, sending, apiClient, events, realtimeClient, storage, allowViewHistory, needsPreChat]);
981
+ const handleNewConversation = (0, import_hooks5.useCallback)(async () => {
982
+ realtimeClient.unsubscribe();
983
+ storage.clear();
984
+ setConversation(null);
985
+ setMessages([]);
986
+ if (allowViewHistory) {
987
+ apiClient.getVisitorConversations().then(setConversations).catch(() => {
988
+ });
989
+ setView("conversations");
990
+ } else if (needsPreChat()) {
991
+ setView("prechat");
992
+ } else {
993
+ await startNewConversationRef.current();
994
+ }
995
+ }, [realtimeClient, storage, allowViewHistory, apiClient, needsPreChat]);
1000
996
  const handleReopen = (0, import_hooks5.useCallback)(async () => {
1001
997
  if (!conversation) return;
1002
998
  try {
@@ -1068,7 +1064,7 @@ function ChatWindow({
1068
1064
  }
1069
1065
  ) : /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { class: "bp-closed-banner", children: [
1070
1066
  /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { class: "bp-closed-banner__text", children: t.chat.closed }),
1071
- channelInfo.config.allowReopenConversation && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("button", { class: "bp-closed-banner__reopen", onClick: handleReopen, children: t.chat.reopen })
1067
+ channelInfo.config.allowReopenConversation ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("button", { class: "bp-closed-banner__reopen", onClick: handleReopen, children: t.chat.reopen }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("button", { class: "bp-closed-banner__reopen", onClick: handleNewConversation, children: t.chat.newConversation })
1072
1068
  ] }),
1073
1069
  channelInfo.config.privacyPolicyUrl && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { class: "bp-privacy-footer", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1074
1070
  "a",