@sawport/react-sdk 1.0.8 → 1.0.9

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
@@ -67909,7 +67909,7 @@ const immerImpl = (initializer) => (set2, get2, store) => {
67909
67909
  return initializer(store.setState, get2, store);
67910
67910
  };
67911
67911
  const immer = immerImpl;
67912
- const __vite_import_meta_env__ = { "BASE_URL": "/", "DEV": false, "MODE": "production", "PROD": true, "SSR": false, "VITE_API_URL": "http://localhost:5000/api/v1/", "VITE_BASE_URL": "http://localhost:5000", "VITE_PROJECT_ID": "dc956202-5374-4256-985e-a492fcd26992" };
67912
+ const __vite_import_meta_env__ = { "BASE_URL": "/", "DEV": false, "MODE": "production", "PROD": true, "SSR": false };
67913
67913
  const trackedConnections = /* @__PURE__ */ new Map();
67914
67914
  const getTrackedConnectionState = (name) => {
67915
67915
  const api2 = trackedConnections.get(name);
@@ -101684,10 +101684,10 @@ const SlotPicker = memo(
101684
101684
  } = useRequest({ asyncRequest: getSlots });
101685
101685
  const disabledTime = useCallback(
101686
101686
  () => ({
101687
- disabledHours: () => getDisabledHours(workHours, timezone2, date4),
101687
+ disabledHours: () => getDisabledHours(workHours, timezone2, date4, data2, callRequestDuration),
101688
101688
  disabledMinutes: (selectedHour) => getDisabledMinutes(workHours, timezone2, date4, selectedHour, data2)
101689
101689
  }),
101690
- [date4, workHours, timezone2, data2]
101690
+ [date4, workHours, timezone2, data2, callRequestDuration]
101691
101691
  );
101692
101692
  const disabledDate = useCallback(
101693
101693
  (current2) => {
@@ -101734,69 +101734,99 @@ const SlotPicker = memo(
101734
101734
  ] });
101735
101735
  }
101736
101736
  );
