@sawport/react-sdk 1.4.0-alpha.1 → 1.4.0-alpha.2

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.js CHANGED
@@ -104639,6 +104639,7 @@ const useChatStore = create()(
104639
104639
  chatInit: false,
104640
104640
  chatClose: true,
104641
104641
  agent: void 0,
104642
+ popupVisible: false,
104642
104643
  scheduleReminderCanceled: false,
104643
104644
  companyClosed,
104644
104645
  dataRef: null,
@@ -104656,6 +104657,7 @@ const useChatStore = create()(
104656
104657
  chatInit: false,
104657
104658
  chatClose: false,
104658
104659
  agent: void 0,
104660
+ popupVisible: false,
104659
104661
  scheduleReminderCanceled: false,
104660
104662
  companyClosed,
104661
104663
  dataRef: null,
@@ -104680,7 +104682,7 @@ const useChatStore = create()(
104680
104682
  } else {
104681
104683
  updateWait((_c = dataRef == null ? void 0 : dataRef.wait) == null ? void 0 : _c.id, { status: "ended" });
104682
104684
  }
104683
- set2({ chatClose, scheduleReminderCanceled: false });
104685
+ set2({ chatClose, popupVisible: false, scheduleReminderCanceled: false });
104684
104686
  }
104685
104687
  },
104686
104688
  setIsWidgetLaunched: (isWidgetLaunched) => set2({ isWidgetLaunched }),
@@ -109080,8 +109082,9 @@ function ChatWidgetScreen({ welcome_message, company, isOngoingChat }) {
109080
109082
  ] });
109081
109083
  }
109082
109084
  const ChatInput = memo(function({ company }) {
109083
- var _a2, _b, _c, _d, _e, _f, _g, _h;
109085
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i2, _j;
109084
109086
  const {
109087
+ agent,
109085
109088
  dataRef,
109086
109089
  scheduleReminderCanceled,
109087
109090
  popupVisible,
@@ -109102,6 +109105,12 @@ const ChatInput = memo(function({ company }) {
109102
109105
  };
109103
109106
  const agentConnected = ((_a2 = dataRef == null ? void 0 : dataRef.wait) == null ? void 0 : _a2.status) === "connected";
109104
109107
  const agentDetails = transferredAgent || ((_f = (_e = (_b = dataRef == null ? void 0 : dataRef.wait) == null ? void 0 : _b.connectors) == null ? void 0 : _e[((_d = (_c = dataRef == null ? void 0 : dataRef.wait) == null ? void 0 : _c.connectors) == null ? void 0 : _d.length) - 1]) == null ? void 0 : _f.agent);
109108
+ const hasAgentConnected = agentConnected || Boolean(
109109
+ (agent == null ? void 0 : agent.id) || (transferredAgent == null ? void 0 : transferredAgent.id) || ((_h = (_g = dataRef == null ? void 0 : dataRef.wait) == null ? void 0 : _g.connectors) == null ? void 0 : _h.some((item) => {
109110
+ var _a3;
109111
+ return (_a3 = item == null ? void 0 : item.agent) == null ? void 0 : _a3.id;
109112
+ }))
109113
+ );
109105
109114
  const handleOk = () => {
109106
109115
  setPopupVisible(false);
109107
109116
  quickStopChat({ companyClosed: true, offlineMode: true });
@@ -109196,15 +109205,16 @@ const ChatInput = memo(function({ company }) {
109196
109205
  [`agent.connected.${(_a3 = dataRef == null ? void 0 : dataRef.wait) == null ? void 0 : _a3.id}`]: ({ waitList }) => {
109197
109206
  const audio = new Audio(connectedSound);
109198
109207
  audio.play();
109208
+ setPopupVisible(false);
109199
109209
  setWait(waitList);
109200
109210
  },
109201
109211
  [`WaitList.transferred.${((_b2 = dataRef == null ? void 0 : dataRef.wait) == null ? void 0 : _b2.conversation.id) || ((_c2 = dataRef == null ? void 0 : dataRef.wait) == null ? void 0 : _c2.conversation)}`]: ({
109202
- agent
109212
+ agent: agent2
109203
109213
  }) => {
109204
109214
  setEvent((state) => {
109205
- state.transferredAgent = agent;
109215
+ state.transferredAgent = agent2;
109206
109216
  });
109207
- t.emit("agent-joined", { ...agent.user, agent });
109217
+ t.emit("agent-joined", { ...agent2.user, agent: agent2 });
109208
109218
  },
109209
109219
  [`typing.${(dataRef == null ? void 0 : dataRef.wait.conversation.id) || (dataRef == null ? void 0 : dataRef.wait.conversation)}`]: () => {
109210
109220
  const timeOut = setTimeout(() => {
@@ -109221,26 +109231,28 @@ const ChatInput = memo(function({ company }) {
109221
109231
  }
109222
109232
  };
109223
109233
  },
109224
- [t, (dataRef == null ? void 0 : dataRef.wait.conversation.id) || (dataRef == null ? void 0 : dataRef.wait.conversation), (_g = dataRef == null ? void 0 : dataRef.wait) == null ? void 0 : _g.id]
109234
+ [t, (dataRef == null ? void 0 : dataRef.wait.conversation.id) || (dataRef == null ? void 0 : dataRef.wait.conversation), (_i2 = dataRef == null ? void 0 : dataRef.wait) == null ? void 0 : _i2.id]
109225
109235
  );
109226
109236
  useEffect(() => {
109227
109237
  var _a3;
109228
109238
  let popupTimeoutId = null;
109239
+ if (hasAgentConnected) {
109240
+ setPopupVisible(false);
109241
+ return () => void 0;
109242
+ }
109229
109243
  if (!scheduleReminderCanceled && ((_a3 = company == null ? void 0 : company.options) == null ? void 0 : _a3.schedulePopUpTime)) {
109230
- if (!agentConnected || !(agentDetails == null ? void 0 : agentDetails.id)) {
109244
+ if (!hasAgentConnected) {
109231
109245
  popupTimeoutId = setTimeout(() => {
109232
- if (!agentConnected || !(agentDetails == null ? void 0 : agentDetails.id)) {
109246
+ if (!hasAgentConnected) {
109233
109247
  setPopupVisible(true);
109234
109248
  }
109235
109249
  }, company.options.schedulePopUpTime);
109236
- } else {
109237
- setPopupVisible(false);
109238
109250
  }
109239
109251
  }
109240
109252
  return () => {
109241
109253
  if (popupTimeoutId) clearTimeout(popupTimeoutId);
109242
109254
  };
109243
- }, [agentConnected, agentDetails == null ? void 0 : agentDetails.id, (_h = company == null ? void 0 : company.options) == null ? void 0 : _h.schedulePopUpTime, scheduleReminderCanceled, setPopupVisible]);
109255
+ }, [(_j = company == null ? void 0 : company.options) == null ? void 0 : _j.schedulePopUpTime, hasAgentConnected, scheduleReminderCanceled, setPopupVisible]);
109244
109256
  const [, colors] = useToken();
109245
109257
  useSocketListeners({ listeners });
109246
109258
  return /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -109317,7 +109329,7 @@ const ChatInput = memo(function({ company }) {
109317
109329
  placement: "left",
109318
109330
  title: "Wait time too long?",
109319
109331
  description: "Schedule a call with an agent.",
109320
- open: popupVisible,
109332
+ open: popupVisible && !hasAgentConnected,
109321
109333
  onConfirm: handleOk,
109322
109334
  onCancel: handleCancel
109323
109335
  }