Files
calendar/apps/web/lib/hooks/useIsBookingPage.ts
T
Hariom BalharaandGitHub 150e93dc6e fix: Add /router to isBookingPages to prevent 500 error on customPageMessage redirect (#25522)
* Add /router to isBookingPages

* Remove Dynamic Posthog Provider from AppProvider.tsx because that is only used by the pages router, and the pages router is only in use by the /router endpoint, which is a booking page and we havent implemented corresponding GeoProvider support for it
2025-12-02 13:51:04 +00:00

30 lines
1.5 KiB
TypeScript

import { usePathname } from "next/navigation";
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
// TODO: This approach of checking booking page isn't correct.
// app.cal.com/rick is a booking page but useIsBookingPage won't return true. This is because all unregistered router in Next.js could technically be a booking page throw catch all routes.
// The only way to confirm it is by actually checking if we actually rendered a booking route.
export default function useIsBookingPage(): boolean {
const pathname = usePathname();
const isBookingPage = [
"/booking",
"/cancel",
"/reschedule",
"/instant-meeting", // Instant booking page
"/team", // Team booking pages
"/d", // Private Link of booking page
"/apps/routing-forms/routing-link", // Routing Form page
"/forms/", // Rewrites to /apps/routing-forms/routing-link
"/router", // Headless router page - Loads as a page when redirect type is customPageMessage
].some((route) => pathname?.startsWith(route));
const isBookingsListPage = ["/upcoming", "/unconfirmed", "/recurring", "/cancelled", "/past"].some(
(route) => pathname?.endsWith(route)
);
const searchParams = useCompatSearchParams();
const isUserBookingPage = Boolean(searchParams?.get("user"));
const isUserBookingTypePage = Boolean(searchParams?.get("user") && searchParams?.get("type"));
return (isBookingPage && !isBookingsListPage) || isUserBookingPage || isUserBookingTypePage;
}