import { useRef, useState, useEffect } from 'react' import { FeatureCallout } from '../components/FeatureState.jsx' import { featurePanelClass } from '../components/featureStateStyles.js' import { profileRepository } from '../repositories/profileRepository.js' import { authRepository } from '../repositories/authRepository.js' const cardClass = 'rounded-2xl border border-[#404040] bg-[#262626] shadow-sm' const inputClass = 'h-10 rounded-sm border border-[#404040] bg-[#171717] px-3 text-sm text-[#e5e5e5] outline-none transition placeholder:text-[#a3a3a3] focus:border-[#3b82f6] focus:ring-2 focus:ring-[#3b82f6]/20' export function ProfilePage({ navigate }) { const [saved, setSaved] = useState(false) const [profile, setProfile] = useState({ name: '', role: '', email: '', phone: '', unit: '', avatarUrl: '' }) const [loading, setLoading] = useState(true) const [uploadingAvatar, setUploadingAvatar] = useState(false) const [avatarError, setAvatarError] = useState('') const fileInputRef = useRef(null) useEffect(() => { profileRepository.getCurrentUserProfile().then(data => { setProfile(data) setLoading(false) }).catch(() => setLoading(false)) }, []) function update(field, value) { setSaved(false) setProfile((current) => ({ ...current, [field]: value })) } async function handleLogout() { await authRepository.logout() navigate('/login') } async function handleAvatarChange(event) { const file = event.target.files?.[0] if (!file) return setUploadingAvatar(true) setAvatarError('') try { const result = await profileRepository.updateAvatar(file) setProfile((current) => ({ ...current, avatarUrl: result.avatarUrl || URL.createObjectURL(file), })) } catch (err) { setAvatarError(err.message || 'Erro ao enviar avatar.') } finally { setUploadingAvatar(false) event.target.value = '' } } if (loading) { return
Localizando dados do paciente...
} return (

Perfil

Dados locais do usuário logado e preferências básicas do shell.

{profile.avatarUrl ? ( ) : (
{initials(profile.name)}
)}

{profile.name}

{profile.role}

{avatarError ?

{avatarError}

: null}
{ event.preventDefault() setSaved(true) }} >
update('name', event.target.value)} value={profile.name} /> update('role', event.target.value)} value={profile.role} />
update('email', event.target.value)} type="email" value={profile.email} /> update('phone', event.target.value)} value={profile.phone} />
{saved ? Preferências salvas localmente : null}
) } function Field({ children, label }) { return ( ) } function Info({ label, value }) { return (
{label}
{value}
) } function initials(name) { return String(name || 'US') .split(' ') .filter(Boolean) .slice(0, 2) .map((part) => part[0]) .join('') .toUpperCase() }