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