import type { IServiceOrganization } from '@openpanel/db'; import { useQuery } from '@tanstack/react-query'; import { Link, useLocation, useParams } from '@tanstack/react-router'; import { MenuIcon, XIcon } from 'lucide-react'; import { useEffect, useState } from 'react'; import { FeedbackButton } from './feedback-button'; import { LogoSquare } from './logo'; import { ProfileToggle } from './profile-toggle'; import ProjectSelector from './project-selector'; import SidebarOrganizationMenu, { ActionCTAButton as ActionOrganizationCTAButton, } from './sidebar-organization-menu'; import SidebarProjectMenu, { ActionCTAButton as ActionProjectCTAButton, } from './sidebar-project-menu'; import { Button } from './ui/button'; import { useAppContext } from '@/hooks/use-app-context'; import { useTRPC } from '@/integrations/trpc/react'; import { cn } from '@/utils/cn'; export function Sidebar() { const { organizationId, projectId } = useParams({ strict: false }); const trpc = useTRPC(); // Get organizations data const { data: organizations = [] } = useQuery( trpc.organization.list.queryOptions() ); // Get projects data when we have an organization const { data: projects = [] } = useQuery({ ...trpc.project.list.queryOptions({ organizationId: organizationId || null, }), enabled: !!organizationId, }); // Get dashboards data when we have a project const { data: dashboards = [] } = useQuery({ ...trpc.dashboard.list.queryOptions({ projectId: projectId || '', }), enabled: !!projectId, }); if (projectId && organizationId) { return ( ); } // Otherwise show the original sidebar structure return ( Organization o.id === organizationId)!} /> ); } interface SidebarContainerProps { organizations: IServiceOrganization[]; projects: Array<{ id: string; name: string; organizationId: string }>; children: React.ReactNode; } export function SidebarContainer({ organizations, projects, children, }: SidebarContainerProps) { const [active, setActive] = useState(false); const location = useLocation(); const { isSelfHosted } = useAppContext(); useEffect(() => { setActive(false); }, [location]); return ( <> setActive(false)} type="button" /> setActive((p) => !p)} size="icon" variant={'outline'} > {active ? : } {children} Docs {isSelfHosted && ( Support Us Pay What You Want )} > ); }