People directories, ministries, organization contacts (migrations 062 to 064)
- People tags (062): Data → People tags (Musicians seeded); a person's Directories repeater tags them and their Specialty line shows on their tile. A People directory section preset shows a tag's first 12 and links to its full page, /directory/<tag>, with page meta and a sitemap entry. Tiles' details panels show a person's links. - Ministries (063): a new organization kind. A group picks its ministry and its page says "Ministry: <name>", linked to the ministry's website. Ministries have no public page, list, sitemap or timeline entry, and aren't offered where a record links to its organization. organizations is rebuilt for the kind CHECK. - Organization contacts (064): Data → Contact types; a private Contacts repeater on each organization (editors and up, readRole on a child collection). Tools → Newsletter → Recipients filters them by type, kind, region and published and downloads a Mailchimp CSV. - A trigger refusing a save with a sentence is shown as that message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
07e56bfd20
commit
0ed7315156
38 changed files with 1108 additions and 29 deletions
|
|
@ -396,6 +396,19 @@
|
|||
text-underline-offset: 2px;
|
||||
}
|
||||
|
||||
/* A directory person's links: one per line's worth, wrapping. */
|
||||
.pl__links {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.25rem 0.75rem;
|
||||
}
|
||||
|
||||
.pl__links a {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
}
|
||||
|
||||
.pl__bio-text {
|
||||
margin: 0;
|
||||
font-size: 0.9375rem;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import { mediaUrl, initials } from "../lib/media.ts";
|
|||
import { useSmallImage } from "../lib/useSmallImage.ts";
|
||||
import { paletteFill } from "../lib/color.ts";
|
||||
import { useReadingMode } from "../lib/readingMode.ts";
|
||||
import PlatformIcon from "./PlatformIcon.tsx";
|
||||
import "./PeopleTiles.css";
|
||||
|
||||
/**
|
||||
|
|
@ -96,6 +97,8 @@ export interface Person {
|
|||
pronouns?: string | null;
|
||||
location_label?: string | null;
|
||||
public_email?: string | null;
|
||||
/** Their website, music and social links (a directory's people). */
|
||||
links?: PersonLink[] | null;
|
||||
org?: string | { id?: string; name: string; href?: string } | null;
|
||||
bio?: string | string[] | null;
|
||||
accent?: string;
|
||||
|
|
@ -105,6 +108,13 @@ export interface Person {
|
|||
isOwner?: boolean;
|
||||
}
|
||||
|
||||
export interface PersonLink {
|
||||
kind?: string;
|
||||
platform?: string | null;
|
||||
label: string;
|
||||
url: string;
|
||||
}
|
||||
|
||||
/** A person named by slug. Any other field overrides the record. */
|
||||
export interface PersonRef extends Partial<Omit<Person, "name">> {
|
||||
peopleslug: string;
|
||||
|
|
@ -881,6 +891,19 @@ function DetailPanel({
|
|||
</dd>
|
||||
</div>
|
||||
)}
|
||||
{person.links?.length ? (
|
||||
<div className="pl__fact">
|
||||
<dt>Links</dt>
|
||||
<dd className="pl__links">
|
||||
{person.links.map((link) => (
|
||||
<a key={link.url} href={link.url} target="_blank" rel="noreferrer">
|
||||
<PlatformIcon platform={link.platform} />
|
||||
{link.label}
|
||||
</a>
|
||||
))}
|
||||
</dd>
|
||||
</div>
|
||||
) : null}
|
||||
</dl>
|
||||
|
||||
{paragraphs.filter(Boolean).map((paragraph, index) => (
|
||||
|
|
@ -931,6 +954,11 @@ function ReadingPeople({ groups, level }: { groups: PeopleGroup[]; level: 3 | 4
|
|||
Email: <a href={`mailto:${person.public_email}`}>{person.public_email}</a>
|
||||
</p>
|
||||
)}
|
||||
{person.links?.map((link) => (
|
||||
<p key={link.url}>
|
||||
<a href={link.url}>{link.label}</a>
|
||||
</p>
|
||||
))}
|
||||
{bio.filter(Boolean).map((paragraph, i) => (
|
||||
<p key={i}>{paragraph}</p>
|
||||
))}
|
||||
|
|
@ -1022,7 +1050,11 @@ function hasDetails(person: Person): boolean {
|
|||
return true;
|
||||
}
|
||||
return Boolean(
|
||||
person.pronouns || resolveOrg(person.org) || person.location_label || person.public_email,
|
||||
person.pronouns ||
|
||||
resolveOrg(person.org) ||
|
||||
person.location_label ||
|
||||
person.public_email ||
|
||||
person.links?.length,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
222
src/components/admin/NewsletterRecipients.tsx
Normal file
222
src/components/admin/NewsletterRecipients.tsx
Normal file
|
|
@ -0,0 +1,222 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
NEWSLETTER RECIPIENTS (Tools → Newsletter)
|
||||
|
||||
Organization contacts (064_org_contacts.sql) as a mailing list:
|
||||
pick contact types, organization kinds and a region, see who
|
||||
matches, and download a CSV that Mailchimp (or a spreadsheet)
|
||||
imports. Contacts are added on each organization; their types are
|
||||
Data → Contact types. Private, so editors and up only (the API
|
||||
says no to anyone else too: GET /admin/contacts).
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { DownloadSimple } from '@phosphor-icons/react'
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
import { get } from '../../lib/api.ts'
|
||||
|
||||
type Option = { id: string; label: string }
|
||||
|
||||
type Contact = {
|
||||
name: string | null
|
||||
email: string | null
|
||||
phone: string | null
|
||||
type_name: string
|
||||
org_name: string
|
||||
org_kind: string
|
||||
region_name: string | null
|
||||
}
|
||||
|
||||
/* The organization kinds, as the CHECK on organizations.kind has them. */
|
||||
const KINDS: Array<[string, string]> = [
|
||||
['national', 'National'],
|
||||
['region', 'Regions'],
|
||||
['group', 'Groups'],
|
||||
['partner', 'Partners'],
|
||||
['ministry', 'Ministries'],
|
||||
]
|
||||
|
||||
/* How many matches show under the filters; the CSV has them all. */
|
||||
const PREVIEW_ROWS = 8
|
||||
|
||||
const MUTED = 'var(--color-muted)'
|
||||
const input =
|
||||
'border border-muted/25 bg-surface px-3 py-2 text-sm text-body outline-none focus:border-brand focus:ring-2 focus:ring-brand/25'
|
||||
const button =
|
||||
'btn inline-flex items-center gap-2 border border-brand px-4 py-2 text-sm text-link transition-colors hover:bg-tint disabled:opacity-50'
|
||||
|
||||
const toggle = (list: string[], value: string) =>
|
||||
list.includes(value) ? list.filter((v) => v !== value) : [...list, value]
|
||||
|
||||
/* "Jane Q. Doe" → Jane, Q. Doe: Mailchimp's First and Last Name. */
|
||||
function splitName(name: string | null): [string, string] {
|
||||
const parts = (name ?? '').trim().split(/\s+/).filter(Boolean)
|
||||
return [parts[0] ?? '', parts.slice(1).join(' ')]
|
||||
}
|
||||
|
||||
const csvCell = (value: string | null) => {
|
||||
const text = value ?? ''
|
||||
return /[",\n]/.test(text) ? `"${text.replace(/"/g, '""')}"` : text
|
||||
}
|
||||
|
||||
function toCsv(rows: Contact[]): string {
|
||||
const head = ['Email', 'First Name', 'Last Name', 'Phone', 'Organization', 'Kind', 'Region', 'Contact type']
|
||||
const lines = rows.map((row) => {
|
||||
const [first, last] = splitName(row.name)
|
||||
return [row.email, first, last, row.phone, row.org_name, row.org_kind, row.region_name, row.type_name]
|
||||
.map(csvCell)
|
||||
.join(',')
|
||||
})
|
||||
return [head.join(','), ...lines].join('\n')
|
||||
}
|
||||
|
||||
export default function NewsletterRecipients() {
|
||||
const [types, setTypes] = useState<Option[]>([])
|
||||
const [regions, setRegions] = useState<Option[]>([])
|
||||
const [picked, setPicked] = useState<string[]>([])
|
||||
const [kinds, setKinds] = useState<string[]>([])
|
||||
const [region, setRegion] = useState('')
|
||||
const [unpublished, setUnpublished] = useState(false)
|
||||
const [contacts, setContacts] = useState<Contact[] | null>(null)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
get('/admin/options?only=contact_types,regions', { ttl: 0 })
|
||||
.then((data: { options: { contact_types: Option[]; regions: Option[] } }) => {
|
||||
setTypes(data.options.contact_types)
|
||||
setRegions(data.options.regions)
|
||||
})
|
||||
.catch((err) => setError(err instanceof Error ? err.message : 'Couldn’t load the contact types.'))
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const query = new URLSearchParams()
|
||||
if (picked.length) query.set('types', picked.join(','))
|
||||
if (kinds.length) query.set('kinds', kinds.join(','))
|
||||
if (region) query.set('region', region)
|
||||
if (unpublished) query.set('unpublished', '1')
|
||||
let live = true
|
||||
get(`/admin/contacts?${query}`, { ttl: 0 })
|
||||
.then((data: { contacts: Contact[] }) => {
|
||||
if (!live) return
|
||||
setContacts(data.contacts)
|
||||
setError(null)
|
||||
})
|
||||
.catch((err) => live && setError(err instanceof Error ? err.message : 'Couldn’t load the contacts.'))
|
||||
return () => {
|
||||
live = false
|
||||
}
|
||||
}, [picked, kinds, region, unpublished])
|
||||
|
||||
const withEmail = contacts?.filter((row) => row.email) ?? []
|
||||
|
||||
function download() {
|
||||
const blob = new Blob([toCsv(withEmail)], { type: 'text/csv' })
|
||||
const link = document.createElement('a')
|
||||
link.href = URL.createObjectURL(blob)
|
||||
link.download = `newsletter-recipients-${new Date().toISOString().slice(0, 10)}.csv`
|
||||
link.click()
|
||||
URL.revokeObjectURL(link.href)
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="mt-10 border-l-4 border-brand bg-raised p-5 shadow-sm">
|
||||
<h2 className="text-lg font-bold text-link">Recipients</h2>
|
||||
<p className="mt-1 text-sm" style={{ color: MUTED }}>
|
||||
Organization contacts as a mailing list. Add contacts on each organization; make their types under Data → Contact
|
||||
types. Nothing picked in a filter means all of it.
|
||||
</p>
|
||||
|
||||
<div className="mt-4 grid gap-5 md:grid-cols-3">
|
||||
<fieldset>
|
||||
<legend className="text-sm font-semibold text-body">Contact types</legend>
|
||||
{types.length === 0 && (
|
||||
<p className="mt-1 text-sm" style={{ color: MUTED }}>
|
||||
None yet: add them under Data → Contact types.
|
||||
</p>
|
||||
)}
|
||||
{types.map((type) => (
|
||||
<label key={type.id} className="mt-1 flex items-center gap-2 text-sm text-body">
|
||||
<input type="checkbox" checked={picked.includes(type.id)} onChange={() => setPicked(toggle(picked, type.id))} />
|
||||
{type.label}
|
||||
</label>
|
||||
))}
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<legend className="text-sm font-semibold text-body">Organization kinds</legend>
|
||||
{KINDS.map(([kind, label]) => (
|
||||
<label key={kind} className="mt-1 flex items-center gap-2 text-sm text-body">
|
||||
<input type="checkbox" checked={kinds.includes(kind)} onChange={() => setKinds(toggle(kinds, kind))} />
|
||||
{label}
|
||||
</label>
|
||||
))}
|
||||
</fieldset>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-semibold text-body">
|
||||
Region
|
||||
<select value={region} onChange={(e) => setRegion(e.target.value)} className={`mt-1 block w-full ${input}`}>
|
||||
<option value="">Default: every region</option>
|
||||
{regions.map((r) => (
|
||||
<option key={r.id} value={r.id}>
|
||||
{r.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<p className="mt-1 text-xs" style={{ color: MUTED }}>
|
||||
The region itself and the groups in it
|
||||
</p>
|
||||
<label className="mt-3 flex items-center gap-2 text-sm text-body">
|
||||
<input type="checkbox" checked={unpublished} onChange={(e) => setUnpublished(e.target.checked)} />
|
||||
Include unpublished organizations
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-5 flex flex-wrap items-center gap-3">
|
||||
<button type="button" onClick={download} className={button} disabled={withEmail.length === 0}>
|
||||
<DownloadSimple weight="bold" aria-hidden="true" />
|
||||
Download CSV
|
||||
</button>
|
||||
<p role="status" className={`text-sm ${error ? 'text-danger' : ''}`} style={error ? undefined : { color: MUTED }}>
|
||||
{error ??
|
||||
(contacts === null
|
||||
? 'Loading…'
|
||||
: `${withEmail.length} with an email` +
|
||||
(contacts.length > withEmail.length ? ` (${contacts.length - withEmail.length} more have only a phone, left out)` : ''))}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{withEmail.length > 0 && (
|
||||
<div className="mt-4 overflow-x-auto">
|
||||
<table className="w-full text-left text-sm">
|
||||
<thead>
|
||||
<tr className="text-xs" style={{ color: MUTED }}>
|
||||
<th className="py-1 pr-4 font-semibold">Email</th>
|
||||
<th className="py-1 pr-4 font-semibold">Name</th>
|
||||
<th className="py-1 pr-4 font-semibold">Organization</th>
|
||||
<th className="py-1 pr-4 font-semibold">Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{withEmail.slice(0, PREVIEW_ROWS).map((row, index) => (
|
||||
<tr key={`${row.email}-${index}`} className="border-t border-muted/15 text-body">
|
||||
<td className="py-1 pr-4">{row.email}</td>
|
||||
<td className="py-1 pr-4">{row.name || '-'}</td>
|
||||
<td className="py-1 pr-4">{row.org_name}</td>
|
||||
<td className="py-1 pr-4">{row.type_name}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
{withEmail.length > PREVIEW_ROWS && (
|
||||
<p className="mt-2 text-xs" style={{ color: MUTED }}>
|
||||
and {withEmail.length - PREVIEW_ROWS} more in the CSV
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue