From cc9b906eebd45b6c4764017667d54650bf196fa8 Mon Sep 17 00:00:00 2001 From: Sidney Gomes Date: Wed, 22 Jul 2026 21:28:39 -0300 Subject: [PATCH] fix(dashboard): MRR calculation and user menu --- server-prisma.ts | 16 ++++---- src/components/Navbar.tsx | 7 ++++ src/routes/userRoutes.ts | 82 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 src/routes/userRoutes.ts diff --git a/server-prisma.ts b/server-prisma.ts index bc32762..8893db3 100644 --- a/server-prisma.ts +++ b/server-prisma.ts @@ -803,13 +803,15 @@ app.get('/api/admin/dashboard', authenticateToken, requireAdmin, async (req: Aut let mrr = 0; for (const userId of activeUsersIds) { const studentPayments = allPayments.filter(p => p.userId === userId && (p.status === 'CONFIRMED' || p.status === 'RECEIVED')); - if (studentPayments.length > 0) { - const latest = studentPayments[0]; - if (latest.planId && latest.plan) { - if (latest.plan.cycle === 'MONTHLY') mrr += latest.plan.price; - else if (latest.plan.cycle === 'YEARLY') mrr += (latest.plan.price / 12); - } else if (!latest.courseId) { - mrr += latest.value; + // Find the latest payment that is a subscription (either a plan or no courseId) + const latestSubscription = studentPayments.find(p => p.planId || (!p.courseId && !p.planId)); + + if (latestSubscription) { + if (latestSubscription.planId && latestSubscription.plan) { + if (latestSubscription.plan.cycle === 'MONTHLY') mrr += latestSubscription.plan.price; + else if (latestSubscription.plan.cycle === 'YEARLY') mrr += (latestSubscription.plan.price / 12); + } else if (!latestSubscription.courseId) { + mrr += latestSubscription.value; } } } diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index 3328e19..372dcf1 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -220,6 +220,13 @@ export default function Navbar({ user, activeView, setView, onLogout }: NavbarPr Meus dados +