WIP 1.51.11: money on v2 via v1 handlers (viaV1 adapter)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ls1vMdg2GYqbnKZmPaX1ot
This commit is contained in:
2026-10-29 13:43:36 +02:00
co-authored by Claude Opus 5.5
parent de08f057ad
commit fb36e9c8ac
36 changed files with 10334 additions and 154 deletions
@@ -3,11 +3,11 @@
import React, { useCallback, useEffect, useState } from "react";
import { ArrowDown, ArrowUp, Wallet } from "lucide-react";
import { useAuth } from "@/hooks/useAuth";
import { apiFetch } from "@/lib/api";
import { useDismissingState } from "@/hooks/useDismissingState";
import { errorMessage } from "@/lib/utils";
import { YocoTab } from "@/components/admin/YocoTab";
import { PayFastSettings } from "@/components/admin/PayFastSettings";
import { apiV2Data } from "@/lib/apiV2";
type ProviderSetting = { id: string; label: string; enabled: boolean; configured: boolean };
@@ -25,7 +25,7 @@ export function PaymentsTab({ active }: { active: boolean }) {
const load = useCallback(async () => {
if (!token) return;
try {
const res = await apiFetch<{ providers: ProviderSetting[]; minimumAmount: number }>("/api/payments/providers/settings", { authToken: token });
const res = await (apiV2Data("get", "/payments/providers/settings", { authToken: token }) as Promise<{ providers: ProviderSetting[]; minimumAmount: number }>);
setProviders(res.providers);
setMinimum(res.minimumAmount);
} catch (e) {
@@ -40,9 +40,10 @@ export function PaymentsTab({ active }: { active: boolean }) {
setProviders(next);
setSaving(true);
try {
const res = await apiFetch<{ message: string; providers: ProviderSetting[] }>("/api/payments/providers/settings", {
method: "PUT", authToken: token, body: { providers: next.map(p => ({ id: p.id, enabled: p.enabled })) },
});
const res = await (apiV2Data("put", "/payments/providers/settings", {
authToken: token,
body: { providers: next.map(p => ({ id: p.id, enabled: p.enabled })) },
}) as Promise<{ message: string; providers: ProviderSetting[] }>);
setProviders(res.providers);
setMessage({ type: "ok", text: res.message });
} catch (e) {
@@ -2,10 +2,11 @@
import React, { useState } from "react";
import { ListPlus, X } from "lucide-react";
import { apiFetch, ApiError } from "@/lib/api";
import { ApiError } from "@/lib/api";
import { useAuth } from "@/hooks/useAuth";
import type { WaitlistLine } from "@/lib/waitlist";
import { ModalOverlay } from "@/components/shared/ModalOverlay";
import { apiV2Data } from "@/lib/apiV2";
export type { WaitlistLine };
@@ -40,9 +41,8 @@ export function JoinWaitlistButton({ eventId, lines, guestsAllowed, initialLine,
setBusy(true);
setError(null);
try {
const res = await apiFetch<{ message: string }>("/api/waitlist", {
method: "POST",
authToken: token || undefined,
const res = await (apiV2Data("post", "/waitlist", {
authToken: token,
body: {
eventId,
eventOptionId: line.eventOptionId,
@@ -51,7 +51,7 @@ export function JoinWaitlistButton({ eventId, lines, guestsAllowed, initialLine,
quantity: qty,
...(!loggedIn ? { guestName: guest.name.trim(), guestEmail: guest.email.trim(), guestPhone: guest.phone.trim() || undefined } : {}),
},
});
}) as Promise<{ message: string }>);
setDone(res.message);
} catch (err) {
setError(err instanceof ApiError ? err.message : "Couldn't join the waitlist. Please try again.");
@@ -2,11 +2,11 @@
import React, { useEffect, useState } from "react";
import { HeartHandshake, X } from "lucide-react";
import { apiFetch } from "@/lib/api";
import { useAuth } from "@/hooks/useAuth";
import { errorMessage } from "@/lib/utils";
import { useOnlinePayments } from "@/lib/onlinePayments";
import { ModalOverlay } from "@/components/shared/ModalOverlay";
import { apiV2Data } from "@/lib/apiV2";
type Sponsorship = { enabled: boolean; open?: boolean; spotPrice?: number | null; showProgress?: boolean; goalSpots?: number | null; spotsFunded?: number | null; sponsors?: number | null };
@@ -35,7 +35,7 @@ export function SponsorSpot({ eventId, eventTitle }: { eventId: string; eventTit
const online = useOnlinePayments();
useEffect(() => {
apiFetch<Sponsorship>(`/api/sponsorships/event/${encodeURIComponent(eventId)}`).then(setData).catch(() => setData(null));
(apiV2Data("get", "/events/{id}/sponsorship", { params: { id: eventId } }) as Promise<Sponsorship>).then(setData).catch(() => setData(null));
try {
const s = new URLSearchParams(window.location.search).get("sponsored");
if (s) setReturned(s);
@@ -55,8 +55,7 @@ export function SponsorSpot({ eventId, eventTitle }: { eventId: string; eventTit
setBusy(true);
setError(null);
try {
const res = await apiFetch<{ redirectUrl: string }>("/api/sponsorships/checkout", {
method: "POST",
const res = await (apiV2Data("post", "/sponsorships/checkout", {
...(loggedIn ? { authToken: token! } : {}),
body: {
eventId,
@@ -66,7 +65,7 @@ export function SponsorSpot({ eventId, eventTitle }: { eventId: string; eventTit
...(message.trim() ? { message: message.trim() } : {}),
...(!loggedIn ? { name: guest.name, email: guest.email } : {}),
},
});
}) as Promise<{ redirectUrl: string }>);
window.location.href = res.redirectUrl;
} catch (err) {
setError(errorMessage(err) || "Couldn't start the payment");
@@ -1,8 +1,8 @@
"use client";
import React, { useCallback, useEffect, useState } from "react";
import { apiFetch } from "@/lib/api";
import { errorMessage } from "@/lib/utils";
import { apiV2Data } from "@/lib/apiV2";
type OpenCheckout = {
id: string;
@@ -40,7 +40,7 @@ export function WaitingForPayment({ token, onRecorded }: { token: string | null;
const load = useCallback(async () => {
if (!token) return;
try {
const res = await apiFetch<{ checkouts: OpenCheckout[] }>("/api/payments/checkouts/open", { authToken: token });
const res = await (apiV2Data("get", "/payments/open-checkouts", { authToken: token }) as Promise<{ checkouts: OpenCheckout[] }>);
setList(res.checkouts);
} catch (e) {
setMessage({ ok: false, text: errorMessage(e) || "Couldn't load waiting payments" });
@@ -53,9 +53,10 @@ export function WaitingForPayment({ token, onRecorded }: { token: string | null;
setBusy(ids?.[0] || "all");
setMessage(null);
try {
const res = await apiFetch<{ results: Record<string, CheckResult>; recorded: number; message: string }>("/api/payments/checkouts/check", {
method: "POST", authToken: token, body: ids ? { ids } : {},
});
const res = await (apiV2Data("post", "/payments/open-checkouts/check", {
authToken: token,
body: ids ? { ids } : {},
}) as Promise<{ results: Record<string, CheckResult>; recorded: number; message: string }>);
setResults(r => ({ ...r, ...res.results }));
setMessage({ ok: true, text: res.message });
if (res.recorded > 0) onRecorded();
@@ -318,7 +318,7 @@ export default function ReportsV2({ backHref }: { backHref?: string } = {}) {
const byEv: Record<string, Payment[]> = {};
for (const id of eventIds) {
try {
const list = await apiFetch<Payment[]>(`/api/payments/event/${encodeURIComponent(id)}`, { authToken: token });
const list = await (apiV2Data("get", "/events/{id}/payments", { params: { id: id }, authToken: token }) as Promise<Payment[]>);
byEv[id] = Array.isArray(list) ? list : [];
} catch {
byEv[id] = [];
@@ -360,7 +360,7 @@ export default function ReportsV2({ backHref }: { backHref?: string } = {}) {
const byEv: Record<string, EventFinancials | null> = {};
for (const id of eventIds) {
try {
byEv[id] = await apiFetch<EventFinancials>(`/api/cashups/event/${encodeURIComponent(id)}`, { authToken: token });
byEv[id] = await (apiV2Data("get", "/events/{id}/cashup", { params: { id: id }, authToken: token }) as Promise<EventFinancials>);
} catch {
byEv[id] = null;
}
@@ -383,7 +383,7 @@ export default function ReportsV2({ backHref }: { backHref?: string } = {}) {
const loadFeedback = async (eventIds: string[]) => {
if (!token || !eventIds.length) return [];
try {
return await apiFetch<FeedbackEventSummary[]>(`/api/feedback/summary?eventIds=${encodeURIComponent(eventIds.join(","))}`, { authToken: token });
return await (apiV2Data("get", "/feedback/summary", { query: { eventIds: eventIds.join(",") }, authToken: token }) as Promise<FeedbackEventSummary[]>);
} catch {
return [];
}
@@ -412,7 +412,7 @@ export default function ReportsV2({ backHref }: { backHref?: string } = {}) {
const ev = filteredEvents.find((e) => e.id === id);
if (!ev?.requiresParentalConsent) continue;
try {
const res = await apiFetch<{ rows?: (ConsentRow | MedicalRow)[] }>(`/api/consent/events/${encodeURIComponent(id)}${kind === "medical" ? "/medical" : ""}`, { authToken: token });
const res = await ((kind === "medical" ? apiV2Data("get", "/events/{id}/consent/medical", { params: { id }, authToken: token }) : apiV2Data("get", "/events/{id}/consent", { params: { id }, authToken: token })) as Promise<{ rows?: (ConsentRow | MedicalRow)[] }>);
(res?.rows || []).forEach((r) => out.push({ ...r, eventTitle: ev.title }));
} catch { /* not allowed or not found — skip */ }
}
@@ -426,7 +426,7 @@ export default function ReportsV2({ backHref }: { backHref?: string } = {}) {
if (auditTo) query.set("to", auditTo);
if (eventIds.length === 1) query.set("eventId", eventIds[0]);
try {
const rows = await apiFetch<AuditRow[]>(`/api/cashups/audit?${query.toString()}`, { authToken: token });
const rows = await (apiV2Data("get", "/cashups/audit", { query: Object.fromEntries(query), authToken: token }) as Promise<AuditRow[]>);
const idSet = new Set(eventIds);
const filtered = eventIds.length > 1 ? (rows || []).filter(r => idSet.has(r.eventId)) : (rows || []);
return computeAuditDeltas(filtered).sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
@@ -2,7 +2,6 @@
import React, { useMemo, useState } from "react";
import { Users, Send } from "lucide-react";
import { apiFetch } from "@/lib/api";
import { isMinorOn } from "@/components/shared/AttendeeNamesEditor";
import { errorMessage } from "@/lib/utils";
import type { Attendee } from "@/types";
@@ -139,7 +138,7 @@ export function AttendeesPanel({ registration, token, canEdit, hasForm, onSaved,
const resendConsent = async (requestId: string) => {
try {
const res = await apiFetch<{ message: string }>(`/api/consent/requests/${encodeURIComponent(requestId)}/resend`, { method: "POST", authToken: token });
const res = await (apiV2Data("post", "/consent-requests/{id}/resend", { params: { id: requestId }, authToken: token, body: {} }) as Promise<{ message: string }>);
onMessage(res.message);
} catch (e) {
setError(errorMessage(e) || "Couldn't re-send the consent request");
@@ -2,9 +2,9 @@
import React, { useCallback, useEffect, useState } from "react";
import { ListChecks } from "lucide-react";
import { apiFetch } from "@/lib/api";
import { errorMessage } from "@/lib/utils";
import { entryLineName } from "@/lib/waitlist";
import { apiV2Data } from "@/lib/apiV2";
type Entry = {
id: string;
@@ -22,7 +22,7 @@ type Entry = {
export function MyWaitlists({ token, onMessage }: { token: string; onMessage: (m: string) => void }) {
const [entries, setEntries] = useState<Entry[]>([]);
const load = useCallback(() => {
apiFetch<Entry[]>("/api/waitlist/mine", { authToken: token }).then(setEntries).catch(() => setEntries([]));
(apiV2Data("get", "/me/waitlist", { authToken: token }) as Promise<Entry[]>).then(setEntries).catch(() => setEntries([]));
}, [token]);
useEffect(() => { load(); }, [load]);
@@ -30,7 +30,7 @@ export function MyWaitlists({ token, onMessage }: { token: string; onMessage: (m
const leave = async (id: string) => {
try {
const res = await apiFetch<{ message: string }>(`/api/waitlist/${encodeURIComponent(id)}`, { method: "DELETE", authToken: token });
const res = await (apiV2Data("delete", "/waitlist/{id}", { params: { id: id }, authToken: token }) as Promise<{ message: string }>);
onMessage(res.message);
load();
} catch (e) {