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:
@@ -31,24 +31,25 @@ interface Props {
|
||||
}
|
||||
|
||||
export function DeadlineTrafficLights({ data, onFilter }: Props) {
|
||||
const safe = data ?? { overdue_count: 0, due_this_week: 0, due_next_week: 0, ok_count: 0 };
|
||||
const cards = [
|
||||
{
|
||||
key: "overdue" as const,
|
||||
label: "Überfällig",
|
||||
count: data.overdue_count,
|
||||
count: safe.overdue_count ?? 0,
|
||||
icon: AlertTriangle,
|
||||
bg: "bg-red-50",
|
||||
border: "border-red-200",
|
||||
iconColor: "text-red-500",
|
||||
countColor: "text-red-700",
|
||||
labelColor: "text-red-600",
|
||||
ring: data.overdue_count > 0 ? "ring-2 ring-red-300 ring-offset-1" : "",
|
||||
pulse: data.overdue_count > 0,
|
||||
ring: (safe.overdue_count ?? 0) > 0 ? "ring-2 ring-red-300 ring-offset-1" : "",
|
||||
pulse: (safe.overdue_count ?? 0) > 0,
|
||||
},
|
||||
{
|
||||
key: "this_week" as const,
|
||||
label: "Diese Woche",
|
||||
count: data.due_this_week,
|
||||
count: safe.due_this_week ?? 0,
|
||||
icon: Clock,
|
||||
bg: "bg-amber-50",
|
||||
border: "border-amber-200",
|
||||
@@ -61,7 +62,7 @@ export function DeadlineTrafficLights({ data, onFilter }: Props) {
|
||||
{
|
||||
key: "ok" as const,
|
||||
label: "Im Zeitplan",
|
||||
count: data.ok_count + data.due_next_week,
|
||||
count: (safe.ok_count ?? 0) + (safe.due_next_week ?? 0),
|
||||
icon: CheckCircle,
|
||||
bg: "bg-emerald-50",
|
||||
border: "border-emerald-200",
|
||||
|
||||
Reference in New Issue
Block a user