@sawport/react-sdk 1.0.8 → 1.0.9-alpha.0
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 +130 -76
- package/dist/index.umd.js +2 -2
- package/package.json +1 -1
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
|
|
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
|
|
101743
|
-
|
|
101744
|
-
|
|
101745
|
-
|
|
101746
|
-
|
|
101747
|
-
|
|
101748
|
-
|
|
101749
|
-
|
|
101750
|
-
|
|
101751
|
-
|
|
101752
|
-
|
|
101753
|
-
|
|
101754
|
-
|
|
101755
|
-
|
|
101756
|
-
|
|
101757
|
-
|
|
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
|
-
|
|
101760
|
-
|
|
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,
|
|
101767
|
-
if (!date4
|
|
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
|
|
101772
|
-
|
|
101773
|
-
|
|
101774
|
-
|
|
101775
|
-
|
|
101776
|
-
const
|
|
101777
|
-
const
|
|
101778
|
-
|
|
101779
|
-
|
|
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 (
|
|
101782
|
-
|
|
101783
|
-
|
|
101784
|
-
|
|
101785
|
-
|
|
101786
|
-
minutesSet.add(
|
|
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
|
|
102041
|
-
const
|
|
102042
|
-
const
|
|
102043
|
-
const
|
|
102044
|
-
|
|
102045
|
-
|
|
102046
|
-
}
|
|
102047
|
-
const
|
|
102048
|
-
|
|
102049
|
-
|
|
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
|
|
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 (
|
|
103323
|
-
|
|
103324
|
-
|
|
103325
|
-
|
|
103326
|
-
|
|
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
|
|
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:
|
|
103536
|
+
disabled: isSending
|
|
103483
103537
|
}
|
|
103484
103538
|
),
|
|
103485
103539
|
/* @__PURE__ */ jsxRuntimeExports.jsx(
|