import { useState } from 'react' import { Link } from 'react-router-dom' import { User as UserIcon, Loader2, AlertCircle, Check } from 'lucide-react' import { authApi } from '@/api/auth' import { useAuthStore } from '@/store/authStore' import { cn } from '@/lib/utils' import { toast } from '@/lib/toast' import type { UserUpdate } from '@/types' const inputClass = cn( 'mt-1 block w-full rounded-[10px] border border-border bg-card px-3 py-2', 'text-foreground placeholder:text-muted-foreground', 'focus:border-[rgba(6,182,212,0.3)] focus:outline-hidden focus:ring-1 focus:ring-primary/20' ) export function ProfileSettingsPage() { const user = useAuthStore((s) => s.user) const fetchUser = useAuthStore((s) => s.fetchUser) const [name, setName] = useState(user?.name ?? '') const [email, setEmail] = useState(user?.email ?? '') const [phone, setPhone] = useState(user?.phone ?? '') const [jobTitle, setJobTitle] = useState(user?.job_title ?? '') const [timezone, setTimezone] = useState(user?.timezone ?? 'UTC') const [currentPassword, setCurrentPassword] = useState('') const [isSaving, setIsSaving] = useState(false) const [error, setError] = useState(null) const emailChanged = email !== user?.email const hasChanges = emailChanged || name !== user?.name || phone !== (user?.phone ?? '') || jobTitle !== (user?.job_title ?? '') || timezone !== (user?.timezone ?? 'UTC') const handleSave = async (e: React.FormEvent) => { e.preventDefault() if (!hasChanges) return setIsSaving(true) setError(null) try { const payload: UserUpdate = {} if (name !== user?.name) payload.name = name.trim() if (emailChanged) { payload.email = email.trim() payload.current_password = currentPassword } if (phone !== (user?.phone ?? '')) payload.phone = phone.trim() || null if (jobTitle !== (user?.job_title ?? '')) payload.job_title = jobTitle.trim() || null if (timezone !== (user?.timezone ?? 'UTC')) payload.timezone = timezone await authApi.updateProfile(payload) await fetchUser() setCurrentPassword('') toast.success('Profile updated') } catch (err) { const axiosErr = err as { response?: { data?: { detail?: string } } } setError(axiosErr.response?.data?.detail ?? 'Failed to update profile') } finally { setIsSaving(false) } } return (

Profile Settings

Update your name, email, and personal details

{/* Name */}
setName(e.target.value)} required className={inputClass} />
{/* Email */}
setEmail(e.target.value)} required className={inputClass} />
{/* Password confirmation for email change */} {emailChanged && (

Required to change your email address

setCurrentPassword(e.target.value)} required className={inputClass} />
)} {/* Phone */}
setPhone(e.target.value)} placeholder="Optional" className={inputClass} />
{/* Job Title */}
setJobTitle(e.target.value)} placeholder="e.g. Network Engineer" className={inputClass} />
{/* Timezone */}
{error && (
{error}
)}
Change Password
) } const COMMON_TIMEZONES = [ 'UTC', 'America/New_York', 'America/Chicago', 'America/Denver', 'America/Los_Angeles', 'America/Anchorage', 'Pacific/Honolulu', 'America/Toronto', 'America/Vancouver', 'Europe/London', 'Europe/Paris', 'Europe/Berlin', 'Europe/Amsterdam', 'Asia/Tokyo', 'Asia/Shanghai', 'Asia/Kolkata', 'Asia/Dubai', 'Australia/Sydney', 'Australia/Melbourne', 'Pacific/Auckland', ] export default ProfileSettingsPage