import { TrendingUpIcon } from 'lucide-react'; import { Area, AreaChart, CartesianGrid, Tooltip as RechartTooltip, ResponsiveContainer, XAxis, YAxis, } from 'recharts'; import { WidgetHead, WidgetTitle } from '../overview/overview-widget'; import { useXAxisProps, useYAxisProps, } from '@/components/report-chart/common/axis'; import { Widget, WidgetBody } from '@/components/widget'; import { useFormatDateInterval } from '@/hooks/use-format-date-interval'; import { useNumber } from '@/hooks/use-numer-formatter'; import { getChartColor } from '@/utils/theme'; type Props = { data: { date: string; count: number }[]; }; function Tooltip(props: any) { const number = useNumber(); const formatDate = useFormatDateInterval({ interval: 'day', short: false }); const payload = props.payload?.[0]?.payload; if (!payload) { return null; } return (
{formatDate(new Date(payload.timestamp))}
Total members
{number.format(payload.cumulative)}
{payload.count > 0 && (
+{number.format(payload.count)} new
)}
); } export function GroupMemberGrowth({ data }: Props) { const xAxisProps = useXAxisProps({ interval: 'day' }); const yAxisProps = useYAxisProps({}); const color = getChartColor(0); let cumulative = 0; const chartData = data.map((item) => { cumulative += item.count; return { date: item.date, timestamp: new Date(item.date).getTime(), count: item.count, cumulative, }; }); const gradientId = 'memberGrowthGradient'; return ( New members last 30 days {data.length === 0 ? (

No data yet

) : (
} cursor={{ stroke: color, strokeOpacity: 0.3 }} />
)}
); }