@@ -4,9 +4,10 @@ import dayjs from "@calcom/dayjs";
4
4
import { AvailableTimes , AvailableTimesSkeleton } from "@calcom/features/bookings" ;
5
5
import { useSlotsForMultipleDates } from "@calcom/features/schedules/lib/use-schedule/useSlotsForDate" ;
6
6
import { classNames } from "@calcom/lib" ;
7
+ import { trpc } from "@calcom/trpc" ;
7
8
8
9
import { useBookerStore } from "../store" ;
9
- import { useScheduleForEvent } from "../utils/event" ;
10
+ import { useEvent , useScheduleForEvent } from "../utils/event" ;
10
11
11
12
type AvailableTimeSlotsProps = {
12
13
extraDays ?: number ;
@@ -22,10 +23,27 @@ type AvailableTimeSlotsProps = {
22
23
* in columns next to each other.
23
24
*/
24
25
export const AvailableTimeSlots = ( { extraDays, limitHeight, seatsPerTimeslot } : AvailableTimeSlotsProps ) => {
26
+ const reserveSlotMutation = trpc . viewer . public . slots . reserveSlot . useMutation ( ) ;
25
27
const selectedDate = useBookerStore ( ( state ) => state . selectedDate ) ;
28
+ const duration = useBookerStore ( ( state ) => state . selectedDuration ) ;
26
29
const setSelectedTimeslot = useBookerStore ( ( state ) => state . setSelectedTimeslot ) ;
30
+ const event = useEvent ( ) ;
27
31
const date = selectedDate || dayjs ( ) . format ( "YYYY-MM-DD" ) ;
28
32
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
+
29
47
const schedule = useScheduleForEvent ( {
30
48
prefetchNextMonth : ! ! extraDays && dayjs ( date ) . month ( ) !== dayjs ( date ) . add ( extraDays , "day" ) . month ( ) ,
31
49
} ) ;
@@ -66,7 +84,7 @@ export const AvailableTimeSlots = ({ extraDays, limitHeight, seatsPerTimeslot }:
66
84
className = "w-full"
67
85
key = { slots . date }
68
86
showTimeformatToggle = { ! isMultipleDates }
69
- onTimeSelect = { setSelectedTimeslot }
87
+ onTimeSelect = { onTimeSelect }
70
88
date = { dayjs ( slots . date ) }
71
89
slots = { slots . slots }
72
90
seatsPerTimeslot = { seatsPerTimeslot }
0 commit comments