"use client"
import { useAuth } from "@/context/auth-context"
import { useEffect, useState } from "react"
import { useRouter } from "next/navigation"
import {
User,
LogOut,
Settings,
Trophy,
BookOpen,
Target,
TrendingUp,
Wallet,
Mail,
Calendar,
Award,
BarChart3,
Activity,
Edit3,
Save,
X
} from "lucide-react"
export default function DashboardPage() {
const { user, firebaseUser, walletConnected, logout, authMethod } = useAuth()
const router = useRouter()
const [isEditingProfile, setIsEditingProfile] = useState(false)
const [profileData, setProfileData] = useState({
name: user?.name || '',
bio: user?.bio || '',
avatar: user?.avatar || ''
})
const [stats, setStats] = useState({
coursesCompleted: 12,
totalXP: 2450,
currentStreak: 7,
rank: 156,
certificatesEarned: 3,
hoursLearned: 45
})
useEffect(() => {
if (!user && !firebaseUser) {
router.replace("/auth/login")
}
}, [user, firebaseUser, router])
const handleProfileUpdate = async () => {
try {
// Here you would call your API to update profile
// await updateProfile(profileData)
setIsEditingProfile(false)
console.log("Profile updated:", profileData)
} catch (error) {
console.error("Failed to update profile:", error)
}
}
if (!user && !firebaseUser) {
return (
)
}
return (
{/* Professional Header */}
OpenLearnX
Learn • Earn • Grow
{/* Main Dashboard Content */}
{/* Welcome Section */}
Welcome back! 👋
Ready to continue your learning journey?
{authMethod === "metamask" && user ? (
Connected: {user.wallet_address.slice(0, 6)}...{user.wallet_address.slice(-4)}
) : firebaseUser && (
{firebaseUser.email}
)}
{/* Stats Grid */}
Total XP
{stats.totalXP.toLocaleString()}
+12% from last week
Courses
{stats.coursesCompleted}
Streak
{stats.currentStreak} days
🔥 Keep it up!
Global Rank
#{stats.rank}
{/* Main Content Grid */}
{/* Profile Card with Edit Functionality */}
Profile
{isEditingProfile ? (
setProfileData({...profileData, name: e.target.value})}
placeholder="Your name"
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500 text-center"
/>
) : (
{profileData.name || "Your Name"}
{profileData.bio || "Add a bio to tell others about yourself"}
)}
{authMethod === "metamask" ? (
) : (
)}
Auth Method
{authMethod === "metamask" ? "MetaMask Wallet" : "Email Account"}
{stats.hoursLearned}
Hours Learned
{stats.certificatesEarned}
Certificates
{/* Recent Activity */}
Recent Activity
{[
{
type: "course",
title: "Completed React Fundamentals",
time: "2 hours ago",
icon: BookOpen,
color: "green",
bgColor: "bg-green-100",
textColor: "text-green-600"
},
{
type: "quiz",
title: "Scored 95% on JavaScript Quiz",
time: "1 day ago",
icon: Award,
color: "blue",
bgColor: "bg-blue-100",
textColor: "text-blue-600"
},
{
type: "streak",
title: "7-day learning streak!",
time: "Today",
icon: Target,
color: "orange",
bgColor: "bg-orange-100",
textColor: "text-orange-600"
},
{
type: "rank",
title: "Moved up 5 positions in leaderboard",
time: "2 days ago",
icon: TrendingUp,
color: "purple",
bgColor: "bg-purple-100",
textColor: "text-purple-600"
},
].map((activity, index) => (
{activity.title}
{activity.time}
))}
🚀 Keep Learning!
You're doing great! Complete 2 more courses this week to maintain your streak.
)
}