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/README.md
CHANGED
|
@@ -11,7 +11,7 @@ A reusable React / Next.js meeting scheduler component.
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
13
|
```tsx
|
|
14
|
-
import { MeetingScheduler } from "
|
|
14
|
+
import { MeetingScheduler } from "meeting-scheduler-npm-package";
|
|
15
15
|
|
|
16
16
|
export default function Page() {
|
|
17
17
|
return <MeetingScheduler />;
|
|
@@ -1,4 +1,26 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
|
|
2
|
+
export interface Slot {
|
|
3
|
+
start_local: string;
|
|
4
|
+
end_local: string;
|
|
5
|
+
start_utc: string;
|
|
6
|
+
end_utc: string;
|
|
7
|
+
is_booked: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface FormData {
|
|
10
|
+
name: string;
|
|
11
|
+
email: string;
|
|
12
|
+
phone: string;
|
|
13
|
+
message: string;
|
|
14
|
+
}
|
|
15
|
+
export interface MeetingSchedulerProps {
|
|
16
|
+
userId?: string | number;
|
|
17
|
+
availabilityId?: string | number;
|
|
18
|
+
authToken?: string;
|
|
19
|
+
email?: string;
|
|
20
|
+
password?: string;
|
|
21
|
+
apiBase: string;
|
|
22
|
+
onSuccess?: () => void;
|
|
23
|
+
onError?: (err: string) => void;
|
|
24
|
+
}
|
|
3
25
|
declare const MeetingScheduler: React.FC<MeetingSchedulerProps>;
|
|
4
26
|
export default MeetingScheduler;
|
package/dist/config.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const API_BASE = "
|
|
1
|
+
export declare const API_BASE = "http://160.250.197.118:9000/api";
|
package/dist/index.cjs.js
CHANGED
|
@@ -488,10 +488,8 @@ function IoIosArrowBack (props) {
|
|
|
488
488
|
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);
|
|
489
489
|
}
|
|
490
490
|
|
|
491
|
-
const API_BASE = "https://schedule-api.betopialimited.com/api";
|
|
492
|
-
|
|
493
491
|
const daysOfWeek = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];
|
|
494
|
-
const MeetingScheduler = ({ userId, availabilityId, authToken, onSuccess, onError, }) => {
|
|
492
|
+
const MeetingScheduler = ({ userId = 1, availabilityId = 1, authToken: propAuthToken, email = "superadmin1@gmail.com", password = "password", apiBase, onSuccess, onError, }) => {
|
|
495
493
|
const [currentMonth, setCurrentMonth] = React.useState(new Date());
|
|
496
494
|
const [selectedDate, setSelectedDate] = React.useState(null);
|
|
497
495
|
const [availableSlots, setAvailableSlots] = React.useState([]);
|
|
@@ -522,23 +520,49 @@ const MeetingScheduler = ({ userId, availabilityId, authToken, onSuccess, onErro
|
|
|
522
520
|
const today = new Date();
|
|
523
521
|
today.setHours(0, 0, 0, 0);
|
|
524
522
|
const isPastDate = (date) => date <= today;
|
|
523
|
+
/* ============ Auth ============ */
|
|
524
|
+
const getAuthToken = async () => {
|
|
525
|
+
var _a;
|
|
526
|
+
if (propAuthToken)
|
|
527
|
+
return propAuthToken;
|
|
528
|
+
const existing = localStorage.getItem("auth_token");
|
|
529
|
+
if (existing)
|
|
530
|
+
return existing;
|
|
531
|
+
try {
|
|
532
|
+
const res = await fetch(`${apiBase}/v1/user/login`, {
|
|
533
|
+
method: "POST",
|
|
534
|
+
headers: { "Content-Type": "application/json" },
|
|
535
|
+
body: JSON.stringify({ email, password }),
|
|
536
|
+
});
|
|
537
|
+
const data = await res.json();
|
|
538
|
+
const token = data.token || data.access_token || ((_a = data.data) === null || _a === void 0 ? void 0 : _a.token);
|
|
539
|
+
if (token)
|
|
540
|
+
localStorage.setItem("auth_token", token);
|
|
541
|
+
return token || null;
|
|
542
|
+
}
|
|
543
|
+
catch (_b) {
|
|
544
|
+
return null;
|
|
545
|
+
}
|
|
546
|
+
};
|
|
525
547
|
/* ============ API ============ */
|
|
526
548
|
const fetchSlots = async (date) => {
|
|
549
|
+
setLoading(true);
|
|
550
|
+
const token = await getAuthToken();
|
|
551
|
+
if (!token) {
|
|
552
|
+
onError === null || onError === void 0 ? void 0 : onError("Authentication failed");
|
|
553
|
+
setLoading(false);
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
const yyyy = date.getFullYear();
|
|
557
|
+
const mm = String(date.getMonth() + 1).padStart(2, "0");
|
|
558
|
+
const dd = String(date.getDate()).padStart(2, "0");
|
|
527
559
|
try {
|
|
528
|
-
|
|
529
|
-
const yyyy = date.getFullYear();
|
|
530
|
-
const mm = String(date.getMonth() + 1).padStart(2, "0");
|
|
531
|
-
const dd = String(date.getDate()).padStart(2, "0");
|
|
532
|
-
const res = await fetch(`${API_BASE}/v1/meeting-schedule/check-schedule/${yyyy}-${mm}-${dd}?timezone=${timezone}`, {
|
|
533
|
-
headers: authToken
|
|
534
|
-
? { Authorization: `Bearer ${authToken}` }
|
|
535
|
-
: {},
|
|
536
|
-
});
|
|
560
|
+
const res = await fetch(`${apiBase}/v1/meeting-schedule/check-schedule/${yyyy}-${mm}-${dd}?timezone=${timezone}`, { headers: { Authorization: `Bearer ${token}` } });
|
|
537
561
|
const data = await res.json();
|
|
538
562
|
setAvailableSlots(data.slots || []);
|
|
539
563
|
}
|
|
540
564
|
catch (_a) {
|
|
541
|
-
onError === null || onError === void 0 ? void 0 : onError("Failed to
|
|
565
|
+
onError === null || onError === void 0 ? void 0 : onError("Failed to fetch slots");
|
|
542
566
|
}
|
|
543
567
|
finally {
|
|
544
568
|
setLoading(false);
|
|
@@ -547,11 +571,20 @@ const MeetingScheduler = ({ userId, availabilityId, authToken, onSuccess, onErro
|
|
|
547
571
|
const handleBooking = async () => {
|
|
548
572
|
if (!selectedSlot)
|
|
549
573
|
return;
|
|
574
|
+
setLoading(true);
|
|
575
|
+
const token = await getAuthToken();
|
|
576
|
+
if (!token) {
|
|
577
|
+
onError === null || onError === void 0 ? void 0 : onError("Authentication failed");
|
|
578
|
+
setLoading(false);
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
550
581
|
try {
|
|
551
|
-
|
|
552
|
-
const res = await fetch(`${API_BASE}/v1/meeting-schedule/book-schedule`, {
|
|
582
|
+
const res = await fetch(`${apiBase}/v1/meeting-schedule/book-schedule`, {
|
|
553
583
|
method: "POST",
|
|
554
|
-
headers:
|
|
584
|
+
headers: {
|
|
585
|
+
"Content-Type": "application/json",
|
|
586
|
+
Authorization: `Bearer ${token}`,
|
|
587
|
+
},
|
|
555
588
|
body: JSON.stringify({
|
|
556
589
|
user_id: userId,
|
|
557
590
|
availability_id: availabilityId,
|
|
@@ -562,13 +595,16 @@ const MeetingScheduler = ({ userId, availabilityId, authToken, onSuccess, onErro
|
|
|
562
595
|
});
|
|
563
596
|
if (!res.ok)
|
|
564
597
|
throw new Error();
|
|
598
|
+
// Swal.fire("Success", "Meeting booked!", "success");
|
|
565
599
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess();
|
|
566
600
|
setFormData({ name: "", email: "", phone: "", message: "" });
|
|
567
|
-
setSelectedSlot(null);
|
|
568
601
|
setSelectedDate(null);
|
|
602
|
+
setSelectedSlot(null);
|
|
603
|
+
setAvailableSlots([]);
|
|
569
604
|
}
|
|
570
605
|
catch (_a) {
|
|
571
606
|
onError === null || onError === void 0 ? void 0 : onError("Booking failed");
|
|
607
|
+
// Swal.fire("Error", "Booking failed.", "error");
|
|
572
608
|
}
|
|
573
609
|
finally {
|
|
574
610
|
setLoading(false);
|