Type caught errors as unknown in the frontend

Replace `catch (e: any)` with `catch (e)` and read the message through a
new errorMessage() helper. ApiError.data gets a real type, and
useDismissingState's setter keeps one identity across renders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-21 11:10:00 +02:00
co-authored by Claude Opus 5.5
parent 958a5a5950
commit 619b5b9a93
55 changed files with 400 additions and 332 deletions
@@ -7,6 +7,7 @@ import { apiFetch, fetchAllUsers, fetchAllPayments } from "@/lib/api";
import { useDismissingState } from "@/hooks/useDismissingState";
import { scoreUser } from "@/lib/fuzzyMatch";
import { Wallet, RotateCcw, HandHeart, ScanLine, Link2 } from "lucide-react";
import { errorMessage } from "@/lib/utils";
// A donation is never mutated once created — assigning it to a registration creates a separate
// "leg" Payment row (isDonation:false, originalPaymentId -> the donation, amount > 0) instead.
@@ -150,8 +151,8 @@ function PaymentsContent() {
setLoadingList(true);
const list = await fetchAllPayments(token);
setPayments(list.sort((a: any, b: any) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()));
} catch (e: any) {
setError(e?.message || "Failed to load payments");
} catch (e) {
setError(errorMessage(e) || "Failed to load payments");
} finally {
setLoadingList(false);
}
@@ -327,8 +328,8 @@ function PaymentsContent() {
if (!res.redirectUrl) { setError("Failed to generate link"); return; }
setLinkResult({ redirectUrl: res.redirectUrl, amount: res.amount ?? amt, registrationId: linkRegistrationId });
setInfo("Payment link generated");
} catch (e: any) {
setError(e?.message || "Failed to generate payment link");
} catch (e) {
setError(errorMessage(e) || "Failed to generate payment link");
} finally {
setLinkGenerating(false);
}
@@ -356,8 +357,8 @@ function PaymentsContent() {
body: { registrationId: linkResult.registrationId, redirectUrl: linkResult.redirectUrl, channel },
});
setInfo(`Payment link sent via ${channel === "email" ? "email" : "WhatsApp"}`);
} catch (e: any) {
setError(e?.message || `Failed to send link via ${channel}`);
} catch (e) {
setError(errorMessage(e) || `Failed to send link via ${channel}`);
} finally {
setLinkSending(null);
}
@@ -433,8 +434,8 @@ function PaymentsContent() {
setInfo(`Payment created (R ${amt.toFixed(2)})`);
setAmount(""); setRegistrationId(""); setIsDonation(false); setEventId(""); setPaidAtLocal("");
await Promise.all([loadPayments(), loadRegistrations()]);
} catch (e: any) {
setError(e?.message || "Failed to create payment");
} catch (e) {
setError(errorMessage(e) || "Failed to create payment");
} finally {
setSubmitting(false);
}
@@ -515,8 +516,8 @@ function PaymentsContent() {
}
setReconcileForm({ txId: null, type: null, userId: '', registrationId: '', eventId: '', submitting: false });
await Promise.all([loadYocoUnreconciled(), loadPayments(), loadRegistrations()]);
} catch (e: any) {
setError(e?.message || 'Failed to reconcile');
} catch (e) {
setError(errorMessage(e) || 'Failed to reconcile');
} finally {
setReconcileForm(prev => ({ ...prev, submitting: false }));
}
@@ -944,8 +945,8 @@ function RefundSection({ payments, allUsers, regsForUser, regOutstanding, onDone
});
setUserId(""); setPaymentId(""); setRegistrationId(""); setAmount(""); setReason(""); setMethod("");
await onDone();
} catch (e: any) {
setErr(e?.message || 'Failed to create refund');
} catch (e) {
setErr(errorMessage(e) || 'Failed to create refund');
} finally {
setSubmitting(false);
}
@@ -1083,8 +1084,8 @@ function AssignedDonationsList({ payments, onDone }: AssignedDonationsListProps)
body: { legId: leg.id }
});
await onDone();
} catch (e: any) {
setErr(e?.message || 'Failed to unassign donation');
} catch (e) {
setErr(errorMessage(e) || 'Failed to unassign donation');
} finally {
setUnassigningId(null);
}
@@ -1267,8 +1268,8 @@ function DonationAssignSection({ payments, allUsers, registrations, regOutstandi
});
setUserId(""); setRegistrationId(""); setPaymentId(""); setAmountStr("");
await onDone();
} catch (e: any) {
setErr(e?.message || 'Failed to assign donation');
} catch (e) {
setErr(errorMessage(e) || 'Failed to assign donation');
} finally {
setAssigning(false);
}