Files
hope-events/frontend/src/components/reports/ReportsShell.tsx
T
joshuaandClaude Sonnet 5 8e6cb542d9 Full site redesign, help system, and dashboard stats fixes
Multi-phase visual facelift (design tokens, dashboards, sidebar/navbar
shell, per-page help guides, and a layout/content pass across every
remaining page) plus backend fixes to the dashboard KPI stats:

- Admin/Supervisor dashboard KPIs (revenue, donations, registrations,
  tickets sold) now use a rolling trailing-month window (today back one
  calendar month, e.g. 9 May - 8 June if today is 8 June) instead of
  calendar month-to-date, which under-counted for most of the month.
  The comparison window shifts the same way, so like is still compared
  with like.
- Reports deep-links from those stat tiles now match the same window
  (range=trailing_month, replacing range=this_month).
- Design tokens (brand-* Tailwind scale + shadcn CSS variables), a
  site-wide contextual help button, fixed dashboard sidebar/navbar,
  Admin/Supervisor/Staff/User dashboard rebuilds backed by a new
  GET /api/stats/overview endpoint, a dedicated Contact page, Site
  Settings restyle with WhatsApp config folded in, and an Account
  activity feed backed by a new SecurityEvent model.
- Every remaining page (home, events, registration flow, auth, legal,
  payment results, and every Admin/Supervisor/Staff/User tool page)
  restyled onto the same design tokens, several with real layout
  upgrades (home hero, events list/detail, donate page, auth pages).
- 20+ new dedicated help guides so the whole site has page-specific
  help content instead of falling back to a generic guide.
- Assorted fixes surfaced along the way: donation-leg double-counting
  in payment stats, donations not counting toward revenue, refund
  netting in per-method report breakdowns, and donation
  over-allocation after a refund.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-06 15:00:10 +02:00

202 lines
8.9 KiB
TypeScript

