import { useState, useEffect, useMemo } from "react"; import { useNavigate, useSearchParams } from "react-router-dom"; import Layout from "@/components/Layout"; import { Button } from "@/components/ui/button"; import { useAuth } from "@/contexts/AuthContext"; import { aethexToast } from "@/lib/aethex-toast"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import LoadingScreen from "@/components/LoadingScreen"; import { Link } from "react-router-dom"; import OAuthConnections from "@/components/settings/OAuthConnections"; import RealmSwitcher, { RealmKey } from "@/components/settings/RealmSwitcher"; import { User, Settings, TrendingUp, Users, Bell, Star, Trophy, Rocket, Code, Database, Shield, ChevronRight, Activity, LogOut, Sparkles, CheckCircle, ArrowRight, } from "lucide-react"; const ARMS = [ { id: "staff", label: "Staff", color: "#7c3aed", href: "/staff/dashboard", icon: Shield, description: "Operations & Administration", bgGradient: "from-purple-500/20 to-purple-900/20", borderColor: "border-purple-500/30 hover:border-purple-500/60", }, { id: "labs", label: "Labs", color: "#FBBF24", href: "/dashboard/labs", icon: Code, description: "Research & Development", bgGradient: "from-amber-500/20 to-amber-900/20", borderColor: "border-amber-500/30 hover:border-amber-500/60", }, { id: "gameforge", label: "GameForge", color: "#22C55E", href: "/dashboard/gameforge", icon: Rocket, description: "Game Development", bgGradient: "from-green-500/20 to-green-900/20", borderColor: "border-green-500/30 hover:border-green-500/60", }, { id: "corp", label: "Corp", color: "#3B82F6", href: "/hub/client", icon: Users, description: "Business & Consulting", bgGradient: "from-blue-500/20 to-blue-900/20", borderColor: "border-blue-500/30 hover:border-blue-500/60", }, { id: "foundation", label: "Foundation", color: "#EF4444", href: "/dashboard/foundation", icon: Trophy, description: "Education & Mentorship", bgGradient: "from-red-500/20 to-red-900/20", borderColor: "border-red-500/30 hover:border-red-500/60", }, { id: "devlink", label: "Dev-Link", color: "#06B6D4", href: "/dashboard/dev-link", icon: Database, description: "Developer Network", bgGradient: "from-cyan-500/20 to-cyan-900/20", borderColor: "border-cyan-500/30 hover:border-cyan-500/60", }, { id: "nexus", label: "Nexus", color: "#A855F7", href: "/dashboard/nexus", icon: Sparkles, description: "Talent Marketplace", bgGradient: "from-purple-500/20 to-fuchsia-900/20", borderColor: "border-purple-500/30 hover:border-purple-500/60", }, ]; export default function Dashboard() { const navigate = useNavigate(); const { user, profile, loading: authLoading, signOut, profileComplete, linkedProviders, linkProvider, unlinkProvider } = useAuth(); const [searchParams] = useSearchParams(); const [activeTab, setActiveTab] = useState(() => searchParams.get("tab") ?? "realms"); const [displayName, setDisplayName] = useState(""); const [bio, setBio] = useState(""); const [website, setWebsite] = useState(""); const [linkedin, setLinkedin] = useState(""); const [github, setGithub] = useState(""); const [twitter, setTwitter] = useState(""); const [savingProfile, setSavingProfile] = useState(false); useEffect(() => { if (profile) { setDisplayName(profile.full_name || ""); setBio(profile.bio || ""); setWebsite(profile.website_url || ""); setLinkedin(profile.linkedin_url || ""); setGithub(profile.github_url || ""); setTwitter(profile.twitter_url || ""); } }, [profile]); const handleSaveProfile = async () => { if (!user) return; setSavingProfile(true); try { const { error } = await (window as any).supabaseClient .from("user_profiles") .update({ full_name: displayName, bio: bio, website_url: website, linkedin_url: linkedin, github_url: github, twitter_url: twitter, }) .eq("id", user.id); if (error) throw error; aethexToast({ message: "Profile updated successfully!", type: "success", }); } catch (error: any) { aethexToast({ message: error?.message || "Failed to update profile", type: "error", }); } finally { setSavingProfile(false); } }; if (authLoading) { return ; } if (!user) { return ( Welcome to AeThex Sign in to access your personalized dashboard navigate("/login")} className="w-full bg-gradient-to-r from-purple-600 to-blue-600 hover:from-purple-700 hover:to-blue-700 text-white text-lg py-6" > Sign In to Dashboard navigate("/onboarding")} variant="outline" className="w-full text-lg py-6 border-purple-500/30 text-purple-300 hover:bg-purple-500/10" > Create New Account ); } const showProfileSetup = !profileComplete; return ( {/* Header Section */} Dashboard Welcome back, {profile?.full_name || user.email?.split("@")[0]} {profileComplete && ( Profile Complete )} {profile?.level && ( Level {profile.level} )} {/* Setup Banner */} {showProfileSetup && ( Complete Your Profile Set up your profile to unlock all AeThex features and join the community setActiveTab("profile")} className="bg-orange-600 hover:bg-orange-700 shrink-0" > Setup Now )} {/* Tabs Section */} Realms Arms Profile Connections Settings {/* Realms Tab */} {ARMS.map((arm) => { const IconComponent = arm.icon; return ( { e.preventDefault(); navigate(arm.href); }} className="group relative overflow-hidden" > {arm.label} {arm.description} Explore ); })} {/* Profile Tab */} {/* Profile Card */} {profile?.full_name || "User"} {user.email} Level {profile?.level || 1} {/* Edit Profile Form */} Edit Profile Update your public profile information Display Name setDisplayName(e.target.value)} placeholder="Your full name" className="bg-purple-950/30 border-purple-500/20" /> Bio setBio(e.target.value)} placeholder="Tell us about yourself" className="bg-purple-950/30 border-purple-500/20 resize-none h-24" /> Website setWebsite(e.target.value)} placeholder="https://example.com" className="bg-purple-950/30 border-purple-500/20" /> GitHub setGithub(e.target.value)} placeholder="github.com/username" className="bg-purple-950/30 border-purple-500/20" /> LinkedIn setLinkedin(e.target.value)} placeholder="linkedin.com/in/username" className="bg-purple-950/30 border-purple-500/20" /> Twitter/X setTwitter(e.target.value)} placeholder="@username" className="bg-purple-950/30 border-purple-500/20" /> {savingProfile ? "Saving..." : "Save Profile"} {/* Connections Tab */} Connected Accounts Link external accounts to your AeThex profile {/* Settings Tab */} {/* Realm Preference */} Primary Realm Choose your primary area of focus {/* Account Actions */} Account Actions Manage your account signOut()} > Sign Out ); }
Sign in to access your personalized dashboard
Welcome back, {profile?.full_name || user.email?.split("@")[0]}
Complete Your Profile
Set up your profile to unlock all AeThex features and join the community
{arm.description}
{user.email}