'use client'; import { CodeIcon, Laptop, LogOut, Moon, Settings, Sun } from "lucide-react" import { Button } from "@/components/ui/button" import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { useTheme } from "next-themes" import { useMemo } from "react" import { KeymapType } from "@/lib/types" import { cn } from "@/lib/utils" import { useKeymapType } from "@/hooks/useKeymapType" import { useSession } from "next-auth/react"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { signOut } from "next-auth/react" import { env } from "@/env.mjs"; import posthog from "posthog-js"; import { useDomain } from "@/hooks/useDomain"; interface SettingsDropdownProps { menuButtonClassName?: string; displaySettingsOption: boolean; } export const SettingsDropdown = ({ menuButtonClassName, displaySettingsOption, }: SettingsDropdownProps) => { const { theme: _theme, setTheme } = useTheme(); const [keymapType, setKeymapType] = useKeymapType(); const { data: session, update } = useSession(); const domain = useDomain(); const theme = useMemo(() => { return _theme ?? "light"; }, [_theme]); const ThemeIcon = useMemo(() => { switch (theme) { case "light": return ; case "dark": return ; case "system": return ; default: return ; } }, [theme]); return ( // Was hitting a bug with invite code login where the first time the user signs in, the settingsDropdown doesn't have a valid session. To fix this // we can simply update the session everytime the settingsDropdown is opened. This isn't a super frequent operation and updating the session is low cost, // so this is a simple solution to the problem. { if (isOpen) { update(); } }}> {session?.user && (
{session.user.name && session.user.name.length > 0 ? session.user.name[0] : 'U'}

{session.user.email ?? "User"}

{ signOut({ redirectTo: "/login", }).then(() => { posthog.reset(); }) }} > Log out
)} {ThemeIcon} Theme Light Dark System Code navigation setKeymapType(value as KeymapType)}> Default Vim {displaySettingsOption && ( Settings )}
version: {env.NEXT_PUBLIC_SOURCEBOT_VERSION}
) }