fix(settings): use $updateProfileError and changePasswordFx per spec

This commit is contained in:
Kirill
2026-05-22 15:10:20 +05:00
parent e273c29c36
commit fa276eb7f3
3 changed files with 21 additions and 4 deletions
@@ -8,8 +8,14 @@ import Typography from '@mui/material/Typography'
import { useMutation } from '@tanstack/react-query' import { useMutation } from '@tanstack/react-query'
import { useUnit } from 'effector-react' import { useUnit } from 'effector-react'
import { useForm } from 'react-hook-form' import { useForm } from 'react-hook-form'
import { apiClient } from '@/shared/api/client' import {
import { $user, fetchAuthMethodsFx, setPasswordFx, unlinkOAuthFx, type AuthMethod } from '@/shared/model/auth' $user,
changePasswordFx,
fetchAuthMethodsFx,
setPasswordFx,
unlinkOAuthFx,
type AuthMethod,
} from '@/shared/model/auth'
const METHOD_LABELS: Record<string, string> = { password: 'Пароль', vk: 'ВКонтакте', yandex: 'Яндекс' } const METHOD_LABELS: Record<string, string> = { password: 'Пароль', vk: 'ВКонтакте', yandex: 'Яндекс' }
@@ -56,7 +62,7 @@ export function AuthMethodsSection() {
const changePasswordMutation = useMutation({ const changePasswordMutation = useMutation({
mutationFn: async (params: { oldPassword: string; newPassword: string }) => { mutationFn: async (params: { oldPassword: string; newPassword: string }) => {
await apiClient.post('me/change-password', params) await changePasswordFx(params)
}, },
onSuccess: () => { onSuccess: () => {
setShowChangePassword(false) setShowChangePassword(false)
@@ -1,3 +1,4 @@
import Alert from '@mui/material/Alert'
import Box from '@mui/material/Box' import Box from '@mui/material/Box'
import Button from '@mui/material/Button' import Button from '@mui/material/Button'
import Stack from '@mui/material/Stack' import Stack from '@mui/material/Stack'
@@ -5,11 +6,12 @@ import TextField from '@mui/material/TextField'
import Typography from '@mui/material/Typography' import Typography from '@mui/material/Typography'
import { useUnit } from 'effector-react' import { useUnit } from 'effector-react'
import { useForm } from 'react-hook-form' import { useForm } from 'react-hook-form'
import { $user, updateProfileFx } from '@/shared/model/auth' import { $user, $updateProfileError, updateProfileFx } from '@/shared/model/auth'
export function ProfileSection() { export function ProfileSection() {
const user = useUnit($user) const user = useUnit($user)
const pendingProfile = useUnit(updateProfileFx.pending) const pendingProfile = useUnit(updateProfileFx.pending)
const updateProfileError = useUnit($updateProfileError)
const profileForm = useForm<{ displayName: string }>({ const profileForm = useForm<{ displayName: string }>({
defaultValues: { displayName: user?.displayName ? String(user.displayName) : '' }, defaultValues: { displayName: user?.displayName ? String(user.displayName) : '' },
@@ -28,6 +30,11 @@ export function ProfileSection() {
slotProps={{ htmlInput: { maxLength: 40 } }} slotProps={{ htmlInput: { maxLength: 40 } }}
{...profileForm.register('displayName')} {...profileForm.register('displayName')}
/> />
{updateProfileError && (
<Alert severity="error" sx={{ mt: 1 }}>
{updateProfileError}
</Alert>
)}
<Button <Button
variant="contained" variant="contained"
disabled={pendingProfile} disabled={pendingProfile}
+4
View File
@@ -100,6 +100,10 @@ export const unlinkOAuthFx = createEffect(async (provider: 'vk' | 'yandex') => {
await apiClient.delete(`me/oauth/${provider}`) await apiClient.delete(`me/oauth/${provider}`)
}) })
export const changePasswordFx = createEffect(async (params: { oldPassword: string; newPassword: string }) => {
await apiClient.post('me/change-password', params)
})
// ----- Error stores ----- // ----- Error stores -----
export const $updateProfileError = createErrorStore(updateProfileFx).$error export const $updateProfileError = createErrorStore(updateProfileFx).$error