Add active users last 24h card to admin dashboard

This commit is contained in:
2026-05-11 18:52:40 +05:00
parent c1ae048c14
commit 77016a03c7
+15
View File
@@ -3,6 +3,7 @@ import Link from "next/link";
export default async function AdminDashboard() { export default async function AdminDashboard() {
const now = new Date(); const now = new Date();
const dayAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000);
const weekAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000); const weekAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000);
const monthAgo = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000); const monthAgo = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000);
@@ -17,6 +18,7 @@ export default async function AdminDashboard() {
homeworkTotal, homeworkTotal,
progressTotal, progressTotal,
balanceAggregate, balanceAggregate,
activeLast24h,
] = await Promise.all([ ] = await Promise.all([
prisma.user.count({ where: { role: "student" } }), prisma.user.count({ where: { role: "student" } }),
prisma.user.count({ where: { role: "student", createdAt: { gte: monthAgo } } }), prisma.user.count({ where: { role: "student", createdAt: { gte: monthAgo } } }),
@@ -32,6 +34,11 @@ export default async function AdminDashboard() {
prisma.homeworkSubmission.count(), prisma.homeworkSubmission.count(),
prisma.lessonProgress.count(), prisma.lessonProgress.count(),
prisma.balanceTransaction.aggregate({ _sum: { amount: true } }), prisma.balanceTransaction.aggregate({ _sum: { amount: true } }),
prisma.session.findMany({
where: { createdAt: { gte: dayAgo } },
select: { userId: true },
distinct: ["userId"],
}).then((rows) => rows.length),
]); ]);
const totalBalance = Number(balanceAggregate._sum.amount ?? 0); const totalBalance = Number(balanceAggregate._sum.amount ?? 0);
@@ -179,6 +186,14 @@ export default async function AdminDashboard() {
</p> </p>
<p className="text-xs mt-0.5" style={{ color: "var(--muted-foreground)" }}>сумма по всем пользователям</p> <p className="text-xs mt-0.5" style={{ color: "var(--muted-foreground)" }}>сумма по всем пользователям</p>
</Link> </Link>
<div className="card-aubade p-5">
<p className="text-xs font-bold uppercase tracking-widest mb-3" style={{ color: "var(--muted-foreground)" }}>
Авторизации за 24 часа
</p>
<p className="text-3xl font-bold">{activeLast24h}</p>
<p className="text-xs mt-0.5" style={{ color: "var(--muted-foreground)" }}>уникальных пользователей</p>
</div>
</div> </div>
</div> </div>
</div> </div>