Campus-scoped staff: frontend and e2e
Admin -> Users 'Limit to campuses'; staff campus pickers, reports, dashboards and audience picker follow the scope (useMyCampuses); scoped people pick one of their campuses for new events, and church-wide / other campuses' events open read-only; 'You work with ...' note; warning before turning campuses off while staff are limited. e2e: scanner refusal naming the campus, scoped events list and read-only editor. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,7 @@ type Person = { id: string; name: string; email: string };
|
||||
type AdminCampus = Campus & {
|
||||
archivedAt: string | null;
|
||||
notifyRecipients: Person[];
|
||||
_count: { events: number; homeOf: number };
|
||||
_count: { events: number; homeOf: number; scopedStaff: number };
|
||||
};
|
||||
type Draft = {
|
||||
name: string; slug: string; address: string; defaultLocation: string;
|
||||
@@ -150,7 +150,12 @@ export function CampusesTab({ active }: { active: boolean }) {
|
||||
} finally { setBusy(false); }
|
||||
};
|
||||
|
||||
const toggle = (on: boolean) => run(() => apiFetch("/api/campuses/settings", { method: "PUT", authToken: token, body: { enabled: on } }), on ? "Campuses are on." : "Campuses are off — campus fields are hidden, nothing is deleted.");
|
||||
const toggle = (on: boolean) => {
|
||||
// Limits are ignored while campuses are off, so limited staff would see every campus.
|
||||
const limited = (campuses || []).reduce((n, c) => n + (c._count.scopedStaff || 0), 0);
|
||||
if (!on && limited > 0 && !window.confirm(`Some staff are limited to campuses (${limited} limit${limited === 1 ? "" : "s"} set). While campuses are off those limits are ignored and they'll see every campus. Turn campuses off?`)) return;
|
||||
return run(() => apiFetch("/api/campuses/settings", { method: "PUT", authToken: token, body: { enabled: on } }), on ? "Campuses are on." : "Campuses are off — campus fields are hidden, nothing is deleted.");
|
||||
};
|
||||
const save = async (d: Draft, id?: string) => {
|
||||
const body = { ...d, notifyRecipients: undefined, notifyRecipientIds: d.notifyRecipients.map(p => p.id) };
|
||||
const ok = await run(() => id
|
||||
@@ -205,7 +210,7 @@ export function CampusesTab({ active }: { active: boolean }) {
|
||||
<p className="font-medium text-gray-900">{c.name}</p>
|
||||
<p className="text-xs text-gray-500">
|
||||
<Link href={`/campus/${c.slug}`} className="hover:underline">/campus/{c.slug}</Link>
|
||||
{" · "}{c._count.events} event{c._count.events === 1 ? "" : "s"}{" · "}{c._count.homeOf} {c._count.homeOf === 1 ? "person" : "people"} call it home
|
||||
{" · "}{c._count.events} event{c._count.events === 1 ? "" : "s"}{" · "}{c._count.homeOf} {c._count.homeOf === 1 ? "person" : "people"} call it home{c._count.scopedStaff ? <>{" · "}{c._count.scopedStaff} staff limited to it</> : null}
|
||||
{c.address && <> · <MapPin className="inline w-3 h-3" /> {c.address}</>}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user