AI_Agent_V4 / web /src /components /ProfileEditor.tsx
SarahXia0405's picture
Upload 77 files
198828b verified
import React, { useState } 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 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');
}
};
return (
<Dialog open onOpenChange={(open) => { if (!open) onClose(); }}>
<DialogContent className="sm:max-w-2xl p-0 gap-0 max-h-[90vh] overflow-hidden">
<div className="flex flex-col max-h-[90vh]">
{/* Header */}
<div className="border-b border-border p-4 flex items-center justify-between flex-shrink-0">
<DialogTitle className="text-xl font-medium">Edit Profile</DialogTitle>
</div>
{/* Content */}
<div className="p-6 space-y-6 overflow-y-auto flex-1">
{/* Profile Picture */}
<div className="flex items-center gap-4">
<div className="w-20 h-20 rounded-full bg-gradient-to-br from-red-500 to-orange-500 flex items-center justify-center text-white text-2xl">
{name.charAt(0).toUpperCase()}
</div>
<div>
<Button variant="outline" size="sm">
Change Photo
</Button>
<p className="text-xs text-muted-foreground mt-1">
JPG, PNG or GIF. Max size 2MB
</p>
</div>
</div>
{/* Basic Information */}
<div className="space-y-4">
<h3 className="text-sm font-medium">Basic Information</h3>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div className="space-y-2">
<Label htmlFor="edit-name">Full Name *</Label>
<Input
id="edit-name"
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="Enter your full name"
/>
</div>
<div className="space-y-2">
<Label htmlFor="edit-email">Email *</Label>
<Input
id="edit-email"
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder="Enter your email"
/>
</div>
<div className="space-y-2">
<Label htmlFor="edit-student-id">Student ID</Label>
<Input
id="edit-student-id"
value={studentId}
onChange={(e) => setStudentId(e.target.value)}
placeholder="Enter your student ID"
/>
</div>
<div className="space-y-2">
<Label htmlFor="edit-department">Department</Label>
<Input
id="edit-department"
value={department}
onChange={(e) => setDepartment(e.target.value)}
placeholder="Enter your department"
/>
</div>
</div>
</div>
{/* Academic Background */}
<div className="space-y-4">
<h3 className="text-sm font-medium">Academic Background</h3>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div className="space-y-2">
<Label htmlFor="edit-year">Year Level</Label>
<Select value={year} onValueChange={setYear}>
<SelectTrigger id="edit-year">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="1st Year">1st Year</SelectItem>
<SelectItem value="2nd Year">2nd Year</SelectItem>
<SelectItem value="3rd Year">3rd Year</SelectItem>
<SelectItem value="4th Year">4th Year</SelectItem>
<SelectItem value="Graduate">Graduate</SelectItem>
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label htmlFor="edit-major">Major</Label>
<Input
id="edit-major"
value={major}
onChange={(e) => setMajor(e.target.value)}
placeholder="Enter your major"
/>
</div>
</div>
</div>
{/* Bio */}
<div className="space-y-2">
<Label htmlFor="edit-bio">Bio</Label>
<Textarea
id="edit-bio"
value={bio}
onChange={(e) => setBio(e.target.value)}
placeholder="Tell us about yourself..."
className="min-h-[100px] resize-none"
/>
<p className="text-xs text-muted-foreground">
Brief description for your profile. Max 200 characters.
</p>
</div>
{/* Learning Preferences */}
<div className="space-y-4">
<h3 className="text-sm font-medium">Learning Preferences</h3>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div className="space-y-2">
<Label htmlFor="edit-learning-style">Preferred Learning Style</Label>
<Select defaultValue="visual">
<SelectTrigger id="edit-learning-style">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="visual">Visual</SelectItem>
<SelectItem value="auditory">Auditory</SelectItem>
<SelectItem value="reading">Reading/Writing</SelectItem>
<SelectItem value="kinesthetic">Kinesthetic</SelectItem>
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label htmlFor="edit-pace">Learning Pace</Label>
<Select defaultValue="moderate">
<SelectTrigger id="edit-pace">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="slow">Slow & Steady</SelectItem>
<SelectItem value="moderate">Moderate</SelectItem>
<SelectItem value="fast">Fast-paced</SelectItem>
</SelectContent>
</Select>
</div>
</div>
</div>
</div>
{/* Footer */}
<div className="border-t border-border p-4 flex justify-end gap-2 flex-shrink-0">
<Button variant="outline" onClick={onClose}>
Cancel
</Button>
<Button onClick={handleSave}>
Save Changes
</Button>
</div>
</div>
</DialogContent>
</Dialog>
);
}