@baseportal/chat-widget 0.1.2 → 0.1.4

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.esm.js CHANGED
@@ -165,6 +165,7 @@ var pt = {
165
165
  placeholder: "Digite uma mensagem...",
166
166
  closed: "Esta conversa foi encerrada.",
167
167
  reopen: "Reabrir conversa",
168
+ newConversation: "Nova conversa",
168
169
  attachFile: "Anexar arquivo",
169
170
  uploading: "Enviando...",
170
171
  fileTooLarge: "Arquivo muito grande (m\xE1x. 25MB)",
@@ -196,6 +197,7 @@ var en = {
196
197
  placeholder: "Type a message...",
197
198
  closed: "This conversation has been closed.",
198
199
  reopen: "Reopen conversation",
200
+ newConversation: "New conversation",
199
201
  attachFile: "Attach file",
200
202
  uploading: "Uploading...",
201
203
  fileTooLarge: "File too large (max 25MB)",
@@ -227,6 +229,7 @@ var es = {
227
229
  placeholder: "Escribe un mensaje...",
228
230
  closed: "Esta conversaci\xF3n ha sido cerrada.",
229
231
  reopen: "Reabrir conversaci\xF3n",
232
+ newConversation: "Nueva conversaci\xF3n",
230
233
  attachFile: "Adjuntar archivo",
231
234
  uploading: "Subiendo...",
232
235
  fileTooLarge: "Archivo demasiado grande (m\xE1x. 25MB)",
@@ -742,18 +745,11 @@ function ChatWindow({
742
745
  if (storedId) {
743
746
  try {
744
747
  const conv = await apiClient.getConversation(storedId);
745
- if (!conv.open) {
746
- storage.clear();
747
- if (needsPreChat()) {
748
- setView("prechat");
749
- } else {
750
- await startNewConversation();
751
- }
752
- } else {
753
- const msgs = await apiClient.getMessages(storedId, { limit: 50 });
754
- setMessages(Array.isArray(msgs) ? msgs.reverse() : []);
755
- setConversation(conv);
756
- setView("chat");
748
+ const msgs = await apiClient.getMessages(storedId, { limit: 50 });
749
+ setMessages(Array.isArray(msgs) ? msgs.reverse() : []);
750
+ setConversation(conv);
751
+ setView("chat");
752
+ if (conv.open) {
757
753
  connectRealtime(storedId);
758
754
  }
759
755
  } catch {
@@ -810,21 +806,6 @@ function ChatWindow({
810
806
  );
811
807
  if (!conv.open) {
812
808
  events.emit("conversation:closed", conv);
813
- setTimeout(() => {
814
- realtimeClient.unsubscribe();
815
- storage.clear();
816
- setConversation(null);
817
- setMessages([]);
818
- if (allowViewHistory) {
819
- apiClient.getVisitorConversations().then(setConversations).catch(() => {
820
- });
821
- setView("conversations");
822
- } else if (needsPreChat()) {
823
- setView("prechat");
824
- } else {
825
- startNewConversationRef.current();
826
- }
827
- }, 2e3);
828
809
  }
829
810
  }
830
811
  });
@@ -941,18 +922,7 @@ function ChatWindow({
941
922
  const errMsg = e instanceof Error ? e.message : "";
942
923
  if (errMsg.includes("Row not found") || errMsg.includes("404")) {
943
924
  realtimeClient.unsubscribe();
944
- storage.clear();
945
- setConversation(null);
946
- setMessages([]);
947
- if (allowViewHistory) {
948
- apiClient.getVisitorConversations().then(setConversations).catch(() => {
949
- });
950
- setView("conversations");
951
- } else if (needsPreChat()) {
952
- setView("prechat");
953
- } else {
954
- await startNewConversationRef.current();
955
- }
925
+ setConversation((prev) => prev ? { ...prev, open: false } : prev);
956
926
  } else {
957
927
  setInputValue(content);
958
928
  }
@@ -960,6 +930,21 @@ function ChatWindow({
960
930
  setSending(false);
961
931
  }
962
932
  }, [inputValue, uploadedFileId, conversation, sending, apiClient, events, realtimeClient, storage, allowViewHistory, needsPreChat]);
933
+ const handleNewConversation = useCallback3(async () => {
934
+ realtimeClient.unsubscribe();
935
+ storage.clear();
936
+ setConversation(null);
937
+ setMessages([]);
938
+ if (allowViewHistory) {
939
+ apiClient.getVisitorConversations().then(setConversations).catch(() => {
940
+ });
941
+ setView("conversations");
942
+ } else if (needsPreChat()) {
943
+ setView("prechat");
944
+ } else {
945
+ await startNewConversationRef.current();
946
+ }
947
+ }, [realtimeClient, storage, allowViewHistory, apiClient, needsPreChat]);
963
948
  const handleReopen = useCallback3(async () => {
964
949
  if (!conversation) return;
965
950
  try {
@@ -1031,7 +1016,7 @@ function ChatWindow({
1031
1016
  }
1032
1017
  ) : /* @__PURE__ */ jsxs9("div", { class: "bp-closed-banner", children: [
1033
1018
  /* @__PURE__ */ jsx9("span", { class: "bp-closed-banner__text", children: t.chat.closed }),
1034
- channelInfo.config.allowReopenConversation && /* @__PURE__ */ jsx9("button", { class: "bp-closed-banner__reopen", onClick: handleReopen, children: t.chat.reopen })
1019
+ channelInfo.config.allowReopenConversation ? /* @__PURE__ */ jsx9("button", { class: "bp-closed-banner__reopen", onClick: handleReopen, children: t.chat.reopen }) : /* @__PURE__ */ jsx9("button", { class: "bp-closed-banner__reopen", onClick: handleNewConversation, children: t.chat.newConversation })
1035
1020
  ] }),
1036
1021
  channelInfo.config.privacyPolicyUrl && /* @__PURE__ */ jsx9("div", { class: "bp-privacy-footer", children: /* @__PURE__ */ jsx9(
1037
1022
  "a",