import { LOCAL_STORAGE_KEYS, useFlag, useIsMFAEnabled, useParams } from 'common' import { AnimatePresence, motion, MotionProps } from 'framer-motion' import { Home } from 'icons' import { isUndefined } from 'lodash' import { Blocks, Boxes, ChartArea, PanelLeftDashed, Receipt, Settings, Users } from 'lucide-react' import Link from 'next/link' import { useRouter } from 'next/router' import { ComponentProps, ComponentPropsWithoutRef, FC, ReactNode, useEffect } from 'react' import { Button, cn, DropdownMenu, DropdownMenuContent, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuTrigger, Separator, SidebarContent as SidebarContentPrimitive, SidebarFooter, SidebarGroup, SidebarMenu, SidebarMenuButton, SidebarMenuItem, Sidebar as SidebarPrimitive, useSidebar, } from 'ui' import { Shortcut } from '../ui/Shortcut' import { Route } from '../ui/ui.types' import { useUnifiedLogsPreview } from './App/FeaturePreview/FeaturePreviewContext' import { generateOtherRoutes, generateProductRoutes, generateSettingsRoutes, generateToolRoutes, } from '@/components/layouts/Navigation/NavigationBar/NavigationBar.utils' import { ProjectIndexPageLink } from '@/data/prefetchers/project.$ref' import { useHideSidebar } from '@/hooks/misc/useHideSidebar' import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled' import { useLints } from '@/hooks/misc/useLints' import { useLocalStorageQuery } from '@/hooks/misc/useLocalStorage' import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization' import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject' import { SHORTCUT_IDS } from '@/state/shortcuts/registry' export const ICON_SIZE = 32 export const ICON_STROKE_WIDTH = 1.5 export type SidebarBehaviourType = 'expandable' | 'open' | 'closed' export const DEFAULT_SIDEBAR_BEHAVIOR = 'expandable' const SidebarMotion = motion.create(SidebarPrimitive) as FC< ComponentProps & { transition?: MotionProps['transition'] } > export interface SidebarProps extends ComponentPropsWithoutRef {} export const Sidebar = ({ className, ...props }: SidebarProps) => { const { setOpen } = useSidebar() const hideSideBar = useHideSidebar() const [sidebarBehaviour, setSidebarBehaviour] = useLocalStorageQuery( LOCAL_STORAGE_KEYS.SIDEBAR_BEHAVIOR, DEFAULT_SIDEBAR_BEHAVIOR ) useEffect(() => { // logic to toggle sidebar open based on sidebarBehaviour state if (sidebarBehaviour === 'open') setOpen(true) if (sidebarBehaviour === 'closed') setOpen(false) }, [sidebarBehaviour, setOpen]) return ( {!hideSideBar && ( { if (sidebarBehaviour === 'expandable') setOpen(true) }} onMouseLeave={() => { if (sidebarBehaviour === 'expandable') setOpen(false) }} >