import { useEffect, useState } from "react" import { meApi } from "@/api/me.ts" import { orgStore } from "@/auth/org.ts" import { authStore } from "@/auth/store.ts" import { adminNav, mainNav, orgNav, userNav } from "@/layouts/nav-config.ts" import { OrgSwitcher } from "@/layouts/org-switcher.tsx" import { Topbar } from "@/layouts/topbar.tsx" import { NavLink, Outlet } from "react-router-dom" import { cn } from "@/lib/utils.ts" import { useAuthActions } from "@/hooks/use-auth-actions.ts" import { Button } from "@/components/ui/button.tsx" import { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarInset, SidebarMenu, SidebarMenuButton, SidebarMenuItem, SidebarProvider, } from "@/components/ui/sidebar.tsx" type Org = { id: string name: string } export const AppShell = () => { const [orgs, setOrgs] = useState([]) const { logout } = useAuthActions() useEffect(() => { let alive = true ;(async () => { try { const me = await meApi.getMe() // HandlersMeResponse const list = (me.organizations ?? []).map((o) => ({ id: o.id, name: o.name ?? o.id, })) if (!alive) return setOrgs(list as Org[]) // default selection if none if (!orgStore.get() && list.length > 0) { orgStore.set(list[0].id!) } } catch { // ignore; ProtectedRoute will handle auth } })() return () => { alive = false } }, []) return (
Navigation {mainNav.map((n) => ( cn("flex items-center gap-2", isActive && "text-primary") } > {n.label} ))} Organization {orgNav.map((n) => ( cn("flex items-center gap-2", isActive && "text-primary") } > {n.label} ))} User {userNav.map((n) => ( cn("flex items-center gap-2", isActive && "text-primary") } > {n.label} ))} Admin {adminNav.map((n) => ( cn("flex items-center gap-2", isActive && "text-primary") } > {n.label} ))}
) }