/* ═══════════════════════════════════════════════════════════════
ORG TEAMS
An organization's leadership as people tiles, one block per team:
the team's name (linked to its page) and tagline, then its people.
Leadership arrives flat with team_id and team_name on each row,
so grouping costs nothing; `teams` gives the order and lists a
team with nobody in it yet. Used on an organization's page and on
the Organization page (NGU's own Board, Retreat Team and the rest).
═══════════════════════════════════════════════════════════════ */
import { Link } from 'react-router-dom'
import PeopleTiles from './PeopleTiles.tsx'
import type { Leader, OrganizationRecord } from '../lib/useContent.ts'
import { teamHref } from '../lib/hrefs.ts'
import { mediaUrl } from '../lib/media.ts'
import { accentText } from '../lib/color.ts'
const BODY = 'var(--color-muted)'
/* Whether the organization has any leadership to show. */
export const hasTeams = (org: OrganizationRecord) => groupLeadership(org).length > 0
export default function OrgTeams({ org, accent }: { org: OrganizationRecord; accent: string }) {
const teamBlocks = groupLeadership(org)
return (
)
}
/* ── Leadership → team blocks ────────────────────────────────── */
type TeamBlock = {
key: string
teamId: string | null
label: string | null
tagline?: string | null
accent?: string | null
people: Leader[]
}
/* Order comes from `teams` (the admin's sort_order), not from the
order people happen to appear in. Three cases to cover:
affiliations with no team at all, teams with nobody in them, and
people filed under a team that is no longer published. */
function groupLeadership(org: OrganizationRecord): TeamBlock[] {
const byTeam = new Map()
const loose: Leader[] = []
for (const leader of org.leadership) {
if (!leader.team_id) {
loose.push(leader)
continue
}
const list = byTeam.get(leader.team_id)
if (list) list.push(leader)
else byTeam.set(leader.team_id, [leader])
}
const blocks: TeamBlock[] = []
// People who hold a role in the organization without sitting on a
// team. Usually the leads. No heading, they are the page.
if (loose.length > 0) {
blocks.push({ key: 'loose', teamId: null, label: null, people: loose })
}
for (const team of org.teams) {
blocks.push({
key: team.id,
teamId: team.id,
label: team.name,
tagline: team.tagline,
accent: team.color,
people: byTeam.get(team.id) ?? [],
})
byTeam.delete(team.id)
}
// Whatever is left is filed under an unpublished team. Its page
// isn't reachable, so the heading is plain text, but the people
// are real and shouldn't silently vanish from the org.
for (const [teamId, people] of byTeam) {
blocks.push({
key: teamId,
teamId: null,
label: people[0]?.team_name ?? null,
people,
})
}
return blocks
}