* display UTM parameters * persist view (list | calendar) in localStorage * move to next page on clicking "next" of last item in the page improve navigation ^ Conflicts: ^ apps/web/modules/bookings/components/BookingCalendarContainer.tsx * fix navigation on calendar view * Delete apps/web/modules/bookings/NAVIGATION_IMPLEMENTATION.md * avoid page size being 0 * check feature flag on user level * use map to improve useBookingListData * address feedback * feat(bookings): add smart navigation for calendar view - Add sort option to tRPC bookings.get schema and handler - Create NAVIGATION_PROBE_WINDOW_MONTHS constant (3 months) - Create useNearestFutureBooking hook to find nearest future booking - Create useNearestPastBooking hook to find nearest past booking - Update useCalendarNavigationCapabilities to use probe results - Update BookingCalendarContainer to wire up probe hooks This enables the booking details sheet to: - Disable next/prev buttons when no bookings exist in that direction - Jump directly to the week containing the nearest booking Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * fix type error * feat: add booking selection state when using slideover (#25637) * implement booking selection when using slideover * remove pixel shift * fix * auto scroll to selected event on calendar * make DateValues header sticky when scrolling --------- Co-authored-by: Eunjae Lee <hey@eunjae.dev> * prefetch previous / next weeks on calendar view * clean up classes * handle "fetched & but no data" situation more correctly in useCalendarAutoSelector --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
109 lines
3.8 KiB
TypeScript
109 lines
3.8 KiB
TypeScript
"use client";
|
|
|
|
import { useMemo, useEffect } from "react";
|
|
|
|
import dayjs from "@calcom/dayjs";
|
|
import { useTimePreferences } from "@calcom/features/bookings/lib";
|
|
import { Calendar } from "@calcom/features/calendars/weeklyview";
|
|
import type { CalendarEvent } from "@calcom/features/calendars/weeklyview/types/events";
|
|
import { useBanners } from "@calcom/features/shell/banners/useBanners";
|
|
import { useGetTheme } from "@calcom/lib/hooks/useTheme";
|
|
|
|
import { useBookingDetailsSheetStore } from "../store/bookingDetailsSheetStore";
|
|
import type { BookingOutput } from "../types";
|
|
|
|
type BookingCalendarViewProps = {
|
|
bookings: BookingOutput[];
|
|
currentWeekStart: dayjs.Dayjs;
|
|
onWeekStartChange: (weekStart: dayjs.Dayjs) => void;
|
|
};
|
|
|
|
export function BookingCalendarView({
|
|
bookings,
|
|
currentWeekStart,
|
|
onWeekStartChange,
|
|
}: BookingCalendarViewProps) {
|
|
const setSelectedBookingUid = useBookingDetailsSheetStore((state) => state.setSelectedBookingUid);
|
|
const selectedBookingUid = useBookingDetailsSheetStore((state) => state.selectedBookingUid);
|
|
const { timezone } = useTimePreferences();
|
|
const { resolvedTheme, forcedTheme } = useGetTheme();
|
|
const { bannersHeight } = useBanners();
|
|
|
|
const startDate = useMemo(() => currentWeekStart.toDate(), [currentWeekStart]);
|
|
const endDate = useMemo(() => currentWeekStart.add(6, "day").toDate(), [currentWeekStart]);
|
|
|
|
// Intentionally only runs on mount to trigger the initial currentWeekStart
|
|
useEffect(() => {
|
|
onWeekStartChange(currentWeekStart);
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, []);
|
|
|
|
const events = useMemo<CalendarEvent[]>(() => {
|
|
const hasDarkTheme = !forcedTheme && resolvedTheme === "dark";
|
|
|
|
return bookings
|
|
.filter((booking) => {
|
|
const bookingStart = dayjs(booking.startTime);
|
|
return (
|
|
(bookingStart.isAfter(currentWeekStart) || bookingStart.isSame(currentWeekStart)) &&
|
|
bookingStart.isBefore(currentWeekStart.add(7, "day"))
|
|
);
|
|
})
|
|
.sort((a, b) => {
|
|
const startDiff = new Date(a.startTime).getTime() - new Date(b.startTime).getTime();
|
|
if (startDiff !== 0) return startDiff;
|
|
return new Date(a.endTime).getTime() - new Date(b.endTime).getTime();
|
|
})
|
|
.map((booking, idx) => {
|
|
// Parse eventTypeColor and extract the appropriate color based on theme
|
|
const eventTypeColor =
|
|
booking.eventType?.eventTypeColor &&
|
|
booking.eventType.eventTypeColor[hasDarkTheme ? "darkEventTypeColor" : "lightEventTypeColor"];
|
|
|
|
return {
|
|
id: idx,
|
|
title: booking.title,
|
|
start: new Date(booking.startTime),
|
|
end: new Date(booking.endTime),
|
|
options: {
|
|
status: booking.status,
|
|
...(eventTypeColor && { color: eventTypeColor }),
|
|
bookingUid: booking.uid,
|
|
},
|
|
};
|
|
});
|
|
}, [bookings, currentWeekStart, resolvedTheme, forcedTheme]);
|
|
|
|
return (
|
|
<>
|
|
<div
|
|
className="border-subtle flex flex-1 flex-col overflow-y-auto overflow-x-hidden rounded-2xl border"
|
|
style={{ height: `calc(100vh - 6rem - ${bannersHeight}px)` }}>
|
|
<Calendar
|
|
timezone={timezone}
|
|
sortEvents
|
|
startHour={0}
|
|
endHour={23}
|
|
events={events}
|
|
startDate={startDate}
|
|
endDate={endDate}
|
|
gridCellsPerHour={4}
|
|
hoverEventDuration={0}
|
|
showBackgroundPattern={false}
|
|
showBorder={false}
|
|
borderColor="subtle"
|
|
selectedBookingUid={selectedBookingUid}
|
|
onEventClick={(event) => {
|
|
const bookingUid = event.options?.bookingUid;
|
|
if (bookingUid) {
|
|
setSelectedBookingUid(bookingUid);
|
|
}
|
|
}}
|
|
showTimezone
|
|
hideHeader
|
|
/>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|