import { Center, Grid, Image, Loader, Stack } from "@mantine/core"; import { CheckCircle, FileText, MessageCircle, Users } from "lucide-react"; import { useEffect, useState } from "react"; import { apiClient } from "@/utils/api-client"; import { ActivityList } from "./dashboard/activity-list"; import { ChartAPBDes } from "./dashboard/chart-apbdes"; import { ChartSurat } from "./dashboard/chart-surat"; import { DivisionProgress } from "./dashboard/division-progress"; import { SatisfactionChart } from "./dashboard/satisfaction-chart"; import { SDGSCard } from "./dashboard/sdgs-card"; import { StatCard } from "./dashboard/stat-card"; export function DashboardContent() { const [stats, setStats] = useState({ complaints: { total: 0, baru: 0, proses: 0, selesai: 0 }, residents: { total: 0, heads: 0, poor: 0 }, weeklyService: 0, loading: true, }); const [sdgsData, setSdgsData] = useState< { title: string; score: number; image: string | null }[] >([]); const [sdgsLoading, setSdgsLoading] = useState(true); useEffect(() => { async function fetchStats() { try { const [complaintRes, residentRes, weeklyServiceRes, sdgsRes] = await Promise.all([ apiClient.GET("/api/complaint/stats"), apiClient.GET("/api/resident/stats"), apiClient.GET("/api/complaint/service-weekly"), apiClient.GET("/api/dashboard/sdgs"), ]); setStats({ complaints: (complaintRes.data as { data: typeof stats.complaints }) ?.data || { total: 0, baru: 0, proses: 0, selesai: 0, }, residents: (residentRes.data as { data: typeof stats.residents }) ?.data || { total: 0, heads: 0, poor: 0, }, weeklyService: (weeklyServiceRes.data as { data: { count: number } })?.data ?.count || 0, loading: false, }); if (sdgsRes.data?.data) { setSdgsData(sdgsRes.data.data); } setSdgsLoading(false); } catch (error) { console.error("Failed to fetch dashboard content", error); setStats((prev) => ({ ...prev, loading: false })); setSdgsLoading(false); } } fetchStats(); }, []); return ( {/* Header Metrics - 4 Stat Cards */} } /> } /> } /> } /> {/* Section 2: Chart & Division Progress */} {/* Section 3: APBDes Chart */} {/* */} {/* Section 6: SDGs Desa Cards */} {sdgsLoading ? (
) : ( {sdgsData.map((sdg) => ( : null } title={sdg.title} score={sdg.score} /> ))} )}
); }