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:
Kirill
2026-05-22 15:15:50 +05:00
parent fa276eb7f3
commit be9a9bad8e
3 changed files with 20 additions and 2 deletions
@@ -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' }}>