Fix profile name update persistence
Replace placeholder implementation with proper API integration: - Create /api/user/profile PUT endpoint with JWT validation - Update profile page to call actual API instead of setTimeout - Use refreshUser() to update UI immediately after changes - Ensure name changes persist to database and across page refreshes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -28,7 +28,7 @@ import {
|
||||
} from '@mui/icons-material'
|
||||
|
||||
export default function ProfilePage() {
|
||||
const { user } = useAuth()
|
||||
const { user, refreshUser } = useAuth()
|
||||
const t = useTranslations('profile')
|
||||
const [isEditing, setIsEditing] = useState(false)
|
||||
const [name, setName] = useState(user?.name || '')
|
||||
@@ -40,10 +40,31 @@ export default function ProfilePage() {
|
||||
setMessage('')
|
||||
|
||||
try {
|
||||
// TODO: Implement profile update API
|
||||
await new Promise(resolve => setTimeout(resolve, 1000)) // Placeholder
|
||||
setMessage(t('profileUpdated'))
|
||||
setIsEditing(false)
|
||||
const token = localStorage.getItem('authToken')
|
||||
if (!token) {
|
||||
setMessage(t('updateError'))
|
||||
return
|
||||
}
|
||||
|
||||
const response = await fetch(`/api/user/profile?locale=${navigator.language.split('-')[0]}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify({ name })
|
||||
})
|
||||
|
||||
const data = await response.json()
|
||||
|
||||
if (response.ok) {
|
||||
setMessage(t('profileUpdated'))
|
||||
setIsEditing(false)
|
||||
// Refresh user data in context to show updated name
|
||||
await refreshUser()
|
||||
} else {
|
||||
setMessage(data.error || t('updateError'))
|
||||
}
|
||||
} catch (error) {
|
||||
setMessage(t('updateError'))
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user