fix(client): parse error message properly in ProfileSection
This commit is contained in:
@@ -7,6 +7,7 @@ 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 { getApiErrorMessage } from '@/shared/lib/get-api-error-message'
|
||||||
import { $user, $updateProfileError, updateProfileFx } from '@/shared/model/auth'
|
import { $user, $updateProfileError, updateProfileFx } from '@/shared/model/auth'
|
||||||
|
|
||||||
export function ProfileSection() {
|
export function ProfileSection() {
|
||||||
@@ -14,6 +15,8 @@ export function ProfileSection() {
|
|||||||
const pendingProfile = useUnit(updateProfileFx.pending)
|
const pendingProfile = useUnit(updateProfileFx.pending)
|
||||||
const updateProfileError = useUnit($updateProfileError)
|
const updateProfileError = useUnit($updateProfileError)
|
||||||
|
|
||||||
|
const profileErrorMsg = getApiErrorMessage(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) : '' },
|
||||||
mode: 'onChange',
|
mode: 'onChange',
|
||||||
@@ -35,9 +38,9 @@ export function ProfileSection() {
|
|||||||
slotProps={{ htmlInput: { maxLength: 40 } }}
|
slotProps={{ htmlInput: { maxLength: 40 } }}
|
||||||
{...profileForm.register('displayName')}
|
{...profileForm.register('displayName')}
|
||||||
/>
|
/>
|
||||||
{updateProfileError && (
|
{profileErrorMsg && (
|
||||||
<Alert severity="error" sx={{ mt: 1 }}>
|
<Alert severity="error" sx={{ mt: 1 }}>
|
||||||
{updateProfileError}
|
{profileErrorMsg}
|
||||||
</Alert>
|
</Alert>
|
||||||
)}
|
)}
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
Reference in New Issue
Block a user