import { useEffect, useState } from "react";
import { Layers, GitBranch, Building2, Loader2, Link } from "lucide-react";
import { api, MyOrgMembership } from "@/lib/api";
import { Skeleton } from "@/components/ui/skeleton";
import { Badge } from "@/components/ui/badge";
function MembershipsSkeleton() {
return (
);
}
export default function MyMembershipsPage() {
const [orgs, setOrgs] = useState([]);
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
api.users.getMyMemberships()
.then((res) => setOrgs(res.orgs ?? []))
.catch(console.error)
.finally(() => setIsLoading(false));
}, []);
const totalDepts = orgs.reduce((s, o) => s + o.departments.length, 0);
const totalPrincipals = orgs.reduce((s, o) => s + o.principals.length, 0);
return (
My Memberships
Departments and principals you belong to across your organizations
{isLoading ? (
) : orgs.length === 0 ? (
You're not a member of any organizations yet.
) : (
{/* Summary chips */}
{totalDepts}
department{totalDepts !== 1 ? "s" : ""}
{totalPrincipals}
principal{totalPrincipals !== 1 ? "s" : ""}
{orgs.map((org) => (
{/* Org header */}
{org.org_name}
{org.role.toLowerCase()}
{/* Departments */}
Departments
{org.departments.length === 0 ? (
Not assigned to any departments.
) : (
{org.departments.map((dept) => (
-
{dept.name}
{dept.description && (
{dept.description}
)}
))}
)}
{/* Principals */}
Principals
{org.principals.length === 0 ? (
No principals assigned.
) : (
{org.principals.map((p) => (
-
{p.name}
{p.description && (
{p.description}
)}
{p.via_department && (
via dept
)}
))}
)}
))}
)}
);
}