Skip to content

Commit

Permalink
Fixed changing a user photo in the header (#2812)
Browse files Browse the repository at this point in the history
  • Loading branch information
Made1ra authored Nov 22, 2024
1 parent ceaa991 commit 8054428
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/containers/navigation-icons/AccountIcon.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -37,6 +37,18 @@ const AccountIcon: FC<AccountIconProps> = ({ 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 <Avatar sx={styles.accountIcon} />
}
Expand All @@ -46,10 +58,7 @@ const AccountIcon: FC<AccountIconProps> = ({ openMenu }) => {
<Avatar
alt='User Avatar'
onClick={openMenu}
src={
photo &&
createUrlPath(import.meta.env.VITE_APP_IMG_USER_URL || '', photo)
}
src={avatarSrc}
sx={styles.accountIcon}
>
{!loading && firstName && lastName && `${firstName[0]}${lastName[0]}`}
Expand Down

0 comments on commit 8054428

Please sign in to comment.