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

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
@@ -67739,7 +67739,7 @@ const Offline = react.exports.memo(({
67739
67739
  children: [/* @__PURE__ */ jsxs(Button$1, {
67740
67740
  type: "primary",
67741
67741
  htmlType: "submit",
67742
- disabled: isLoading,
67742
+ disabled: isLoading || isRecording,
67743
67743
  className: styles$2.scheduleBtn + " mt-1 mb-1 py-1 px-4 col",
67744
67744
  children: [isLoading ? /* @__PURE__ */ jsx(SpinFC$1, {
67745
67745
  size: "sm",
@@ -67747,6 +67747,7 @@ const Offline = react.exports.memo(({
67747
67747
  }) : "", calendar2 ? "Update Call" : "Request Call"]
67748
67748
  }), /* @__PURE__ */ jsx(Button$1, {
67749
67749
  outline: "true",
67750
+ disabled: isRecording,
67750
67751
  style: {
67751
67752
  borderColor: hexcode
67752
67753
  },
@@ -72003,16 +72004,22 @@ function ChatWidgetScreen({
72003
72004
  }
72004
72005
  }, []);
72005
72006
  react.exports.useEffect(() => {
72006
- if (popupTime && !agentConnected && !timeoutTriggered) {
72007
- const timer = setTimeout(() => {
72007
+ let timer;
72008
+ if (timeoutTriggered && !agentDetails) {
72009
+ if (timer)
72010
+ clearTimeout(timer);
72011
+ return;
72012
+ } else if (popupTime && !agentDetails || !timeoutTriggered) {
72013
+ clearTimeout(timer);
72014
+ timer = setTimeout(() => {
72008
72015
  setPopupVisible(true);
72009
72016
  setTimeoutTriggered(true);
72010
72017
  }, popupTime);
72011
- return () => {
72012
- clearTimeout(timer);
72013
- };
72014
72018
  }
72015
- }, [popupTime, agentConnected, timeoutTriggered]);
72019
+ return () => {
72020
+ clearTimeout(timer);
72021
+ };
72022
+ }, [popupTime, agentDetails, timeoutTriggered]);
72016
72023
  return /* @__PURE__ */ jsx(Fragment, {
72017
72024
  children: offlineMode ? /* @__PURE__ */ jsx(Offline, {
72018
72025
  companyUser,
@@ -73090,6 +73097,7 @@ function useVideoCalling({ userId, conversation_id }) {
73090
73097
  ref.current.screenStream = null;
73091
73098
  ref.current.localICECandidates = [];
73092
73099
  ref.current.localVideoTrack = null;
73100
+ ref.current.connected = false;
73093
73101
  setState({
73094
73102
  isIncoming: false,
73095
73103
  isOutgoing: false,
@@ -74213,11 +74221,15 @@ const WidgetFormDisplay = react.exports.memo(({
74213
74221
  }
74214
74222
  }, [socket2.connected, chatInit, customer == null ? void 0 : customer.id]);
74215
74223
  const quickStopChat = react.exports.useCallback(() => {
74224
+ var _a2, _b2;
74216
74225
  setState({
74217
74226
  chatInit: false,
74218
74227
  chatClose: true,
74219
74228
  companyClosed: companyIsClosed
74220
74229
  });
74230
+ updateWait((_b2 = (_a2 = dataRef.current) == null ? void 0 : _a2.wait) == null ? void 0 : _b2.id, {
74231
+ status: "missed"
74232
+ });
74221
74233
  dataRef.current = null;
74222
74234
  }, [companyIsClosed, dataRef]);
74223
74235
  const setChatClose = (chatClose2, isAgent) => {
@@ -74360,13 +74372,14 @@ const ChatMode = react.exports.memo(({
74360
74372
  calendar: calendar2,
74361
74373
  quickStopChat
74362
74374
  }) => {
74363
- var _a, _b, _c;
74375
+ var _a, _b;
74364
74376
  const {
74365
74377
  state: {
74366
74378
  data: data2
74367
74379
  },
74368
74380
  setState: _setState
74369
74381
  } = useRequest({
74382
+ loadOnMount: !!(customer == null ? void 0 : customer.id),
74370
74383
  asyncRequest: getConnectedWait,
74371
74384
  params: [{
74372
74385
  customer: customer == null ? void 0 : customer.id
@@ -74379,14 +74392,15 @@ const ChatMode = react.exports.memo(({
74379
74392
  return (_b2 = connectors == null ? void 0 : connectors[(connectors == null ? void 0 : connectors.length) - 1]) == null ? void 0 : _b2.agent;
74380
74393
  }, [data2]);
74381
74394
  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,
74395
+ wait: data2 == null ? void 0 : data2[0],
74396
+ conversation: (_a = data2 == null ? void 0 : data2[0]) == null ? void 0 : _a.conversation,
74384
74397
  agent: agent_,
74385
74398
  setState: _setState,
74386
74399
  customer,
74387
74400
  dataRef,
74388
74401
  setParentState: setState,
74389
- setIsOngoingChat
74402
+ setIsOngoingChat,
74403
+ chatSession: (_b = company == null ? void 0 : company.options) == null ? void 0 : _b.chatSession
74390
74404
  }) : /* @__PURE__ */ jsx(WidgetInitForm$1, {
74391
74405
  company_id,
74392
74406
  companyUser,
@@ -74412,20 +74426,21 @@ const ChatMode = react.exports.memo(({
74412
74426
  });
74413
74427
  const OngoingChat = ({
74414
74428
  setState,
74415
- waitId,
74429
+ wait,
74416
74430
  dataRef,
74417
74431
  customer,
74418
- conversationId,
74432
+ conversation,
74419
74433
  setParentState,
74420
74434
  agent,
74421
- setIsOngoingChat
74435
+ setIsOngoingChat,
74436
+ chatSession
74422
74437
  }) => {
74423
74438
  const {
74424
74439
  socket: socket2
74425
74440
  } = useSocket();
74426
74441
  const endChat = () => {
74427
74442
  t$3.emit("chat-ended");
74428
- updateWait(waitId, {
74443
+ updateWait(wait == null ? void 0 : wait.id, {
74429
74444
  status: "ended"
74430
74445
  });
74431
74446
  setState({
@@ -74444,9 +74459,9 @@ const OngoingChat = ({
74444
74459
  wait: {
74445
74460
  customer,
74446
74461
  conversation: {
74447
- id: conversationId
74462
+ id: conversation == null ? void 0 : conversation.id
74448
74463
  },
74449
- id: waitId
74464
+ id: wait == null ? void 0 : wait.id
74450
74465
  }
74451
74466
  };
74452
74467
  const updates = {
@@ -74462,7 +74477,7 @@ const OngoingChat = ({
74462
74477
  setIsOngoingChat(true);
74463
74478
  socket2.emit("customer-joined-conversation", {
74464
74479
  conversation: {
74465
- id: conversationId
74480
+ id: conversation == null ? void 0 : conversation.id
74466
74481
  },
74467
74482
  customer: {
74468
74483
  id: customer == null ? void 0 : customer.id
@@ -74472,6 +74487,20 @@ const OngoingChat = ({
74472
74487
  console.log(error);
74473
74488
  }
74474
74489
  };
74490
+ react.exports.useEffect(() => {
74491
+ if ((wait == null ? void 0 : wait.status) === "connected" && (conversation == null ? void 0 : conversation.offlineAt) && chatSession) {
74492
+ const currentTimestamp = new Date().getTime();
74493
+ const offlineAt = new Date(`${conversation == null ? void 0 : conversation.offlineAt}`).getTime();
74494
+ const timeDifferenceInMilliseconds = currentTimestamp - offlineAt;
74495
+ const timeDifferenceInMinutes = Math.floor(timeDifferenceInMilliseconds / (1e3 * 60));
74496
+ if (timeDifferenceInMinutes >= chatSession) {
74497
+ toast.info("Time expired for going off chat", {
74498
+ autoClose: 2e3
74499
+ });
74500
+ endChat();
74501
+ }
74502
+ }
74503
+ }, []);
74475
74504
  return /* @__PURE__ */ jsxs("div", {
74476
74505
  className: "p-4 d-flex flex-column align-items-center justify-content-center",
74477
74506
  children: [/* @__PURE__ */ jsx("h3", {