import { FunctionComponent, useMemo } from 'react'; import { Cell, Pie, PieChart } from 'recharts'; import { ctw } from '@/common/utils/ctw/ctw'; import { ChartContainer } from '@ballerine/ui'; import { useNavigate } from 'react-router-dom'; type PieChartData = { status?: string; riskLevel?: string; count: number; href?: string }; export type CasePieChartProps = { data: PieChartData[]; getDefinition: (key: string) => { color: string; text: string }; nameKey: 'status' | 'riskLevel'; config: Record; }; export const CasePieChart: FunctionComponent = ({ data, getDefinition, nameKey, config, }) => { const totalCount = useMemo(() => data.reduce((acc, curr) => acc + curr.count, 0), [data]); const navigate = useNavigate(); if (data.length === 0) { return (
No Data Available
); } return ( <> {totalCount} {data.map((entry, index) => ( { if (entry.href) { navigate(entry.href); } }} /> ))} ); };