meeting-scheduler-npm-package 1.0.2 → 1.0.4
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/README.md +1 -1
- package/dist/components/MeetingScheduler.d.ts +23 -1
- package/dist/config.d.ts +1 -1
- package/dist/index.cjs.js +53 -17
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +53 -17
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/index.esm.js
CHANGED
|
@@ -486,10 +486,8 @@ function IoIosArrowBack (props) {
|
|
|
486
486
|
return GenIcon({"attr":{"viewBox":"0 0 512 512"},"child":[{"tag":"path","attr":{"d":"M294.1 256L167 129c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.3 34 0L345 239c9.1 9.1 9.3 23.7.7 33.1L201.1 417c-4.7 4.7-10.9 7-17 7s-12.3-2.3-17-7c-9.4-9.4-9.4-24.6 0-33.9l127-127.1z"},"child":[]}]})(props);
|
|
487
487
|
}
|
|
488
488
|
|
|
489
|
-
const API_BASE = "https://schedule-api.betopialimited.com/api";
|
|
490
|
-
|
|
491
489
|
const daysOfWeek = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];
|
|
492
|
-
const MeetingScheduler = ({ userId, availabilityId, authToken, onSuccess, onError, }) => {
|
|
490
|
+
const MeetingScheduler = ({ userId = 1, availabilityId = 1, authToken: propAuthToken, email = "superadmin1@gmail.com", password = "password", apiBase, onSuccess, onError, }) => {
|
|
493
491
|
const [currentMonth, setCurrentMonth] = useState(new Date());
|
|
494
492
|
const [selectedDate, setSelectedDate] = useState(null);
|
|
495
493
|
const [availableSlots, setAvailableSlots] = useState([]);
|
|
@@ -520,23 +518,49 @@ const MeetingScheduler = ({ userId, availabilityId, authToken, onSuccess, onErro
|
|
|
520
518
|
const today = new Date();
|
|
521
519
|
today.setHours(0, 0, 0, 0);
|
|
522
520
|
const isPastDate = (date) => date <= today;
|
|
521
|
+
/* ============ Auth ============ */
|
|
522
|
+
const getAuthToken = async () => {
|
|
523
|
+
var _a;
|
|
524
|
+
if (propAuthToken)
|
|
525
|
+
return propAuthToken;
|
|
526
|
+
const existing = localStorage.getItem("auth_token");
|
|
527
|
+
if (existing)
|
|
528
|
+
return existing;
|
|
529
|
+
try {
|
|
530
|
+
const res = await fetch(`${apiBase}/v1/user/login`, {
|
|
531
|
+
method: "POST",
|
|
532
|
+
headers: { "Content-Type": "application/json" },
|
|
533
|
+
body: JSON.stringify({ email, password }),
|
|
534
|
+
});
|
|
535
|
+
const data = await res.json();
|
|
536
|
+
const token = data.token || data.access_token || ((_a = data.data) === null || _a === void 0 ? void 0 : _a.token);
|
|
537
|
+
if (token)
|
|
538
|
+
localStorage.setItem("auth_token", token);
|
|
539
|
+
return token || null;
|
|
540
|
+
}
|
|
541
|
+
catch (_b) {
|
|
542
|
+
return null;
|
|
543
|
+
}
|
|
544
|
+
};
|
|
523
545
|
/* ============ API ============ */
|
|
524
546
|
const fetchSlots = async (date) => {
|
|
547
|
+
setLoading(true);
|
|
548
|
+
const token = await getAuthToken();
|
|
549
|
+
if (!token) {
|
|
550
|
+
onError === null || onError === void 0 ? void 0 : onError("Authentication failed");
|
|
551
|
+
setLoading(false);
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
const yyyy = date.getFullYear();
|
|
555
|
+
const mm = String(date.getMonth() + 1).padStart(2, "0");
|
|
556
|
+
const dd = String(date.getDate()).padStart(2, "0");
|
|
525
557
|
try {
|
|
526
|
-
|
|
527
|
-
const yyyy = date.getFullYear();
|
|
528
|
-
const mm = String(date.getMonth() + 1).padStart(2, "0");
|
|
529
|
-
const dd = String(date.getDate()).padStart(2, "0");
|
|
530
|
-
const res = await fetch(`${API_BASE}/v1/meeting-schedule/check-schedule/${yyyy}-${mm}-${dd}?timezone=${timezone}`, {
|
|
531
|
-
headers: authToken
|
|
532
|
-
? { Authorization: `Bearer ${authToken}` }
|
|
533
|
-
: {},
|
|
534
|
-
});
|
|
558
|
+
const res = await fetch(`${apiBase}/v1/meeting-schedule/check-schedule/${yyyy}-${mm}-${dd}?timezone=${timezone}`, { headers: { Authorization: `Bearer ${token}` } });
|
|
535
559
|
const data = await res.json();
|
|
536
560
|
setAvailableSlots(data.slots || []);
|
|
537
561
|
}
|
|
538
562
|
catch (_a) {
|
|
539
|
-
onError === null || onError === void 0 ? void 0 : onError("Failed to
|
|
563
|
+
onError === null || onError === void 0 ? void 0 : onError("Failed to fetch slots");
|
|
540
564
|
}
|
|
541
565
|
finally {
|
|
542
566
|
setLoading(false);
|
|
@@ -545,11 +569,20 @@ const MeetingScheduler = ({ userId, availabilityId, authToken, onSuccess, onErro
|
|
|
545
569
|
const handleBooking = async () => {
|
|
546
570
|
if (!selectedSlot)
|
|
547
571
|
return;
|
|
572
|
+
setLoading(true);
|
|
573
|
+
const token = await getAuthToken();
|
|
574
|
+
if (!token) {
|
|
575
|
+
onError === null || onError === void 0 ? void 0 : onError("Authentication failed");
|
|
576
|
+
setLoading(false);
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
548
579
|
try {
|
|
549
|
-
|
|
550
|
-
const res = await fetch(`${API_BASE}/v1/meeting-schedule/book-schedule`, {
|
|
580
|
+
const res = await fetch(`${apiBase}/v1/meeting-schedule/book-schedule`, {
|
|
551
581
|
method: "POST",
|
|
552
|
-
headers:
|
|
582
|
+
headers: {
|
|
583
|
+
"Content-Type": "application/json",
|
|
584
|
+
Authorization: `Bearer ${token}`,
|
|
585
|
+
},
|
|
553
586
|
body: JSON.stringify({
|
|
554
587
|
user_id: userId,
|
|
555
588
|
availability_id: availabilityId,
|
|
@@ -560,13 +593,16 @@ const MeetingScheduler = ({ userId, availabilityId, authToken, onSuccess, onErro
|
|
|
560
593
|
});
|
|
561
594
|
if (!res.ok)
|
|
562
595
|
throw new Error();
|
|
596
|
+
// Swal.fire("Success", "Meeting booked!", "success");
|
|
563
597
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess();
|
|
564
598
|
setFormData({ name: "", email: "", phone: "", message: "" });
|
|
565
|
-
setSelectedSlot(null);
|
|
566
599
|
setSelectedDate(null);
|
|
600
|
+
setSelectedSlot(null);
|
|
601
|
+
setAvailableSlots([]);
|
|
567
602
|
}
|
|
568
603
|
catch (_a) {
|
|
569
604
|
onError === null || onError === void 0 ? void 0 : onError("Booking failed");
|
|
605
|
+
// Swal.fire("Error", "Booking failed.", "error");
|
|
570
606
|
}
|
|
571
607
|
finally {
|
|
572
608
|
setLoading(false);
|