'use client'; import { useState, useEffect } from 'react'; import { Card, CardContent, CardHeader, CardTitle } from "@workspace/ui/components/card" import { Button } from "@workspace/ui/components/button" import { Badge } from "@workspace/ui/components/badge" import { Separator } from "@workspace/ui/components/separator" import { Input } from "@workspace/ui/components/input" import { Label } from "@workspace/ui/components/label" import { Textarea } from "@workspace/ui/components/textarea" import { User, Mail, Phone, MapPin, Calendar, GraduationCap, BookOpen, Award, Edit, Save, Camera, Linkedin, Github, FileText, Download, Upload, CheckCircle, AlertCircle, X } from "lucide-react" import { getStudentProfile, updateStudentProfile } from "../actions" // Mock student data as fallback const mockStudent = { id: 1, firstName: "John", middleName: "Michael", lastName: "Doe", email: "john.doe@college.edu", rollNumber: "2021CS001", phoneNumber: "+91 98765 43210", address: "123 College Street, Mumbai, Maharashtra", gender: "Male", dob: "2000-05-15", degree: "Bachelor of Technology", branch: "Computer Science", year: "4th Year", skills: ["JavaScript", "React", "Node.js", "Python", "SQL", "Git"], linkedin: "https://linkedin.com/in/johndoe", github: "https://github.com/johndoe", ssc: 9.2, hsc: 8.8, isDiploma: false, verified: true, markedOut: false, profilePicture: null, resumes: [ { id: 1, title: "Resume_v2.pdf", link: "/resumes/resume_v2.pdf" } ] } export default function ProfilePage() { const [student, setStudent] = useState(mockStudent); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); const [editingSection, setEditingSection] = useState(null); const [editData, setEditData] = useState({}); const [isSaving, setIsSaving] = useState(false); useEffect(() => { loadStudentProfile(); }, []); const loadStudentProfile = async () => { try { const result = await getStudentProfile(1); // Using student ID 1 for demo if (result.success && result.student) { setStudent(result.student as any); } else { setError(result.error || 'Failed to load profile'); } } catch (err) { setError('Failed to load profile data'); } finally { setIsLoading(false); } }; const handleEdit = (section: string) => { setEditingSection(section); setEditData({}); }; const handleCancel = () => { setEditingSection(null); setEditData({}); }; const handleSave = async (section: string) => { setIsSaving(true); try { const result = await updateStudentProfile(student.id, editData); if (result.success) { setStudent(prev => ({ ...prev, ...editData })); setEditingSection(null); setEditData({}); } else { setError(result.error || 'Failed to update profile'); } } catch (err) { setError('Failed to update profile'); } finally { setIsSaving(false); } }; const handleInputChange = (field: string, value: string) => { setEditData((prev: any) => ({ ...prev, [field]: value })); }; if (isLoading) { return (

Loading profile...

); } return (
{/* Header */}

My Profile

Manage your personal information and academic details

{error && (
{error}
)}
{/* Profile Overview */}
{student.firstName?.[0] || 'S'}{student.lastName?.[0] || 'T'}

{student.firstName} {student.middleName} {student.lastName}

{student.email}

{student.verified ? ( <> Verified ) : ( <> Pending Verification )} {student.markedOut && ( Marked Out )}
Roll Number: {student.rollNumber}
{/* Quick Stats */}
Academic Year {student.year}
Branch {student.branch}
SSC Score {student.ssc}/10
HSC Score {student.hsc}/10
{/* Social Links */}

Social Links

{/* Main Content */}
{/* Personal Information */}
Personal Information {editingSection !== 'personal' ? ( ) : (
)}
{editingSection === 'personal' ? ( handleInputChange('firstName', e.target.value)} /> ) : ( )}
{editingSection === 'personal' ? ( handleInputChange('middleName', e.target.value)} /> ) : ( )}
{editingSection === 'personal' ? ( handleInputChange('lastName', e.target.value)} /> ) : ( )}
{editingSection === 'personal' ? ( handleInputChange('phoneNumber', e.target.value)} /> ) : ( )}
{editingSection === 'personal' ? ( handleInputChange('gender', e.target.value)} /> ) : ( )}
{editingSection === 'personal' ? ( handleInputChange('dob', e.target.value)} /> ) : ( )}
{editingSection === 'personal' ? (