This repository has been archived on 2026-11-23. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
hope-events/frontend/src/app/dashboard/admin/cashup/page.tsx
T
joshuaandClaude Opus 5.5 2bcc9ac651 Setting events up on API v2, pg-boss 11 (1.51.7)
- v2: /events/manage, create, PATCH, deactivate, copy-from, notify-recipients.
- src/services/events.ts (from eventController.js, with the schedule helpers); v1 uses it.
- fetchManagedEvents() for every picker; the event wizard writes through v2.
- pg-boss 11 in its own schema (pgboss_v11); old pgboss schema left in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ls1vMdg2GYqbnKZmPaX1ot
2026-10-29 11:57:08 +02:00

119 lines
5.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client";
import React, { useEffect, useMemo, useState } from "react";
import { useRouter } from "next/navigation";
import { useAuth } from "@/hooks/useAuth";
import { fetchManagedEvents } from "@/lib/api";
import { useDismissingState } from "@/hooks/useDismissingState";
import { Wallet } from "lucide-react";
import { errorMessage } from "@/lib/utils";
import type { Event } from "@/types";
import { BackLink } from "@/components/shared/BackLink";
export default function CashupLandingPage() {
const { token } = useAuth();
const router = useRouter();
const [events, setEvents] = useState<Event[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useDismissingState<string | null>(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 fetchManagedEvents<Event>(token, { past: true, inactive: true });
setEvents(Array.isArray(evs) ? evs : []);
} catch (e) {
setError(errorMessage(e) || "Failed to load events");
} finally {
setLoading(false);
}
})();
}, [token, setError]);
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 (
<div className="max-w-3xl mx-auto space-y-4">
<div className="flex items-center justify-between gap-3 flex-wrap">
<div className="flex items-center gap-3">
<div className="w-10 h-10 rounded-xl bg-brand-50 flex items-center justify-center shrink-0">
<Wallet className="w-5 h-5 text-brand-600" />
</div>
<div>
<BackLink href="/dashboard" />
<h1 className="text-xl font-semibold text-gray-900 mt-0.5">Post-event Cashup</h1>
<p className="text-sm text-gray-500 mt-1">Set costs, reconcile takings, and close out an event. Admin only.</p>
</div>
</div>
</div>
{error && <div className="text-sm text-red-600 bg-red-50 border border-red-100 rounded p-2">{error}</div>}
<div className="bg-white border rounded-lg p-3 flex flex-wrap items-center gap-3">
<input
className="border rounded px-3 py-1.5 text-sm flex-1 min-w-48"
placeholder="Search events…"
value={search}
onChange={e => setSearch(e.target.value)}
/>
<label className="flex items-center gap-1.5 text-sm text-gray-600">
<input type="checkbox" checked={showPast} onChange={e => setShowPast(e.target.checked)} /> Past events
</label>
<label className="flex items-center gap-1.5 text-sm text-gray-600">
<input type="checkbox" checked={showInactive} onChange={e => setShowInactive(e.target.checked)} /> Inactive events
</label>
<label className="flex items-center gap-1.5 text-sm text-gray-600">
<input type="checkbox" checked={showClosed} onChange={e => setShowClosed(e.target.checked)} /> Closed events
</label>
</div>
{loading && <div className="text-sm text-gray-400">Loading…</div>}
{!loading && (
<ul className="space-y-2">
{filtered.map(ev => {
const isClosed = ev.cashupStatus === "closed";
return (
<li
key={ev.id}
className="border rounded-lg p-3 bg-white hover:bg-brand-50/40 cursor-pointer transition-colors flex items-center justify-between gap-3"
onClick={() => router.push(`/dashboard/admin/cashup/${ev.id}`)}
>
<div className="min-w-0">
<div className="flex items-center gap-2 flex-wrap">
<span className="font-medium text-sm">{ev.title}</span>
<span className={"text-[10px] px-1.5 py-0.5 rounded " + (isClosed ? "bg-rose-50 text-rose-700" : "bg-emerald-50 text-emerald-700")}>
{isClosed ? "Closed" : "Open"}
</span>
</div>
<div className="text-xs text-gray-500 mt-0.5">
{ev.startDate ? new Date(ev.startDate).toLocaleDateString() : ""}{ev.endDate ? ` – ${new Date(ev.endDate).toLocaleDateString()}` : ""}
</div>
</div>
<span className="text-xs text-brand-600 shrink-0">Manage →</span>
</li>
);
})}
{filtered.length === 0 && <div className="text-sm text-gray-400">No events match the current filters.</div>}
</ul>
)}
</div>
);
}