@sawport/react-sdk 0.1.0-alpha.66 → 0.1.0-alpha.68

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
@@ -24043,7 +24043,12 @@ const exts = {
24043
24043
  mpg: "video",
24044
24044
  "3pg": "video",
24045
24045
  wmv: "video",
24046
- mp4: "video"
24046
+ mp4: "video",
24047
+ doc: "document",
24048
+ docx: "document",
24049
+ docm: "document",
24050
+ odt: "document",
24051
+ pdf: "document"
24047
24052
  };
24048
24053
  const isFileType = (ext) => exts[ext];
24049
24054
  const getUrlExt = (url3) => {
@@ -67215,7 +67220,8 @@ const SlotPicker = react.exports.memo(({
67215
67220
  days: days2,
67216
67221
  fromDay,
67217
67222
  toDay,
67218
- date: date4
67223
+ date: date4,
67224
+ timezone: timezone2
67219
67225
  }) => {
67220
67226
  const {
67221
67227
  state: {
@@ -67228,8 +67234,8 @@ const SlotPicker = react.exports.memo(({
67228
67234
  disabledHours: () => {
67229
67235
  var _a, _b, _c, _d;
67230
67236
  const times = [];
67231
- const timeformat = "hh:mm:ss";
67232
- const from2 = hooks(fromTime, timeformat).get("h"), to2 = hooks(toTime, timeformat).get("h");
67237
+ const timeformat = "HH:mm:ss";
67238
+ const from2 = hooks.tz(fromTime, timeformat, timezone2).local().get("h"), to2 = hooks.tz(toTime, timeformat, timezone2).local().get("h");
67233
67239
  for (let index2 = 0; index2 <= 23; index2++) {
67234
67240
  const half = parseFloat(`${index2}.3`);
67235
67241
  if (!(index2 >= from2 && index2 < to2) || ((_b = (_a = data2 == null ? void 0 : data2[date4]) == null ? void 0 : _a[index2]) == null ? void 0 : _b.full) && ((_d = (_c = data2 == null ? void 0 : data2[date4]) == null ? void 0 : _c[half]) == null ? void 0 : _d.full)) {
@@ -67250,7 +67256,7 @@ const SlotPicker = react.exports.memo(({
67250
67256
  }
67251
67257
  return mins;
67252
67258
  }
67253
- }), [toTime, fromTime, date4, data2]);
67259
+ }), [toTime, fromTime, date4, data2, timezone2]);
67254
67260
  const disabledDate = react.exports.useCallback((current) => {
67255
67261
  const day = current.day();
67256
67262
  return hooks(hooks().subtract(1, "d")).isSameOrAfter(current.toDate()) || !(day >= days2[fromDay] && day <= days2[toDay]);
@@ -67314,7 +67320,8 @@ const SlotPicker = react.exports.memo(({
67314
67320
  name: "time"
67315
67321
  }
67316
67322
  }),
67317
- status: errors["time"] && "error"
67323
+ status: errors["time"] && "error",
67324
+ disabled: !date4
67318
67325
  })]
67319
67326
  })]
67320
67327
  });
