/* ═══════════════════════════════════════════════════════════════ ORGANIZATION DETAIL /regions/:id /groups/:id /partners/:id /organizations/:id One component behind four routes, because organizations are one table. The kind decides which extras render, not which file runs. The URL kind is decoration, the slug is what identifies the record, so a request for /groups/great-lakes when that slug is a region redirects to the canonical path rather than rendering a correct page at a wrong address. Leadership arrives flat with team_id and team_name on each row, so grouping costs nothing. `teams` is fetched alongside anyway: a team with no current public members would otherwise be invisible here instead of listed, and its page unreachable. ═══════════════════════════════════════════════════════════════ */ import { Link, Navigate, useLocation, useParams } from 'react-router-dom' import PageShell from '../components/PageShell.tsx' import PageState from '../components/PageState.tsx' import PlatformIcon from '../components/PlatformIcon.tsx' import ContentBlocks from '../components/ContentBlocks.tsx' import PeopleTiles from '../components/PeopleTiles.tsx' import EventListCards from './sections/EventList-Cards.tsx' import { useOrganization, type Leader, type OrganizationRecord, } from '../lib/useContent.ts' import { orgHref, orgListHref, teamHref } from '../lib/hrefs.ts' import { mediaUrl } from '../lib/media.ts' import { initialsFor } from '../lib/organizations.ts' import Logo from '../components/Logo.tsx' import { withAlpha, accentText, readableOn, BRAND } from '../lib/color.ts' const BODY = 'var(--color-muted)' export default function OrganizationDetail() { const { id } = useParams() const { pathname } = useLocation() const { data: org, loading, error, notFound, reload } = useOrganization(id) if (!org) { return ( ) } // /groups/x when x is a region: same record, wrong address. // // useLocation, not window.location: the latter is outside the // router's awareness, always "/" under HashRouter, and free to // be stale mid-navigation, either of which turns this into a // redirect loop rather than a one-shot correction. // // Guarded on org.id because a record with no id would redirect to // /groups/undefined, which is a worse page than the one we're // already on. All four organization routes must be registered or // this redirects somewhere nothing matches. const canonical = org.id ? orgHref(org.id, org.kind) : null if (canonical && decodeURIComponent(pathname) !== canonical) { return } const accent = org.color || BRAND const back = orgListHref(org.kind) const sections: any[] = [ { id: 'about', title: 'About', accent, background: 'var(--color-surface)', content: (
{org.description.map((paragraph, index) => (

{paragraph}

))}
), }, ] const teamBlocks = groupLeadership(org) if (teamBlocks.length > 0) { sections.push({ id: 'leadership', title: 'Who runs it', accent, background: 'var(--color-tint)', content: (
{teamBlocks.map((block) => (
{block.teamId ? (

{block.label}

) : ( block.label && (

{block.label}

) )} {block.tagline && (

{block.tagline}

)}
{block.people.length > 0 ? ( ({ id: leader.person_id, name: leader.display_name, title: leader.title, pronouns: leader.pronouns, public_email: leader.public_email, photo: mediaUrl(leader.photo), is_owner: leader.is_owner, }))} /> ) : (

No members listed yet.

)}
))}
), }) } if (org.kind === 'region' && (org.details.groups?.length ?? 0) > 0) { sections.push({ id: 'groups', title: 'Groups', blurb: org.details.map_note ?? undefined, accent, background: 'var(--color-surface)', content: (
{(org.details.groups ?? []).map((group) => ( {group.name} {group.location_label && ( {group.location_label} )} ))}
), }) } if (org.awards.length > 0) { sections.push({ id: 'awards', title: 'Awards', blurb: `Given by ${org.short_name || org.name}.`, accent, background: 'var(--color-tint)', content: (
{org.awards.map((award) => ( {award.name} {award.description && ( {award.description} )} {award.recipient_count === 0 ? 'No recipients yet' : `${award.recipient_count} recipient${award.recipient_count === 1 ? '' : 's'}`} ))}
), }) } // EventList-Cards fetches and renders this itself, its own // docstring offers `host` for exactly this case, and a card there // already knows about gradients, logos, past-event collapsing and // the carousel. A second grid here was the same component written // worse. // // `org.events` is still what decides whether the section exists at // all: an organization that has never hosted anything shouldn't // get a heading followed by "events coming soon". if (org.events.length > 0) { sections.push({ id: 'events', title: 'Gatherings', accent, background: 'var(--color-surface)', content: ( ), }) } return } /* ── Pieces ──────────────────────────────────────────────────── */ function Facts({ org, accent, back, }: { org: OrganizationRecord accent: string back: { to: string; label: string } }) { const where = org.location_label || [org.locality, org.state_code].filter(Boolean).join(', ') return (
{where && {where}} {org.kind === 'region' && org.details.scope && ( {org.details.scope} )} {org.kind === 'group' && org.details.region_id && ( Part of{' '} {org.details.region_name} )} {org.kind === 'group' && org.details.meets && ( Meets {org.details.meets} )} {org.kind === 'group' && org.details.started && ( Since {org.details.started} )} {org.is_online && Online} {back.label}
) } function Contact({ org, accent }: { org: OrganizationRecord; accent: string }) { const hasAny = org.links.length > 0 || org.socials.length > 0 || org.website || org.email if (!hasAny) return null return (
{org.links.map((link) => ( {link.label} ))} {/* website and email arrive as bare strings (splitLinks in shape.js); socials are whole link rows. */} {[ org.website ? { url: org.website, label: 'Website', platform: null } : null, org.email ? { url: `mailto:${org.email}`, label: org.email, platform: null } : null, ...org.socials, ] .filter((link): link is NonNullable => Boolean(link)) .map((link) => ( {link.label} ))}
) } function GroupMark({ file, name, accent }: { file?: string | null; name: string; accent: string }) { return (