* feat: implement booking calendar view with weekly layout - Create reusable WeekCalendarView component that displays bookings in a weekly calendar format - Replace EmptyScreen in BookingsCalendar with the new calendar view - Calendar view includes: - Week navigation with Today, Previous, and Next buttons - 7-day week view with time slots from 12 AM to 11 PM - Bookings displayed as colored blocks positioned by time - Support for event type colors and status-based colors - Responsive design that fills the viewport - Hover tooltips showing booking details - Filters remain functional at the top of the view Co-Authored-By: [email protected] <[email protected]> * refactor: use existing Calendar component from weeklyview - Replace custom calendar implementation with the existing Calendar component - Use parseEventTypeColor to properly handle event type colors - Simplify implementation by leveraging existing calendar infrastructure - Maintain week navigation and filtering functionality Co-Authored-By: [email protected] <[email protected]> * fix imports * fix: replace isSameOrAfter with isAfter || isSame - isSameOrAfter method does not exist in dayjs - Use combination of isAfter and isSame instead Co-Authored-By: [email protected] <[email protected]> * remove useBookerTime dependency from weekly calendar view * modify date range filters * initial callback * sort events * clean up FilterBar * add showBackgroundPattern * update styles * update style * update styles * fix type error * fix error * update styles * update styles * update event colors * rename component * persist weekStart on the url * use FilterBar * apply feedback * extract BorderColor type * use client * clean up * adjust styles * color-code events * rename borderColor to color * restore class name * add feature flag * update class name --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
94 lines
3.1 KiB
TypeScript
94 lines
3.1 KiB
TypeScript
import { useEffect, useMemo } from "react";
|
|
|
|
import dayjs from "@calcom/dayjs";
|
|
import { useBookerStoreContext } from "@calcom/features/bookings/Booker/BookerStoreProvider";
|
|
import { useAvailableTimeSlots } from "@calcom/features/bookings/Booker/components/hooks/useAvailableTimeSlots";
|
|
import { useBookerTime } from "@calcom/features/bookings/Booker/components/hooks/useBookerTime";
|
|
import type { BookerEvent } from "@calcom/features/bookings/types";
|
|
import { Calendar } from "@calcom/features/calendars/weeklyview";
|
|
import { localStorage } from "@calcom/lib/webstorage";
|
|
import type { BookingStatus } from "@calcom/prisma/enums";
|
|
|
|
import { useBookings } from "../../platform/atoms/hooks/bookings/useBookings";
|
|
import type { useScheduleForEventReturnType } from "../bookings/Booker/utils/event";
|
|
import { getQueryParam } from "../bookings/Booker/utils/query-param";
|
|
|
|
export const LargeCalendar = ({
|
|
extraDays,
|
|
schedule,
|
|
isLoading,
|
|
event,
|
|
}: {
|
|
extraDays: number;
|
|
schedule?: useScheduleForEventReturnType["data"];
|
|
isLoading: boolean;
|
|
event: {
|
|
data?: Pick<BookerEvent, "length" | "id"> | null;
|
|
};
|
|
}) => {
|
|
const selectedDate = useBookerStoreContext((state) => state.selectedDate);
|
|
const selectedEventDuration = useBookerStoreContext((state) => state.selectedDuration);
|
|
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();
|
|
|
|
const { data: upcomingBookings } = useBookings({
|
|
take: 150,
|
|
skip: 0,
|
|
status: ["upcoming", "past", "recurring"],
|
|
eventTypeId: event?.data?.id,
|
|
afterStart: startDate.toISOString(),
|
|
beforeEnd: endDate.toISOString(),
|
|
});
|
|
|
|
// 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 (!upcomingBookings) return [];
|
|
|
|
return upcomingBookings?.map((booking) => {
|
|
return {
|
|
id: booking.id,
|
|
title: booking.title ?? `Busy`,
|
|
start: new Date(booking.start),
|
|
end: new Date(booking.end),
|
|
options: {
|
|
status: booking.status.toUpperCase() as BookingStatus,
|
|
"data-test-id": "troubleshooter-busy-event",
|
|
className: "border-[1.5px]",
|
|
},
|
|
};
|
|
});
|
|
}, [upcomingBookings]);
|
|
|
|
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}
|
|
gridCellsPerHour={60 / eventDuration}
|
|
hoverEventDuration={eventDuration}
|
|
hideHeader
|
|
timezone={timezone}
|
|
/>
|
|
</div>
|
|
);
|
|
};
|