"use client";
import React, { useMemo, useState } from "react";
import { ArrowLeft, Search } from "lucide-react";
import { REPORTS, REPORT_CATEGORIES, type ReportKey, type ReportCategory } from "./ReportCatalog";
import EventsDropdown from "./EventsDropdown";
type EventLite = { id: string; title: string };
type DatePreset = "all_time" | "this_month" | "last_month" | "this_year" | "custom";
export default function ReportsShell({
events, isAdmin,
showPastEvents, setShowPastEvents,
showInactiveEvents, setShowInactiveEvents,
showClosedEvents, setShowClosedEvents,
selectedEventIds, setSelectedEventIds,
dateFrom, setDateFrom, dateTo, setDateTo,
report, setReport,
onViewReport, busy,
onBack,
}: {
events: EventLite[]; isAdmin: boolean;
showPastEvents: boolean; setShowPastEvents: (v: boolean) => void;
showInactiveEvents: boolean; setShowInactiveEvents: (v: boolean) => void;
showClosedEvents: boolean; setShowClosedEvents: (v: boolean) => void;
selectedEventIds: string[]; setSelectedEventIds: (v: string[]) => void;
dateFrom: string; setDateFrom: (v: string) => void; dateTo: string; setDateTo: (v: string) => void;
report: ReportKey; setReport: (r: ReportKey) => void;
onViewReport: () => void; busy: boolean;
onBack?: () => void;
}) {
const [search, setSearch] = useState("");
const [category, setCategory] = useState<"All" | ReportCategory>("All");
const [datePreset, setDatePreset] = useState<DatePreset>("all_time");
const iso = (d: Date) => d.toISOString().slice(0, 10);
const applyPreset = (preset: DatePreset) => {
setDatePreset(preset);
const now = new Date();
if (preset === "this_month") {
setDateFrom(iso(new Date(now.getFullYear(), now.getMonth(), 1)));
setDateTo(iso(new Date(now.getFullYear(), now.getMonth() + 1, 0)));
} else if (preset === "last_month") {
setDateFrom(iso(new Date(now.getFullYear(), now.getMonth() - 1, 1)));
setDateTo(iso(new Date(now.getFullYear(), now.getMonth(), 0)));
} else if (preset === "this_year") {
setDateFrom(iso(new Date(now.getFullYear(), 0, 1)));
setDateTo(iso(new Date(now.getFullYear(), 11, 31)));
} else if (preset === "all_time") {
setDateFrom(""); setDateTo("");
}
// 'custom' leaves dateFrom/dateTo as whatever's typed in the fields below
};
const filteredReports = useMemo(() => {
return REPORTS.filter(r => {
if (category !== "All" && r.category !== category) return false;
if (search.trim()) {
const q = search.trim().toLowerCase();
if (!r.label.toLowerCase().includes(q) && !r.description.toLowerCase().includes(q)) return false;
}
return true;
});
}, [search, category]);
return (
<div>
<div className="flex flex-wrap items-start justify-between gap-3 sm:gap-4 mb-6">
<div className="min-w-0">
<h1 className="text-2xl font-semibold text-gray-900">Reports</h1>
<p className="text-sm text-gray-500 mt-0.5">View, export, or email operational reports for events.</p>
</div>
<div className="flex items-center gap-3 w-full sm:w-auto">
<div className="relative flex-1 min-w-0 sm:flex-none">
<Search className="w-4 h-4 absolute left-2.5 top-1/2 -translate-y-1/2 text-gray-400" />
<input
className="w-full sm:w-56 border rounded-lg pl-8 pr-3 py-2 text-sm"
placeholder="Search reports…"
value={search}
onChange={e => setSearch(e.target.value)}
/>
</div>
{onBack && (
<button type="button" className="shrink-0 flex items-center gap-1.5 px-3 py-2 text-sm rounded-lg bg-gray-100 hover:bg-gray-200 text-gray-800" onClick={onBack}>
<ArrowLeft className="w-4 h-4" /> Back
</button>
)}
</div>
</div>
<div className="flex flex-col lg:flex-row gap-6">
{/* Sidebar: universal filters */}
<aside className="lg:w-72 shrink-0 space-y-5">
<div className="border rounded-xl p-4 bg-white shadow-sm space-y-4">
<div className="text-sm font-semibold">Filters</div>
<div>
<div className="text-xs font-medium text-gray-600 mb-1">Events</div>
<EventsDropdown options={events.map(ev => ({ value: ev.id, label: ev.title }))} value={selectedEventIds} onChange={setSelectedEventIds} />
</div>
<div className="space-y-1.5 text-sm">
<label className="flex items-center gap-2 cursor-pointer">
<input type="checkbox" checked={showPastEvents} onChange={e => setShowPastEvents(e.target.checked)} />
Include past events
</label>
{isAdmin && (
<label className="flex items-center gap-2 cursor-pointer">
<input type="checkbox" checked={showInactiveEvents} onChange={e => setShowInactiveEvents(e.target.checked)} />
Include inactive events
</label>
)}
<label className="flex items-center gap-2 cursor-pointer">
<input type="checkbox" checked={showClosedEvents} onChange={e => setShowClosedEvents(e.target.checked)} />
Include closed (cashed-up) events
</label>
</div>
<div>
<div className="text-xs font-medium text-gray-600 mb-1">Date range (where applicable)</div>
<select className="w-full border rounded px-2 py-1.5 text-sm mb-2" value={datePreset} onChange={e => applyPreset(e.target.value as DatePreset)}>
<option value="all_time">All time</option>
<option value="this_month">This month</option>
<option value="last_month">Last month</option>
<option value="this_year">This year</option>
<option value="custom">Custom</option>
</select>
{datePreset === "custom" && (
<div className="space-y-2">
<div>
<div className="text-[11px] text-gray-500 mb-0.5">From</div>
<input type="date" className="w-full min-w-0 border rounded px-2 py-1.5 text-sm" value={dateFrom} onChange={e => setDateFrom(e.target.value)} />
</div>
<div>
<div className="text-[11px] text-gray-500 mb-0.5">To</div>
<input type="date" className="w-full min-w-0 border rounded px-2 py-1.5 text-sm" value={dateTo} onChange={e => setDateTo(e.target.value)} />
</div>
</div>
)}
</div>
</div>
</aside>
{/* Main: categories, report grid */}
<div className="flex-1 min-w-0">
<div className="flex flex-wrap gap-2 mb-4">
{(["All", ...REPORT_CATEGORIES] as const).map(c => (
<button
key={c}
type="button"
className={"px-3 py-1.5 text-sm rounded-lg border " + (category === c ? "bg-brand-600 text-white border-brand-600" : "bg-white text-gray-700 border-gray-200 hover:bg-gray-50")}
onClick={() => setCategory(c)}
>
{c}
</button>
))}
</div>
<div className="grid sm:grid-cols-2 xl:grid-cols-4 gap-3">
{filteredReports.map(r => {
const Icon = r.icon;
const selected = report === r.key;
return (
<button
key={r.key}
type="button"
onClick={() => setReport(r.key)}
className={"text-left border rounded-xl p-4 transition " + (selected ? "border-brand-500 ring-2 ring-brand-100 bg-brand-50/40" : "border-gray-200 hover:border-gray-300 bg-white")}
>
<div className="w-9 h-9 rounded-lg bg-gray-100 flex items-center justify-center mb-3">
<Icon className="w-5 h-5 text-gray-600" />
</div>
<div className="text-sm font-semibold text-gray-900 mb-1">{r.label}</div>
<div className="text-xs text-gray-500 mb-3">{r.description}</div>
<div className="flex items-center justify-between text-[11px] text-gray-400">
<span>{r.category}</span>
<span>{r.fields} fields</span>
</div>
</button>
);
})}
{filteredReports.length === 0 && (
<div className="col-span-full text-sm text-gray-500 py-8 text-center">No reports match your search.</div>
)}
</div>
<div className="mt-6 flex items-center justify-between bg-gray-50 border rounded-xl px-4 py-3">
<div className="text-xs text-gray-500">Filters will be applied to the selected report where relevant.</div>
<button
disabled={busy}
onClick={onViewReport}
className="px-4 py-2 text-sm rounded-lg bg-brand-600 text-white hover:bg-brand-700 disabled:opacity-50"
>
{busy ? "Loading…" : "View report"}
</button>
</div>
</div>
</div>
</div>
);
}