fix(Task 2): add error handling and sync state with user
- AuthMethodsSection: show Alert on fetchAuthMethodsFx failure - AvatarSection: sync selectedStyle with user.avatarStyle via Select key - ProfileSection: reset form defaultValues when user.displayName changes
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import Alert from '@mui/material/Alert'
|
||||
import Box from '@mui/material/Box'
|
||||
import Button from '@mui/material/Button'
|
||||
import Chip from '@mui/material/Chip'
|
||||
@@ -24,6 +25,7 @@ export function AuthMethodsSection() {
|
||||
|
||||
const [authMethods, setAuthMethods] = useState<AuthMethod[]>([])
|
||||
const [showSetPassword, setShowSetPassword] = useState(false)
|
||||
const [fetchError, setFetchError] = useState<string | null>(null)
|
||||
const passwordForm = useForm<{ password: string; passwordConfirm: string }>({
|
||||
defaultValues: { password: '', passwordConfirm: '' },
|
||||
})
|
||||
@@ -31,8 +33,9 @@ export function AuthMethodsSection() {
|
||||
useEffect(() => {
|
||||
fetchAuthMethodsFx()
|
||||
.then(setAuthMethods)
|
||||
.catch(() => {
|
||||
.catch((err) => {
|
||||
setAuthMethods([])
|
||||
setFetchError(err?.message || 'Не удалось загрузить методы авторизации')
|
||||
})
|
||||
}, [])
|
||||
|
||||
@@ -81,6 +84,11 @@ export function AuthMethodsSection() {
|
||||
<Typography variant="h6" gutterBottom>
|
||||
Методы входа
|
||||
</Typography>
|
||||
{fetchError && (
|
||||
<Alert severity="error" sx={{ mb: 2 }}>
|
||||
{fetchError}
|
||||
</Alert>
|
||||
)}
|
||||
<Stack spacing={1}>
|
||||
{authMethods.map((m) => (
|
||||
<Stack key={m.type} direction="row" spacing={2} sx={{ alignItems: 'center' }}>
|
||||
|
||||
Reference in New Issue
Block a user