'use client' import { useState, useEffect } from 'react' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { User, Save, Loader2 } from 'lucide-react' export default function SettingsPage() { const [fullName, setFullName] = useState('') const [company, setCompany] = useState('') const [email, setEmail] = useState('') const [role, setRole] = useState('') const [isLoading, setIsLoading] = useState(true) const [isSaving, setIsSaving] = useState(false) const [message, setMessage] = useState<{ type: 'success' | 'error'; text: string } | null>(null) useEffect(() => { fetch('/api/profile') .then((r) => r.json()) .then((data) => { if (data.user) { setFullName(data.user.fullName || '') setCompany(data.user.company || '') setEmail(data.user.email || '') setRole(data.user.role || 'user') } }) .finally(() => setIsLoading(false)) }, []) const handleSave = async (e: React.FormEvent) => { e.preventDefault() setIsSaving(true) setMessage(null) const res = await fetch('/api/profile', { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ fullName, company }), }) const data = await res.json() if (res.ok) { setMessage({ type: 'success', text: 'Profile updated successfully' }) } else { setMessage({ type: 'error', text: data.error || 'Failed to save' }) } setIsSaving(false) } if (isLoading) { return (
Manage your account settings and preferences
{email}
Role
{role}