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

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
@@ -67379,7 +67379,8 @@ const Offline = react.exports.memo(({
67379
67379
  const check2 = hooks(value2, timeformat), beforeTime = hooks(fromTime, timeformat), afterTime = hooks(toTime, timeformat);
67380
67380
  return hooks(check2).isBetween(beforeTime, afterTime);
67381
67381
  }),
67382
- reason: create$4().min(1).required("Reason is required")
67382
+ reason: create$4().min(1).required("Reason is required"),
67383
+ mobile: create$4().min(7).required()
67383
67384
  });
67384
67385
  const emptyFields = react.exports.useMemo(() => {
67385
67386
  const filledState = {};
@@ -67975,7 +67976,7 @@ function WidgetInitForm({
67975
67976
  const possibleShape = {
67976
67977
  account: create$3().required().min(10).positive(),
67977
67978
  bvn: create$3().required().min(11).positive(),
67978
- mobile: create$3().required().min(5).positive()
67979
+ mobile: create$4().min(7).required()
67979
67980
  };
67980
67981
  const fieldKeys = ["account", "bvn", "mobile"];
67981
67982
  fieldKeys.map((key) => {
@@ -71636,7 +71637,7 @@ const getWaitConnectors = async (data2) => api("wait-connectors", data2);
71636
71637
  const getLongestWaitTime = async (data2) => api("waits/longest", data2);
71637
71638
  const updateWait = async (id2, data2) => api(`waits/${id2}`, data2, "put");
71638
71639
  const getConnectedWait = async (data2) => api("waits/connected", data2);
71639
- const getWaitList = async (data2) => api("waits", data2);
71640
+ const getWaitPosition = async (createdAt) => api(`waits/position/${createdAt}`);
71640
71641
  function Feedback({
71641
71642
  agent: agent_,
71642
71643
  quickStopChat,
@@ -71968,6 +71969,10 @@ function ChatWidgetScreen({
71968
71969
  state.waitlistTransferredStatus = true;
71969
71970
  state.transferredAgent = agent;
71970
71971
  });
71972
+ t$3.emit("agent-joined", {
71973
+ ...agent.user,
71974
+ agent
71975
+ });
71971
71976
  },
71972
71977
  [`typing.${((_i = dataRef.current) == null ? void 0 : _i.wait.conversation.id) || ((_j = dataRef.current) == null ? void 0 : _j.wait.conversation)}`]: ({
71973
71978
  data: data2
@@ -74189,19 +74194,9 @@ const WidgetFormDisplay = react.exports.memo(({
74189
74194
  }, [companyUser == null ? void 0 : companyUser.email]);
74190
74195
  const customer = (data2 == null ? void 0 : data2.id) ? data2 : (_a = dataRef.current) == null ? void 0 : _a.customer;
74191
74196
  const getWaitingCustomers = async () => {
74197
+ var _a2, _b2;
74192
74198
  try {
74193
- const {
74194
- data: data22
74195
- } = await getWaitList({
74196
- status: "waiting",
74197
- orderBy: "createdAt",
74198
- order: "ASC",
74199
- limit: 1e3
74200
- });
74201
- const position2 = data22.findIndex((waitlist) => {
74202
- var _a2, _b2;
74203
- return (waitlist == null ? void 0 : waitlist.id) === ((_b2 = (_a2 = dataRef.current) == null ? void 0 : _a2.wait) == null ? void 0 : _b2.id);
74204
- });
74199
+ const position2 = await getWaitPosition((_b2 = (_a2 = dataRef.current) == null ? void 0 : _a2.wait) == null ? void 0 : _b2.createdAt);
74205
74200
  setState({
74206
74201
  customerCount: position2
74207
74202
  });
@@ -74221,39 +74216,48 @@ const WidgetFormDisplay = react.exports.memo(({
74221
74216
  }
74222
74217
  }, [socket2.connected, chatInit, customer == null ? void 0 : customer.id]);
74223
74218
  const quickStopChat = react.exports.useCallback(() => {
74224
- var _a2, _b2;
74219
+ var _a2, _b2, _c2, _d2;
74225
74220
  setState({
74226
74221
  chatInit: false,
74227
74222
  chatClose: true,
74228
74223
  companyClosed: companyIsClosed
74229
74224
  });
74230
- updateWait((_b2 = (_a2 = dataRef.current) == null ? void 0 : _a2.wait) == null ? void 0 : _b2.id, {
74231
- status: "missed"
74232
- });
74225
+ if (((_b2 = (_a2 = dataRef.current) == null ? void 0 : _a2.wait) == null ? void 0 : _b2.status) === "waiting") {
74226
+ updateWait((_d2 = (_c2 = dataRef.current) == null ? void 0 : _c2.wait) == null ? void 0 : _d2.id, {
74227
+ status: "missed"
74228
+ });
74229
+ }
74233
74230
  dataRef.current = null;
74234
74231
  }, [companyIsClosed, dataRef]);
74235
74232
  const setChatClose = (chatClose2, isAgent) => {
74236
- var _a2, _b2;
74233
+ var _a2, _b2, _c2, _d2, _e2, _f2;
74237
74234
  if (!isAgent) {
74238
74235
  t$3.emit("chat-ended");
74239
- updateWait((_b2 = (_a2 = dataRef.current) == null ? void 0 : _a2.wait) == null ? void 0 : _b2.id, {
74240
- status: "ended"
74236
+ if (((_b2 = (_a2 = dataRef.current) == null ? void 0 : _a2.wait) == null ? void 0 : _b2.status) === "waiting") {
74237
+ updateWait((_d2 = (_c2 = dataRef.current) == null ? void 0 : _c2.wait) == null ? void 0 : _d2.id, {
74238
+ status: "missed"
74239
+ });
74240
+ } else {
74241
+ updateWait((_f2 = (_e2 = dataRef.current) == null ? void 0 : _e2.wait) == null ? void 0 : _f2.id, {
74242
+ status: "ended"
74243
+ });
74244
+ }
74245
+ setState({
74246
+ chatClose: chatClose2
74241
74247
  });
74242
74248
  }
74243
- setState({
74244
- chatClose: chatClose2
74245
- });
74246
74249
  };
74247
74250
  o$3({
74248
74251
  listeners: {
74249
74252
  "video-toggle": (videoToggle2) => setState({
74250
74253
  videoToggle: videoToggle2
74251
74254
  }),
74252
- "agent-joined": async (agent2) => {
74253
- if (!stateRef.current.agent) {
74254
- if (typeof agent2 === "string" || !(agent2 == null ? void 0 : agent2.agent)) {
74255
+ "agent-joined": async (agentUser) => {
74256
+ var _a2, _b2;
74257
+ if (agentUser.user_type === "agent" && (!stateRef.current.agent || ((_a2 = stateRef.current.agent) == null ? void 0 : _a2.id) !== ((_b2 = agentUser == null ? void 0 : agentUser.agent) == null ? void 0 : _b2.id))) {
74258
+ if (!(agentUser == null ? void 0 : agentUser.agent)) {
74255
74259
  try {
74256
- const user$1 = await user(typeof agent2 === "string" ? agent2 : agent2 == null ? void 0 : agent2.id);
74260
+ const user$1 = await user(agentUser == null ? void 0 : agentUser.id);
74257
74261
  const agentObj = {
74258
74262
  ...user$1,
74259
74263
  user: user$1
@@ -74267,8 +74271,8 @@ const WidgetFormDisplay = react.exports.memo(({
74267
74271
  }
74268
74272
  } else {
74269
74273
  const agentObj = {
74270
- ...agent2.agent,
74271
- user: agent2
74274
+ ...agentUser.agent,
74275
+ user: agentUser
74272
74276
  };
74273
74277
  setState({
74274
74278
  agent: agentObj
@@ -74278,9 +74282,15 @@ const WidgetFormDisplay = react.exports.memo(({
74278
74282
  }
74279
74283
  }
74280
74284
  }, [stateRef]);
74281
- const listeners2 = react.exports.useMemo(() => ({
74282
- "WaitList.connected": async () => await getWaitingCustomers()
74283
- }), [(_e = (_d = dataRef.current) == null ? void 0 : _d.wait) == null ? void 0 : _e.id, t$3, customer]);
74285
+ const listeners2 = react.exports.useMemo(() => {
74286
+ var _a2, _b2;
74287
+ return {
74288
+ "WaitList.connected": async () => await getWaitingCustomers(),
74289
+ [`agent.connected.${(_b2 = (_a2 = dataRef.current) == null ? void 0 : _a2.wait) == null ? void 0 : _b2.id}`]: () => {
74290
+ dataRef.current.wait.status = "connected";
74291
+ }
74292
+ };
74293
+ }, [(_e = (_d = dataRef.current) == null ? void 0 : _d.wait) == null ? void 0 : _e.id, t$3, customer]);
74284
74294
  useSocketListeners({
74285
74295
  listeners: listeners2
74286
74296
  });
@@ -74310,7 +74320,7 @@ const WidgetFormDisplay = react.exports.memo(({
74310
74320
  paddingLeft: "4%",
74311
74321
  backgroundColor: `${hex_code}`
74312
74322
  },
74313
- children: ["You have ", customerCount > 0 ? customerCount : 0, " customer(s) ahead of you!"]
74323
+ children: ["You have ", customerCount, " customer(s) ahead of you!"]
74314
74324
  }), /* @__PURE__ */ jsx(LongestWaitime, {})]
74315
74325
  })
74316
74326
  }), /* @__PURE__ */ jsx("div", {