import { useState } from 'react'; import { useProfile } from '@/hooks/useProfile'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Loader2 } from 'lucide-react'; export function SettingsProfile() { const { user, loading, updateProfile } = useProfile(); const [editMode, setEditMode] = useState(false); const [formData, setFormData] = useState({ full_name: '', email: '' }); const [isSaving, setIsSaving] = useState(false); // Initialize form with user data // In a real app, we'd use useEffect to set this when user loads // For simplicity, we'll initialize on mount assuming user exists const handleSave = async () => { setIsSaving(true); try { await updateProfile({ full_name: formData.full_name.trim(), email: formData.email.trim() }); setEditMode(false); } catch (err) { // Error handled by useProfile hook } finally { setIsSaving(false); } }; if (loading) { return (

Loading...

); } if (!user) { return (

Please log in to view your profile

); } // Initialize form data if not already set // Using a simple approach - in practice this would be in useEffect const initialized = formData.full_name !== '' || formData.email !== ''; if (!initialized && user) { setFormData({ full_name: user.full_name, email: user.email }); } return (
{editMode ? ( Edit Profile
{ e.preventDefault(); handleSave(); }}>
setFormData({ ...formData, full_name: e.target.value })} required autoComplete="name" />
setFormData({ ...formData, email: e.target.value })} required autoComplete="email" />
) : ( <> Profile Information

{user.full_name}

{user.email}

Account Details

{new Date(user.created_at).toLocaleDateString()}

{user.is_active ? 'Active' : 'Inactive'}

)}
); }