fix: add array guards to all frontend components consuming API responses

Prevents "M.forEach is not a function" crashes when API returns error
objects or unexpected shapes instead of arrays. Guards all useQuery
consumers with Array.isArray checks and safe defaults for object props.

Files fixed: DeadlineList, AppointmentList, TenantSwitcher,
DeadlineTrafficLights, UpcomingTimeline, CaseOverviewGrid,
AISummaryCard, TeamSettings, and all page-level components
(dashboard, cases, fristen, termine, ai/extract).
This commit is contained in:
m
2026-03-25 18:34:11 +01:00
parent e635efa71e
commit 50bfa3deb4
14 changed files with 42 additions and 33 deletions

View File

@@ -73,12 +73,13 @@ export function AppointmentList({ onEdit }: AppointmentListProps) {
const caseMap = useMemo(() => {
const map = new Map<string, Case>();
cases?.cases?.forEach((c) => map.set(c.id, c));
const arr = Array.isArray(cases?.cases) ? cases.cases : [];
arr.forEach((c) => map.set(c.id, c));
return map;
}, [cases]);
const filtered = useMemo(() => {
if (!appointments) return [];
if (!Array.isArray(appointments)) return [];
return appointments
.filter((a) => {
if (caseFilter !== "all" && a.case_id !== caseFilter) return false;
@@ -91,7 +92,7 @@ export function AppointmentList({ onEdit }: AppointmentListProps) {
const grouped = useMemo(() => groupByDate(filtered), [filtered]);
const counts = useMemo(() => {
if (!appointments) return { today: 0, thisWeek: 0, total: 0 };
if (!Array.isArray(appointments)) return { today: 0, thisWeek: 0, total: 0 };
let today = 0;
let thisWeek = 0;
for (const a of appointments) {
@@ -148,7 +149,7 @@ export function AppointmentList({ onEdit }: AppointmentListProps) {
</option>
))}
</select>
{cases?.cases && cases.cases.length > 0 && (
{Array.isArray(cases?.cases) && cases.cases.length > 0 && (
<select
value={caseFilter}
onChange={(e) => setCaseFilter(e.target.value)}