Skip to content

Scheduling infrastructure for absolutely everyone.

fix: Adjust height of sidebar to fit on screen when top banner is visible (#8795)

paridhi754271283af07
diff --git a/packages/features/shell/Shell.tsx b/packages/features/shell/Shell.tsx
index 690ec1c50ca..9799b031fa4 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<HTMLDivElement | null>(null);
+ const [bannersHeight, setBannersHeight] = useState<number>(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 */}
<TimezoneChangeDialog />
- <div className="flex min-h-screen flex-col">
- <div className="divide-y divide-black">
+ <div style={{ paddingTop: `${bannersHeight}px` }} className="flex min-h-screen flex-col">
+ <div ref={bannerRef} className="fixed top-0 z-10 w-full divide-y divide-black">
<TeamsUpgradeBanner />
<ImpersonatingBanner />
<AdminPasswordBanner />
</div>
<div className="flex flex-1" data-testid="dashboard-shell">
- {props.SidebarContainer || <SideBarContainer />}
+ {props.SidebarContainer || <SideBarContainer bannersHeight={bannersHeight} />}
<div className="flex w-0 flex-1 flex-col">
<MainContainer {...props} />
</div>
@@ -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 <SideBar />;
+ return <SideBar bannersHeight={bannersHeight} />;
}
-function SideBar() {
+function SideBar({ bannersHeight }: SideBarProps) {
return (
<div className="relative">
- <aside className="desktop-transparent bg-muted border-muted top-0 hidden h-full max-h-screen w-14 flex-col overflow-y-auto overflow-x-hidden border-r dark:bg-gradient-to-tr dark:from-[#2a2a2a] dark:to-[#1c1c1c] md:sticky md:flex lg:w-56 lg:px-4">
+ <aside
+ style={{ maxHeight: `calc(100vh - ${bannersHeight}px)`, top: `${bannersHeight}px` }}
+ className="desktop-transparent bg-muted border-muted fixed left-0 hidden h-full max-h-screen w-14 flex-col overflow-y-auto overflow-x-hidden border-r dark:bg-gradient-to-tr dark:from-[#2a2a2a] dark:to-[#1c1c1c] md:sticky md:flex lg:w-56 lg:px-4">
<div className="flex h-full flex-col justify-between py-3 lg:pt-6 ">
<header className="items-center justify-between md:hidden lg:flex">
<Link href="/event-types" className="px-2">