import type { User as UserAuth } from "next-auth"; import { useSession } from "next-auth/react"; import dynamic from "next/dynamic"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { getBookerBaseUrlSync } from "@calcom/features/ee/organizations/lib/getBookerBaseUrlSync"; import { useFlagMap } from "@calcom/features/flags/context/provider"; import { IS_VISUAL_REGRESSION_TESTING, ENABLE_PROFILE_SWITCHER } from "@calcom/lib/constants"; import { getPlaceholderAvatar } from "@calcom/lib/defaultAvatarImage"; import { useIsStandalone } from "@calcom/lib/hooks/useIsStandalone"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { UserPermissionRole } from "@calcom/prisma/enums"; import classNames from "@calcom/ui/classNames"; import { Avatar } from "@calcom/ui/components/avatar"; import { Credits } from "@calcom/ui/components/credits"; import { ButtonOrLink } from "@calcom/ui/components/dropdown"; import { Icon } from "@calcom/ui/components/icon"; import { ArrowLeftIcon, ArrowRightIcon } from "@coss/ui/icons"; import { Logo } from "@calcom/ui/components/logo"; import { SkeletonText } from "@calcom/ui/components/skeleton"; import { Tooltip } from "@calcom/ui/components/tooltip"; import { KBarTrigger } from "./Kbar"; import { Navigation } from "./navigation/Navigation"; import { useBottomNavItems } from "./useBottomNavItems"; import { ProfileDropdown } from "./user-dropdown/ProfileDropdown"; import { UserDropdown } from "./user-dropdown/UserDropdown"; // need to import without ssr to prevent hydration errors const Tips = dynamic(() => import("./Tips").then((mod) => mod.default), { ssr: false, }); export type SideBarContainerProps = { bannersHeight: number; isPlatformUser?: boolean; }; export type SideBarProps = { bannersHeight: number; user?: UserAuth | null; isPlatformUser?: boolean; }; export function SideBarContainer({ bannersHeight, isPlatformUser = false }: SideBarContainerProps) { const { status, data } = useSession(); const isStandalone = useIsStandalone(); // Make sure that Sidebar is rendered optimistically so that a refresh of pages when logged in have SideBar from the beginning. // This improves the experience of refresh on app store pages(when logged in) which are SSG. // Though when logged out, app store pages would temporarily show SideBar until session status is confirmed. if (status !== "loading" && status !== "authenticated") return null; if (isStandalone) return null; return ; } export function SideBar({ bannersHeight, user }: SideBarProps) { const session = useSession(); const { t, isLocaleReady } = useLocale(); const pathname = usePathname(); const isPlatformPages = pathname?.startsWith("/settings/platform"); const isAdmin = session.data?.user.role === UserPermissionRole.ADMIN; const flags = useFlagMap(); const publicPageUrl = `${getBookerBaseUrlSync(user?.org?.slug ?? null)}/${user?.orgAwareUsername}`; const bottomNavItems = useBottomNavItems({ publicPageUrl, isAdmin, user, }); const sidebarStylingAttributes = { maxHeight: `calc(100vh - ${bannersHeight}px)`, top: `${bannersHeight}px`, }; return (
); }