Files
calendar/packages/features/bookings/Booker/components/hooks/useAvailableTimeSlots.ts
T
Rajiv SahalandGitHub 63740c02c7 feat: calendar view atom v1 (#23840)
* fix: refactor

* add `isMonthViewProp` to header

* feat: init v1 for calendar view atom

* test breaking toggle buttons

* fix: make sure week start is always sunday for calendar view atom

* fixup

* fix: remove extra comments

* fix: add calendar view page in examples app

* chore: add changesets

* fix: coderabbit feedback

* fixup
2025-09-22 12:17:33 +00:00

31 lines
999 B
TypeScript

import { useMemo } from "react";
import dayjs from "@calcom/dayjs";
import type { CalendarAvailableTimeslots } from "@calcom/features/calendars/weeklyview/types/state";
import type { IGetAvailableSlots } from "@calcom/trpc/server/routers/viewer/slots/util";
interface UseAvailableTimeSlotsProps {
eventDuration: number;
schedule?: IGetAvailableSlots;
}
export const useAvailableTimeSlots = ({ schedule, eventDuration }: UseAvailableTimeSlotsProps) => {
return useMemo(() => {
const availableTimeslots: CalendarAvailableTimeslots = {};
if (!schedule || !schedule.slots) return availableTimeslots;
for (const day in schedule.slots) {
availableTimeslots[day] = schedule.slots[day].map((slot) => {
const { time, ...rest } = slot;
return {
start: dayjs(time).toDate(),
end: dayjs(time).add(eventDuration, "minutes").toDate(),
...rest,
};
});
}
return availableTimeslots;
}, [schedule, eventDuration]);
};