"use client"; import React, { useEffect, useMemo, useState } from "react"; import { useRouter } from "next/navigation"; import { useAuth } from "@/hooks/useAuth"; import { apiFetch } from "@/lib/api"; import { useDismissingState } from "@/hooks/useDismissingState"; export default function CashupLandingPage() { const { token } = useAuth(); const router = useRouter(); const [events, setEvents] = useState([]); const [loading, setLoading] = useState(false); const [error, setError] = useDismissingState(null); const [search, setSearch] = useState(""); const [showPast, setShowPast] = useState(true); const [showInactive, setShowInactive] = useState(false); const [showClosed, setShowClosed] = useState(false); useEffect(() => { if (!token) return; (async () => { setLoading(true); setError(null); try { const evs = await apiFetch("/api/events/all?includePast=true&includeInactive=true", { authToken: token }); setEvents(Array.isArray(evs) ? evs : []); } catch (e: any) { setError(e?.message || "Failed to load events"); } finally { setLoading(false); } })(); }, [token]); const filtered = useMemo(() => { const now = new Date(); return events .filter(ev => showPast || !ev.endDate || new Date(ev.endDate) >= now) .filter(ev => showInactive || ev.isActive !== false) .filter(ev => showClosed || ev.cashupStatus !== "closed") .filter(ev => !search.trim() || ev.title?.toLowerCase().includes(search.trim().toLowerCase())) .sort((a, b) => new Date(b.startDate).getTime() - new Date(a.startDate).getTime()); }, [events, showPast, showInactive, showClosed, search]); return (

Post-event Cashup

Set costs, reconcile takings, and close out an event. Admin only.

{error &&
{error}
}
setSearch(e.target.value)} />
{loading &&
Loading…
} {!loading && (
    {filtered.map(ev => { const isClosed = ev.cashupStatus === "closed"; return (
  • router.push(`/dashboard/admin/cashup/${ev.id}`)} >
    {ev.title} {isClosed ? "Closed" : "Open"}
    {ev.startDate ? new Date(ev.startDate).toLocaleDateString() : ""}{ev.endDate ? ` – ${new Date(ev.endDate).toLocaleDateString()}` : ""}
    Manage →
  • ); })} {filtered.length === 0 &&
    No events match the current filters.
    }
)}
); }