Add person detail page and link people tiles to it
GET /api/people/:id returns a published person's profile, public roles (current and past), published events they were billed at or hosted, and public awards, each under the same visibility rules its own page applies. public_phone is never sent. PersonDetail renders it at /people/:id, the route personHref already pointed at. PeopleTiles links a tile with a people id to that page; an expandable tile keeps its details panel and the panel carries a "View full profile" link instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
300c9b74f0
commit
6ec2fb240a
6 changed files with 643 additions and 6 deletions
363
src/pages/PersonDetail.tsx
Normal file
363
src/pages/PersonDetail.tsx
Normal file
|
|
@ -0,0 +1,363 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
PERSON DETAIL — /people/:id
|
||||
|
||||
Everything public that points at one person, gathered by
|
||||
GET /people/:id in people.js. Visibility is decided there, the
|
||||
same way each list's own page decides it, so nothing here
|
||||
filters.
|
||||
|
||||
Roles are current and past. A roster only ever wants who holds
|
||||
a seat now; a person's record is also where "served on the board
|
||||
2018–2022" belongs, so ended affiliations list under Previously.
|
||||
|
||||
public_phone is never sent. The email is the one contact detail
|
||||
the page offers.
|
||||
|
||||
Sections after About alternate background in the order they
|
||||
appear, so a person with no roles doesn't get two tinted bands
|
||||
in a row.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { Link, useParams } from 'react-router-dom'
|
||||
|
||||
import PageShell, { type ShellSection } from '../components/PageShell.tsx'
|
||||
import PageState from '../components/PageState.tsx'
|
||||
import ContentBlocks from '../components/ContentBlocks.tsx'
|
||||
import {
|
||||
usePerson,
|
||||
type PersonEvent,
|
||||
type PersonRecord,
|
||||
type PersonRole,
|
||||
} from '../lib/useContent.ts'
|
||||
import { awardHref, eventHref, orgHref, teamHref } from '../lib/hrefs.ts'
|
||||
import { initials, personPhoto } from '../lib/media.ts'
|
||||
import { eventTypeLabel } from '../lib/eventTypes.ts'
|
||||
|
||||
const TEAL = '#138ba0'
|
||||
const BODY = '#4a6b72'
|
||||
const BACKGROUNDS = ['#ffffff', '#eef9fb']
|
||||
|
||||
/* affiliations.role, for a row with no title of its own. */
|
||||
const ROLE_LABEL: Record<string, string> = {
|
||||
lead: 'Lead',
|
||||
board: 'Board member',
|
||||
staff: 'Staff',
|
||||
volunteer: 'Volunteer',
|
||||
member: 'Member',
|
||||
}
|
||||
|
||||
const capitalize = (word: string) =>
|
||||
word ? word.charAt(0).toUpperCase() + word.slice(1) : ''
|
||||
|
||||
export default function PersonDetail() {
|
||||
const { id } = useParams()
|
||||
const { data: person, loading, error, notFound, reload } = usePerson(id)
|
||||
|
||||
if (!person) {
|
||||
return (
|
||||
<PageState
|
||||
loading={loading}
|
||||
error={error}
|
||||
notFound={notFound}
|
||||
onRetry={reload}
|
||||
noun="person"
|
||||
backTo="/leadership"
|
||||
backLabel="Leadership"
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const accent = TEAL
|
||||
const current = person.roles.filter((role) => !role.ended_on)
|
||||
const previous = person.roles.filter((role) => role.ended_on)
|
||||
|
||||
const sections: ShellSection[] = [
|
||||
{
|
||||
id: 'about',
|
||||
title: 'About',
|
||||
accent,
|
||||
background: BACKGROUNDS[0],
|
||||
content: (
|
||||
<div className="max-w-6xl mx-auto px-6 space-y-8">
|
||||
<Facts person={person} accent={accent} />
|
||||
|
||||
{[...person.bio, ...person.description].map((paragraph, index) => (
|
||||
<p key={index} className="leading-relaxed max-w-3xl" style={{ color: BODY }}>
|
||||
{paragraph}
|
||||
</p>
|
||||
))}
|
||||
|
||||
<div className="max-w-3xl">
|
||||
<ContentBlocks blocks={person.blocks} accent={accent} />
|
||||
</div>
|
||||
|
||||
<Contact person={person} accent={accent} />
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]
|
||||
|
||||
if (person.roles.length > 0) {
|
||||
sections.push({
|
||||
id: 'roles',
|
||||
title: 'Roles',
|
||||
accent,
|
||||
background: BACKGROUNDS[sections.length % 2],
|
||||
content: (
|
||||
<div className="max-w-6xl mx-auto px-6 space-y-8">
|
||||
{current.length > 0 && <RoleList roles={current} accent={accent} />}
|
||||
|
||||
{previous.length > 0 && (
|
||||
<div>
|
||||
{current.length > 0 && (
|
||||
<h3 className="mb-4 text-lg font-semibold" style={{ color: accent }}>
|
||||
Previously
|
||||
</h3>
|
||||
)}
|
||||
<RoleList roles={previous} accent={accent} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
if (person.events.length > 0) {
|
||||
sections.push({
|
||||
id: 'events',
|
||||
title: 'Events',
|
||||
accent,
|
||||
background: BACKGROUNDS[sections.length % 2],
|
||||
content: (
|
||||
<div className="max-w-6xl mx-auto px-6">
|
||||
<ul className="space-y-5">
|
||||
{person.events.map((event) => (
|
||||
<li key={event.id}>
|
||||
<EventRow event={event} accent={accent} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
if (person.awards.length > 0) {
|
||||
sections.push({
|
||||
id: 'awards',
|
||||
title: 'Awards',
|
||||
accent,
|
||||
background: BACKGROUNDS[sections.length % 2],
|
||||
content: (
|
||||
<div className="max-w-6xl mx-auto px-6 space-y-6">
|
||||
{person.awards.map((entry, index) => (
|
||||
<div
|
||||
key={`${entry.award.id}:${entry.awarded_on ?? index}`}
|
||||
className="border-l-2 pl-5"
|
||||
style={{ borderColor: accent }}
|
||||
>
|
||||
<p className="font-semibold" style={{ color: accent }}>
|
||||
<Link to={awardHref(entry.award.id)} className="hover:underline">
|
||||
{entry.award.name}
|
||||
</Link>
|
||||
</p>
|
||||
{(entry.awarded_on || entry.event) && (
|
||||
<p className="text-sm" style={{ color: BODY }}>
|
||||
{year(entry.awarded_on)}
|
||||
{entry.event && (
|
||||
<>
|
||||
{entry.awarded_on && ' · '}
|
||||
<Link
|
||||
to={eventHref(entry.event.id)}
|
||||
className="hover:underline"
|
||||
style={{ color: accent }}
|
||||
>
|
||||
{entry.event.title}
|
||||
</Link>
|
||||
</>
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
{entry.citation && (
|
||||
<p className="mt-1 max-w-2xl italic leading-relaxed" style={{ color: BODY }}>
|
||||
{entry.citation}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<PageShell title={person.name} intro={person.tagline ?? undefined} sections={sections} />
|
||||
)
|
||||
}
|
||||
|
||||
/* ── The strip of facts under the heading ────────────────────── */
|
||||
|
||||
function Facts({ person, accent }: { person: PersonRecord; accent: string }) {
|
||||
const photo = personPhoto(person.photo)
|
||||
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-x-6 gap-y-3 text-sm">
|
||||
{photo ? (
|
||||
<img
|
||||
src={photo}
|
||||
alt=""
|
||||
loading="lazy"
|
||||
decoding="async"
|
||||
className="h-24 w-24 shrink-0 rounded-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className="flex h-24 w-24 shrink-0 items-center justify-center rounded-full text-2xl font-bold text-white"
|
||||
style={{ background: accent }}
|
||||
>
|
||||
{initials(person.name)}
|
||||
</span>
|
||||
)}
|
||||
|
||||
{person.pronouns && <span style={{ color: BODY }}>{person.pronouns}</span>}
|
||||
|
||||
{person.org && (
|
||||
<Link
|
||||
to={orgHref(person.org.id, person.org.kind)}
|
||||
className="font-medium hover:underline"
|
||||
style={{ color: accent }}
|
||||
>
|
||||
{person.org.name}
|
||||
</Link>
|
||||
)}
|
||||
|
||||
{person.location_label && <span style={{ color: BODY }}>{person.location_label}</span>}
|
||||
|
||||
<Link to="/leadership" className="ml-auto hover:underline" style={{ color: accent }}>
|
||||
Leadership
|
||||
</Link>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function Contact({ person, accent }: { person: PersonRecord; accent: string }) {
|
||||
const outlined = [
|
||||
person.website ? { url: person.website, label: 'Website' } : null,
|
||||
person.public_email
|
||||
? { url: `mailto:${person.public_email}`, label: person.public_email }
|
||||
: null,
|
||||
...person.socials,
|
||||
].filter((link): link is NonNullable<typeof link> => Boolean(link))
|
||||
|
||||
if (person.links.length === 0 && outlined.length === 0) return null
|
||||
|
||||
return (
|
||||
<div className="flex flex-wrap gap-3">
|
||||
{person.links.map((link) => (
|
||||
<a
|
||||
key={link.url}
|
||||
href={link.url}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="rounded-full px-5 py-2 text-sm font-semibold text-white transition-transform hover:scale-105"
|
||||
style={{ background: accent }}
|
||||
>
|
||||
{link.label}
|
||||
</a>
|
||||
))}
|
||||
|
||||
{outlined.map((link) => (
|
||||
<a
|
||||
key={link.url}
|
||||
href={link.url}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="rounded-full border px-4 py-1.5 text-sm font-medium transition-colors hover:bg-[#eef9fb]"
|
||||
style={{ borderColor: accent, color: accent }}
|
||||
>
|
||||
{link.label}
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/* ── Roles ───────────────────────────────────────────────────── */
|
||||
|
||||
function RoleList({ roles, accent }: { roles: PersonRole[]; accent: string }) {
|
||||
return (
|
||||
<ul className="grid gap-4 sm:grid-cols-2">
|
||||
{roles.map((role, index) => (
|
||||
<li
|
||||
key={`${role.org.id}:${role.team?.id ?? ''}:${role.title ?? role.role}:${index}`}
|
||||
className="rounded-xl border-l-4 bg-white px-5 py-3"
|
||||
style={{ borderColor: accent }}
|
||||
>
|
||||
<p className="font-semibold" style={{ color: accent }}>
|
||||
{role.title || ROLE_LABEL[role.role] || capitalize(role.role)}
|
||||
</p>
|
||||
<p className="text-sm" style={{ color: BODY }}>
|
||||
{role.team && (
|
||||
<>
|
||||
<Link to={teamHref(role.team.id)} className="hover:underline">
|
||||
{role.team.name}
|
||||
</Link>
|
||||
{' · '}
|
||||
</>
|
||||
)}
|
||||
<Link to={orgHref(role.org.id, role.org.kind)} className="hover:underline">
|
||||
{role.org.name}
|
||||
</Link>
|
||||
</p>
|
||||
{tenure(role) && (
|
||||
<p className="text-xs" style={{ color: BODY }}>
|
||||
{tenure(role)}
|
||||
</p>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
|
||||
/* "2018 – 2022", "Since 2021", "Until 2019", or null. Years only:
|
||||
affiliation dates are often backfilled from memory. */
|
||||
function tenure(role: PersonRole): string | null {
|
||||
const from = year(role.started_on)
|
||||
const to = year(role.ended_on)
|
||||
if (from && to) return from === to ? from : `${from} – ${to}`
|
||||
if (from) return `Since ${from}`
|
||||
if (to) return `Until ${to}`
|
||||
return null
|
||||
}
|
||||
|
||||
/* ── Events ──────────────────────────────────────────────────── */
|
||||
|
||||
function EventRow({ event, accent }: { event: PersonEvent; accent: string }) {
|
||||
const when = event.date_label || year(event.starts_on)
|
||||
const capacities = event.roles
|
||||
.map((role) => role.title || capitalize(role.role))
|
||||
.join(', ')
|
||||
|
||||
return (
|
||||
<div className="border-l-2 pl-5" style={{ borderColor: accent }}>
|
||||
<p className="font-semibold" style={{ color: accent }}>
|
||||
<Link to={eventHref(event.id)} className="hover:underline">
|
||||
{event.title}
|
||||
</Link>
|
||||
</p>
|
||||
<p className="text-sm" style={{ color: BODY }}>
|
||||
{[capacities, eventTypeLabel(event.event_type), when].filter(Boolean).join(' · ')}
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/* Dates here may be partial ('2019', '2019-06'), so take the
|
||||
leading year rather than parsing. */
|
||||
function year(date?: string | null): string | null {
|
||||
if (!date) return null
|
||||
const match = /^(\d{4})/.exec(date)
|
||||
return match ? match[1] : date
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue