import React, { useEffect, useState } from 'react'; import { Link } from 'react-router-dom'; import api from '../../utils/api'; import { Card } from '../../components/ui/card'; import { Button } from '../../components/ui/button'; import { Badge } from '../../components/ui/badge'; import { Users, Calendar, Clock, CheckCircle, Mail, AlertCircle } from 'lucide-react'; const AdminDashboard = () => { const [stats, setStats] = useState({ totalMembers: 0, pendingValidations: 0, activeMembers: 0 }); const [usersNeedingAttention, setUsersNeedingAttention] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { fetchDashboardStats(); }, []); const fetchDashboardStats = async () => { try { const usersResponse = await api.get('/admin/users'); const users = usersResponse.data; setStats({ totalMembers: users.filter(u => u.role === 'member').length, pendingValidations: users.filter(u => ['pending_email', 'pending_validation', 'pre_validated', 'payment_pending'].includes(u.status) ).length, activeMembers: users.filter(u => u.status === 'active' && u.role === 'member').length }); // Find users who have received 3+ reminders (may need personal outreach) const needingAttention = users.filter(u => { const emailReminders = u.email_verification_reminders_sent || 0; const eventReminders = u.event_attendance_reminders_sent || 0; const paymentReminders = u.payment_reminders_sent || 0; const totalReminders = emailReminders + eventReminders + paymentReminders; return totalReminders >= 3; }).map(u => ({ ...u, totalReminders: (u.email_verification_reminders_sent || 0) + (u.event_attendance_reminders_sent || 0) + (u.payment_reminders_sent || 0) })).sort((a, b) => b.totalReminders - a.totalReminders).slice(0, 5); // Top 5 setUsersNeedingAttention(needingAttention); } catch (error) { console.error('Failed to fetch stats:', error); } finally { setLoading(false); } }; return ( <>
Manage users, events, and membership applications.
{loading ? '-' : stats.totalMembers}
Total Members
{loading ? '-' : stats.pendingValidations}
Pending Validations
{loading ? '-' : stats.activeMembers}
Active Members
View and manage paying members and their subscription status.
Review and validate pending membership applications.
These members have received multiple reminder emails. Consider calling them directly.
Email: {user.email}
Phone: {user.phone || 'N/A'}
Status: {user.status.replace('_', ' ')}
{user.email_verification_reminders_sent > 0 && (
💡 Tip for helping older members: Many of our members are older ladies who may struggle with email. A friendly phone call can help them complete the registration process and feel more welcomed to the community.