@sawport/react-sdk 0.1.0-alpha.82.1 → 0.1.0-alpha.82.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
@@ -75464,7 +75464,7 @@ const ChatMessage = reactExports.memo(function({
75464
75464
  ext: attachment == null ? void 0 : attachment.split(".").pop()
75465
75465
  }, [attachment]);
75466
75466
  return msg.isSender ? /* @__PURE__ */ jsx("div", {
75467
- className: "chat-send-container mb-5",
75467
+ className: "chat-send-container mb-2",
75468
75468
  children: ((_a = msg.message) == null ? void 0 : _a.length) ? /* @__PURE__ */ jsxs(Fragment, {
75469
75469
  children: [/* @__PURE__ */ jsx("p", {
75470
75470
  className: "widget-chat-send",
@@ -75556,7 +75556,7 @@ const ChatMessage = reactExports.memo(function({
75556
75556
  })]
75557
75557
  }) : null
75558
75558
  }, msg.id) : /* @__PURE__ */ jsxs("div", {
75559
- className: "chat-receive-container mb-4 d-flex align-items-center",
75559
+ className: "chat-receive-container mb-2 d-flex align-items-center",
75560
75560
  children: [/* @__PURE__ */ jsxs("div", {
75561
75561
  className: "pt-3 mr-1",
75562
75562
  children: [/* @__PURE__ */ jsx(Avatar, {
@@ -75738,30 +75738,13 @@ function ChatWidgetScreen({
75738
75738
  setChatClose,
75739
75739
  videoRef,
75740
75740
  company,
75741
- isOngoingChat,
75742
- handleOk,
75743
- popupVisible,
75744
- handleCancel,
75745
- setPopupVisible
75741
+ isOngoingChat
75746
75742
  }) {
75747
75743
  var _a, _b, _c, _d, _e, _f;
75748
75744
  const {
75749
75745
  socket: socket2
75750
75746
  } = useSocket();
75751
75747
  const timeoutRef = reactExports.useRef();
75752
- const [{
75753
- typingEvent,
75754
- agentDetails,
75755
- waitlistTransferredStatus,
75756
- transferredAgent,
75757
- agentConnected
75758
- }, setEvent] = useState({
75759
- typingEvent: false,
75760
- agentDetails: void 0,
75761
- waitlistTransferredStatus: null,
75762
- transferredAgent: null,
75763
- agentConnected: false
75764
- });
75765
75748
  const [{
75766
75749
  pdfModal,
75767
75750
  selectedPdfURL
@@ -75798,18 +75781,13 @@ function ChatWidgetScreen({
75798
75781
  const el2 = document.getElementById("widget-chat-send");
75799
75782
  el2.scrollTop = el2.scrollHeight;
75800
75783
  }, []);
75801
- if (typingEvent && waitlistTransferredStatus)
75802
- setEvent((state) => {
75803
- state.waitlistTransferredStatus = false;
75804
- state.transferredAgent = null;
75805
- });
75806
75784
  const listeners2 = reactExports.useMemo(() => {
75807
- var _a2, _b2, _c2, _d2, _e2, _f2, _g, _h, _i, _j;
75785
+ var _a2, _b2, _c2, _d2, _e2;
75808
75786
  return {
75809
75787
  [`message.new.${((_a2 = dataRef.current) == null ? void 0 : _a2.wait.conversation.id) || ((_b2 = dataRef.current) == null ? void 0 : _b2.wait.conversation)}`]: async ({
75810
75788
  message
75811
75789
  }) => {
75812
- var _a3, _b3, _c3, _d3, _e3, _f3, _g2;
75790
+ var _a3, _b3, _c3, _d3, _e3, _f2, _g;
75813
75791
  const sender = ((_a3 = message.user) == null ? void 0 : _a3.id) || message.user;
75814
75792
  const customer = (_b3 = dataRef.current) == null ? void 0 : _b3.customer;
75815
75793
  const isSender = ((_c3 = customer == null ? void 0 : customer.user) == null ? void 0 : _c3.id) === (((_d3 = message.user) == null ? void 0 : _d3.id) || message.user);
@@ -75822,8 +75800,8 @@ function ChatWidgetScreen({
75822
75800
  if (sender !== ((_e3 = customer == null ? void 0 : customer.user) == null ? void 0 : _e3.id)) {
75823
75801
  t$5.emit("agent-joined", message.user);
75824
75802
  }
75825
- if (agentDetails == null ? void 0 : agentDetails.userId) {
75826
- await readConversation(((_f3 = dataRef.current) == null ? void 0 : _f3.wait.conversation.id) || ((_g2 = dataRef.current) == null ? void 0 : _g2.wait.conversation), agentDetails == null ? void 0 : agentDetails.userId);
75803
+ if (!isSender) {
75804
+ readConversation((_f2 = dataRef.current) == null ? void 0 : _f2.wait.conversation.id, (_g = message.user) == null ? void 0 : _g.id);
75827
75805
  }
75828
75806
  },
75829
75807
  [`Conversation.read.${((_c2 = dataRef.current) == null ? void 0 : _c2.wait.conversation.id) || ((_d2 = dataRef.current) == null ? void 0 : _d2.wait.conversation)}`]: async ({
@@ -75844,47 +75822,6 @@ function ChatWidgetScreen({
75844
75822
  },
75845
75823
  [`WaitList.closed.${(_e2 = dataRef.current) == null ? void 0 : _e2.wait.id}`]: () => {
75846
75824
  setChatClose(false, false);
75847
- },
75848
- [`agent.connected.${(_f2 = dataRef.current) == null ? void 0 : _f2.wait.id}`]: ({
75849
- agent
75850
- }) => {
75851
- const audio = new Audio(connectedSound);
75852
- audio.play();
75853
- setEvent((state) => {
75854
- state.agentConnected = true;
75855
- state.transferredAgent = agent;
75856
- });
75857
- },
75858
- [`WaitList.transferred.${((_g = dataRef.current) == null ? void 0 : _g.wait.conversation.id) || ((_h = dataRef.current) == null ? void 0 : _h.wait.conversation)}`]: ({
75859
- agent
75860
- }) => {
75861
- setEvent((state) => {
75862
- state.waitlistTransferredStatus = true;
75863
- state.transferredAgent = agent;
75864
- });
75865
- t$5.emit("agent-joined", {
75866
- ...agent.user,
75867
- agent
75868
- });
75869
- },
75870
- [`typing.${((_i = dataRef.current) == null ? void 0 : _i.wait.conversation.id) || ((_j = dataRef.current) == null ? void 0 : _j.wait.conversation)}`]: ({
75871
- data: data2
75872
- }) => {
75873
- setEvent((state) => {
75874
- state.typingEvent = true;
75875
- state.agentDetails = data2 == null ? void 0 : data2.agentDetails;
75876
- state.agentConnected = false;
75877
- if (state.timeOut) {
75878
- clearTimeout(state.timeOut);
75879
- }
75880
- state.timeOut = setTimeout(() => {
75881
- setEvent({
75882
- timeOut: true,
75883
- typingEvent: false
75884
- });
75885
- }, 2e3);
75886
- return state;
75887
- });
75888
75825
  }
75889
75826
  };
75890
75827
  }, [(_c = (_b = dataRef.current) == null ? void 0 : _b.customer) == null ? void 0 : _c.id, t$5, setChatClose, ((_d = dataRef.current) == null ? void 0 : _d.wait.conversation.id) || ((_e = dataRef.current) == null ? void 0 : _e.wait.conversation), (_f = dataRef.current) == null ? void 0 : _f.wait.id]);
@@ -75894,17 +75831,6 @@ function ChatWidgetScreen({
75894
75831
  reactExports.useEffect(() => {
75895
75832
  isOngoingChat && clearInterval(timeoutRef.current);
75896
75833
  }, [timeoutRef, isOngoingChat]);
75897
- reactExports.useEffect(() => {
75898
- var _a2;
75899
- if (!agentConnected && !agentDetails) {
75900
- const intervalId = setInterval(() => {
75901
- setPopupVisible(true);
75902
- }, (_a2 = company == null ? void 0 : company.options) == null ? void 0 : _a2.schedulePopUpTime);
75903
- return () => clearInterval(intervalId);
75904
- } else {
75905
- setPopupVisible(false);
75906
- }
75907
- }, [agentConnected, agentDetails]);
75908
75834
  reactExports.useEffect(() => {
75909
75835
  var _a2, _b2, _c2;
75910
75836
  socket2.connected && socket2.emit("customer-joined-conversation", {
@@ -75922,7 +75848,7 @@ function ChatWidgetScreen({
75922
75848
  id: "widget-chat-send",
75923
75849
  className: "widget-chat-display-container",
75924
75850
  children: [/* @__PURE__ */ jsx("div", {
75925
- className: "chat-receive-container mb-4 d-flex align-items-center",
75851
+ className: "chat-receive-container mb-2 d-flex align-items-center",
75926
75852
  children: /* @__PURE__ */ jsx("p", {
75927
75853
  className: `widget-chat-receive mb-0`,
75928
75854
  children: welcome_message
@@ -75934,15 +75860,6 @@ function ChatWidgetScreen({
75934
75860
  setPDFstate,
75935
75861
  setViewstate
75936
75862
  })]
75937
- }), /* @__PURE__ */ jsx(ChatInput, {
75938
- dataRef,
75939
- agentDetails,
75940
- transferredAgent,
75941
- waitlistTransferredStatus,
75942
- agentConnected,
75943
- popupVisible,
75944
- handleCancel,
75945
- handleOk
75946
75863
  }), /* @__PURE__ */ jsx(ViewDocument$1, {
75947
75864
  open: pdfModal,
75948
75865
  fileURL: selectedPdfURL,
@@ -75951,26 +75868,47 @@ function ChatWidgetScreen({
75951
75868
  open: videoModal,
75952
75869
  fileURL: selectedVideoFileURL,
75953
75870
  setVideoState: setViewstate
75954
- }), /* @__PURE__ */ jsx("span", {
75955
- style: {
75956
- fontStyle: "italic",
75957
- fontSize: "10px"
75958
- },
75959
- children: agentDetails && typingEvent ? `${agentDetails == null ? void 0 : agentDetails.firstName} is typing...` : ""
75960
75871
  })]
75961
75872
  });
75962
75873
  }
75963
75874
  const ChatInput = reactExports.memo(function({
75964
75875
  dataRef,
75965
- agentDetails,
75966
- transferredAgent,
75967
- waitlistTransferredStatus,
75968
- agentConnected,
75969
75876
  popupVisible,
75970
75877
  handleCancel,
75971
- handleOk
75878
+ handleOk,
75879
+ setPopupVisible,
75880
+ company
75972
75881
  }) {
75973
- var _a;
75882
+ var _a, _b, _c, _d;
75883
+ const [{
75884
+ typingEvent,
75885
+ agentDetails,
75886
+ waitlistTransferredStatus,
75887
+ transferredAgent,
75888
+ agentConnected
75889
+ }, setEvent] = useState({
75890
+ typingEvent: false,
75891
+ agentDetails: void 0,
75892
+ waitlistTransferredStatus: null,
75893
+ transferredAgent: null,
75894
+ agentConnected: false
75895
+ });
75896
+ if (typingEvent && waitlistTransferredStatus)
75897
+ setEvent((state) => {
75898
+ state.waitlistTransferredStatus = false;
75899
+ state.transferredAgent = null;
75900
+ });
75901
+ reactExports.useEffect(() => {
75902
+ var _a2;
75903
+ if (!agentConnected && !agentDetails) {
75904
+ const intervalId = setInterval(() => {
75905
+ setPopupVisible(true);
75906
+ }, (_a2 = company == null ? void 0 : company.options) == null ? void 0 : _a2.schedulePopUpTime);
75907
+ return () => clearInterval(intervalId);
75908
+ } else {
75909
+ setPopupVisible(false);
75910
+ }
75911
+ }, [agentConnected, agentDetails, company]);
75974
75912
  const [{
75975
75913
  chatFiles
75976
75914
  }, setState, stateRef] = useState({
@@ -75981,12 +75919,12 @@ const ChatInput = reactExports.memo(function({
75981
75919
  socket: socket2
75982
75920
  } = useSocket();
75983
75921
  const sendMessage = async () => {
75984
- var _a2, _b, _c, _d;
75922
+ var _a2, _b2, _c2, _d2;
75985
75923
  if (((_a2 = stateRef.current.messageText) == null ? void 0 : _a2.length) || stateRef.current.chatFiles) {
75986
75924
  socket2.emit("messageFromClient", {
75987
75925
  message: stateRef.current.messageText,
75988
- conversation: (_b = dataRef.current) == null ? void 0 : _b.wait.conversation.id,
75989
- customer: ((_c = dataRef.current) == null ? void 0 : _c.customer.id) || ((_d = dataRef.current) == null ? void 0 : _d.customer)
75926
+ conversation: (_b2 = dataRef.current) == null ? void 0 : _b2.wait.conversation.id,
75927
+ customer: ((_c2 = dataRef.current) == null ? void 0 : _c2.customer.id) || ((_d2 = dataRef.current) == null ? void 0 : _d2.customer)
75990
75928
  });
75991
75929
  }
75992
75930
  document.getElementById("widget-chat-input-field").value = "";
@@ -75997,11 +75935,11 @@ const ChatInput = reactExports.memo(function({
75997
75935
  });
75998
75936
  };
75999
75937
  const sendFile = reactExports.useCallback(async () => {
76000
- var _a2, _b, _c;
75938
+ var _a2, _b2, _c2;
76001
75939
  try {
76002
75940
  const data2 = new FormData();
76003
75941
  data2.append("customer", (_a2 = dataRef.current) == null ? void 0 : _a2.customer.id);
76004
- data2.append("conversation", (_c = (_b = dataRef.current) == null ? void 0 : _b.wait) == null ? void 0 : _c.conversation.id);
75942
+ data2.append("conversation", (_c2 = (_b2 = dataRef.current) == null ? void 0 : _b2.wait) == null ? void 0 : _c2.conversation.id);
76005
75943
  data2.append("message", stateRef == null ? void 0 : stateRef.current.messageText);
76006
75944
  data2.append("attachment", stateRef == null ? void 0 : stateRef.current.chatFiles);
76007
75945
  await createMessage(data2, {
@@ -76020,9 +75958,9 @@ const ChatInput = reactExports.memo(function({
76020
75958
  }
76021
75959
  }, [stateRef, dataRef, socket2.connected, stateRef]);
76022
75960
  const handleFileUpload = (event) => {
76023
- var _a2, _b, _c;
75961
+ var _a2, _b2, _c2;
76024
75962
  if ((_a2 = event == null ? void 0 : event.target) == null ? void 0 : _a2.files[0]) {
76025
- const fileExtension = (_c = (_b = event == null ? void 0 : event.target) == null ? void 0 : _b.files[0]) == null ? void 0 : _c.type.split("/").pop();
75963
+ const fileExtension = (_c2 = (_b2 = event == null ? void 0 : event.target) == null ? void 0 : _b2.files[0]) == null ? void 0 : _c2.type.split("/").pop();
76026
75964
  if (["image", "video", "document"].includes(isFileType(fileExtension))) {
76027
75965
  const file = event.target.files[0];
76028
75966
  const fileSizeLimit = 4 * 1024 * 1024;
@@ -76045,20 +75983,69 @@ const ChatInput = reactExports.memo(function({
76045
75983
  }
76046
75984
  };
76047
75985
  const onChange = (e2) => {
76048
- var _a2, _b;
75986
+ var _a2, _b2;
76049
75987
  setState({
76050
75988
  messageText: e2.target.value
76051
75989
  });
76052
75990
  (agentDetails == null ? void 0 : agentDetails.userId) && socket2.emit("typing", {
76053
75991
  to: agentDetails == null ? void 0 : agentDetails.userId,
76054
- conversation: ((_a2 = dataRef.current) == null ? void 0 : _a2.wait.conversation.id) || ((_b = dataRef.current) == null ? void 0 : _b.wait.conversation),
75992
+ conversation: ((_a2 = dataRef.current) == null ? void 0 : _a2.wait.conversation.id) || ((_b2 = dataRef.current) == null ? void 0 : _b2.wait.conversation),
76055
75993
  message: e2.target.value
76056
75994
  });
76057
75995
  };
76058
- return /* @__PURE__ */ jsx(Fragment, {
76059
- children: /* @__PURE__ */ jsxs("div", {
75996
+ const listeners2 = reactExports.useMemo(() => {
75997
+ var _a2, _b2, _c2, _d2, _e;
75998
+ return {
75999
+ [`agent.connected.${(_a2 = dataRef.current) == null ? void 0 : _a2.wait.id}`]: ({
76000
+ agent
76001
+ }) => {
76002
+ const audio = new Audio(connectedSound);
76003
+ audio.play();
76004
+ setEvent((state) => {
76005
+ state.agentConnected = true;
76006
+ state.transferredAgent = agent;
76007
+ });
76008
+ },
76009
+ [`WaitList.transferred.${((_b2 = dataRef.current) == null ? void 0 : _b2.wait.conversation.id) || ((_c2 = dataRef.current) == null ? void 0 : _c2.wait.conversation)}`]: ({
76010
+ agent
76011
+ }) => {
76012
+ setEvent((state) => {
76013
+ state.waitlistTransferredStatus = true;
76014
+ state.transferredAgent = agent;
76015
+ });
76016
+ t$5.emit("agent-joined", {
76017
+ ...agent.user,
76018
+ agent
76019
+ });
76020
+ },
76021
+ [`typing.${((_d2 = dataRef.current) == null ? void 0 : _d2.wait.conversation.id) || ((_e = dataRef.current) == null ? void 0 : _e.wait.conversation)}`]: ({
76022
+ data: data2
76023
+ }) => {
76024
+ setEvent((state) => {
76025
+ state.typingEvent = true;
76026
+ state.agentDetails = data2 == null ? void 0 : data2.agentDetails;
76027
+ state.agentConnected = false;
76028
+ if (state.timeOut) {
76029
+ clearTimeout(state.timeOut);
76030
+ }
76031
+ state.timeOut = setTimeout(() => {
76032
+ setEvent({
76033
+ timeOut: true,
76034
+ typingEvent: false
76035
+ });
76036
+ }, 2e3);
76037
+ return state;
76038
+ });
76039
+ }
76040
+ };
76041
+ }, [t$5, ((_a = dataRef.current) == null ? void 0 : _a.wait.conversation.id) || ((_b = dataRef.current) == null ? void 0 : _b.wait.conversation), (_c = dataRef.current) == null ? void 0 : _c.wait.id]);
76042
+ useSocketListeners({
76043
+ listeners: listeners2
76044
+ });
76045
+ return /* @__PURE__ */ jsxs(Fragment, {
76046
+ children: [/* @__PURE__ */ jsxs("div", {
76060
76047
  className: "widget-chat-form-container w-100 justify-content-between align-items-center",
76061
- children: [/* @__PURE__ */ jsx("p", {
76048
+ children: [(waitlistTransferredStatus || agentConnected) && /* @__PURE__ */ jsx("p", {
76062
76049
  className: "transfer-notification",
76063
76050
  children: waitlistTransferredStatus ? `You have been transferred to ${transferredAgent == null ? void 0 : transferredAgent.first_name} from ${transferredAgent == null ? void 0 : transferredAgent.team}
76064
76051
  Team` : agentConnected ? `You are now connected to ${transferredAgent == null ? void 0 : transferredAgent.first_name} ${transferredAgent == null ? void 0 : transferredAgent.last_name}` : ""
@@ -76093,7 +76080,7 @@ const ChatInput = reactExports.memo(function({
76093
76080
  id: "widget-chat-input-field",
76094
76081
  autoComplete: "off",
76095
76082
  autoFocus: true,
76096
- disabled: ((_a = document.getElementById("widget-file-upload-input")) == null ? void 0 : _a.value) !== ""
76083
+ disabled: ((_d = document.getElementById("widget-file-upload-input")) == null ? void 0 : _d.value) !== ""
76097
76084
  }), /* @__PURE__ */ jsx("img", {
76098
76085
  onClick: chatFiles ? sendFile : sendMessage,
76099
76086
  className: "widget-send-img",
@@ -76111,7 +76098,13 @@ const ChatInput = reactExports.memo(function({
76111
76098
  onCancel: handleCancel
76112
76099
  })]
76113
76100
  })]
76114
- })
76101
+ }), /* @__PURE__ */ jsx("span", {
76102
+ style: {
76103
+ fontStyle: "italic",
76104
+ fontSize: "10px"
76105
+ },
76106
+ children: agentDetails && typingEvent ? `${agentDetails == null ? void 0 : agentDetails.firstName} is typing...` : ""
76107
+ })]
76115
76108
  });
76116
76109
  });
76117
76110
  const Messages = reactExports.memo(function({
@@ -77077,6 +77070,7 @@ function useVideoCalling({ userId, conversation_id }) {
77077
77070
  otherUserScreenShared: false,
77078
77071
  ...append2
77079
77072
  });
77073
+ t$5.emit("video-state", false);
77080
77074
  stopSound();
77081
77075
  };
77082
77076
  const initPeer = reactExports.useCallback(
@@ -77201,6 +77195,7 @@ function useVideoCalling({ userId, conversation_id }) {
77201
77195
  if (userId) {
77202
77196
  const incoming = async (data2) => {
77203
77197
  ref.current.data = data2;
77198
+ t$5.emit("video-state", true);
77204
77199
  if (!stateRef.current.getCalled) {
77205
77200
  playSound(callignSound, (sound2) => sound2.loop = true);
77206
77201
  setState({ isIncoming: true });
@@ -77270,7 +77265,8 @@ function useVideoCalling({ userId, conversation_id }) {
77270
77265
  ref,
77271
77266
  initPeer,
77272
77267
  sendOffer,
77273
- playSound
77268
+ playSound,
77269
+ t$5
77274
77270
  ]);
77275
77271
  useSocketListeners({ listeners: listeners2 });
77276
77272
  reactExports.useEffect(() => {
@@ -78603,18 +78599,27 @@ const ChatMode = reactExports.memo(({
78603
78599
  fields: company == null ? void 0 : company.fields,
78604
78600
  widgetColor: company == null ? void 0 : company.hex_code,
78605
78601
  customer
78606
- }) : /* @__PURE__ */ jsx(ChatWidgetScreen$1, {
78607
- welcome_message: company == null ? void 0 : company.welcome_message,
78608
- dataRef,
78609
- setChatClose,
78610
- videoRef,
78611
- company,
78612
- agent: agent_,
78613
- isOngoingChat,
78614
- handleOk,
78615
- popupVisible,
78616
- handleCancel,
78617
- setPopupVisible
78602
+ }) : /* @__PURE__ */ jsxs(Fragment, {
78603
+ children: [/* @__PURE__ */ jsx(ChatWidgetScreen$1, {
78604
+ welcome_message: company == null ? void 0 : company.welcome_message,
78605
+ dataRef,
78606
+ setChatClose,
78607
+ videoRef,
78608
+ company,
78609
+ agent: agent_,
78610
+ isOngoingChat,
78611
+ handleOk,
78612
+ popupVisible,
78613
+ handleCancel,
78614
+ setPopupVisible
78615
+ }), /* @__PURE__ */ jsx(ChatInput, {
78616
+ dataRef,
78617
+ popupVisible,
78618
+ handleCancel,
78619
+ handleOk,
78620
+ setPopupVisible,
78621
+ company
78622
+ })]
78618
78623
  });
78619
78624
  });
78620
78625
  const OngoingChat = ({