mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
feat: add completed documents per month graph
This commit is contained in:
@ -0,0 +1,57 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { DateTime } from 'luxon';
|
||||||
|
import { Bar, BarChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts';
|
||||||
|
|
||||||
|
import type { GetUserMonthlyGrowthResult } from '@documenso/lib/server-only/user/get-user-monthly-growth';
|
||||||
|
import { cn } from '@documenso/ui/lib/utils';
|
||||||
|
|
||||||
|
export type MonthlyCompletedDocumentsChartProps = {
|
||||||
|
className?: string;
|
||||||
|
data: GetUserMonthlyGrowthResult;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const MonthlyCompletedDocumentsChart = ({
|
||||||
|
className,
|
||||||
|
data,
|
||||||
|
}: MonthlyCompletedDocumentsChartProps) => {
|
||||||
|
const formattedData = [...data].reverse().map(({ month, cume_count: count }) => {
|
||||||
|
return {
|
||||||
|
month: DateTime.fromFormat(month, 'yyyy-MM').toFormat('LLLL'),
|
||||||
|
count: Number(count),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={cn('flex flex-col', className)}>
|
||||||
|
<div className="flex items-center px-4">
|
||||||
|
<h3 className="text-lg font-semibold">Completed Documents per Month</h3>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="border-border mt-2.5 flex flex-1 items-center justify-center rounded-2xl border p-6 pl-2 pt-12 shadow-sm hover:shadow">
|
||||||
|
<ResponsiveContainer width="100%" height={400}>
|
||||||
|
<BarChart data={formattedData}>
|
||||||
|
<XAxis dataKey="month" />
|
||||||
|
<YAxis />
|
||||||
|
|
||||||
|
<Tooltip
|
||||||
|
labelStyle={{
|
||||||
|
color: 'hsl(var(--primary-foreground))',
|
||||||
|
}}
|
||||||
|
formatter={(value) => [Number(value).toLocaleString('en-US'), 'Total Users']}
|
||||||
|
cursor={{ fill: 'hsl(var(--primary) / 10%)' }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Bar
|
||||||
|
dataKey="count"
|
||||||
|
fill="hsl(var(--primary))"
|
||||||
|
radius={[4, 4, 0, 0]}
|
||||||
|
maxBarSize={60}
|
||||||
|
label="Total Users"
|
||||||
|
/>
|
||||||
|
</BarChart>
|
||||||
|
</ResponsiveContainer>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
@ -2,6 +2,7 @@ import type { Metadata } from 'next';
|
|||||||
|
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
import { getCompletedDocumentsMonthly } from '@documenso/lib/server-only/user/get-monthly-completed-document';
|
||||||
import { getUserMonthlyGrowth } from '@documenso/lib/server-only/user/get-user-monthly-growth';
|
import { getUserMonthlyGrowth } from '@documenso/lib/server-only/user/get-user-monthly-growth';
|
||||||
|
|
||||||
import { FUNDING_RAISED } from '~/app/(marketing)/open/data';
|
import { FUNDING_RAISED } from '~/app/(marketing)/open/data';
|
||||||
@ -12,6 +13,7 @@ import { CallToAction } from '~/components/(marketing)/call-to-action';
|
|||||||
import { BarMetric } from './bar-metrics';
|
import { BarMetric } from './bar-metrics';
|
||||||
import { CapTable } from './cap-table';
|
import { CapTable } from './cap-table';
|
||||||
import { FundingRaised } from './funding-raised';
|
import { FundingRaised } from './funding-raised';
|
||||||
|
import { MonthlyCompletedDocumentsChart } from './monthly-completed-documents-chart copy';
|
||||||
import { MonthlyNewUsersChart } from './monthly-new-users-chart';
|
import { MonthlyNewUsersChart } from './monthly-new-users-chart';
|
||||||
import { MonthlyTotalUsersChart } from './monthly-total-users-chart';
|
import { MonthlyTotalUsersChart } from './monthly-total-users-chart';
|
||||||
import { TeamMembers } from './team-members';
|
import { TeamMembers } from './team-members';
|
||||||
@ -140,6 +142,7 @@ export default async function OpenPage() {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
const MONTHLY_USERS = await getUserMonthlyGrowth();
|
const MONTHLY_USERS = await getUserMonthlyGrowth();
|
||||||
|
const MONTHLY_COMPLETED_DOCUMENTS = await getCompletedDocumentsMonthly();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@ -240,6 +243,11 @@ export default async function OpenPage() {
|
|||||||
<MonthlyTotalUsersChart data={MONTHLY_USERS} className="col-span-12 lg:col-span-6" />
|
<MonthlyTotalUsersChart data={MONTHLY_USERS} className="col-span-12 lg:col-span-6" />
|
||||||
<MonthlyNewUsersChart data={MONTHLY_USERS} className="col-span-12 lg:col-span-6" />
|
<MonthlyNewUsersChart data={MONTHLY_USERS} className="col-span-12 lg:col-span-6" />
|
||||||
|
|
||||||
|
<MonthlyCompletedDocumentsChart
|
||||||
|
data={MONTHLY_COMPLETED_DOCUMENTS}
|
||||||
|
className="col-span-12 lg:col-span-6"
|
||||||
|
/>
|
||||||
|
|
||||||
<Typefully className="col-span-12 lg:col-span-6" />
|
<Typefully className="col-span-12 lg:col-span-6" />
|
||||||
|
|
||||||
<div className="col-span-12 mt-12 flex flex-col items-center justify-center">
|
<div className="col-span-12 mt-12 flex flex-col items-center justify-center">
|
||||||
|
|||||||
@ -0,0 +1,35 @@
|
|||||||
|
import { DateTime } from 'luxon';
|
||||||
|
|
||||||
|
import { prisma } from '@documenso/prisma';
|
||||||
|
|
||||||
|
export type GetCompletedDocumentsMonthlyResult = Array<{
|
||||||
|
month: string;
|
||||||
|
count: number;
|
||||||
|
cume_count: number;
|
||||||
|
}>;
|
||||||
|
|
||||||
|
type GetCompletedDocumentsMonthlyQueryResult = Array<{
|
||||||
|
month: Date;
|
||||||
|
count: bigint;
|
||||||
|
cume_count: bigint;
|
||||||
|
}>;
|
||||||
|
|
||||||
|
export const getCompletedDocumentsMonthly = async () => {
|
||||||
|
const result = await prisma.$queryRaw<GetCompletedDocumentsMonthlyQueryResult>`
|
||||||
|
SELECT
|
||||||
|
DATE_TRUNC('month', "completedAt") AS "month",
|
||||||
|
COUNT("id") as "count",
|
||||||
|
SUM(COUNT("id")) OVER (ORDER BY DATE_TRUNC('month', "completedAt")) as "cume_count"
|
||||||
|
FROM "Document"
|
||||||
|
WHERE "status" = 'COMPLETED'
|
||||||
|
GROUP BY "month"
|
||||||
|
ORDER BY "month" DESC
|
||||||
|
LIMIT 12
|
||||||
|
`;
|
||||||
|
|
||||||
|
return result.map((row) => ({
|
||||||
|
month: DateTime.fromJSDate(row.month).toFormat('yyyy-MM'),
|
||||||
|
count: Number(row.count),
|
||||||
|
cume_count: Number(row.cume_count),
|
||||||
|
}));
|
||||||
|
};
|
||||||
@ -182,6 +182,7 @@ const createCompletedDocument = async (sender: User, recipients: User[]) => {
|
|||||||
title: `[${PULL_REQUEST_NUMBER}] Document 1 - Completed`,
|
title: `[${PULL_REQUEST_NUMBER}] Document 1 - Completed`,
|
||||||
status: DocumentStatus.COMPLETED,
|
status: DocumentStatus.COMPLETED,
|
||||||
documentDataId: documentData.id,
|
documentDataId: documentData.id,
|
||||||
|
completedAt: new Date(),
|
||||||
userId: sender.id,
|
userId: sender.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user