"use client"; import { useEffect, useState } from "react"; import { PieChart, Pie, Cell, ResponsiveContainer, Tooltip } from "recharts"; import { Card } from "ikoncomponents"; import { getStatusWiseProjectCount } from "@/app/utils/api/productDashboardApi"; import { StatusWiseProjectResponseData } from "@/app/utils/api/productDashboardApi/types"; const COLORS = [ "#3b82f6", "#f59e0b", "#ef4444", "#06b6d4", "#a855f7", "#10b981", "#f97316", "#14b8a6", ]; export const ProjectsByStatusChartPage = () => { const [data, setData] = useState< { name: string; value: number; color: string; }[] >([]); const [loading, setLoading] = useState(true); useEffect(() => { const fetchStatusData = async () => { try { const response = await getStatusWiseProjectCount(); const formattedData = response.map( (item: StatusWiseProjectResponseData, index: number) => ({ name: item.status, value: item.projectCount, color: COLORS[index % COLORS.length], }), ); setData(formattedData); } catch (error) { console.error("Error fetching status wise project data:", error); } finally { setLoading(false); } }; fetchStatusData(); }, []); if (loading) { return ( Loading chart... ); } if (!data.length) { return ( No data available ); } return ( Projects by Status {/* Chart */} {data.map((entry, index) => ( ))} {/* Legend */} {data.map((item, index) => ( {item.name} {item.value} ))} ); }; export default ProjectsByStatusChartPage;
Loading chart...
No data available