"use client"; import { useState, useEffect } from "react"; import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, BarChart, Bar, ComposedChart } from 'recharts'; export default function TeamLeadsDashboard() { const [chartData, setChartData] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { fetchDashboardData(); }, []); const fetchDashboardData = async () => { try { const response = await fetch('/api/dashboard'); if (!response.ok) { throw new Error('Failed to fetch dashboard data'); } const data = await response.json(); setChartData(data); } catch (err) { setError(err.message); } finally { setLoading(false); } }; const formatCurrency = (value) => { return new Intl.NumberFormat('pl-PL', { style: 'currency', currency: 'PLN', minimumFractionDigits: 0, maximumFractionDigits: 0 }).format(value); }; const CustomTooltip = ({ active, payload, label }) => { if (active && payload && payload.length) { // Find the monthly and cumulative values const monthlyData = payload.find(p => p.dataKey === 'value'); const cumulativeData = payload.find(p => p.dataKey === 'cumulative'); return (
{`Month: ${label}`}
{`Monthly Value: ${monthlyData ? formatCurrency(monthlyData.value) : 'N/A'}`}
{`Cumulative: ${cumulativeData ? formatCurrency(cumulativeData.value) : 'N/A'}`}
This chart shows the cumulative value of completed projects over time, with monthly additions.