import { Box, Card, Group, Loader, Text, Title, useMantineColorScheme, } from "@mantine/core"; import { useEffect, useState } from "react"; import { Cell, Pie, PieChart, ResponsiveContainer, Tooltip } from "recharts"; import { apiClient } from "@/utils/api-client"; interface SatisfactionData { name: string; value: number; color: string; } export function SatisfactionChart() { const { colorScheme } = useMantineColorScheme(); const dark = colorScheme === "dark"; const [data, setData] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { async function fetchSatisfaction() { try { const res = await apiClient.GET("/api/dashboard/satisfaction"); if (res.data?.data) { setData( res.data.data.map((d) => ({ name: d.category, value: d.value, color: d.color, })), ); } } catch (error) { console.error("Failed to fetch satisfaction data", error); } finally { setLoading(false); } } fetchSatisfaction(); }, []); return ( Tingkat Kepuasan Tingkat kepuasan layanan {loading ? ( ) : ( {data.map((entry) => ( ))} )} {data.map((item) => ( {item.name} ))} ); }