From 55a8129aff06848cd448018ef73eb7e6a46ba4b3 Mon Sep 17 00:00:00 2001 From: Barresi Date: Wed, 17 Apr 2024 00:38:06 +0700 Subject: [PATCH] fix: avatar state --- .../edit-account/ui/avatar-change/avatar-change.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/widgets/edit-account/ui/avatar-change/avatar-change.tsx b/src/widgets/edit-account/ui/avatar-change/avatar-change.tsx index f6542a6c..f2c2b982 100644 --- a/src/widgets/edit-account/ui/avatar-change/avatar-change.tsx +++ b/src/widgets/edit-account/ui/avatar-change/avatar-change.tsx @@ -26,9 +26,15 @@ const AvatarChange: FC = () => { const [avatarImg, setAvatarImg] = useState(null) useEffect(() => { - const urlOnBackend = - import.meta.env.VITE_BACKEND_DOMEN + '/ftp/avatars/' + user?.avatar - setAvatarImg(previewUrl || urlOnBackend || null) + if (previewUrl) { + setAvatarImg(previewUrl) + } else if (user?.avatar) { + const urlOnBackend = + import.meta.env.VITE_BACKEND_DOMEN + '/ftp/avatars/' + user?.avatar + setAvatarImg(urlOnBackend) + } else { + setAvatarImg(null) + } }, [previewUrl, user?.avatar]) return (