'use client'; import { useEffect, useState } from 'react'; import { useI18n } from '../components/I18nProvider'; type User = { id: string; email: string; role: string; status: string; emailVerifiedAt: string | null; approvedAt: string | null; name: string | null }; export default function ProfilePage() { const { t } = useI18n(); const [user, setUser] = useState(null); const [error, setError] = useState(null); const [name, setName] = useState(''); const [password, setPassword] = useState(''); const [saving, setSaving] = useState(false); const [message, setMessage] = useState(null); useEffect(() => { fetch('/api/auth/me', { cache: 'no-store' }) .then((res) => res.json()) .then((data) => { if (data.user) { setUser(data.user); setName(data.user.name ?? ''); } else setError(t('notLoggedIn')); }) .catch(() => setError(t('notLoggedIn'))); }, [t]); async function onSave(e: React.FormEvent) { e.preventDefault(); setSaving(true); setError(null); setMessage(null); try { const res = await fetch('/api/me', { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name, password: password || undefined }), }); const data = await res.json(); if (!res.ok) { setError(data.error || 'Update failed'); } else { setUser(data.user); setPassword(''); setMessage(t('profileUpdated')); } } catch (err) { setError('Update failed'); } finally { setSaving(false); } } return (

{t('myProfileTitle')}

{message ?

{message}

: null} {user ? ( <>
  • {t('profileEmail')}: {user.email}
  • {t('profileName')}: {user.name ?? '—'}
  • {t('profileRole')}: {user.role}
  • {t('profileStatus')}: {user.status}
  • {t('profileEmailVerified')}: {user.emailVerifiedAt ? t('yes') : t('no')}
  • {t('profileApproved')}: {user.approvedAt ? t('yes') : t('no')}
{t('navMyListings')} {t('navNewListing')}

{t('emailLocked')}

) : (

{error ?? t('notLoggedIn')}

)}
); }