diff --git a/web/components/layout/auth/DesktopSidebar.tsx b/web/components/layout/auth/DesktopSidebar.tsx index 1018e63d17..14204f7b18 100644 --- a/web/components/layout/auth/DesktopSidebar.tsx +++ b/web/components/layout/auth/DesktopSidebar.tsx @@ -16,7 +16,7 @@ import { } from "@heroicons/react/24/outline"; import Link from "next/link"; import { useRouter } from "next/router"; -import { useMemo } from "react"; +import { useMemo, useEffect, useRef, useState } from "react"; import { useOrg } from "../organizationContext"; import OrgDropdown from "../orgDropdown"; import NavItem from "./NavItem"; @@ -90,6 +90,35 @@ const DesktopSidebar = ({ NAVIGATION }: SidebarProps) => { }); }, [NAVIGATION, isCollapsed, expandedItems]); + const sidebarRef = useRef(null); + const navItemsRef = useRef(null); + const [canShowInfoBox, setCanShowInfoBox] = useState(false); + + // Function to calculate if there's enough space to show the InfoBox + const calculateAvailableSpace = () => { + if (sidebarRef.current && navItemsRef.current) { + const sidebarHeight = sidebarRef.current.offsetHeight; + const navItemsHeight = navItemsRef.current.offsetHeight; + const fixedContentHeight = 100; // Approximate height of fixed elements (header, footer) + const infoBoxHeight = 150; // Approximate height of the InfoBox + + const availableHeight = + sidebarHeight - navItemsHeight - fixedContentHeight; + + setCanShowInfoBox(availableHeight >= infoBoxHeight); + } + }; + + useEffect(() => { + calculateAvailableSpace(); + + // Add event listener for window resize + window.addEventListener("resize", calculateAvailableSpace); + return () => { + window.removeEventListener("resize", calculateAvailableSpace); + }; + }, [isCollapsed, expandedItems]); + return ( <>
{ )} />
@@ -154,6 +184,7 @@ const DesktopSidebar = ({ NAVIGATION }: SidebarProps) => { )}
@@ -171,14 +202,14 @@ const DesktopSidebar = ({ NAVIGATION }: SidebarProps) => {
- {!isCollapsed && ( + {canShowInfoBox && !isCollapsed && (
<>} className="flex flex-col">
- + Early Adopter Exclusive: $120 Credit for the year.
- + Switch to Pro and get $10/mo credit for 1 year, as a thank you for your early support! @@ -278,25 +309,6 @@ const DesktopSidebar = ({ NAVIGATION }: SidebarProps) => { )}
- {/* {tier === "free" && - org?.currentOrg?.organization_type !== "customer" && ( -
- - - -
- )} */}