diff --git a/packages/features/shell/Shell.tsx b/packages/features/shell/Shell.tsx index 690ec1c50c..9799b031fa 100644 --- a/packages/features/shell/Shell.tsx +++ b/packages/features/shell/Shell.tsx @@ -5,7 +5,7 @@ import Link from "next/link"; import type { NextRouter } from "next/router"; import { useRouter } from "next/router"; import type { Dispatch, ReactNode, SetStateAction } from "react"; -import React, { Fragment, useEffect, useState } from "react"; +import React, { Fragment, useEffect, useState, useRef, useLayoutEffect } from "react"; import { Toaster } from "react-hot-toast"; import dayjs from "@calcom/dayjs"; @@ -140,6 +140,27 @@ function useRedirectToOnboardingIfNeeded() { const Layout = (props: LayoutProps) => { const pageTitle = typeof props.heading === "string" && !props.title ? props.heading : props.title; + const bannerRef = useRef(null); + const [bannersHeight, setBannersHeight] = useState(0); + + useLayoutEffect(() => { + const resizeObserver = new ResizeObserver((entries) => { + const { offsetHeight } = entries[0].target as HTMLElement; + setBannersHeight(offsetHeight); + }); + + const currentBannerRef = bannerRef.current; + + if (currentBannerRef) { + resizeObserver.observe(currentBannerRef); + } + + return () => { + if (currentBannerRef) { + resizeObserver.unobserve(currentBannerRef); + } + }; + }, [bannerRef]); return ( <> @@ -155,14 +176,14 @@ const Layout = (props: LayoutProps) => { {/* todo: only run this if timezone is different */} -
-
+
+
- {props.SidebarContainer || } + {props.SidebarContainer || }
@@ -736,7 +757,15 @@ const MobileNavigationMoreItem: React.FC<{ ); }; -function SideBarContainer() { +type SideBarContainerProps = { + bannersHeight: number; +}; + +type SideBarProps = { + bannersHeight: number; +}; + +function SideBarContainer({ bannersHeight }: SideBarContainerProps) { const { status } = useSession(); const router = useRouter(); @@ -745,13 +774,15 @@ function SideBarContainer() { // Though when logged out, app store pages would temporarily show SideBar until session status is confirmed. if (status !== "loading" && status !== "authenticated") return null; if (router.route.startsWith("/v2/settings/")) return null; - return ; + return ; } -function SideBar() { +function SideBar({ bannersHeight }: SideBarProps) { return (
-