feat(booking): implement cross-page/week navigation in booking details sheet with view persistence (#25545)
* 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: [email protected] <[email protected]> * 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 <[email protected]> * 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 <[email protected]>
This commit is contained in:
30 files changed
+997
-141
No files matched your search
@@ -43,6 +43,7 @@ export class BookingDetailsService {
|
||||
return {
|
||||
rescheduledToBooking,
|
||||
previousBooking,
|
||||
tracking: booking.tracking,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ function CalendarInner(props: CalendarComponentProps) {
|
||||
className="bg-default dark:bg-cal-muted relative isolate flex h-full flex-auto flex-col">
|
||||
<div
|
||||
style={{ width: "165%" }}
|
||||
className="flex h-full max-w-full flex-none flex-col sm:max-w-none md:max-w-full">
|
||||
className="flex max-w-full flex-none flex-col sm:max-w-none md:max-w-full">
|
||||
<DateValues
|
||||
containerNavRef={containerNav}
|
||||
days={days}
|
||||
@@ -80,9 +80,9 @@ function CalendarInner(props: CalendarComponentProps) {
|
||||
className={classNames(
|
||||
"bg-default dark:bg-cal-muted ring-muted sticky left-0 z-10 w-16 flex-none ring-1",
|
||||
showBorder &&
|
||||
(borderColor === "subtle"
|
||||
? "border-subtle border-l border-r"
|
||||
: "border-default border-l border-r")
|
||||
(borderColor === "subtle"
|
||||
? "border-subtle border-l border-r"
|
||||
: "border-default border-l border-r")
|
||||
)}
|
||||
/>
|
||||
<div
|
||||
@@ -91,10 +91,10 @@ function CalendarInner(props: CalendarComponentProps) {
|
||||
showBackgroundPattern === false
|
||||
? undefined
|
||||
: {
|
||||
backgroundColor: "var(--disabled-gradient-background)",
|
||||
background:
|
||||
"repeating-linear-gradient(-45deg, var(--disabled-gradient-background), var(--disabled-gradient-background) 2.5px, var(--disabled-gradient-foreground) 2.5px, var(--disabled-gradient-foreground) 5px)",
|
||||
}
|
||||
backgroundColor: "var(--disabled-gradient-background)",
|
||||
background:
|
||||
"repeating-linear-gradient(-45deg, var(--disabled-gradient-background), var(--disabled-gradient-background) 2.5px, var(--disabled-gradient-foreground) 2.5px, var(--disabled-gradient-foreground) 5px)",
|
||||
}
|
||||
}>
|
||||
<HorizontalLines
|
||||
hours={hours}
|
||||
|
||||
@@ -32,7 +32,7 @@ const eventClasses = cva(
|
||||
false: "hover:cursor-pointer",
|
||||
},
|
||||
selected: {
|
||||
true: "bg-inverted text-inverted border border-transparent",
|
||||
true: "",
|
||||
false: "",
|
||||
},
|
||||
borderOnly: {
|
||||
@@ -120,7 +120,7 @@ export function Event({
|
||||
borderOnly: options?.borderOnly ?? false,
|
||||
}),
|
||||
options?.className,
|
||||
isHovered && "ring-brand-default shadow-lg ring-2 ring-offset-0"
|
||||
(isHovered || selected) && "ring-brand-default shadow-lg ring-2 ring-offset-0"
|
||||
)}
|
||||
style={{
|
||||
transition: "all 100ms ease-out",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMemo, useState } from "react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { shallow } from "zustand/shallow";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
@@ -13,11 +13,12 @@ type Props = {
|
||||
};
|
||||
|
||||
export function EventList({ day }: Props) {
|
||||
const { startHour, events, eventOnClick } = useCalendarStore(
|
||||
const { startHour, events, eventOnClick, selectedBookingUid } = useCalendarStore(
|
||||
(state) => ({
|
||||
startHour: state.startHour,
|
||||
events: state.events,
|
||||
eventOnClick: state.onEventClick,
|
||||
selectedBookingUid: state.selectedBookingUid,
|
||||
}),
|
||||
shallow
|
||||
);
|
||||
@@ -60,6 +61,29 @@ export function EventList({ day }: Props) {
|
||||
const hoveredEventLayout = hoveredEventId ? layoutMap.get(hoveredEventId) : null;
|
||||
const hoveredGroupIndex = hoveredEventLayout?.groupIndex ?? null;
|
||||
|
||||
// Find the event ID that matches the selected booking UID (only for events on this day)
|
||||
const selectedEventId = useMemo(() => {
|
||||
if (!selectedBookingUid) return undefined;
|
||||
const matchingEvent = dayEvents.find((event) => event.options?.bookingUid === selectedBookingUid);
|
||||
return matchingEvent?.id;
|
||||
}, [dayEvents, selectedBookingUid]);
|
||||
|
||||
// Scroll to the selected event when it changes
|
||||
useEffect(() => {
|
||||
if (selectedEventId === undefined) return;
|
||||
|
||||
// Use requestAnimationFrame to ensure the DOM has updated
|
||||
requestAnimationFrame(() => {
|
||||
const eventElement = document.querySelector(`[data-calendar-event-id="${selectedEventId}"]`);
|
||||
if (eventElement) {
|
||||
eventElement.scrollIntoView({
|
||||
behavior: "smooth",
|
||||
block: "nearest",
|
||||
});
|
||||
}
|
||||
});
|
||||
}, [selectedEventId]);
|
||||
|
||||
return (
|
||||
<>
|
||||
{dayEvents.map((event) => {
|
||||
@@ -72,8 +96,9 @@ export function EventList({ day }: Props) {
|
||||
const { eventStart, eventDuration, eventStartDiff } = calc;
|
||||
|
||||
const isHovered = hoveredEventId === event.id;
|
||||
const isSelected = selectedEventId === event.id;
|
||||
const isInHoveredGroup = hoveredGroupIndex !== null && layout.groupIndex === hoveredGroupIndex;
|
||||
const zIndex = isHovered ? 100 : layout.baseZIndex;
|
||||
const zIndex = isHovered || isSelected ? 79 : layout.baseZIndex;
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -83,6 +108,7 @@ export function EventList({ day }: Props) {
|
||||
event.options?.borderOnly && "pointer-events-none"
|
||||
)}
|
||||
data-testid={event.options?.["data-test-id"]}
|
||||
data-calendar-event-id={event.id}
|
||||
onMouseEnter={() => setHoveredEventId(event.id)}
|
||||
onMouseLeave={() => setHoveredEventId(null)}
|
||||
style={{
|
||||
@@ -91,7 +117,7 @@ export function EventList({ day }: Props) {
|
||||
zIndex,
|
||||
top: `calc(${eventStartDiff}*var(--one-minute-height))`,
|
||||
height: `max(15px, calc(${eventDuration}*var(--one-minute-height)))`,
|
||||
transform: isHovered ? "scale(1.02)" : "scale(1)",
|
||||
transform: isHovered || isSelected ? "scale(1.02)" : "scale(1)",
|
||||
opacity: hoveredGroupIndex !== null && !isHovered && isInHoveredGroup ? 0.6 : 1,
|
||||
}}>
|
||||
<Event
|
||||
@@ -99,6 +125,7 @@ export function EventList({ day }: Props) {
|
||||
eventDuration={eventDuration}
|
||||
onEventClick={eventOnClick}
|
||||
isHovered={isHovered}
|
||||
currentlySelectedEventId={selectedEventId}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -50,6 +50,7 @@ export function createCalendarStore(initial?: Partial<CalendarComponentProps>):
|
||||
...state,
|
||||
blockingDates,
|
||||
events,
|
||||
selectedBookingUid: state.selectedBookingUid,
|
||||
});
|
||||
},
|
||||
setSelectedEvent: (event) => set({ selectedEvent: event }),
|
||||
|
||||
@@ -154,6 +154,10 @@ export type CalendarState = {
|
||||
* @default false
|
||||
*/
|
||||
showTimezone?: boolean;
|
||||
/**
|
||||
* Selected booking UID to highlight the corresponding event
|
||||
*/
|
||||
selectedBookingUid?: string | null;
|
||||
};
|
||||
|
||||
export type CalendarComponentProps = CalendarPublicActions & CalendarState & { isPending?: boolean };
|
||||
|
||||
@@ -105,6 +105,12 @@ export function DataTableWrapper<TData>({
|
||||
}));
|
||||
}, [table, sorting, columnFilters, columnVisibility, setSorting, setColumnVisibility]);
|
||||
|
||||
// Scroll to top when table data changes
|
||||
useScrollToTopOnDataChange({
|
||||
tableData: table.options.data,
|
||||
paginationMode,
|
||||
});
|
||||
|
||||
let view: "loader" | "empty" | "error" | "table" = "table";
|
||||
if (hasError && ErrorView) {
|
||||
view = "error";
|
||||
@@ -170,3 +176,33 @@ export function DataTableWrapper<TData>({
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scrolls to top when table data changes (pagination, filters, etc.)
|
||||
* Only active for standard pagination mode where we show discrete pages
|
||||
*/
|
||||
function useScrollToTopOnDataChange<TData>({
|
||||
tableData,
|
||||
paginationMode,
|
||||
}: {
|
||||
tableData: TData[];
|
||||
paginationMode: "standard" | "infinite";
|
||||
}) {
|
||||
const previousDataRef = useRef(tableData);
|
||||
const isInitialMount = useRef(true);
|
||||
|
||||
useEffect(() => {
|
||||
// Skip on initial mount
|
||||
if (isInitialMount.current) {
|
||||
isInitialMount.current = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const hasDataChanged = previousDataRef.current !== tableData;
|
||||
previousDataRef.current = tableData;
|
||||
|
||||
if (paginationMode === "standard" && hasDataChanged) {
|
||||
window.scrollTo(0, 0);
|
||||
}
|
||||
}, [tableData, paginationMode]);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { SortingState, VisibilityState, ColumnSizingState } from "@tanstack/react-table";
|
||||
import { parseAsArrayOf, parseAsJson, parseAsInteger, parseAsString } from "nuqs";
|
||||
import { parseAsArrayOf, parseAsJson, parseAsInteger, parseAsString, createParser } from "nuqs";
|
||||
|
||||
import { ZActiveFilter, ZSorting, ZColumnVisibility, ZColumnSizing } from "./types";
|
||||
import type { ActiveFilters } from "./types";
|
||||
@@ -20,5 +20,13 @@ export const columnVisibilityParser = parseAsJson(ZColumnVisibility.parse).withD
|
||||
export const columnSizingParser = parseAsJson(ZColumnSizing.parse).withDefault(DEFAULT_COLUMN_SIZING);
|
||||
export const segmentIdParser = parseAsString.withDefault("");
|
||||
export const pageIndexParser = parseAsInteger.withDefault(0);
|
||||
export const pageSizeParser = parseAsInteger.withDefault(DEFAULT_PAGE_SIZE);
|
||||
// Custom parser that validates pageSize is positive to prevent division by zero
|
||||
export const pageSizeParser = createParser({
|
||||
parse: (value) => {
|
||||
const parsed = parseAsInteger.parse(value);
|
||||
// Return null for invalid values (0 or negative), which will fall back to default
|
||||
return parsed !== null && parsed > 0 ? parsed : null;
|
||||
},
|
||||
serialize: (value) => String(value),
|
||||
}).withDefault(DEFAULT_PAGE_SIZE);
|
||||
export const searchTermParser = parseAsString.withDefault("");
|
||||
Reference in new issue
Block a user