import { useCallback, useEffect, useState } from "react"; import { useNavigate } from "react-router-dom"; import { agentsApi, type OrgNode } from "../api/agents"; import { useCompany } from "../context/CompanyContext"; import { useBreadcrumbs } from "../context/BreadcrumbContext"; import { useApi } from "../hooks/useApi"; import { StatusBadge } from "../components/StatusBadge"; import { EmptyState } from "../components/EmptyState"; import { ChevronRight, GitBranch } from "lucide-react"; import { cn } from "../lib/utils"; function OrgTree({ nodes, depth = 0, onSelect, }: { nodes: OrgNode[]; depth?: number; onSelect: (id: string) => void; }) { return (
{nodes.map((node) => ( ))}
); } function OrgTreeNode({ node, depth, onSelect, }: { node: OrgNode; depth: number; onSelect: (id: string) => void; }) { const [expanded, setExpanded] = useState(true); const hasChildren = node.reports.length > 0; return (
onSelect(node.id)} > {hasChildren ? ( ) : ( )} {node.name} {node.role}
{hasChildren && expanded && ( )}
); } export function Org() { const { selectedCompanyId } = useCompany(); const { setBreadcrumbs } = useBreadcrumbs(); const navigate = useNavigate(); useEffect(() => { setBreadcrumbs([{ label: "Org Chart" }]); }, [setBreadcrumbs]); const fetcher = useCallback(() => { if (!selectedCompanyId) return Promise.resolve([] as OrgNode[]); return agentsApi.org(selectedCompanyId); }, [selectedCompanyId]); const { data, loading, error } = useApi(fetcher); if (!selectedCompanyId) { return ; } return (

Org Chart

{loading &&

Loading...

} {error &&

{error.message}

} {data && data.length === 0 && ( )} {data && data.length > 0 && (
navigate(`/agents/${id}`)} />
)}
); }