diff --git a/Frontend/src/components/Explore/MentorCard.jsx b/Frontend/src/components/Explore/MentorCard.jsx index 0e80e58..8f8cf56 100644 --- a/Frontend/src/components/Explore/MentorCard.jsx +++ b/Frontend/src/components/Explore/MentorCard.jsx @@ -1,67 +1,29 @@ -import React, { useState, useEffect } from 'react'; +import React, { useCallback, useMemo } from 'react'; import { useNavigate } from 'react-router-dom'; import { FiStar, FiGift } from 'react-icons/fi'; -const MentorCard = ({ mentor }) => { +const MentorCard = ({ mentor, mentorStats = {} }) => { const navigate = useNavigate(); - const [mentorStats, setMentorStats] = useState({ - mentoredStudents: 0, - totalSessions: 0 - }); + + // Memoize stats to prevent unnecessary recalculations + const stats = useMemo(() => ({ + mentoredStudents: mentorStats[mentor.id]?.mentoredStudents || 0, + totalSessions: mentorStats[mentor.id]?.totalSessions || 0 + }), [mentorStats, mentor.id]); - useEffect(() => { - const fetchMentorStats = async () => { - try { - const token = localStorage.getItem("token"); - if (!token || !mentor.id) { - console.log('⚠️ [MentorCard] Missing token or mentor.id:', { hasToken: !!token, mentorId: mentor.id }); - return; - } - - console.log('🔍 [MentorCard] Fetching stats for mentor:', mentor.id, 'Name:', mentor.name); - - // Fetch mentor stats using the correct endpoint - const url = `http://localhost:4000/api/bookings/mentor/stats?mentorId=${mentor.id}`; - console.log('📍 [MentorCard] API URL:', url); - - const response = await fetch(url, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - 'Authorization': `Bearer ${token}` - } - }); - - const data = await response.json(); - console.log('📊 [MentorCard] API Response:', { status: response.status, success: data.success, sessionsCompleted: data.data?.sessionsCompleted }); - - if (response.ok && data.success && data.data) { - console.log('✅ [MentorCard] Stats for', mentor.name, ':', { - mentoredStudents: data.data.sessionsCompleted, - totalSessions: data.data.sessionsCompleted - }); - - setMentorStats({ - mentoredStudents: data.data.sessionsCompleted || 0, - totalSessions: data.data.sessionsCompleted || 0 - }); - } - } catch (err) { - console.error('❌ [MentorCard] Error fetching mentor stats:', err); - } - }; - - fetchMentorStats(); - }, [mentor.id]); - - const handleCardClick = () => { + // Memoize click handler + const handleCardClick = useCallback(() => { navigate(`/mentor-profile?mentor=${encodeURIComponent(mentor.name)}&mentorId=${mentor.id}`); - }; + }, [navigate, mentor.name, mentor.id]); return (
- Accessible and tailored mentorship experience for everyone. +
+ Transforming lives through personalized mentorship. Connect with expert mentors to achieve your goals and unlock your full potential.
+- © 2026 Ment2Be. All rights reserved. -
-