import { ROADMAP } from "@calcom/lib/constants"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import useMeQuery from "@calcom/trpc/react/hooks/useMeQuery"; import classNames from "@calcom/ui/classNames"; import { Avatar } from "@calcom/ui/components/avatar"; import { Menu, MenuItem, MenuPopup, MenuSeparator, MenuSub, MenuSubPopup, MenuSubTrigger, MenuTrigger, } from "@coss/ui/components/menu"; import { BlocksIcon, ChevronDownIcon, ChevronUpIcon, CircleHelpIcon, LogOutIcon, MapIcon, MoonIcon, SettingsIcon, UserIcon, } from "@coss/ui/icons"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { signOut } from "next-auth/react"; import type { MouseEvent } from "react"; import { useEffect, useState } from "react"; declare global { interface Window { Support?: { open: () => void; shouldShowTriggerButton: (showTrigger: boolean) => void; }; Beacon?: BeaconFunction; } } type BeaconFunction = { (command: "session-data", data: Record): void; // Catch-all for other methods - add explicit types above if using new commands (...args: unknown[]): void; }; interface UserDropdownProps { small?: boolean; } export function UserDropdown({ small }: UserDropdownProps) { const isPlatformUser = false; const { t } = useLocale(); const { data: user, isPending } = useMeQuery(); const pathname = usePathname(); const isPlatformPages = pathname?.startsWith("/settings/platform"); useEffect(() => { if (typeof window === "undefined") return; const sendSessionData = () => { const Beacon = window.Beacon; if (Beacon) { Beacon("session-data", { username: user?.username || "Unknown", screenResolution: `${screen.width}x${screen.height}`, }); return true; } return false; }; // Try immediately, then poll if Beacon isn't loaded yet if (!sendSessionData()) { const intervalId = setInterval(() => { if (sendSessionData()) { clearInterval(intervalId); } }, 1000); return () => clearInterval(intervalId); } }, [user?.username]); const [menuOpen, setMenuOpen] = useState(false); const [openSupportAfterClose, setOpenSupportAfterClose] = useState(false); const handleHelpClick = (e?: MouseEvent) => { e?.preventDefault(); e?.stopPropagation(); setOpenSupportAfterClose(true); setMenuOpen(false); }; useEffect(() => { if (typeof window === "undefined") return; if (!menuOpen && openSupportAfterClose) { setTimeout(() => { window.Support?.open(); }, 0); setOpenSupportAfterClose(false); } }, [menuOpen, openSupportAfterClose]); // Prevent rendering dropdown if user isn't available. // We don't want to show nameless user. if (!user && !isPending) { return null; } return ( }> {!small && ( {isPending ? "Loading..." : (user?.name ?? "Nameless User")} {menuOpen ? ( )} <> {!isPlatformPages && ( <> }> {t("my_profile")} }> {t("my_settings")} }> {t("out_of_office")} )} }> {t("visit_roadmap")} {t("help")} {!isPlatformPages && isPlatformUser && ( } className="todesktop:hidden hidden lg:flex"> {t("platform")} )} { signOut({ callbackUrl: "/auth/logout" }); }}> {t("sign_out")} ); }