101737
- const getDisabledHours = (workHours, timezone2, date4) => {
101737
+ const getDisabledHours = (workHours, timezone2, date4, slotsData, callRequestDuration) => {
101738
101738
  if (!date4) return [];
101739
- const foreignDate = hooks.tz(date4, timezone2);
101740
- const day = foreignDate.format("dddd");
101741
101739
  const hoursSet = /* @__PURE__ */ new Set();
101742
- const { times } = workHours[day];
101743
- times.forEach((time2) => {
101744
- if (time2.length !== 2) return;
101745
- const [start, end] = time2;
101746
- const startTime = hooks.tz(`${foreignDate.format("YYYY-MM-DD")} ${start}`, timezone2).local();
101747
- const endTime = hooks.tz(`${foreignDate.format("YYYY-MM-DD")} ${end}`, timezone2).local();
101748
- if (startTime.isSameOrAfter(endTime)) {
101749
- for (let i2 = 0; i2 < startTime.hour(); i2++) {
101750
- hoursSet.add(i2);
101751
- }
101752
- for (let i2 = endTime.hour(); i2 < 24; i2++) {
101753
- hoursSet.add(i2);
101754
- }
101755
- } else {
101756
- for (let i2 = 0; i2 < startTime.hour(); i2++) {
101757
- hoursSet.add(i2);
101740
+ const formattedDate = hooks(date4).format("YYYY-MM-DD");
101741
+ const isToday = formattedDate === hooks().format("YYYY-MM-DD");
101742
+ const currentHour = hooks().hour();
101743
+ for (let localHour = 0; localHour < 24; localHour++) {
101744
+ if (isToday && localHour < currentHour) {
101745
+ hoursSet.add(localHour);
101746
+ continue;
101747
+ }
101748
+ const localDatetime = hooks(`${date4} ${localHour}:00`);
101749
+ const foreignDatetime = localDatetime.clone().tz(timezone2);
101750
+ const foreignDay = foreignDatetime.format("dddd");
101751
+ const { times, closed } = workHours[foreignDay];
101752
+ if (closed) {
101753
+ hoursSet.add(localHour);
101754
+ continue;
101755
+ }
101756
+ const isWithinOpenHours = times.some((time2) => {
101757
+ if (!time2 || time2.length !== 2) return false;
101758
+ try {
101759
+ const [start, end] = time2;
101760
+ const startTime = hooks.tz(`${date4} ${start}`, timezone2);
101761
+ const endTime = hooks.tz(`${date4} ${end}`, timezone2);
101762
+ return foreignDatetime.isBetween(startTime, endTime, void 0, "[)");
101763
+ } catch (error) {
101764
+ console.error("Error checking work hours", error);
101765
+ return false;
101758
101766
  }
101759
- for (let i2 = endTime.hour(); i2 < 24; i2++) {
101760
- hoursSet.add(i2);
101767
+ });
101768
+ if (!isWithinOpenHours) {
101769
+ hoursSet.add(localHour);
101770
+ }
101771
+ if (slotsData && date4) {
101772
+ const minuteIntervals = generateMinuteIntervals(callRequestDuration || 30);
101773
+ const allIntervalsFull = minuteIntervals.every((minute) => {
101774
+ const floatTime = localHour + minute / 60;
101775
+ return slotsData[formattedDate] && slotsData[formattedDate][floatTime] && slotsData[formattedDate][floatTime].full;
101776
+ });
101777
+ if (allIntervalsFull) {
101778
+ hoursSet.add(localHour);
101761
101779
  }
101762
101780
  }
101763
- });
101781
+ }
101764
101782
  return [...hoursSet];
101765
101783
  };
101766
- const getDisabledMinutes = (workHours, timezone2, date4, selectedHour, data2) => {
101767
- if (!date4 || selectedHour === void 0) return [];
101768
- const currentDate = hooks.tz(date4, timezone2);
101769
- const day = currentDate.format("dddd");
101784
+ const getDisabledMinutes = (workHours, timezone2, date4, selectedHour, slotsData) => {
101785
+ if (!date4) return [];
101770
101786
  const minutesSet = /* @__PURE__ */ new Set();
101771
- const { times } = workHours[day];
101772
- times.forEach((time2) => {
101773
- var _a, _b;
101774
- if (time2.length !== 2) return;
101775
- const [start, end] = time2;
101776
- const startMoment = hooks.tz(`${currentDate.format("YYYY-MM-DD")} ${start}`, timezone2);
101777
- const endMoment = hooks.tz(`${currentDate.format("YYYY-MM-DD")} ${end}`, timezone2);
101778
- if ((_b = (_a = data2 == null ? void 0 : data2[date4]) == null ? void 0 : _a[selectedHour]) == null ? void 0 : _b.full) {
101779
- minutesSet.add(0);
101787
+ const currentMoment = hooks();
101788
+ for (let localMinute = 0; localMinute < 60; localMinute++) {
101789
+ const localDatetime = hooks(
101790
+ `${date4} ${selectedHour}:${localMinute.toString().padStart(2, "0")}`
101791
+ );
101792
+ const foreignDatetime = localDatetime.clone().tz(timezone2);
101793
+ const foreignDay = foreignDatetime.format("dddd");
101794
+ const { times, closed } = workHours[foreignDay];
101795
+ if (closed) {
101796
+ minutesSet.add(localMinute);
101797
+ continue;
101798
+ }
101799
+ const isWithinOpenHours = times.some((time2) => {
101800
+ if (time2.length !== 2) return false;
101801
+ const [start, end] = time2;
101802
+ const startTime = hooks.tz(`${date4} ${start}`, timezone2);
101803
+ const endTime = hooks.tz(`${date4} ${end}`, timezone2);
101804
+ return foreignDatetime.isBetween(startTime, endTime, void 0, "[)");
101805
+ });
101806
+ if (!isWithinOpenHours) {
101807
+ minutesSet.add(localMinute);
101780
101808
  }
101781
- if (selectedHour === startMoment.hour() && selectedHour === endMoment.hour()) {
101782
- for (let i2 = 0; i2 < startMoment.minute(); i2++) {
101783
- minutesSet.add(i2);
101784
- }
101785
- for (let i2 = endMoment.minute(); i2 < 60; i2++) {
101786
- minutesSet.add(i2);
101787
- }
101788
- } else if (selectedHour === startMoment.hour()) {
101789
- for (let i2 = 0; i2 < startMoment.minute(); i2++) {
101790
- minutesSet.add(i2);
101791
- }
101792
- } else if (selectedHour === endMoment.hour()) {
101793
- for (let i2 = endMoment.minute(); i2 < 60; i2++) {
101794
- minutesSet.add(i2);
101809
+ if (slotsData && date4) {
101810
+ const formattedDate = hooks(date4).format("YYYY-MM-DD");
101811
+ const hour = selectedHour;
101812
+ const floatTime = hour + localMinute / 60;
101813
+ if (slotsData[formattedDate] && slotsData[formattedDate][floatTime] && slotsData[formattedDate][floatTime].full) {
101814
+ minutesSet.add(localMinute);
101795
101815
  }
101796
101816
  }
101797
- });
101817
+ if (date4 === currentMoment.format("YYYY-MM-DD") && selectedHour <= currentMoment.hour() && localMinute < currentMoment.minute()) {
101818
+ minutesSet.add(localMinute);
101819
+ }
101820
+ }
101798
101821
  return [...minutesSet];
101799
101822
  };
101823
+ function generateMinuteIntervals(interval) {
101824
+ const intervals = [];
101825
+ for (let minute = 0; minute < 60; minute += interval) {
101826
+ intervals.push(minute);
101827
+ }
101828
+ return intervals;
101829
+ }
101800
101830
  const getWaitConnectors = async (data2) => api("wait-connectors", data2);
101801
101831
  const getLongestWaitTime = async (data2) => api("waits/longest", data2);
101802
101832
  const updateWait = async (id2, data2) => api(`waits/${id2}`, data2, "put");
@@ -102037,16 +102067,29 @@ const Offline = memo(
102037
102067
  }),
102038
102068
  time: create$4().required("Please specify a time").test("time", "Selected time is out of Hours of Operation", function(value, prop) {
102039
102069
  if (!prop.parent.date || !value) return false;
102040
- const dayName = hooks.tz(prop.parent.date, companyTimezone).format("dddd");
102041
- const dateString = hooks(prop.parent.date).format("YYYY-MM-DD");
102042
- const [fromTime, toTime] = workHours[dayName].times[0];
102043
- const datetime = hooks(prop.parent.date).clone().set({
102044
- hours: parseInt(value.split(":")[0], 10),
102045
- minutes: parseInt(value.split(":")[1], 10)
102046
- }).tz(companyTimezone);
102047
- const startTime = hooks.tz(`${dateString} ${fromTime}`, companyTimezone);
102048
- const endTime = hooks.tz(`${dateString} ${toTime}`, companyTimezone);
102049
- return datetime.isBetween(startTime, endTime, "minute", "[]");
102070
+ const selectedDate = prop.parent.date;
102071
+ const [hours2, minutes2] = value.split(":").map((v2) => parseInt(v2, 10));
102072
+ const now2 = hooks().tz(companyTimezone);
102073
+ const selectedDateTime = hooks(selectedDate).clone().set({ hours: hours2, minutes: minutes2 }).tz(companyTimezone);
102074
+ if (selectedDateTime.isBefore(now2)) {
102075
+ return this.createError({ message: "Cannot schedule in the past" });
102076
+ }
102077
+ const dayName = selectedDateTime.format("dddd");
102078
+ if (workHours[dayName].closed) {
102079
+ return this.createError({ message: `${dayName} is not a business day` });
102080
+ }
102081
+ const isWithinBusinessHours = workHours[dayName].times.some((timeRange) => {
102082
+ if (timeRange.length !== 2) return false;
102083
+ const [start, end] = timeRange;
102084
+ const dateString = selectedDateTime.format("YYYY-MM-DD");
102085
+ const startTime = hooks.tz(`${dateString} ${start}`, companyTimezone);
102086
+ const endTime = hooks.tz(`${dateString} ${end}`, companyTimezone);
102087
+ return selectedDateTime.isBetween(startTime, endTime, "minute", "[]");
102088
+ });
102089
+ if (!isWithinBusinessHours) {
102090
+ return this.createError({ message: "Selected time is outside business hours" });
102091
+ }
102092
+ return true;
102050
102093
  }),
102051
102094
  reason: create$4().min(1).required("Reason is required"),
102052
102095
  mobile: create$4().min(7).required(),
@@ -103287,7 +103330,7 @@ function ChatWidgetScreen({
103287
103330
  ] });
103288
103331
  }
103289
103332
  const ChatInput = memo(function({ company }) {
103290
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
103333
+ var _a, _b, _c, _d, _e, _f, _g, _h;
103291
103334
  const {
103292
103335
  dataRef,
103293
103336
  scheduleReminderCanceled,
@@ -103302,6 +103345,7 @@ const ChatInput = memo(function({ company }) {
103302
103345
  waitlistTransferredStatus: void 0,
103303
103346
  transferredAgent: void 0
103304
103347
  });
103348
+ const [isSending, setIsSending] = useState(false);
103305
103349
  const handleCancel = () => {
103306
103350
  setPopupVisible(false);
103307
103351
  setScheduleReminderCanceled(true);
@@ -103319,19 +103363,27 @@ const ChatInput = memo(function({ company }) {
103319
103363
  const { socket: socket2 } = useSocket();
103320
103364
  const sendMessage = async () => {
103321
103365
  var _a2, _b2, _c2;
103322
- if (((_a2 = stateRef.current.messageText) == null ? void 0 : _a2.length) || stateRef.current.chatFiles) {
103323
- socket2.emit("messageFromClient", {
103324
- message: stateRef.current.messageText,
103325
- conversation: (_b2 = dataRef == null ? void 0 : dataRef.wait) == null ? void 0 : _b2.conversation.id,
103326
- customer: ((_c2 = dataRef == null ? void 0 : dataRef.customer) == null ? void 0 : _c2.id) || (dataRef == null ? void 0 : dataRef.customer)
103327
- });
103366
+ if (isSending) return;
103367
+ setIsSending(true);
103368
+ try {
103369
+ if (((_a2 = stateRef.current.messageText) == null ? void 0 : _a2.length) || stateRef.current.chatFiles) {
103370
+ socket2.emit("messageFromClient", {
103371
+ message: stateRef.current.messageText,
103372
+ conversation: (_b2 = dataRef == null ? void 0 : dataRef.wait) == null ? void 0 : _b2.conversation.id,
103373
+ customer: ((_c2 = dataRef == null ? void 0 : dataRef.customer) == null ? void 0 : _c2.id) || (dataRef == null ? void 0 : dataRef.customer)
103374
+ });
103375
+ }
103376
+ document.getElementById("widget-chat-input-field").value = "";
103377
+ document.getElementById("widget-file-upload-input").value = "";
103378
+ setState({ chatFiles: null, messageText: "" });
103379
+ } finally {
103380
+ setIsSending(false);
103328
103381
  }
103329
- document.getElementById("widget-chat-input-field").value = "";
103330
- document.getElementById("widget-file-upload-input").value = "";
103331
- setState({ chatFiles: null, messageText: "" });
103332
103382
  };
103333
103383
  const sendFile = useCallback(async () => {
103334
103384
  var _a2, _b2, _c2;
103385
+ if (isSending) return;
103386
+ setIsSending(true);
103335
103387
  try {
103336
103388
  const data2 = new FormData();
103337
103389
  data2.append("customer", (_a2 = dataRef == null ? void 0 : dataRef.customer) == null ? void 0 : _a2.id);
@@ -103348,8 +103400,10 @@ const ChatInput = memo(function({ company }) {
103348
103400
  setState({ chatFiles: null, messageText: "" });
103349
103401
  } catch (error) {
103350
103402
  console.error(error);
103403
+ } finally {
103404
+ setIsSending(false);
103351
103405
  }
103352
- }, [stateRef, dataRef, setState]);
103406
+ }, [stateRef, dataRef, setState, isSending]);
103353
103407
  const handleFileUpload = (event) => {
103354
103408
  var _a2, _b2;
103355
103409
  if ((_b2 = (_a2 = event == null ? void 0 : event.target) == null ? void 0 : _a2.files) == null ? void 0 : _b2[0]) {
@@ -103363,7 +103417,7 @@ const ChatInput = memo(function({ company }) {
103363
103417
  }
103364
103418
  setState({ chatFiles: event.target.files[0] });
103365
103419
  } else {
103366
- y.info("File forrmat not supported");
103420
+ y.info("File format not supported");
103367
103421
  return;
103368
103422
  }
103369
103423
  }
@@ -103479,7 +103533,7 @@ const ChatInput = memo(function({ company }) {
103479
103533
  id: "widget-chat-input-field",
103480
103534
  autoComplete: "off",
103481
103535
  autoFocus: true,
103482
- disabled: ((_i = document.getElementById("widget-file-upload-input")) == null ? void 0 : _i.value) !== ""
103536
+ disabled: isSending
103483
103537
  }
103484
103538
  ),
103485
103539
  /* @__PURE__ */ jsxRuntimeExports.jsx(