Initial Commit

This commit is contained in:
Koncept Kit
2025-12-05 16:40:33 +07:00
parent 0834f12410
commit 94c7d5aec0
91 changed files with 20446 additions and 0 deletions

230
src/pages/Dashboard.js Normal file
View File

@@ -0,0 +1,230 @@
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 } from 'lucide-react';
const Dashboard = () => {
const { user } = useAuth();
const [events, setEvents] = useState([]);
const [loading, setLoading] = useState(true);
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 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 (
<Badge className={`${config.className} px-4 py-2 rounded-full flex items-center gap-2`}>
<Icon className="h-4 w-4" />
{config.label}
</Badge>
);
};
const getStatusMessage = (status) => {
const messages = {
pending_email: 'Please check your email to verify your account.',
pending_approval: 'Your application is under review by our admin team.',
pre_approved: 'Your application is under review by our admin team.',
payment_pending: 'Please complete your payment to activate your membership.',
active: 'Your membership is active! Enjoy all member benefits.',
inactive: 'Your membership is currently inactive.'
};
return messages[status] || '';
};
return (
<div className="min-h-screen bg-[#FDFCF8]">
<Navbar />
<div className="max-w-7xl mx-auto px-6 py-12">
{/* Welcome Section */}
<div className="mb-12">
<h1 className="text-4xl md:text-5xl font-semibold fraunces text-[#3D405B] mb-4">
Welcome Back, {user?.first_name}!
</h1>
<p className="text-lg text-[#6B708D]">
Here's an overview of your membership status and upcoming events.
</p>
</div>
{/* Status Card */}
<Card className="p-8 bg-white rounded-2xl border border-[#EAE0D5] shadow-lg mb-8" data-testid="status-card">
<div className="flex items-start justify-between flex-wrap gap-4">
<div>
<h2 className="text-2xl font-semibold fraunces text-[#3D405B] mb-2">
Membership Status
</h2>
<div className="mb-4">
{getStatusBadge(user?.status)}
</div>
<p className="text-[#6B708D]">
{getStatusMessage(user?.status)}
</p>
</div>
<Link to="/profile">
<Button
className="bg-[#F2CC8F] text-[#3D405B] hover:bg-[#E5B875] rounded-full px-6"
data-testid="view-profile-button"
>
<User className="h-4 w-4 mr-2" />
View Profile
</Button>
</Link>
</div>
</Card>
{/* Grid Layout */}
<div className="grid lg:grid-cols-3 gap-8">
{/* Quick Stats */}
<Card className="p-6 bg-white rounded-2xl border border-[#EAE0D5]" data-testid="quick-stats-card">
<h3 className="text-xl font-semibold fraunces text-[#3D405B] mb-4">
Quick Info
</h3>
<div className="space-y-4">
<div>
<p className="text-sm text-[#6B708D]">Email</p>
<p className="text-[#3D405B] font-medium">{user?.email}</p>
</div>
<div>
<p className="text-sm text-[#6B708D]">Role</p>
<p className="text-[#3D405B] font-medium capitalize">{user?.role}</p>
</div>
<div>
<p className="text-sm text-[#6B708D]">Member Since</p>
<p className="text-[#3D405B] font-medium">
{user?.created_at ? new Date(user.created_at).toLocaleDateString() : 'N/A'}
</p>
</div>
</div>
</Card>
{/* Upcoming Events */}
<Card className="lg:col-span-2 p-6 bg-white rounded-2xl border border-[#EAE0D5]" data-testid="upcoming-events-card">
<div className="flex justify-between items-center mb-6">
<h3 className="text-xl font-semibold fraunces text-[#3D405B]">
Upcoming Events
</h3>
<Link to="/events">
<Button
variant="ghost"
className="text-[#E07A5F] hover:text-[#D0694E]"
data-testid="view-all-events-button"
>
View All
</Button>
</Link>
</div>
{loading ? (
<p className="text-[#6B708D]">Loading events...</p>
) : events.length > 0 ? (
<div className="space-y-4">
{events.map((event) => (
<Link to={`/events/${event.id}`} key={event.id}>
<div
className="p-4 border border-[#EAE0D5] rounded-xl hover:border-[#E07A5F] hover:shadow-md transition-all cursor-pointer"
data-testid={`event-card-${event.id}`}
>
<div className="flex items-start gap-4">
<div className="bg-[#F2CC8F]/20 p-3 rounded-lg">
<Calendar className="h-6 w-6 text-[#E07A5F]" />
</div>
<div className="flex-1">
<h4 className="font-semibold text-[#3D405B] mb-1">{event.title}</h4>
<p className="text-sm text-[#6B708D] mb-2">
{new Date(event.start_at).toLocaleDateString()} at{' '}
{new Date(event.start_at).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}
</p>
<p className="text-sm text-[#6B708D]">{event.location}</p>
</div>
</div>
</div>
</Link>
))}
</div>
) : (
<div className="text-center py-12">
<Calendar className="h-16 w-16 text-[#EAE0D5] mx-auto mb-4" />
<p className="text-[#6B708D] mb-4">No upcoming events at the moment.</p>
<p className="text-sm text-[#6B708D]">Check back later for new events!</p>
</div>
)}
</Card>
</div>
{/* CTA Section */}
{user?.status === 'pending_approval' && (
<Card className="mt-8 p-8 bg-gradient-to-br from-[#F2CC8F]/20 to-[#E07A5F]/20 rounded-2xl border border-[#EAE0D5]">
<div className="text-center">
<h3 className="text-2xl font-semibold fraunces text-[#3D405B] mb-4">
Application Under Review
</h3>
<p className="text-[#6B708D] mb-6">
Your membership application is being reviewed by our admin team. You'll be notified once approved!
</p>
</div>
</Card>
)}
{/* Payment Prompt for payment_pending status */}
{user?.status === 'payment_pending' && (
<Card className="mt-8 p-8 bg-gradient-to-br from-[#E07A5F]/20 to-[#F2CC8F]/20 rounded-2xl border-2 border-[#E07A5F]">
<div className="text-center">
<div className="mb-4">
<AlertCircle className="h-16 w-16 text-[#E07A5F] mx-auto" />
</div>
<h3 className="text-2xl font-semibold fraunces text-[#3D405B] mb-4">
Complete Your Payment
</h3>
<p className="text-[#6B708D] mb-6">
Great news! Your membership application has been approved. Complete your payment to activate your membership and gain full access to all member benefits.
</p>
<Link to="/plans">
<Button
className="bg-[#E07A5F] text-white hover:bg-[#D0694E] rounded-full px-8 py-6 text-lg font-semibold"
data-testid="complete-payment-cta"
>
<CheckCircle className="mr-2 h-5 w-5" />
Complete Payment
</Button>
</Link>
</div>
</Card>
)}
</div>
</div>
);
};
export default Dashboard;