chore: fix lint issues, remove unused hasAvatar
This commit is contained in:
@@ -43,12 +43,7 @@ export function UserMenu({ user, isAdmin = false, onNavigate, onLogout }: Props)
|
||||
anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}
|
||||
>
|
||||
{user ? (
|
||||
<UserAvatar
|
||||
userId={user.id}
|
||||
avatarUrl={user.avatar}
|
||||
avatarStyle={user.avatarStyle}
|
||||
size={28}
|
||||
/>
|
||||
<UserAvatar userId={user.id} avatarUrl={user.avatar} avatarStyle={user.avatarStyle} size={28} />
|
||||
) : (
|
||||
<PersonIcon sx={{ fontSize: 28 }} />
|
||||
)}
|
||||
|
||||
@@ -63,11 +63,8 @@ export function AdminSettingsPage() {
|
||||
const hasUnsavedPreview = previewSrc !== null
|
||||
|
||||
const profileSaveMut = useMutation({
|
||||
mutationFn: (params: {
|
||||
displayName: string | null
|
||||
avatar?: string | null
|
||||
avatarStyle?: string | null
|
||||
}) => apiClient.patch('admin/profile', params),
|
||||
mutationFn: (params: { displayName: string | null; avatar?: string | null; avatarStyle?: string | null }) =>
|
||||
apiClient.patch('admin/profile', params),
|
||||
onSuccess: (_data, variables) => {
|
||||
const p: UpdateProfileParams = { displayName: variables.displayName ?? null }
|
||||
if (variables.avatar !== undefined) {
|
||||
|
||||
@@ -192,12 +192,7 @@ export function AdminUsersPage() {
|
||||
users.map((u) => (
|
||||
<TableRow key={u.id} hover>
|
||||
<TableCell>
|
||||
<UserAvatar
|
||||
userId={u.id}
|
||||
avatarUrl={u.avatar}
|
||||
avatarStyle={u.avatarStyle}
|
||||
size={28}
|
||||
/>
|
||||
<UserAvatar userId={u.id} avatarUrl={u.avatar} avatarStyle={u.avatarStyle} size={28} />
|
||||
</TableCell>
|
||||
<TableCell>{u.email}</TableCell>
|
||||
<TableCell>{u.displayName ?? '—'}</TableCell>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { render, screen, fireEvent } from '@testing-library/react'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { render, screen, fireEvent } from '@testing-library/react'
|
||||
import { MemoryRouter } from 'react-router-dom'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { AuthPage } from '../ui/AuthPage'
|
||||
|
||||
@@ -112,8 +112,7 @@ export function AuthPage() {
|
||||
getApiErrorMessage(requestCode.error) ||
|
||||
getApiErrorMessage(verifyCode.error)
|
||||
|
||||
const passwordError =
|
||||
isRegister && passwordConfirm && password !== passwordConfirm ? 'Пароли не совпадают' : null
|
||||
const passwordError = isRegister && passwordConfirm && password !== passwordConfirm ? 'Пароли не совпадают' : null
|
||||
|
||||
return (
|
||||
<Box>
|
||||
@@ -121,11 +120,21 @@ export function AuthPage() {
|
||||
Вход / регистрация
|
||||
</Typography>
|
||||
|
||||
{message && <Alert severity="success" sx={{ mb: 2 }}>{message}</Alert>}
|
||||
{oauthError && (
|
||||
<Alert severity="error" sx={{ mb: 2 }} onClose={() => setOauthError(null)}>{oauthError}</Alert>
|
||||
{message && (
|
||||
<Alert severity="success" sx={{ mb: 2 }}>
|
||||
{message}
|
||||
</Alert>
|
||||
)}
|
||||
{oauthError && (
|
||||
<Alert severity="error" sx={{ mb: 2 }} onClose={() => setOauthError(null)}>
|
||||
{oauthError}
|
||||
</Alert>
|
||||
)}
|
||||
{errMsg && (
|
||||
<Alert severity="error" sx={{ mb: 2 }}>
|
||||
{errMsg}
|
||||
</Alert>
|
||||
)}
|
||||
{errMsg && <Alert severity="error" sx={{ mb: 2 }}>{errMsg}</Alert>}
|
||||
|
||||
<Tabs value={tab} onChange={(_, v) => setTab(v)} sx={{ mb: 3 }}>
|
||||
<Tab label="Пароль" />
|
||||
@@ -198,11 +207,7 @@ export function AuthPage() {
|
||||
<Stack spacing={2} sx={{ maxWidth: 520 }}>
|
||||
<TextField label="Email" {...register('email')} fullWidth />
|
||||
<Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
|
||||
<Button
|
||||
variant="outlined"
|
||||
onClick={() => requestCode.mutate()}
|
||||
disabled={!email || requestCode.isPending}
|
||||
>
|
||||
<Button variant="outlined" onClick={() => requestCode.mutate()} disabled={!email || requestCode.isPending}>
|
||||
Отправить код
|
||||
</Button>
|
||||
<TextField label="Код (6 цифр)" inputMode="numeric" {...register('code')} />
|
||||
|
||||
@@ -12,9 +12,9 @@ import Stack from '@mui/material/Stack'
|
||||
import TextField from '@mui/material/TextField'
|
||||
import Typography from '@mui/material/Typography'
|
||||
import { createAvatar } from '@dicebear/core'
|
||||
import { useMutation } from '@tanstack/react-query'
|
||||
import { useUnit } from 'effector-react'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { useMutation } from '@tanstack/react-query'
|
||||
import { AVATAR_STYLES, DEFAULT_STYLE_ID, getStyleById } from '@/shared/lib/avatar-styles'
|
||||
import {
|
||||
$requestEmailChangeCodeError,
|
||||
@@ -62,8 +62,6 @@ export function SettingsPage() {
|
||||
const emailErrorMsg = getApiErrorMessage(errorEmailReq) ?? getApiErrorMessage(errorEmailVerify)
|
||||
const profileErrorMsg = getApiErrorMessage(errorProfile)
|
||||
|
||||
const hasAvatar = Boolean(user?.avatar)
|
||||
|
||||
const [selectedStyle, setSelectedStyle] = useState(user?.avatarStyle || DEFAULT_STYLE_ID)
|
||||
const [previewSrc, setPreviewSrc] = useState<string | null>(null)
|
||||
const [previewStyle, setPreviewStyle] = useState<string>(DEFAULT_STYLE_ID)
|
||||
@@ -77,9 +75,11 @@ export function SettingsPage() {
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
fetchAuthMethodsFx().then(setAuthMethods).catch(() => {
|
||||
setAuthMethods([])
|
||||
})
|
||||
fetchAuthMethodsFx()
|
||||
.then(setAuthMethods)
|
||||
.catch(() => {
|
||||
setAuthMethods([])
|
||||
})
|
||||
}, [])
|
||||
|
||||
const setPasswordMutation = useMutation({
|
||||
@@ -277,12 +277,7 @@ export function SettingsPage() {
|
||||
</Button>
|
||||
)}
|
||||
{!m.active && m.type !== 'password' && (
|
||||
<Button
|
||||
size="small"
|
||||
variant="outlined"
|
||||
component="a"
|
||||
href={`/api/auth/oauth/${m.type}/link`}
|
||||
>
|
||||
<Button size="small" variant="outlined" component="a" href={`/api/auth/oauth/${m.type}/link`}>
|
||||
Привязать
|
||||
</Button>
|
||||
)}
|
||||
|
||||
@@ -92,13 +92,11 @@ export const loginFx = createEffect(async (params: { email: string; password: st
|
||||
return data.user
|
||||
})
|
||||
|
||||
export const registerFx = createEffect(
|
||||
async (params: { email: string; password: string; displayName?: string }) => {
|
||||
const { data } = await apiClient.post<{ token: string; user: AuthUser }>('auth/register', params)
|
||||
tokenSet(data.token)
|
||||
return data.user
|
||||
},
|
||||
)
|
||||
export const registerFx = createEffect(async (params: { email: string; password: string; displayName?: string }) => {
|
||||
const { data } = await apiClient.post<{ token: string; user: AuthUser }>('auth/register', params)
|
||||
tokenSet(data.token)
|
||||
return data.user
|
||||
})
|
||||
|
||||
export const fetchAuthMethodsFx = createEffect(async () => {
|
||||
const { data } = await apiClient.get<{ methods: AuthMethod[] }>('me/auth-methods')
|
||||
|
||||
Reference in New Issue
Block a user