"use client"; import { useCallback, useEffect, useState } from "react"; import Link from "next/link"; import SummaryCard from "@/components/common/SummaryCard"; import { api } from "@/lib/api"; import type { DashboardSummary, EmptyWidget } from "@/types/dashboard"; function getErrorMessage(error: unknown) { if (typeof error === "object" && error !== null && "response" in error) { const response = (error as { response?: { data?: { detail?: string } } }).response; return response?.data?.detail ?? "Dashboard konnte nicht geladen werden"; } return "Dashboard konnte nicht geladen werden"; } export default function DashboardPage() { const [summary, setSummary] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(""); const loadSummary = useCallback(async () => { try { const response = await api.get("/dashboard/summary"); setSummary(response.data); } catch (err) { setError(getErrorMessage(err)); } finally { setLoading(false); } }, []); useEffect(() => { queueMicrotask(() => { void loadSummary(); }); }, [loadSummary]); if (loading) { return
Dashboard wird geladen...
; } if (error || !summary) { return
{error || "Keine Dashboarddaten verfügbar"}
; } const cards = [...summary.customers, ...summary.users, ...summary.roles]; return (

Dashboard

Operative Übersicht für Olympus CRM

{cards.length > 0 ? (
{cards.map((card) => ( ))}
) : ( )}

Letzte Kunden

{summary.latest_customers.length > 0 && ( Alle Kunden )}
{summary.latest_customers.length === 0 ? (

Noch keine Kundendaten vorhanden.

) : (
{summary.latest_customers.map((customer) => (

{customer.company_name}

{customer.customer_number}

{customer.status} ))}
)}
); } function EmptyPanel({ widget }: { widget: EmptyWidget }) { return (

{widget.title}

{widget.message}

); }