From 805442896dbbd54dd17e638147ac382e4f2d2729 Mon Sep 17 00:00:00 2001 From: Vadym Pavlyk Date: Fri, 22 Nov 2024 19:44:29 +0200 Subject: [PATCH] Fixed changing a user photo in the header (#2812) --- .../navigation-icons/AccountIcon.tsx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/containers/navigation-icons/AccountIcon.tsx b/src/containers/navigation-icons/AccountIcon.tsx index dba1aad21..718d91854 100644 --- a/src/containers/navigation-icons/AccountIcon.tsx +++ b/src/containers/navigation-icons/AccountIcon.tsx @@ -1,4 +1,4 @@ -import { useCallback, FC, MouseEvent } from 'react' +import { useMemo, useCallback, FC, MouseEvent } from 'react' import { useTranslation } from 'react-i18next' import { useAppSelector } from '~/hooks/use-redux' import { AxiosResponse } from 'axios' @@ -37,6 +37,18 @@ const AccountIcon: FC = ({ openMenu }) => { defaultResponse: defaultResponses.object as UserResponse }) + const { photo: statePhoto } = useAppSelector((state) => state.editProfile) + + const avatarSrc = useMemo(() => { + if (statePhoto?.src) { + return statePhoto.src + } + + if (photo) { + return createUrlPath(import.meta.env.VITE_APP_IMG_USER_URL || '', photo) + } + }, [photo, statePhoto]) + if (loading) { return } @@ -46,10 +58,7 @@ const AccountIcon: FC = ({ openMenu }) => { {!loading && firstName && lastName && `${firstName[0]}${lastName[0]}`}