import React, { useEffect, useState } from 'react';
import { Link } from 'react-router-dom';
import { useAuth } from '../context/AuthContext';
import api from '../utils/api';
import { Card } from '../components/ui/card';
import { Button } from '../components/ui/button';
import { Badge } from '../components/ui/badge';
import Navbar from '../components/Navbar';
import { Calendar, User, CheckCircle, Clock, AlertCircle, Mail } from 'lucide-react';
import { toast } from 'sonner';
const Dashboard = () => {
const { user, resendVerificationEmail } = useAuth();
const [events, setEvents] = useState([]);
const [loading, setLoading] = useState(true);
const [resendLoading, setResendLoading] = useState(false);
useEffect(() => {
fetchUpcomingEvents();
}, []);
const fetchUpcomingEvents = async () => {
try {
const response = await api.get('/events');
const upcomingEvents = response.data.slice(0, 3);
setEvents(upcomingEvents);
} catch (error) {
console.error('Failed to fetch events:', error);
} finally {
setLoading(false);
}
};
const handleResendVerification = async () => {
setResendLoading(true);
try {
await resendVerificationEmail();
toast.success('Verification email sent! Please check your inbox.');
} catch (error) {
const errorMessage = error.response?.data?.detail || 'Failed to send verification email';
toast.error(errorMessage);
} finally {
setResendLoading(false);
}
};
const getStatusBadge = (status) => {
const statusConfig = {
pending_email: { icon: Clock, label: 'Pending Email', className: 'bg-[#F2CC8F] text-[#3D405B]' },
pending_approval: { icon: Clock, label: 'Pending Approval', className: 'bg-[#A3B1C6] text-white' },
pre_approved: { icon: CheckCircle, label: 'Pre-Approved', className: 'bg-[#81B29A] text-white' },
payment_pending: { icon: AlertCircle, label: 'Payment Pending', className: 'bg-[#E07A5F] text-white' },
active: { icon: CheckCircle, label: 'Active', className: 'bg-[#81B29A] text-white' },
inactive: { icon: AlertCircle, label: 'Inactive', className: 'bg-[#6B708D] text-white' }
};
const config = statusConfig[status] || statusConfig.inactive;
const Icon = config.icon;
return (
Here's an overview of your membership status and upcoming events.
Please verify your email address to complete your registration. Check your inbox for the verification link.
{getStatusMessage(user?.status)}
{user?.email}
Role
{user?.role}
Member Since
{user?.created_at ? new Date(user.created_at).toLocaleDateString() : 'N/A'}
Loading events...
) : events.length > 0 ? ({new Date(event.start_at).toLocaleDateString()} at{' '} {new Date(event.start_at).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}
{event.location}
No upcoming events at the moment.
Check back later for new events!
Your membership application is being reviewed by our admin team. You'll be notified once approved!
Great news! Your membership application has been approved. Complete your payment to activate your membership and gain full access to all member benefits.