fix: admin metrics broken (#1845)

This commit is contained in:
Ephraim Duncan
2025-06-17 11:15:11 +00:00
committed by GitHub
parent 4fd8a767b2
commit 484f6c8b85
2 changed files with 10 additions and 44 deletions

View File

@ -19,6 +19,7 @@ import { getDocumentStats } from '@documenso/lib/server-only/admin/get-documents
import { getRecipientsStats } from '@documenso/lib/server-only/admin/get-recipients-stats'; import { getRecipientsStats } from '@documenso/lib/server-only/admin/get-recipients-stats';
import { import {
getOrganisationsWithSubscriptionsCount, getOrganisationsWithSubscriptionsCount,
getUserWithSignedDocumentMonthlyGrowth,
getUsersCount, getUsersCount,
} from '@documenso/lib/server-only/admin/get-users-stats'; } from '@documenso/lib/server-only/admin/get-users-stats';
import { getSignerConversionMonthly } from '@documenso/lib/server-only/user/get-signer-conversion'; import { getSignerConversionMonthly } from '@documenso/lib/server-only/user/get-signer-conversion';
@ -37,18 +38,14 @@ export async function loader() {
docStats, docStats,
recipientStats, recipientStats,
signerConversionMonthly, signerConversionMonthly,
// userWithAtLeastOneDocumentPerMonth, monthlyUsersWithDocuments,
// userWithAtLeastOneDocumentSignedPerMonth,
// MONTHLY_USERS_SIGNED,
] = await Promise.all([ ] = await Promise.all([
getUsersCount(), getUsersCount(),
getOrganisationsWithSubscriptionsCount(), getOrganisationsWithSubscriptionsCount(),
getDocumentStats(), getDocumentStats(),
getRecipientsStats(), getRecipientsStats(),
getSignerConversionMonthly(), getSignerConversionMonthly(),
// getUserWithAtLeastOneDocumentPerMonth(), getUserWithSignedDocumentMonthlyGrowth(),
// getUserWithAtLeastOneDocumentSignedPerMonth(),
// getUserWithSignedDocumentMonthlyGrowth(),
]); ]);
return { return {
@ -57,7 +54,7 @@ export async function loader() {
docStats, docStats,
recipientStats, recipientStats,
signerConversionMonthly, signerConversionMonthly,
// MONTHLY_USERS_SIGNED, monthlyUsersWithDocuments,
}; };
} }
@ -70,7 +67,7 @@ export default function AdminStatsPage({ loaderData }: Route.ComponentProps) {
docStats, docStats,
recipientStats, recipientStats,
signerConversionMonthly, signerConversionMonthly,
// MONTHLY_USERS_SIGNED, monthlyUsersWithDocuments,
} = loaderData; } = loaderData;
return ( return (
@ -148,14 +145,12 @@ export default function AdminStatsPage({ loaderData }: Route.ComponentProps) {
</h3> </h3>
<div className="mt-5 grid grid-cols-2 gap-8"> <div className="mt-5 grid grid-cols-2 gap-8">
<AdminStatsUsersWithDocumentsChart <AdminStatsUsersWithDocumentsChart
data={[]} data={monthlyUsersWithDocuments}
// data={MONTHLY_USERS_SIGNED}
title={_(msg`MAU (created document)`)} title={_(msg`MAU (created document)`)}
tooltip={_(msg`Monthly Active Users: Users that created at least one Document`)} tooltip={_(msg`Monthly Active Users: Users that created at least one Document`)}
/> />
<AdminStatsUsersWithDocumentsChart <AdminStatsUsersWithDocumentsChart
data={[]} data={monthlyUsersWithDocuments}
// data={MONTHLY_USERS_SIGNED}
completed completed
title={_(msg`MAU (had document completed)`)} title={_(msg`MAU (had document completed)`)}
tooltip={_( tooltip={_(

View File

@ -1,4 +1,4 @@
import { DocumentStatus, SubscriptionStatus } from '@prisma/client'; import { SubscriptionStatus } from '@prisma/client';
import { DateTime } from 'luxon'; import { DateTime } from 'luxon';
import { prisma } from '@documenso/prisma'; import { prisma } from '@documenso/prisma';
@ -17,37 +17,6 @@ export const getOrganisationsWithSubscriptionsCount = async () => {
}); });
}; };
export const getUserWithAtLeastOneDocumentPerMonth = async () => {
return await prisma.user.count({
where: {
documents: {
some: {
createdAt: {
gte: DateTime.now().minus({ months: 1 }).toJSDate(),
},
},
},
},
});
};
export const getUserWithAtLeastOneDocumentSignedPerMonth = async () => {
return await prisma.user.count({
where: {
documents: {
some: {
status: {
equals: DocumentStatus.COMPLETED,
},
completedAt: {
gte: DateTime.now().minus({ months: 1 }).toJSDate(),
},
},
},
},
});
};
export type GetUserWithDocumentMonthlyGrowth = Array<{ export type GetUserWithDocumentMonthlyGrowth = Array<{
month: string; month: string;
count: number; count: number;
@ -67,6 +36,8 @@ export const getUserWithSignedDocumentMonthlyGrowth = async () => {
COUNT(DISTINCT "Document"."userId") as "count", COUNT(DISTINCT "Document"."userId") as "count",
COUNT(DISTINCT CASE WHEN "Document"."status" = 'COMPLETED' THEN "Document"."userId" END) as "signed_count" COUNT(DISTINCT CASE WHEN "Document"."status" = 'COMPLETED' THEN "Document"."userId" END) as "signed_count"
FROM "Document" FROM "Document"
INNER JOIN "Team" ON "Document"."teamId" = "Team"."id"
INNER JOIN "Organisation" ON "Team"."organisationId" = "Organisation"."id"
GROUP BY "month" GROUP BY "month"
ORDER BY "month" DESC ORDER BY "month" DESC
LIMIT 12 LIMIT 12