@sawport/react-sdk 0.1.0-alpha.57.1 → 0.1.0-alpha.58

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
@@ -72003,16 +72003,22 @@ function ChatWidgetScreen({
72003
72003
  }
72004
72004
  }, []);
72005
72005
  react.exports.useEffect(() => {
72006
- if (popupTime && !agentConnected && !timeoutTriggered) {
72007
- const timer = setTimeout(() => {
72006
+ let timer;
72007
+ if (timeoutTriggered && !agentDetails) {
72008
+ if (timer)
72009
+ clearTimeout(timer);
72010
+ return;
72011
+ } else if (popupTime && !agentDetails || !timeoutTriggered) {
72012
+ clearTimeout(timer);
72013
+ timer = setTimeout(() => {
72008
72014
  setPopupVisible(true);
72009
72015
  setTimeoutTriggered(true);
72010
72016
  }, popupTime);
72011
- return () => {
72012
- clearTimeout(timer);
72013
- };
72014
72017
  }
72015
- }, [popupTime, agentConnected, timeoutTriggered]);
72018
+ return () => {
72019
+ clearTimeout(timer);
72020
+ };
72021
+ }, [popupTime, agentDetails, timeoutTriggered]);
72016
72022
  return /* @__PURE__ */ jsx(Fragment, {
72017
72023
  children: offlineMode ? /* @__PURE__ */ jsx(Offline, {
72018
72024
  companyUser,
@@ -74213,11 +74219,15 @@ const WidgetFormDisplay = react.exports.memo(({
74213
74219
  }
74214
74220
  }, [socket2.connected, chatInit, customer == null ? void 0 : customer.id]);
74215
74221
  const quickStopChat = react.exports.useCallback(() => {
74222
+ var _a2, _b2;
74216
74223
  setState({
74217
74224
  chatInit: false,
74218
74225
  chatClose: true,
74219
74226
  companyClosed: companyIsClosed
74220
74227
  });
74228
+ updateWait((_b2 = (_a2 = dataRef.current) == null ? void 0 : _a2.wait) == null ? void 0 : _b2.id, {
74229
+ status: "missed"
74230
+ });
74221
74231
  dataRef.current = null;
74222
74232
  }, [companyIsClosed, dataRef]);
74223
74233
  const setChatClose = (chatClose2, isAgent) => {
@@ -74360,7 +74370,7 @@ const ChatMode = react.exports.memo(({
74360
74370
  calendar: calendar2,
74361
74371
  quickStopChat
74362
74372
  }) => {
74363
- var _a, _b, _c;
74373
+ var _a, _b;
74364
74374
  const {
74365
74375
  state: {
74366
74376
  data: data2
@@ -74379,14 +74389,15 @@ const ChatMode = react.exports.memo(({
74379
74389
  return (_b2 = connectors == null ? void 0 : connectors[(connectors == null ? void 0 : connectors.length) - 1]) == null ? void 0 : _b2.agent;
74380
74390
  }, [data2]);
74381
74391
  return !chatInit ? (data2 == null ? void 0 : data2.length) ? /* @__PURE__ */ jsx(OngoingChat, {
74382
- waitId: (_a = data2 == null ? void 0 : data2[0]) == null ? void 0 : _a.id,
74383
- conversationId: (_c = (_b = data2 == null ? void 0 : data2[0]) == null ? void 0 : _b.conversation) == null ? void 0 : _c.id,
74392
+ wait: data2 == null ? void 0 : data2[0],
74393
+ conversation: (_a = data2 == null ? void 0 : data2[0]) == null ? void 0 : _a.conversation,
74384
74394
  agent: agent_,
74385
74395
  setState: _setState,
74386
74396
  customer,
74387
74397
  dataRef,
74388
74398
  setParentState: setState,
74389
- setIsOngoingChat
74399
+ setIsOngoingChat,
74400
+ chatSession: (_b = company == null ? void 0 : company.options) == null ? void 0 : _b.chatSession
74390
74401
  }) : /* @__PURE__ */ jsx(WidgetInitForm$1, {
74391
74402
  company_id,
74392
74403
  companyUser,
@@ -74412,20 +74423,21 @@ const ChatMode = react.exports.memo(({
74412
74423
  });
74413
74424
  const OngoingChat = ({
74414
74425
  setState,
74415
- waitId,
74426
+ wait,
74416
74427
  dataRef,
74417
74428
  customer,
74418
- conversationId,
74429
+ conversation,
74419
74430
  setParentState,
74420
74431
  agent,
74421
- setIsOngoingChat
74432
+ setIsOngoingChat,
74433
+ chatSession
74422
74434
  }) => {
74423
74435
  const {
74424
74436
  socket: socket2
74425
74437
  } = useSocket();
74426
74438
  const endChat = () => {
74427
74439
  t$3.emit("chat-ended");
74428
- updateWait(waitId, {
74440
+ updateWait(wait == null ? void 0 : wait.id, {
74429
74441
  status: "ended"
74430
74442
  });
74431
74443
  setState({
@@ -74444,9 +74456,9 @@ const OngoingChat = ({
74444
74456
  wait: {
74445
74457
  customer,
74446
74458
  conversation: {
74447
- id: conversationId
74459
+ id: conversation == null ? void 0 : conversation.id
74448
74460
  },
74449
- id: waitId
74461
+ id: wait == null ? void 0 : wait.id
74450
74462
  }
74451
74463
  };
74452
74464
  const updates = {
@@ -74462,7 +74474,7 @@ const OngoingChat = ({
74462
74474
  setIsOngoingChat(true);
74463
74475
  socket2.emit("customer-joined-conversation", {
74464
74476
  conversation: {
74465
- id: conversationId
74477
+ id: conversation == null ? void 0 : conversation.id
74466
74478
  },
74467
74479
  customer: {
74468
74480
  id: customer == null ? void 0 : customer.id
@@ -74472,6 +74484,20 @@ const OngoingChat = ({
74472
74484
  console.log(error);
74473
74485
  }
74474
74486
  };
74487
+ react.exports.useEffect(() => {
74488
+ if ((wait == null ? void 0 : wait.status) === "connected" && (conversation == null ? void 0 : conversation.offlineAt) && chatSession) {
74489
+ const currentTimestamp = new Date().getTime();
74490
+ const offlineAt = new Date(`${conversation == null ? void 0 : conversation.offlineAt}`).getTime();
74491
+ const timeDifferenceInMilliseconds = currentTimestamp - offlineAt;
74492
+ const timeDifferenceInMinutes = Math.floor(timeDifferenceInMilliseconds / (1e3 * 60));
74493
+ if (timeDifferenceInMinutes >= chatSession) {
74494
+ toast.info("Time expired for going off chat", {
74495
+ autoClose: 2e3
74496
+ });
74497
+ endChat();
74498
+ }
74499
+ }
74500
+ }, []);
74475
74501
  return /* @__PURE__ */ jsxs("div", {
74476
74502
  className: "p-4 d-flex flex-column align-items-center justify-content-center",
74477
74503
  children: [/* @__PURE__ */ jsx("h3", {