Add shared API types and type the smaller frontend pages

Expand src/types with User, Event, EventOption, Registration, Payment,
Ticket, paginated results and dashboard stats, modelled on the Prisma
schema. apiFetch now defaults to unknown instead of any. Dashboard
loaders are wrapped in useCallback so their effects can list them as
dependencies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-21 11:10:01 +02:00
co-authored by Claude Opus 5.5
parent 619b5b9a93
commit 545f3d913e
32 changed files with 375 additions and 175 deletions
@@ -5,10 +5,11 @@ import { apiFetch } from "@/lib/api";
import { useDismissingState } from "@/hooks/useDismissingState";
import { HandHeart } from "lucide-react";
import { errorMessage } from "@/lib/utils";
import type { Event } from "@/types";
export default function DonatePage() {
const { token } = useAuth();
const [events, setEvents] = useState<any[]>([]);
const [events, setEvents] = useState<Event[]>([]);
const [eventId, setEventId] = useState<string>("");
const [amount, setAmount] = useState<string>("");
const [loading, setLoading] = useState(false);
@@ -18,14 +19,14 @@ export default function DonatePage() {
useEffect(() => {
(async () => {
try {
const evs = await apiFetch<any[]>("/api/events");
const evs = await apiFetch<Event[]>("/api/events");
setEvents(evs);
if (evs.length > 0) setEventId(evs[0].id);
} catch (e) {
setError(errorMessage(e) || "Failed to load events");
}
})();
}, []);
}, [setError]);
const submit = async () => {
if (!token) { setError("Please login"); return; }
@@ -8,6 +8,7 @@ import { formatDateTime } from "@/lib/date";
import { formatPaymentMethod } from "@/lib/paymentMethod";
import { Receipt } from "lucide-react";
import { errorMessage } from "@/lib/utils";
import type { Paginated } from "@/types";
interface PaymentItem {
id: string;
@@ -50,7 +51,7 @@ export default function UserPaymentsPage() {
setInfo(null);
setSendingReceipt(true);
try {
const res: any = await apiFetch<any>(`/api/payments/${encodeURIComponent(paymentId)}/send-receipt`, {
const res = await apiFetch<{ message?: string }>(`/api/payments/${encodeURIComponent(paymentId)}/send-receipt`, {
method: "POST",
body: { channel },
authToken: token,
@@ -83,7 +84,7 @@ export default function UserPaymentsPage() {
setError(null);
setFetching(true);
try {
const res = await apiFetch<any>(buildQuery(p), { authToken: token });
const res = await apiFetch<Paginated<PaymentItem>>(buildQuery(p), { authToken: token });
setPayments(Array.isArray(res?.data) ? res.data : []);
setTotal(res?.total ?? 0);
setTotalPages(res?.pages ?? 1);
@@ -93,9 +94,10 @@ export default function UserPaymentsPage() {
} finally {
setFetching(false);
}
}, [token, buildQuery]);
}, [token, buildQuery, setError]);
useEffect(() => { if (token) loadPayments(1); }, [token, startDate, endDate, method, kind]);
// loadPayments changes whenever a filter does (via buildQuery), so this refetches page 1 on filter changes.
useEffect(() => { if (token) loadPayments(1); }, [token, loadPayments]);
const goToPage = (p: number) => loadPayments(p);
@@ -151,7 +153,7 @@ export default function UserPaymentsPage() {
</div>
<div>
<label className="block text-xs text-gray-600 mb-1">Type</label>
<select className="border rounded px-2 py-1.5 text-sm" value={kind} onChange={e => setKind(e.target.value as any)}>
<select className="border rounded px-2 py-1.5 text-sm" value={kind} onChange={e => setKind(e.target.value as "" | "payment" | "refund")}>
<option value="">Payments &amp; refunds</option>
<option value="payment">Payments only</option>
<option value="refund">Refunds only</option>