@@ -67344,7 +67351,8 @@ const Offline = react.exports.memo(({
67344
67351
  customer,
67345
67352
  fields,
67346
67353
  quickStopChat,
67347
- offlineMode
67354
+ offlineMode,
67355
+ timezone: companyTimezone
67348
67356
  }) => {
67349
67357
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
67350
67358
  const callRequestOptions = [...(options == null ? void 0 : options.enableVoicenote) ? ["Leave a voice note"] : [], ...options.callRequestOptions || []];
@@ -67373,7 +67381,7 @@ const Offline = react.exports.memo(({
67373
67381
  timezone: void 0
67374
67382
  });
67375
67383
  const saved = react.exports.useRef();
67376
- const offlineSchema = create$1().shape({
67384
+ const offlineSchema = react.exports.useMemo(() => create$1().shape({
67377
67385
  full_name: create$4().required("Your full name is required"),
67378
67386
  email: create$4().email().required(),
67379
67387
  account: create$3().min(5).required("Your account no. is required"),
@@ -67383,14 +67391,15 @@ const Offline = react.exports.memo(({
67383
67391
  const endDay = days$1[toDay];
67384
67392
  return day >= startDay && day <= endDay;
67385
67393
  }),
67386
- time: create$4().min(4).required("Please specify a time").test("time", "Selected time is out of Hours of Operation", function(value2) {
67387
- const timeformat = "hh:mm:ss";
67388
- const check2 = hooks(value2, timeformat), beforeTime = hooks(fromTime, timeformat), afterTime = hooks(toTime, timeformat);
67389
- return hooks(check2).isBetween(beforeTime, afterTime);
67394
+ time: create$4().required("Please specify a time").test("time", "Selected time is out of Hours of Operation", function(value2, prop) {
67395
+ const timeformat = "HH:mm:ss";
67396
+ const check2 = hooks(value2, timeformat), beforeTime = hooks.tz(fromTime, timeformat, companyTimezone).local(), afterTime = hooks.tz(toTime, timeformat, companyTimezone).local();
67397
+ const isToday = hooks(prop.parent.date).isSame(hooks(), "D");
67398
+ return isToday ? check2.isSameOrAfter(hooks()) && check2.isSameOrBefore(afterTime) : check2.isSameOrAfter(beforeTime) && check2.isSameOrBefore(afterTime);
67390
67399
  }),
67391
67400
  reason: create$4().min(1).required("Reason is required"),
67392
67401
  mobile: create$4().min(7).required()
67393
- });
67402
+ }), [companyTimezone, days$1, fromDay, toDay, fromTime, toTime]);
67394
67403
  const emptyFields = react.exports.useMemo(() => {
67395
67404
  const filledState = {};
67396
67405
  fields && Object.keys(fields || {}).map((key) => {
@@ -67554,7 +67563,10 @@ const Offline = react.exports.memo(({
67554
67563
  scheduled: false
67555
67564
  });
67556
67565
  if (offlineMode) {
67557
- quickStopChat();
67566
+ quickStopChat({
67567
+ companyClosed: false,
67568
+ offlineMode: false
67569
+ });
67558
67570
  }
67559
67571
  };
67560
67572
  return /* @__PURE__ */ jsx("div", {
@@ -67653,7 +67665,8 @@ const Offline = react.exports.memo(({
67653
67665
  days: days$1,
67654
67666
  fromDay,
67655
67667
  toDay,
67656
- date: values.date
67668
+ date: values.date,
67669
+ timezone: companyTimezone
67657
67670
  }), /* @__PURE__ */ jsx(FInput, {
67658
67671
  style: {
67659
67672
  borderRight: void 0,
@@ -71882,14 +71895,14 @@ function ChatWidgetScreen({
71882
71895
  dataRef,
71883
71896
  setChatClose,
71884
71897
  videoRef,
71885
- companyUser,
71886
- calendar: calendar2,
71887
- setIsScheduling,
71888
71898
  company,
71889
- quickStopChat,
71890
- isOngoingChat
71899
+ isOngoingChat,
71900
+ handleOk,
71901
+ popupVisible,
71902
+ handleCancel,
71903
+ setPopupVisible
71891
71904
  }) {
71892
- var _a, _b, _c, _d, _e, _f, _g, _h;
71905
+ var _a, _b, _c, _d, _e, _f, _g;
71893
71906
  const bottomRef = react.exports.useRef();
71894
71907
  const [{
71895
71908
  typingEvent,
@@ -71904,8 +71917,6 @@ function ChatWidgetScreen({
71904
71917
  transferredAgent: null,
71905
71918
  agentConnected: false
71906
71919
  });
71907
- const [popupVisible, setPopupVisible] = useState(false);
71908
- const [offlineMode, setOfflineMode] = useState(false);
71909
71920
  const [timeoutTriggered, setTimeoutTriggered] = useState(false);
71910
71921
  const popupTime = ((_a = company == null ? void 0 : company.options) == null ? void 0 : _a.schedulePopUpTime) || 5;
71911
71922
  const {
@@ -71933,7 +71944,7 @@ function ChatWidgetScreen({
71933
71944
  state.transferredAgent = null;
71934
71945
  });
71935
71946
  const listeners2 = react.exports.useMemo(() => {
71936
- var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i, _j;
71947
+ var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h, _i, _j;
71937
71948
  return {
71938
71949
  [`message.new.${((_a2 = dataRef.current) == null ? void 0 : _a2.wait.conversation.id) || ((_b2 = dataRef.current) == null ? void 0 : _b2.wait.conversation)}`]: async ({
71939
71950
  message
@@ -71984,7 +71995,7 @@ function ChatWidgetScreen({
71984
71995
  state.transferredAgent = agent;
71985
71996
  });
71986
71997
  },
71987
- [`WaitList.transferred.${((_g2 = dataRef.current) == null ? void 0 : _g2.wait.conversation.id) || ((_h2 = dataRef.current) == null ? void 0 : _h2.wait.conversation)}`]: ({
71998
+ [`WaitList.transferred.${((_g2 = dataRef.current) == null ? void 0 : _g2.wait.conversation.id) || ((_h = dataRef.current) == null ? void 0 : _h.wait.conversation)}`]: ({
71988
71999
  agent
71989
72000
  }) => {
71990
72001
  setEvent((state) => {
@@ -72020,11 +72031,6 @@ function ChatWidgetScreen({
72020
72031
  useSocketListeners({
72021
72032
  listeners: listeners2
72022
72033
  });
72023
- const handleOk = () => {
72024
- setOfflineMode(true);
72025
- setPopupVisible(false);
72026
- };
72027
- const handleCancel = () => setPopupVisible(false);
72028
72034
  react.exports.useEffect(() => {
72029
72035
  if (isOngoingChat) {
72030
72036
  setTimeoutTriggered(true);
@@ -72047,59 +72053,41 @@ function ChatWidgetScreen({
72047
72053
  clearTimeout(timer);
72048
72054
  };
72049
72055
  }, [popupTime, agentDetails, timeoutTriggered]);
72050
- return /* @__PURE__ */ jsx(Fragment, {
72051
- children: offlineMode ? /* @__PURE__ */ jsx(Offline, {
72052
- companyUser,
72053
- customer: (_h = dataRef.current) == null ? void 0 : _h.customer,
72054
- fields: company == null ? void 0 : company.fields,
72055
- company_id: company == null ? void 0 : company.id,
72056
- calendar: calendar2,
72057
- hexcode: company == null ? void 0 : company.hex_code,
72058
- website_name: company == null ? void 0 : company.name,
72059
- setIsScheduling,
72060
- toTime: company == null ? void 0 : company.to_time,
72061
- fromTime: company == null ? void 0 : company.from_time,
72062
- toDay: company == null ? void 0 : company.to_day,
72063
- fromDay: company == null ? void 0 : company.from_day,
72064
- options: (company == null ? void 0 : company.options) || {},
72065
- offlineMode,
72066
- quickStopChat
72067
- }) : /* @__PURE__ */ jsxs("div", {
72068
- className: "widget-chat-container",
72069
- children: [/* @__PURE__ */ jsxs("div", {
72070
- id: "widget-chat-send",
72071
- className: "widget-chat-display-container",
72072
- children: [/* @__PURE__ */ jsx("div", {
72073
- className: "chat-receive-container mb-4 d-flex align-items-center",
72074
- children: /* @__PURE__ */ jsx("p", {
72075
- className: `widget-chat-receive mb-0`,
72076
- children: welcome_message
72077
- })
72078
- }), /* @__PURE__ */ jsx(Messages, {
72079
- chatMessages: messages2,
72080
- dataRef,
72081
- companyColor: company == null ? void 0 : company.hex_code
72082
- }), /* @__PURE__ */ jsx("div", {
72083
- ref: bottomRef,
72084
- className: "chat-bottom"
72085
- })]
72086
- }), /* @__PURE__ */ jsx(ChatInput, {
72056
+ return /* @__PURE__ */ jsxs("div", {
72057
+ className: "widget-chat-container",
72058
+ children: [/* @__PURE__ */ jsxs("div", {
72059
+ id: "widget-chat-send",
72060
+ className: "widget-chat-display-container",
72061
+ children: [/* @__PURE__ */ jsx("div", {
72062
+ className: "chat-receive-container mb-4 d-flex align-items-center",
72063
+ children: /* @__PURE__ */ jsx("p", {
72064
+ className: `widget-chat-receive mb-0`,
72065
+ children: welcome_message
72066
+ })
72067
+ }), /* @__PURE__ */ jsx(Messages, {
72068
+ chatMessages: messages2,
72087
72069
  dataRef,
72088
- agentDetails,
72089
- transferredAgent,
72090
- waitlistTransferredStatus,
72091
- agentConnected,
72092
- popupVisible,
72093
- handleCancel,
72094
- handleOk
72095
- }), /* @__PURE__ */ jsx("span", {
72096
- style: {
72097
- fontStyle: "italic",
72098
- fontSize: "10px"
72099
- },
72100
- children: agentDetails && typingEvent ? `${agentDetails == null ? void 0 : agentDetails.firstName} is typing...` : ""
72070
+ companyColor: company == null ? void 0 : company.hex_code
72071
+ }), /* @__PURE__ */ jsx("div", {
72072
+ ref: bottomRef,
72073
+ className: "chat-bottom"
72101
72074
  })]
72102
- })
72075
+ }), /* @__PURE__ */ jsx(ChatInput, {
72076
+ dataRef,
72077
+ agentDetails,
72078
+ transferredAgent,
72079
+ waitlistTransferredStatus,
72080
+ agentConnected,
72081
+ popupVisible,
72082
+ handleCancel,
72083
+ handleOk
72084
+ }), /* @__PURE__ */ jsx("span", {
72085
+ style: {
72086
+ fontStyle: "italic",
72087
+ fontSize: "10px"
72088
+ },
72089
+ children: agentDetails && typingEvent ? `${agentDetails == null ? void 0 : agentDetails.firstName} is typing...` : ""
72090
+ })]
72103
72091
  });
72104
72092
  }
72105
72093
  const ChatInput = react.exports.memo(function({
@@ -72161,10 +72149,25 @@ const ChatInput = react.exports.memo(function({
72161
72149
  console.log(error);
72162
72150
  }
72163
72151
  }, [stateRef, dataRef, socket2.connected, stateRef]);
72164
- const handleFileUpload = (e2) => {
72165
- setState({
72166
- chatFiles: e2.target.files[0]
72167
- });
72152
+ const handleFileUpload = (event) => {
72153
+ var _a2, _b, _c;
72154
+ if ((_a2 = event == null ? void 0 : event.target) == null ? void 0 : _a2.files[0]) {
72155
+ const fileExtension = (_c = (_b = event == null ? void 0 : event.target) == null ? void 0 : _b.files[0]) == null ? void 0 : _c.type.split("/").pop();
72156
+ if (isFileType(fileExtension) === "document") {
72157
+ const file = event.target.files[0];
72158
+ const fileSizeLimit = 4 * 1024 * 1024;
72159
+ if (file.size > fileSizeLimit) {
72160
+ toast.info("File size exceeds the maximum limit (4 MB)");
72161
+ return;
72162
+ }
72163
+ setState({
72164
+ chatFiles: event.target.files[0]
72165
+ });
72166
+ } else {
72167
+ toast.info("File format not supported");
72168
+ return;
72169
+ }
72170
+ }
72168
72171
  };
72169
72172
  const handleEnterKeypress = (e2) => {
72170
72173
  if (e2.key === "Enter") {
@@ -72218,6 +72221,8 @@ const ChatInput = react.exports.memo(function({
72218
72221
  id: "widget-chat-input-field",
72219
72222
  autoComplete: "off",
72220
72223
  autoFocus: true,
72224
+ accept: ".docx, .pdf, .rtf, .txt, .doc",
72225
+ max: "4194304",
72221
72226
  disabled: ((_a = document.getElementById("widget-file-upload-input")) == null ? void 0 : _a.value) !== ""
72222
72227
  }), /* @__PURE__ */ jsx("img", {
72223
72228
  onClick: chatFiles ? sendFile : sendMessage,
@@ -72538,8 +72543,8 @@ function WidgetOfflineHeader({
72538
72543
  }), /* @__PURE__ */ jsx(SubTitle, {
72539
72544
  from_day: company == null ? void 0 : company.from_day.substring(0, 3),
72540
72545
  to_day: company == null ? void 0 : company.to_day.substring(0, 3),
72541
- from_time: hooks.tz(company == null ? void 0 : company.from_time, "hh:mm", company.timezone).local().format("hh:mm A"),
72542
- to_time: hooks.tz(company == null ? void 0 : company.to_time, "hh:mm", company.timezone).local().format("hh:mm A")
72546
+ from_time: hooks.tz(company == null ? void 0 : company.from_time, "HH:mm:ss", company.timezone).local().format("hh:mm A"),
72547
+ to_time: hooks.tz(company == null ? void 0 : company.to_time, "HH:mm:ss", company.timezone).local().format("hh:mm A")
72543
72548
  })]
72544
72549
  });
72545
72550
  }
@@ -74186,7 +74191,8 @@ const WidgetFormDisplay = react.exports.memo(({
74186
74191
  isScheduling,
74187
74192
  companyClosed,
74188
74193
  calendar: calendar2,
74189
- customerCount
74194
+ customerCount,
74195
+ offlineMode
74190
74196
  }, setState, stateRef] = useState({
74191
74197
  chatInit: false,
74192
74198
  chatClose: true,
@@ -74195,7 +74201,8 @@ const WidgetFormDisplay = react.exports.memo(({
74195
74201
  isScheduling: false,
74196
74202
  companyClosed: companyIsClosed,
74197
74203
  calendar: void 0,
74198
- customerCount: 0
74204
+ customerCount: 0,
74205
+ offlineMode: false
74199
74206
  });
74200
74207
  react.exports.useEffect(() => setState({
74201
74208
  companyClosed: companyIsClosed
@@ -74234,12 +74241,13 @@ const WidgetFormDisplay = react.exports.memo(({
74234
74241
  });
74235
74242
  }
74236
74243
  }, [socket2.connected, chatInit, customer == null ? void 0 : customer.id]);
74237
- const quickStopChat = react.exports.useCallback(() => {
74244
+ const quickStopChat = react.exports.useCallback((extraState = {}) => {
74238
74245
  var _a2, _b2, _c2, _d2;
74239
74246
  setState({
74240
74247
  chatInit: false,
74241
74248
  chatClose: true,
74242
- companyClosed: companyIsClosed
74249
+ companyClosed: companyIsClosed,
74250
+ ...extraState
74243
74251
  });
74244
74252
  if (((_b2 = (_a2 = dataRef.current) == null ? void 0 : _a2.wait) == null ? void 0 : _b2.status) === "waiting") {
74245
74253
  updateWait((_d2 = (_c2 = dataRef.current) == null ? void 0 : _c2.wait) == null ? void 0 : _d2.id, {
@@ -74364,7 +74372,10 @@ const WidgetFormDisplay = react.exports.memo(({
74364
74372
  fromTime: company == null ? void 0 : company.from_time,
74365
74373
  toDay: company == null ? void 0 : company.to_day,
74366
74374
  fromDay: company == null ? void 0 : company.from_day,
74367
- options: (company == null ? void 0 : company.options) || {}
74375
+ timezone: company == null ? void 0 : company.timezone,
74376
+ options: (company == null ? void 0 : company.options) || {},
74377
+ offlineMode,
74378
+ quickStopChat
74368
74379
  }) : chatInit && !chatClose ? /* @__PURE__ */ jsx(Feedback$1, {
74369
74380
  quickStopChat,
74370
74381
  agent,
@@ -74415,6 +74426,15 @@ const ChatMode = react.exports.memo(({
74415
74426
  }]
74416
74427
  });
74417
74428
  const [isOngoingChat, setIsOngoingChat] = useState(false);
74429
+ const [popupVisible, setPopupVisible] = useState(false);
74430
+ const handleOk = () => {
74431
+ setPopupVisible(false);
74432
+ quickStopChat({
74433
+ companyClosed: true,
74434
+ offlineMode: true
74435
+ });
74436
+ };
74437
+ const handleCancel = () => setPopupVisible(false);
74418
74438
  const agent_ = react.exports.useMemo(() => {
74419
74439
  var _a2, _b2;
74420
74440
  const connectors = (_a2 = data2 == null ? void 0 : data2[0]) == null ? void 0 : _a2.connectors;
@@ -74444,13 +74464,13 @@ const ChatMode = react.exports.memo(({
74444
74464
  dataRef,
74445
74465
  setChatClose,
74446
74466
  videoRef,
74447
- companyUser,
74448
- calendar: calendar2,
74449
- setIsScheduling,
74450
74467
  company,
74451
- quickStopChat,
74452
74468
  agent: agent_,
74453
- isOngoingChat
74469
+ isOngoingChat,
74470
+ handleOk,
74471
+ popupVisible,
74472
+ handleCancel,
74473
+ setPopupVisible
74454
74474
  });
74455
74475
  });
74456
74476
  const OngoingChat = ({