38b43f75ba
* fix: decouple large calendar from features * fix: move calendar to features since this is the better approach * chore: move OOO slots to features * feat: add DefaultOutOfOfficeSlot fallback for calendar OOO rendering Co-Authored-By: rajiv@cal.com <sahalrajiv6900@gmail.com> * chore: cleanup unused LargeCalendar component --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
88 lines
3.3 KiB
TypeScript
88 lines
3.3 KiB
TypeScript
import { useEffect, useMemo } from "react";
|
|
|
|
import dayjs from "@calcom/dayjs";
|
|
import { useBookerStoreContext } from "@calcom/features/bookings/Booker/BookerStoreProvider";
|
|
import { useOverlayCalendarStore } from "@calcom/features/bookings/Booker/components/OverlayCalendar/store";
|
|
import { useAvailableTimeSlots } from "@calcom/features/bookings/Booker/hooks/useAvailableTimeSlots";
|
|
import { useBookerTime } from "@calcom/features/bookings/Booker/hooks/useBookerTime";
|
|
import { getQueryParam } from "@calcom/features/bookings/Booker/utils/query-param";
|
|
import type { BookerEvent } from "@calcom/features/bookings/types";
|
|
import { Calendar } from "@calcom/features/calendars/weeklyview/components/Calendar";
|
|
import type { CalendarEvent } from "@calcom/features/calendars/weeklyview/types/events";
|
|
import { localStorage } from "@calcom/lib/webstorage";
|
|
|
|
import type { useScheduleForEventReturnType } from "@calcom/web/modules/schedules/hooks/useEvent";
|
|
|
|
import { OutOfOfficeInSlots } from "./OutOfOfficeInSlots";
|
|
|
|
export const LargeCalendar = ({
|
|
extraDays,
|
|
schedule,
|
|
isLoading,
|
|
event,
|
|
}: {
|
|
extraDays: number;
|
|
schedule?: useScheduleForEventReturnType["data"];
|
|
isLoading: boolean;
|
|
event: {
|
|
data?: Pick<BookerEvent, "length"> | null;
|
|
};
|
|
}) => {
|
|
const selectedDate = useBookerStoreContext((state) => state.selectedDate);
|
|
const setSelectedTimeslot = useBookerStoreContext((state) => state.setSelectedTimeslot);
|
|
const selectedEventDuration = useBookerStoreContext((state) => state.selectedDuration);
|
|
const overlayEvents = useOverlayCalendarStore((state) => state.overlayBusyDates);
|
|
const displayOverlay =
|
|
getQueryParam("overlayCalendar") === "true" || localStorage?.getItem("overlayCalendarSwitchDefault");
|
|
const { timezone } = useBookerTime();
|
|
|
|
const eventDuration = selectedEventDuration || event?.data?.length || 30;
|
|
|
|
const availableSlots = useAvailableTimeSlots({ schedule, eventDuration });
|
|
|
|
const startDate = selectedDate ? dayjs(selectedDate).toDate() : dayjs().toDate();
|
|
const endDate = dayjs(startDate)
|
|
.add(extraDays - 1, "day")
|
|
.toDate();
|
|
|
|
// HACK: force rerender when overlay events change
|
|
// Sine we dont use react router here we need to force rerender (ATOM SUPPORT)
|
|
useEffect(() => {}, [displayOverlay]);
|
|
|
|
const overlayEventsForDate = useMemo(() => {
|
|
if (!overlayEvents || !displayOverlay) return [];
|
|
return overlayEvents.map((event, id) => {
|
|
return {
|
|
id,
|
|
start: dayjs(event.start).toDate(),
|
|
end: dayjs(event.end).toDate(),
|
|
title: "Busy",
|
|
options: {
|
|
status: "ACCEPTED",
|
|
borderOnly: true,
|
|
},
|
|
} as CalendarEvent;
|
|
});
|
|
}, [overlayEvents, displayOverlay]);
|
|
|
|
return (
|
|
<div className="h-full [--calendar-dates-sticky-offset:66px]">
|
|
<Calendar
|
|
isPending={isLoading}
|
|
availableTimeslots={availableSlots}
|
|
startHour={0}
|
|
endHour={23}
|
|
events={overlayEventsForDate}
|
|
startDate={startDate}
|
|
endDate={endDate}
|
|
onEmptyCellClick={(date) => setSelectedTimeslot(date.toISOString())}
|
|
gridCellsPerHour={60 / eventDuration}
|
|
hoverEventDuration={eventDuration}
|
|
hideHeader
|
|
timezone={timezone}
|
|
renderOutOfOffice={(props) => <OutOfOfficeInSlots {...props} />}
|
|
/>
|
|
</div>
|
|
);
|
|
};
|