Skip to content

Commit 8c71662

Browse files
CAL-1630: Added reserving of timeslot in new booker (#8923)
Co-authored-by: alannnc <alannnc@gmail.com>
1 parent ddee3e8 commit 8c71662

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

packages/features/bookings/Booker/components/AvailableTimeSlots.tsx

+20-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import dayjs from "@calcom/dayjs";
44
import { AvailableTimes, AvailableTimesSkeleton } from "@calcom/features/bookings";
55
import { useSlotsForMultipleDates } from "@calcom/features/schedules/lib/use-schedule/useSlotsForDate";
66
import { classNames } from "@calcom/lib";
7+
import { trpc } from "@calcom/trpc";
78

89
import { useBookerStore } from "../store";
9-
import { useScheduleForEvent } from "../utils/event";
10+
import { useEvent, useScheduleForEvent } from "../utils/event";
1011

1112
type AvailableTimeSlotsProps = {
1213
extraDays?: number;
@@ -22,10 +23,27 @@ type AvailableTimeSlotsProps = {
2223
* in columns next to each other.
2324
*/
2425
export const AvailableTimeSlots = ({ extraDays, limitHeight, seatsPerTimeslot }: AvailableTimeSlotsProps) => {
26+
const reserveSlotMutation = trpc.viewer.public.slots.reserveSlot.useMutation();
2527
const selectedDate = useBookerStore((state) => state.selectedDate);
28+
const duration = useBookerStore((state) => state.selectedDuration);
2629
const setSelectedTimeslot = useBookerStore((state) => state.setSelectedTimeslot);
30+
const event = useEvent();
2731
const date = selectedDate || dayjs().format("YYYY-MM-DD");
2832

33+
const onTimeSelect = (time: string) => {
34+
setSelectedTimeslot(time);
35+
36+
if (!event.data) return;
37+
reserveSlotMutation.mutate({
38+
slotUtcStartDate: time,
39+
eventTypeId: event.data.id,
40+
slotUtcEndDate: dayjs(time)
41+
.utc()
42+
.add(duration || event.data.length, "minutes")
43+
.format(),
44+
});
45+
};
46+
2947
const schedule = useScheduleForEvent({
3048
prefetchNextMonth: !!extraDays && dayjs(date).month() !== dayjs(date).add(extraDays, "day").month(),
3149
});
@@ -66,7 +84,7 @@ export const AvailableTimeSlots = ({ extraDays, limitHeight, seatsPerTimeslot }:
6684
className="w-full"
6785
key={slots.date}
6886
showTimeformatToggle={!isMultipleDates}
69-
onTimeSelect={setSelectedTimeslot}
87+
onTimeSelect={onTimeSelect}
7088
date={dayjs(slots.date)}
7189
slots={slots.slots}
7290
seatsPerTimeslot={seatsPerTimeslot}

0 commit comments

Comments
 (0)