import React, { useState, useRef } from 'react'; import { Button } from './ui/button'; import { Input } from './ui/input'; import { Label } from './ui/label'; import { Textarea } from './ui/textarea'; import { Dialog, DialogContent, DialogTitle } from './ui/dialog'; import type { User as UserType } from '../App'; import { toast } from 'sonner'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from './ui/select'; interface ProfileEditorProps { user: UserType; onSave: (user: UserType) => void; onClose: () => void; } export function ProfileEditor({ user, onSave, onClose }: ProfileEditorProps) { const [name, setName] = useState(user.name); const [email, setEmail] = useState(user.email); const [studentId, setStudentId] = useState('S12345678'); const [department, setDepartment] = useState('Computer Science'); const [year, setYear] = useState('3rd Year'); const [major, setMajor] = useState('Artificial Intelligence'); const [bio, setBio] = useState('Passionate about AI and machine learning'); const [photoPreview, setPhotoPreview] = useState(null); const fileInputRef = useRef(null); const handleSave = () => { if (name.trim() && email.trim()) { onSave({ name: name.trim(), email: email.trim() }); toast.success('Profile updated successfully!'); onClose(); } else { toast.error('Please fill in all required fields'); } }; const handlePhotoSelect = (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (file) { // Validate file type if (!file.type.startsWith('image/')) { toast.error('Please select an image file'); return; } // Validate file size (2MB) if (file.size > 2 * 1024 * 1024) { toast.error('File size must be less than 2MB'); return; } // Create preview const reader = new FileReader(); reader.onload = (e) => { setPhotoPreview(e.target?.result as string); toast.success('Photo updated successfully!'); }; reader.readAsDataURL(file); } }; const handleChangePhotoClick = () => { fileInputRef.current?.click(); }; return ( { if (!open) onClose(); }}>
{/* Header */}
Edit Profile
{/* Content */}
{/* Profile Picture */}
{photoPreview ? ( Profile ) : ( name.charAt(0).toUpperCase() )}

JPG, PNG or GIF. Max size 2MB

{/* Basic Information */}

Basic Information

setName(e.target.value)} placeholder="Enter your full name" />
setEmail(e.target.value)} placeholder="Enter your email" />
setStudentId(e.target.value)} placeholder="Enter your student ID" />
setDepartment(e.target.value)} placeholder="Enter your department" />
{/* Academic Background */}

Academic Background

setMajor(e.target.value)} placeholder="Enter your major" />
{/* Bio */}