Files
sign/apps/web/src/app/(dashboard)/admin/stats/user-with-document.tsx

77 lines
2.2 KiB
TypeScript
Raw Normal View History

2024-04-05 17:49:32 +00:00
'use client';
import { DateTime } from 'luxon';
import { Bar, BarChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts';
import type { GetUserWithDocumentMonthlyGrowth } from '@documenso/lib/server-only/admin/get-users-stats';
export type UserWithDocumentChartProps = {
className?: string;
2024-05-21 09:28:23 +00:00
title: string;
2024-04-05 17:49:32 +00:00
data: GetUserWithDocumentMonthlyGrowth;
2024-05-21 09:28:23 +00:00
cummulative?: boolean;
completed?: boolean;
2024-04-05 17:49:32 +00:00
};
2024-05-21 09:28:23 +00:00
export const UserWithDocumentChart = ({
className,
data,
title,
cummulative = false,
completed = false,
}: UserWithDocumentChartProps) => {
const formattedData = (data: GetUserWithDocumentMonthlyGrowth, completed: boolean) => {
return [...data]
.reverse()
.map(({ month, count, cume_count, signed_count, cume_signed_count }) => {
const formattedMonth = DateTime.fromFormat(month, 'yyyy-MM').toFormat('LLL');
if (completed) {
return {
month: formattedMonth,
count: Number(signed_count),
cummulative: Number(cume_signed_count),
};
} else {
return {
month: formattedMonth,
count: Number(count),
cummulative: Number(cume_count),
};
}
});
};
2024-04-05 17:49:32 +00:00
return (
<div className={className}>
<div className="border-border flex flex-1 flex-col justify-center rounded-2xl border p-6 pl-2">
2024-05-21 09:28:23 +00:00
<div className="mb-6 flex h-12 px-4">
<h3 className="text-lg font-semibold">{title}</h3>
2024-04-05 17:49:32 +00:00
</div>
<ResponsiveContainer width="100%" height={400}>
2024-05-21 09:28:23 +00:00
<BarChart data={formattedData(data, completed)}>
2024-04-05 17:49:32 +00:00
<XAxis dataKey="month" />
<YAxis />
<Tooltip
labelStyle={{
color: 'hsl(var(--primary-foreground))',
}}
2024-05-21 09:28:23 +00:00
formatter={(value) => [Number(value).toLocaleString('en-US'), 'Documents']}
2024-04-05 17:49:32 +00:00
cursor={{ fill: 'hsl(var(--primary) / 10%)' }}
/>
<Bar
2024-05-21 09:28:23 +00:00
dataKey={cummulative ? 'cummulative' : 'count'}
2024-04-05 17:49:32 +00:00
fill="hsl(var(--primary))"
radius={[4, 4, 0, 0]}
maxBarSize={60}
2024-05-21 09:28:23 +00:00
label="Documents"
2024-04-05 17:49:32 +00:00
/>
</BarChart>
</ResponsiveContainer>
</div>
</div>
);
};