feat(website): people and roles, messages with the YouTube feed, simple events
People: Owners and Admins add someone by email (people.ensure through Accounts), change roles, remove access; only Owners touch Owners, nobody changes themselves, a lower role ends sessions at once. Messages: from a YouTube channel or playlist every hour (public feed, no key) or by hand with a YouTube or Spotify link; own publish, hide. Simple events: own publish, cancel, remove. Tests and e2e with axe on the new screens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,8 +12,11 @@ const NAV = [
|
||||
{ href: "/admin/pages", label: "Pages" },
|
||||
{ href: "/admin/ministries", label: "Ministries" },
|
||||
{ href: "/admin/leaders", label: "Leadership" },
|
||||
{ href: "/admin/messages", label: "Messages" },
|
||||
{ href: "/admin/events", label: "Events" },
|
||||
{ href: "/admin/media", label: "Media library" },
|
||||
{ href: "/admin/publish", label: "Publish and history" },
|
||||
{ href: "/admin/people", label: "People", managers: true },
|
||||
];
|
||||
|
||||
export function AdminShell({ user, children }: { user: { name: string; role: string }; children: React.ReactNode }) {
|
||||
@@ -36,7 +39,7 @@ export function AdminShell({ user, children }: { user: { name: string; role: str
|
||||
<div className="mx-auto grid max-w-6xl gap-6 px-4 py-6 md:grid-cols-[13rem_1fr]">
|
||||
<nav aria-label="Admin">
|
||||
<ul className="flex gap-1 overflow-x-auto md:flex-col">
|
||||
{NAV.map((n) => {
|
||||
{NAV.filter((n) => !("managers" in n) || ["owner", "admin"].includes(user.role)).map((n) => {
|
||||
const current = n.href === "/admin" ? path === "/admin" : path.startsWith(n.href);
|
||||
return (
|
||||
<li key={n.href}>
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
"use client";
|
||||
|
||||
/**
|
||||
* Simple events (§8): title, date and time, place, description, a photo and an optional link (a
|
||||
* sign-up form elsewhere, say). Registrations and payments are Cross Events'. Each publishes on its
|
||||
* own (decision 9). Events from Cross Events show on the site by themselves once it's linked.
|
||||
*/
|
||||
import { useState } from "react";
|
||||
import { api, canEdit } from "@/admin/api";
|
||||
import { ImagePicker } from "@/admin/media";
|
||||
import { Btn, Field, inputClass, Loading, Notice, Panel, Title, useAction, useAdmin, when } from "@/admin/ui";
|
||||
|
||||
type Ev = { id: string; slug: string; title: string; startsAt: string; endsAt: string | null; allDay: boolean; location: string | null; description: string | null; imageId: string | null; image: string | null; link: string | null; cancelled: boolean; published: boolean };
|
||||
type Form = { title: string; date: string; time: string; endDate: string; endTime: string; allDay: boolean; location: string; description: string; imageId: string | null; link: string };
|
||||
|
||||
/** "2026-12-05" + "18:30" in the browser's time zone (the church's, for its admins) → ISO with offset. */
|
||||
const iso = (date: string, time: string) => (date ? new Date(`${date}T${time || "00:00"}`).toISOString() : null);
|
||||
const local = (s: string | null) => {
|
||||
if (!s) return { d: "", t: "" };
|
||||
const x = new Date(s);
|
||||
const p = (n: number) => String(n).padStart(2, "0");
|
||||
return { d: `${x.getFullYear()}-${p(x.getMonth() + 1)}-${p(x.getDate())}`, t: `${p(x.getHours())}:${p(x.getMinutes())}` };
|
||||
};
|
||||
|
||||
function EventForm({ initial, onSave, onCancel }: { initial: Form; onSave: (body: object) => Promise<unknown>; onCancel: () => void }) {
|
||||
const [v, setV] = useState(initial);
|
||||
const { busy, message, fields, run } = useAction();
|
||||
const set = (k: keyof Form, x: unknown) => setV({ ...v, [k]: x });
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<Field label="Title" error={fields.title}><input className={inputClass} value={v.title} maxLength={300} onChange={(e) => set("title", e.target.value)} /></Field>
|
||||
<div className="grid gap-3 sm:grid-cols-4">
|
||||
<Field label="Date" error={fields.startsAt}><input type="date" className={inputClass} value={v.date} onChange={(e) => set("date", e.target.value)} /></Field>
|
||||
{!v.allDay && <Field label="Time"><input type="time" className={inputClass} value={v.time} onChange={(e) => set("time", e.target.value)} /></Field>}
|
||||
<Field label="Ends (date)" error={fields.endsAt}><input type="date" className={inputClass} value={v.endDate} onChange={(e) => set("endDate", e.target.value)} /></Field>
|
||||
{!v.allDay && <Field label="Ends (time)"><input type="time" className={inputClass} value={v.endTime} onChange={(e) => set("endTime", e.target.value)} /></Field>}
|
||||
</div>
|
||||
<label className="flex items-center gap-2 text-sm"><input type="checkbox" checked={v.allDay} onChange={(e) => set("allDay", e.target.checked)} />All day</label>
|
||||
<Field label="Where" error={fields.location}><input className={inputClass} value={v.location} maxLength={500} onChange={(e) => set("location", e.target.value)} /></Field>
|
||||
<Field label="About it" error={fields.description}><textarea className={inputClass} rows={4} value={v.description} maxLength={8000} onChange={(e) => set("description", e.target.value)} /></Field>
|
||||
<Field label="Link (optional)" hint="A sign-up form or more information elsewhere: https://…" error={fields.link}><input className={inputClass} value={v.link} onChange={(e) => set("link", e.target.value)} /></Field>
|
||||
<ImagePicker label="Photo" value={v.imageId} onChange={(id) => set("imageId", id)} />
|
||||
<div className="flex gap-2">
|
||||
<Btn kind="primary" busy={busy} onClick={() => run(() => onSave({
|
||||
title: v.title, startsAt: iso(v.date, v.allDay ? "00:00" : v.time), endsAt: v.endDate ? iso(v.endDate, v.allDay ? "23:59" : v.endTime) : null,
|
||||
allDay: v.allDay, location: v.location || null, description: v.description || null, imageId: v.imageId, link: v.link || null,
|
||||
}))}>Save</Btn>
|
||||
<Btn onClick={onCancel}>Cancel</Btn>
|
||||
</div>
|
||||
{message && <Notice tone={message.tone}>{message.text}</Notice>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const empty: Form = { title: "", date: "", time: "10:00", endDate: "", endTime: "", allDay: false, location: "", description: "", imageId: null, link: "" };
|
||||
|
||||
export default function Events() {
|
||||
const me = useAdmin<{ user: { role: string } }>("/me");
|
||||
const { data, error, reload } = useAdmin<Ev[]>("/events");
|
||||
const [editing, setEditing] = useState<string | null>(null);
|
||||
const { busy, message, run } = useAction();
|
||||
if (!data || !me.data) return <Loading error={error ?? me.error} />;
|
||||
const editor = canEdit(me.data.user.role);
|
||||
const toForm = (e: Ev): Form => {
|
||||
const s = local(e.startsAt);
|
||||
const f = local(e.endsAt);
|
||||
return { title: e.title, date: s.d, time: s.t, endDate: f.d, endTime: f.t, allDay: e.allDay, location: e.location ?? "", description: e.description ?? "", imageId: e.imageId, link: e.link ?? "" };
|
||||
};
|
||||
const state = (e: Ev, change: object, done: string) => run(async () => { await api(`/events/${e.id}/state`, { body: change }); await reload(); }, done);
|
||||
return (
|
||||
<>
|
||||
<Title sub="Simple events made here. Events with registration and payment belong in Cross Events; they show here by themselves once it's linked.">Events</Title>
|
||||
{message && <div className="mb-4"><Notice tone={message.tone}>{message.text}</Notice></div>}
|
||||
<div className="space-y-6">
|
||||
{editor && (
|
||||
<Panel title="Add an event">
|
||||
{editing === "new"
|
||||
? <EventForm initial={empty} onCancel={() => setEditing(null)} onSave={async (b) => { await api("/events", { body: b }); setEditing(null); await reload(); }} />
|
||||
: <Btn kind="primary" onClick={() => setEditing("new")}>Add an event</Btn>}
|
||||
</Panel>
|
||||
)}
|
||||
<Panel title="Your events">
|
||||
{data.length === 0 && <p className="text-gray-600">None yet.</p>}
|
||||
<ul className="divide-y divide-gray-200">
|
||||
{data.map((e) => (
|
||||
<li key={e.id} className="py-3">
|
||||
{editing === e.id ? (
|
||||
<EventForm initial={toForm(e)} onCancel={() => setEditing(null)} onSave={async (b) => { await api(`/events/${e.id}`, { method: "PUT", body: b }); setEditing(null); await reload(); }} />
|
||||
) : (
|
||||
<div className="flex flex-wrap items-center gap-4">
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="font-medium">{e.title}</p>
|
||||
<p className="text-sm text-gray-600">{when(e.startsAt)}{e.location && ` · ${e.location}`}</p>
|
||||
<p className="text-xs">{e.cancelled ? <span className="text-red-700">Cancelled</span> : e.published ? <span className="text-green-800">On the site</span> : <span className="text-gray-500">Not published</span>}</p>
|
||||
</div>
|
||||
{editor && (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Btn onClick={() => setEditing(e.id)}>Edit</Btn>
|
||||
<Btn busy={busy} onClick={() => state(e, { published: !e.published }, e.published ? "Taken off the site." : "On the site now.")}>{e.published ? "Unpublish" : "Publish"}</Btn>
|
||||
<Btn busy={busy} onClick={() => state(e, { cancelled: !e.cancelled }, e.cancelled ? "Back on." : "Cancelled: it's off the site.")}>{e.cancelled ? "Not cancelled" : "Cancel it"}</Btn>
|
||||
<Btn kind="danger" busy={busy} onClick={() => run(async () => { await api(`/events/${e.id}`, { method: "DELETE" }); await reload(); }, "Removed.")}>Remove</Btn>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</Panel>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
"use client";
|
||||
|
||||
/**
|
||||
* Messages (§7): from the church's YouTube channel or playlist automatically, or added by hand with
|
||||
* a YouTube or Spotify link. Each publishes on its own (decision 9); ones from YouTube go live by
|
||||
* themselves. Add the speaker, series and passage afterwards, or hide one.
|
||||
*/
|
||||
import { useState } from "react";
|
||||
import { api, canEdit } from "@/admin/api";
|
||||
import { Btn, Field, inputClass, Loading, Notice, Panel, Title, useAction, useAdmin, when } from "@/admin/ui";
|
||||
|
||||
type Message = { id: string; title: string; date: string; mediaUrl: string; source: string; speaker: string | null; passage: string | null; notes: string | null; series: string | null; hidden: boolean; published: boolean; thumbnail: string | null };
|
||||
type Data = { youtube: { source: { kind: string; id: string } | null; lastSync: string | null; lastError: string | null }; items: Message[] };
|
||||
|
||||
const blank = { title: "", date: new Date().toISOString().slice(0, 10), mediaUrl: "", speaker: "", passage: "", series: "", notes: "", hidden: false };
|
||||
|
||||
function MessageForm({ initial, fromFeed, onSave, onCancel }: { initial: typeof blank; fromFeed: boolean; onSave: (v: typeof blank) => Promise<unknown>; onCancel: () => void }) {
|
||||
const [v, setV] = useState(initial);
|
||||
const { busy, message, fields, run } = useAction();
|
||||
const set = (k: keyof typeof blank, x: string | boolean) => setV({ ...v, [k]: x });
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
<Field label="Title" error={fields.title}><input className={inputClass} value={v.title} maxLength={500} onChange={(e) => set("title", e.target.value)} /></Field>
|
||||
<Field label="Date" error={fields.date}><input type="date" className={inputClass} value={v.date.slice(0, 10)} onChange={(e) => set("date", e.target.value)} /></Field>
|
||||
{!fromFeed && <Field label="YouTube or Spotify link" hint="A video (youtube.com/watch?v=…, youtu.be/…) or a Spotify episode." error={fields.mediaUrl}><input className={inputClass} value={v.mediaUrl} onChange={(e) => set("mediaUrl", e.target.value)} /></Field>}
|
||||
<Field label="Speaker" error={fields.speaker}><input className={inputClass} value={v.speaker} maxLength={300} onChange={(e) => set("speaker", e.target.value)} /></Field>
|
||||
<Field label="Series" hint="Messages with the same series name are grouped." error={fields.series}><input className={inputClass} value={v.series} maxLength={300} onChange={(e) => set("series", e.target.value)} /></Field>
|
||||
<Field label="Bible passage" error={fields.passage}><input className={inputClass} value={v.passage} maxLength={300} onChange={(e) => set("passage", e.target.value)} /></Field>
|
||||
</div>
|
||||
<Field label="Notes" error={fields.notes}><textarea className={inputClass} rows={3} value={v.notes} maxLength={8000} onChange={(e) => set("notes", e.target.value)} /></Field>
|
||||
<label className="flex items-center gap-2 text-sm"><input type="checkbox" checked={v.hidden} onChange={(e) => set("hidden", e.target.checked)} />Hide it from the site</label>
|
||||
<div className="flex gap-2"><Btn kind="primary" busy={busy} onClick={() => run(() => onSave(v))}>Save</Btn><Btn onClick={onCancel}>Cancel</Btn></div>
|
||||
{message && <Notice tone={message.tone}>{message.text}</Notice>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function Messages() {
|
||||
const me = useAdmin<{ user: { role: string } }>("/me");
|
||||
const { data, error, reload } = useAdmin<Data>("/messages");
|
||||
const [editing, setEditing] = useState<string | null>(null);
|
||||
const [youtube, setYoutube] = useState<string | null>(null);
|
||||
const { busy, message, fields, run } = useAction();
|
||||
if (!data || !me.data) return <Loading error={error ?? me.error} />;
|
||||
const editor = canEdit(me.data.user.role);
|
||||
const body = (v: typeof blank) => ({ ...v, date: v.date, speaker: v.speaker || null, passage: v.passage || null, series: v.series || null, notes: v.notes || null });
|
||||
const yt = data.youtube;
|
||||
return (
|
||||
<>
|
||||
<Title sub="Sermons. Audio and video stay on YouTube or Spotify: nothing is uploaded.">Messages</Title>
|
||||
{message && <div className="mb-4"><Notice tone={message.tone}>{message.text}</Notice></div>}
|
||||
<div className="space-y-6">
|
||||
<Panel title="From YouTube, automatically">
|
||||
<p className="mb-3 text-sm text-gray-600">Each new video becomes a message within the hour. A playlist is better when your channel has other videos too.</p>
|
||||
<div className="flex flex-wrap items-end gap-3">
|
||||
<div className="min-w-[18rem] flex-1">
|
||||
<Field label="Channel id or playlist link" hint="Your channel id starts with UC: on YouTube, open Settings → Advanced settings. Or paste a playlist's address." error={fields.youtube}>
|
||||
<input className={inputClass} value={youtube ?? (yt.source ? (yt.source.kind === "playlist" ? `https://www.youtube.com/playlist?list=${yt.source.id}` : yt.source.id) : "")} disabled={!editor} onChange={(e) => setYoutube(e.target.value)} />
|
||||
</Field>
|
||||
</div>
|
||||
{editor && <Btn kind="primary" busy={busy} onClick={() => run(async () => { const r = await api<{ sync: { added: number } | null }>("/messages-youtube", { method: "PUT", body: { youtube: youtube ?? "" } }); setYoutube(null); await reload(); return r; }, "Saved. New videos come in every hour.")}>Save</Btn>}
|
||||
{editor && yt.source && <Btn busy={busy} onClick={() => run(async () => { await api("/messages-youtube/sync", { body: {} }); await reload(); }, "Checked YouTube.")}>Check now</Btn>}
|
||||
</div>
|
||||
{yt.lastSync && <p className="mt-2 text-xs text-gray-500">Last checked {when(yt.lastSync)}</p>}
|
||||
{yt.lastError && <div className="mt-2"><Notice tone="warning">YouTube couldn't be reached last time: {yt.lastError.replace(/^\S+\s/, "")}</Notice></div>}
|
||||
</Panel>
|
||||
|
||||
{editor && (
|
||||
<Panel title="Add one by hand">
|
||||
{editing === "new"
|
||||
? <MessageForm initial={blank} fromFeed={false} onCancel={() => setEditing(null)} onSave={async (v) => { await api("/messages", { body: body(v) }); setEditing(null); await reload(); }} />
|
||||
: <Btn kind="primary" onClick={() => setEditing("new")}>Add a message</Btn>}
|
||||
</Panel>
|
||||
)}
|
||||
|
||||
<Panel title="All messages">
|
||||
{data.items.length === 0 && <p className="text-gray-600">None yet.</p>}
|
||||
<ul className="divide-y divide-gray-200">
|
||||
{data.items.map((m) => (
|
||||
<li key={m.id} className="py-3">
|
||||
{editing === m.id ? (
|
||||
<MessageForm fromFeed={m.source === "youtube_feed"} onCancel={() => setEditing(null)}
|
||||
initial={{ title: m.title, date: m.date.slice(0, 10), mediaUrl: m.mediaUrl, speaker: m.speaker ?? "", passage: m.passage ?? "", series: m.series ?? "", notes: m.notes ?? "", hidden: m.hidden }}
|
||||
onSave={async (v) => { await api(`/messages/${m.id}`, { method: "PUT", body: body(v) }); setEditing(null); await reload(); }} />
|
||||
) : (
|
||||
<div className="flex flex-wrap items-center gap-4">
|
||||
{m.thumbnail ? <img src={m.thumbnail} alt="" className="h-14 w-24 rounded object-cover" /> : <div className="h-14 w-24 rounded bg-gray-100" />}
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="font-medium">{m.title}</p>
|
||||
<p className="text-sm text-gray-600">{[when(m.date).split(",")[0], m.speaker, m.series, m.source === "youtube_feed" ? "from YouTube" : m.source === "spotify" ? "Spotify" : "YouTube"].filter(Boolean).join(" · ")}</p>
|
||||
<p className="text-xs">{m.hidden ? <span className="text-amber-800">Hidden</span> : m.published ? <span className="text-green-800">On the site</span> : <span className="text-gray-500">Not published</span>}</p>
|
||||
</div>
|
||||
{editor && (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Btn onClick={() => setEditing(m.id)}>Edit</Btn>
|
||||
<Btn busy={busy} onClick={() => run(async () => { await api(`/messages/${m.id}/publish`, { body: { live: !m.published } }); await reload(); }, m.published ? "Taken off the site." : "On the site now.")}>{m.published ? "Unpublish" : "Publish"}</Btn>
|
||||
{m.source !== "youtube_feed" && <Btn kind="danger" busy={busy} onClick={() => run(async () => { await api(`/messages/${m.id}`, { method: "DELETE" }); await reload(); }, "Removed.")}>Remove</Btn>}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</Panel>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
"use client";
|
||||
|
||||
/**
|
||||
* People (§10): who can use this website's admin, and as what. Adding someone by email gives them
|
||||
* an account at the church's sign-in if they have none (they get an email to choose a password).
|
||||
*/
|
||||
import { useState } from "react";
|
||||
import { api, ROLE_NAMES } from "@/admin/api";
|
||||
import { Btn, Field, inputClass, Loading, Notice, Panel, Title, useAction, useAdmin, when } from "@/admin/ui";
|
||||
|
||||
type Person = { id: string; name: string; email: string; role: string; ministryId: string | null; ministry: string | null; lastSignInAt: string | null };
|
||||
|
||||
const ROLE_TEXT: Record<string, string> = {
|
||||
owner: "Everything, including who is Owner",
|
||||
admin: "Everything but Owners",
|
||||
editor: "Edits everything and publishes",
|
||||
ministry_leader: "Edits their own ministry; an Editor publishes it",
|
||||
viewer: "Looks, changes nothing",
|
||||
};
|
||||
|
||||
function RolePicker({ role, ministryId, onChange, ministries, canOwner, errors }: { role: string; ministryId: string | null; onChange: (r: string, m: string | null) => void; ministries: { id: string; name: string }[]; canOwner: boolean; errors: Record<string, string> }) {
|
||||
return (
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
<Field label="Role" hint={ROLE_TEXT[role]} error={errors.role}>
|
||||
<select className={inputClass} value={role} onChange={(e) => onChange(e.target.value, ministryId)}>
|
||||
{Object.keys(ROLE_TEXT).filter((r) => canOwner || r !== "owner").map((r) => <option key={r} value={r}>{ROLE_NAMES[r]}</option>)}
|
||||
</select>
|
||||
</Field>
|
||||
{role === "ministry_leader" && (
|
||||
<Field label="Their ministry" error={errors.ministryId}>
|
||||
<select className={inputClass} value={ministryId ?? ""} onChange={(e) => onChange(role, e.target.value || null)}>
|
||||
<option value="">Choose…</option>
|
||||
{ministries.map((m) => <option key={m.id} value={m.id}>{m.name}</option>)}
|
||||
</select>
|
||||
</Field>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function People() {
|
||||
const me = useAdmin<{ user: { id: string; role: string } }>("/me");
|
||||
const list = useAdmin<Person[]>("/people");
|
||||
const ministries = useAdmin<{ id: string; name: string }[]>("/ministries");
|
||||
const [add, setAdd] = useState({ name: "", email: "", role: "editor", ministryId: null as string | null });
|
||||
const [editing, setEditing] = useState<{ id: string; role: string; ministryId: string | null } | null>(null);
|
||||
const { busy, message, fields, run } = useAction();
|
||||
if (!list.data || !me.data) return <Loading error={list.error ?? me.error} />;
|
||||
const owner = me.data.user.role === "owner";
|
||||
const mayTouch = (p: Person) => p.id !== me.data!.user.id && (owner || p.role !== "owner");
|
||||
return (
|
||||
<>
|
||||
<Title sub="Who can use this website's admin. They sign in with their church account.">People</Title>
|
||||
{message && <div className="mb-4"><Notice tone={message.tone}>{message.text}</Notice></div>}
|
||||
<div className="grid gap-6 lg:grid-cols-[3fr_2fr]">
|
||||
<Panel>
|
||||
<ul className="divide-y divide-gray-200">
|
||||
{list.data.map((p) => (
|
||||
<li key={p.id} className="py-3">
|
||||
{editing?.id === p.id ? (
|
||||
<div className="space-y-3">
|
||||
<p className="font-medium">{p.name}</p>
|
||||
<RolePicker role={editing.role} ministryId={editing.ministryId} ministries={ministries.data ?? []} canOwner={owner} errors={fields} onChange={(role, ministryId) => setEditing({ ...editing, role, ministryId })} />
|
||||
<div className="flex gap-2">
|
||||
<Btn kind="primary" busy={busy} onClick={() => run(async () => { await api(`/people/${p.id}`, { method: "PUT", body: { role: editing.role, ministryId: editing.ministryId } }); setEditing(null); await list.reload(); }, "Saved. A lower role takes effect at once.")}>Save</Btn>
|
||||
<Btn onClick={() => setEditing(null)}>Cancel</Btn>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||
<div>
|
||||
<p className="font-medium">{p.name}{p.id === me.data!.user.id && " (you)"}</p>
|
||||
<p className="text-sm text-gray-600">{p.email} · {ROLE_NAMES[p.role]}{p.ministry && ` of ${p.ministry}`}</p>
|
||||
<p className="text-xs text-gray-500">{p.lastSignInAt ? `Last signed in ${when(p.lastSignInAt)}` : "Hasn't signed in yet"}</p>
|
||||
</div>
|
||||
{mayTouch(p) && (
|
||||
<div className="flex gap-2">
|
||||
<Btn onClick={() => setEditing({ id: p.id, role: p.role, ministryId: p.ministryId })}>Change role</Btn>
|
||||
<Btn kind="danger" onClick={() => run(async () => { await api(`/people/${p.id}`, { method: "DELETE" }); await list.reload(); }, `${p.name} no longer has access.`)}>Remove</Btn>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</Panel>
|
||||
<Panel title="Add someone">
|
||||
<div className="space-y-3">
|
||||
<Field label="Name" error={fields.name}><input className={inputClass} value={add.name} maxLength={200} onChange={(e) => setAdd({ ...add, name: e.target.value })} /></Field>
|
||||
<Field label="Email" hint="If they have no church account yet, they get an email to choose a password." error={fields.email}><input type="email" className={inputClass} value={add.email} onChange={(e) => setAdd({ ...add, email: e.target.value })} /></Field>
|
||||
<RolePicker role={add.role} ministryId={add.ministryId} ministries={ministries.data ?? []} canOwner={owner} errors={fields} onChange={(role, ministryId) => setAdd({ ...add, role, ministryId })} />
|
||||
<Btn kind="primary" busy={busy} disabled={!add.name || !add.email} onClick={() => run(async () => {
|
||||
const r = await api<{ newAccount: boolean }>("/people", { body: add });
|
||||
setAdd({ name: "", email: "", role: "editor", ministryId: null });
|
||||
await list.reload();
|
||||
return r;
|
||||
}, "Added. They can sign in now.")}>Add</Btn>
|
||||
</div>
|
||||
</Panel>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user