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>
|
||||
|
||||
@@ -1468,6 +1468,7 @@ export default function ReportsV2({ backHref }: { backHref?: string } = {}) {
|
||||
everyLabel="All campuses (church-wide total)"
|
||||
className="mb-3"
|
||||
id="reports-campus"
|
||||
mine
|
||||
/>
|
||||
|
||||
<ReportsShell
|
||||
|
||||
@@ -4,7 +4,7 @@ import React, { useState } from "react";
|
||||
import { Users } from "lucide-react";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { useCampuses } from "@/hooks/useCampuses";
|
||||
import { useMyCampuses } from "@/hooks/useCampuses";
|
||||
import { errorMessage } from "@/lib/utils";
|
||||
|
||||
/**
|
||||
@@ -15,7 +15,7 @@ import { errorMessage } from "@/lib/utils";
|
||||
*/
|
||||
export function CampusAudiencePicker({ selectedIds, onChange }: { selectedIds: string[]; onChange: (ids: string[]) => void }) {
|
||||
const { token } = useAuth();
|
||||
const { enabled, campuses } = useCampuses();
|
||||
const { enabled, campuses } = useMyCampuses();
|
||||
const [campusId, setCampusId] = useState("");
|
||||
const [registrants, setRegistrants] = useState(true);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
@@ -3,22 +3,26 @@
|
||||
import React from "react";
|
||||
import Link from "next/link";
|
||||
import { MapPin } from "lucide-react";
|
||||
import { useCampuses, type EventCampus } from "@/hooks/useCampuses";
|
||||
import { useCampuses, useMyCampuses, type EventCampus } from "@/hooks/useCampuses";
|
||||
|
||||
/**
|
||||
* A campus dropdown for lists and reports. Renders nothing while campuses are off.
|
||||
* Values: "" = every campus (church-wide total), "all" = only events for all campuses
|
||||
* (when `withChurchWide`), otherwise a campus id.
|
||||
*/
|
||||
export function CampusFilter({ value, onChange, withChurchWide = false, everyLabel = "All campuses", className = "", id = "campus-filter" }: {
|
||||
export function CampusFilter({ value, onChange, withChurchWide = false, everyLabel = "All campuses", className = "", id = "campus-filter", mine = false }: {
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
withChurchWide?: boolean;
|
||||
everyLabel?: string;
|
||||
className?: string;
|
||||
id?: string;
|
||||
// Staff pages: only the campuses a campus-scoped person works with.
|
||||
mine?: boolean;
|
||||
}) {
|
||||
const { enabled, campuses } = useCampuses();
|
||||
const everyCampus = useCampuses();
|
||||
const myCampuses = useMyCampuses();
|
||||
const { enabled, campuses } = mine ? myCampuses : everyCampus;
|
||||
if (!enabled || campuses.length === 0) return null;
|
||||
return (
|
||||
<label className={`inline-flex items-center gap-2 text-sm ${className}`} htmlFor={id}>
|
||||
@@ -56,3 +60,15 @@ export function CampusBadge({ campus, className = "", link = false }: { campus?:
|
||||
);
|
||||
return link ? <Link href={`/campus/${campus.slug}`} className={cls}>{inner}</Link> : <span className={cls}>{inner}</span>;
|
||||
}
|
||||
|
||||
/** For campus-scoped staff: which campuses they work with. Nothing for everyone else. */
|
||||
export function CampusScopeNote({ className = "" }: { className?: string }) {
|
||||
const { scoped, campuses } = useMyCampuses();
|
||||
if (!scoped) return null;
|
||||
return (
|
||||
<p className={`inline-flex items-center gap-1.5 text-xs text-gray-600 bg-gray-50 border rounded-full px-3 py-1 ${className}`}>
|
||||
<MapPin className="w-3.5 h-3.5" aria-hidden />
|
||||
You work with {campuses.map(c => c.name).join(", ") || "your campuses"}, and events for all campuses.
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user