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:
2026-10-27 17:50:03 +02:00
co-authored by Claude Opus 5.5
parent c570fc7ffb
commit 159728d269
14 changed files with 186 additions and 20 deletions
@@ -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>
);
}