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 { useUnit } from 'effector-react'
import { useForm } from 'react-hook-form'
import { apiClient } from '@/shared/api/client'
import { $user, fetchAuthMethodsFx, setPasswordFx, unlinkOAuthFx, type AuthMethod } from '@/shared/model/auth'
import {
$user,
changePasswordFx,
fetchAuthMethodsFx,
setPasswordFx,
unlinkOAuthFx,
type AuthMethod,
} from '@/shared/model/auth'
const METHOD_LABELS: Record<string, string> = { password: 'Пароль', vk: 'ВКонтакте', yandex: 'Яндекс' }
@@ -56,7 +62,7 @@ export function AuthMethodsSection() {
const changePasswordMutation = useMutation({
mutationFn: async (params: { oldPassword: string; newPassword: string }) => {
await apiClient.post('me/change-password', params)
await changePasswordFx(params)
},
onSuccess: () => {
setShowChangePassword(false)
@@ -1,3 +1,4 @@
import Alert from '@mui/material/Alert'
import Box from '@mui/material/Box'
import Button from '@mui/material/Button'
import Stack from '@mui/material/Stack'
@@ -5,11 +6,12 @@ import TextField from '@mui/material/TextField'
import Typography from '@mui/material/Typography'
import { useUnit } from 'effector-react'
import { useForm } from 'react-hook-form'
import { $user, updateProfileFx } from '@/shared/model/auth'
import { $user, $updateProfileError, updateProfileFx } from '@/shared/model/auth'
export function ProfileSection() {
const user = useUnit($user)
const pendingProfile = useUnit(updateProfileFx.pending)
const updateProfileError = useUnit($updateProfileError)
const profileForm = useForm<{ displayName: string }>({
defaultValues: { displayName: user?.displayName ? String(user.displayName) : '' },
@@ -28,6 +30,11 @@ export function ProfileSection() {
slotProps={{ htmlInput: { maxLength: 40 } }}
{...profileForm.register('displayName')}
/>
{updateProfileError && (
<Alert severity="error" sx={{ mt: 1 }}>
{updateProfileError}
</Alert>
)}
<Button
variant="contained"
disabled={pendingProfile}
+4
View File
@@ -100,6 +100,10 @@ export const unlinkOAuthFx = createEffect(async (provider: 'vk' | 'yandex') => {
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 -----
export const $updateProfileError = createErrorStore(updateProfileFx).$error