From 7c28c49e75997751427bccd5dda4b6fbe2dada18 Mon Sep 17 00:00:00 2001 From: "Mahmoud M. Abdalla" Date: Thu, 31 Jul 2025 02:51:24 +0300 Subject: [PATCH] Fix header layout and add debugging for dashboard statistics - Removed 'CourseWorx' text from header - Fixed logo path to use /images/cx-logo.png - Moved navigation items next to Home icon - Added debugging to API calls and dashboard - Added console logging to backend stats endpoints --- backend/routes/courses.js | 4 +++ backend/routes/users.js | 4 +++ frontend/src/components/Layout.js | 58 +++++++++++++++---------------- frontend/src/pages/Dashboard.js | 47 +++++++++++++++++++++++-- 4 files changed, 82 insertions(+), 31 deletions(-) diff --git a/backend/routes/courses.js b/backend/routes/courses.js index 9a45e37..ab19f29 100644 --- a/backend/routes/courses.js +++ b/backend/routes/courses.js @@ -458,6 +458,8 @@ router.get('/trainers/available', auth, requireSuperAdmin, async (req, res) => { // @access Private router.get('/stats/overview', auth, async (req, res) => { try { + console.log('Course stats endpoint called by user:', req.user.id, req.user.role); + const whereClause = {}; if (req.user.role === 'trainer') { whereClause.trainerId = req.user.id; @@ -471,6 +473,8 @@ router.get('/stats/overview', auth, async (req, res) => { where: { ...whereClause, isFeatured: true } }); + console.log('Course stats calculated:', { totalCourses, publishedCourses, featuredCourses, whereClause }); + // For trainers, provide specific stats let myCourses = 0; let myPublishedCourses = 0; diff --git a/backend/routes/users.js b/backend/routes/users.js index b81a6b5..9b087ca 100644 --- a/backend/routes/users.js +++ b/backend/routes/users.js @@ -219,11 +219,15 @@ router.delete('/:id', auth, requireSuperAdmin, async (req, res) => { // @access Private (Super Admin) router.get('/stats/overview', auth, requireSuperAdmin, async (req, res) => { try { + console.log('User stats endpoint called by user:', req.user.id, req.user.role); + const totalUsers = await User.count(); const activeUsers = await User.count({ where: { isActive: true } }); const trainers = await User.count({ where: { role: 'trainer' } }); const trainees = await User.count({ where: { role: 'trainee' } }); + console.log('User stats calculated:', { totalUsers, activeUsers, trainers, trainees }); + res.json({ stats: { totalUsers, diff --git a/frontend/src/components/Layout.js b/frontend/src/components/Layout.js index d182e77..e786fd3 100644 --- a/frontend/src/components/Layout.js +++ b/frontend/src/components/Layout.js @@ -55,41 +55,41 @@ const Layout = () => {
{/* Header */}
- {/* Logo and Home Icon */} -
+ {/* Logo and Navigation */} +
- CourseWorx -

CourseWorx

+ CourseWorx
- -
- - {/* Navigation Items */} -
- {navigation.map((item) => ( - + + + {navigation.map((item) => ( + + + {item.name} + + ))} +
{/* User dropdown menu */} -
+
diff --git a/frontend/src/pages/Dashboard.js b/frontend/src/pages/Dashboard.js index 29412dc..5094915 100644 --- a/frontend/src/pages/Dashboard.js +++ b/frontend/src/pages/Dashboard.js @@ -84,13 +84,40 @@ const Dashboard = () => { const { data: userStats, isLoading: userStatsLoading } = useQuery( ['users', 'stats'], () => usersAPI.getStats(), - { enabled: isSuperAdmin } + { + enabled: isSuperAdmin, + onSuccess: (data) => { + console.log('User stats response:', data); + console.log('User stats data structure:', { + totalUsers: data?.stats?.totalUsers, + trainers: data?.stats?.trainers, + trainees: data?.stats?.trainees + }); + }, + onError: (error) => { + console.error('User stats error:', error); + console.error('User stats error response:', error.response); + } + } ); const { data: courseStats, isLoading: courseStatsLoading } = useQuery( ['courses', 'stats'], () => coursesAPI.getStats(), - { enabled: isSuperAdmin || isTrainer } + { + enabled: isSuperAdmin || isTrainer, + onSuccess: (data) => { + console.log('Course stats response:', data); + console.log('Course stats data structure:', { + totalCourses: data?.stats?.totalCourses, + publishedCourses: data?.stats?.publishedCourses + }); + }, + onError: (error) => { + console.error('Course stats error:', error); + console.error('Course stats error response:', error.response); + } + } ); // New queries for real counts @@ -120,6 +147,19 @@ const Dashboard = () => { return ; } + // Debug section to show raw API responses + const debugSection = ( +
+

Debug Information

+
+

User Stats: {JSON.stringify(userStats)}

+

Course Stats: {JSON.stringify(courseStats)}

+

User Role: {user?.role}

+

Is Super Admin: {isSuperAdmin ? 'Yes' : 'No'}

+
+
+ ); + const renderSuperAdminDashboard = () => (
@@ -397,6 +437,9 @@ const Dashboard = () => {

Welcome back, {user?.firstName}! Here's what's happening.

+ {/* Debug section */} + {debugSection} + {isSuperAdmin && renderSuperAdminDashboard()} {isTrainer && renderTrainerDashboard()} {isTrainee && renderTraineeDashboard()}