Archived
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:
@@ -12,6 +12,7 @@ import ReportViewerModal, { ReportActionButton } from "./ReportViewerModal";
|
||||
import { StatTile, StatTileRow } from "./StatTile";
|
||||
import { HorizontalBarChart } from "./charts/HorizontalBarChart";
|
||||
import { AreaTrendChart } from "@/components/charts/AreaTrendChart";
|
||||
import { errorMessage } from "@/lib/utils";
|
||||
|
||||
const METHOD_KEYS = ["cash", "card", "eft", "other"] as const;
|
||||
const METHOD_LABEL: Record<string, string> = { cash: "Cash", card: "Card", eft: "EFT", other: "Other" };
|
||||
@@ -124,8 +125,8 @@ export default function ReportsV2({ onBack }: { onBack?: () => void } = {}) {
|
||||
setLoadingEvents(true);
|
||||
const evs = await apiFetch<any[]>("/api/events/all?includePast=true&includeInactive=true", { authToken: token || undefined });
|
||||
setEvents(Array.isArray(evs) ? evs : []);
|
||||
} catch (e: any) {
|
||||
setError(e?.message || "Failed to load events");
|
||||
} catch (e) {
|
||||
setError(errorMessage(e) || "Failed to load events");
|
||||
} finally {
|
||||
setLoadingEvents(false);
|
||||
}
|
||||
@@ -1297,8 +1298,8 @@ export default function ReportsV2({ onBack }: { onBack?: () => void } = {}) {
|
||||
const payload = buildReportPayload();
|
||||
if (!payload) return;
|
||||
await downloadReportExcel(API_BASE, token, payload);
|
||||
} catch (e: any) {
|
||||
alert(e?.message || 'Failed to generate Excel file');
|
||||
} catch (e) {
|
||||
alert(errorMessage(e) || 'Failed to generate Excel file');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1327,8 +1328,8 @@ export default function ReportsV2({ onBack }: { onBack?: () => void } = {}) {
|
||||
const payload = buildReportPayload();
|
||||
if (!payload) return;
|
||||
await viewReportPdf(API_BASE, token, payload);
|
||||
} catch (e: any) {
|
||||
alert(e?.message || 'Failed to generate PDF');
|
||||
} catch (e) {
|
||||
alert(errorMessage(e) || 'Failed to generate PDF');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1339,8 +1340,8 @@ export default function ReportsV2({ onBack }: { onBack?: () => void } = {}) {
|
||||
if (!payload) return;
|
||||
await emailReportPdf(API_BASE, token, { ...payload, subject: REPORT_LABEL[report], body: "Report generated on " + new Date().toLocaleString() });
|
||||
alert('Email sent with PDF attachment');
|
||||
} catch (e: any) {
|
||||
alert(e?.message || 'Failed to email PDF');
|
||||
} catch (e) {
|
||||
alert(errorMessage(e) || 'Failed to email PDF');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1351,8 +1352,8 @@ export default function ReportsV2({ onBack }: { onBack?: () => void } = {}) {
|
||||
if (!payload) return;
|
||||
await whatsappReportPdf(API_BASE, token, { ...payload, caption: REPORT_LABEL[report] });
|
||||
alert('Report sent to your WhatsApp');
|
||||
} catch (e: any) {
|
||||
alert(e?.message || 'Failed to send via WhatsApp');
|
||||
} catch (e) {
|
||||
alert(errorMessage(e) || 'Failed to send via WhatsApp');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user