"use client"; import React, { useEffect } from "react"; import { useQuery } from "@tanstack/react-query"; import { Building2, FolderKanban, Bell, Search, ChevronDown, UserCircle, } from "lucide-react"; import { orgs, projects } from "@/lib/api"; import { Dropdown, type Option } from "@/components/ui/Dropdown"; import { Button } from "@/components/ui/Button"; import { useAppStore } from "@/stores/useAppStore"; import { cn } from "@/lib/utils"; export function Topbar({ className }: { className?: string }) { const setOrg = useAppStore((s) => s.setOrg); const setProject = useAppStore((s) => s.setProject); const currentOrg = useAppStore((s) => s.org_id); const currentProject = useAppStore((s) => s.project_id); const openAsf = useAppStore((s) => s.openAsf); const { data: orgList = [] } = useQuery({ queryKey: ["orgs"], queryFn: () => orgs.list({ limit: 50 }), initialData: [], }); const { data: projectList = [] } = useQuery({ queryKey: ["projects"], queryFn: () => projects.list({ limit: 100 }), initialData: [], enabled: !!currentOrg, }); const orgOptions: Option[] = orgList.map((o) => ({ value: o.id, label: o.name, description: o.slug, })); if (orgOptions.length === 0) { // Dev-mode synthetic org (matches NEXT_PUBLIC_DEV_TENANT_ID) orgOptions.push({ value: currentOrg || "00000000-0000-0000-0000-000000000001", label: "Azurian Labs", description: "azurian-labs (bootstrap demo)", }); } const projectOptions: Option[] = projectList.map((p) => ({ value: p.id, label: `${p.key} · ${p.name}`, description: p.description || undefined, })); // Add a synthetic "All projects" option projectOptions.unshift({ value: "__all__", label: "All projects", description: "Tenant-wide view", }); useEffect(() => { if (!currentProject && projectList.length > 0) { setProject(projectList[0].id); } }, [currentProject, projectList, setProject]); return (
{/* Mobile brand */}
A
ASF
} options={orgOptions} value={currentOrg} onChange={(v) => { setOrg(v); setProject(undefined); }} /> } options={projectOptions} value={currentProject === undefined ? "__all__" : currentProject} onChange={(v) => setProject(v === "__all__" ? undefined : v)} />
); }