Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replaced userAvatar throughout the project #2975

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/components/avatar-icon/AvatarIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FC } from 'react'
import Avatar from '@mui/material/Avatar'
import UserAvatar from '~/design-system/components/user-avatar/UserAvatar'
import { SxProps } from '@mui/system'
import { getInitials, spliceSx } from '~/utils/helper-functions'
import { styles } from '~/components/avatar-icon/AvatarIcon.styles'
Expand All @@ -18,13 +18,16 @@ const AvatarIcon: FC<AvatarIconProps> = ({
sx
}) => {
return (
<Avatar
alt='User Avatar'
<UserAvatar
firstName={firstName}
lastName={lastName}
size='profile-lg'
src={photo ?? ''}
sx={spliceSx(styles.avatar, sx)}
variant='photo'
>
{getInitials(firstName, lastName)}
</Avatar>
</UserAvatar>
)
}

Expand Down
14 changes: 9 additions & 5 deletions src/containers/navigation-icons/AccountIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { useTranslation } from 'react-i18next'
import { useAppSelector } from '~/hooks/use-redux'
import { AxiosResponse } from 'axios'

import Avatar from '@mui/material/Avatar'
import Tooltip from '@mui/material/Tooltip'
import UserAvatar from '~/design-system/components/user-avatar/UserAvatar'

import { userService } from '~/services/user-service'
import useAxios from '~/hooks/use-axios'
Expand Down Expand Up @@ -58,19 +58,23 @@ const AccountIcon: FC<AccountIconProps> = ({ openMenu }) => {
}, [photo, statePhoto])

if (loading) {
return <Avatar sx={styles.accountIcon} />
return (
<UserAvatar firstName='' lastName='' src='' sx={styles.accountIcon} />
)
}

return (
<Tooltip arrow title={t('iconsTooltip.account')}>
<Avatar
alt='User Avatar'
<UserAvatar
firstName={firstName}
lastName={lastName}
onClick={openMenu}
src={avatarSrc}
sx={styles.accountIcon}
variant='photo'
>
{!loading && firstName && lastName && `${firstName[0]}${lastName[0]}`}
</Avatar>
</UserAvatar>
</Tooltip>
)
}
Expand Down
10 changes: 5 additions & 5 deletions src/design-system/components/user-avatar/UserAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import CheckIcon from '@mui/icons-material/Check'
import { cn } from '~/utils/cn'

const variants = ['check', 'avatar', 'monogram', 'photo'] as const
const sizes = ['sm', 'md', 'lg'] as const
const sizes = ['sm', 'md', 'lg', 'profile-lg'] as const

interface BaseUserAvatarProps {
variant?: (typeof variants)[number]
src?: string
size?: (typeof sizes)[number]
firstName: string
lastName: string
firstName?: string
lastName?: string
isOnline?: boolean
}

Expand All @@ -29,8 +29,8 @@ const UserAvatar = forwardRef(
variant = 'avatar',
src,
size = 'sm',
firstName,
lastName,
firstName = '',
lastName = '',
Comment on lines +32 to +33
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you add default value to those props, make them optional in BaseUserAvatarProps

isOnline,
onClick,
...props
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/components/avatar-icon/AvatarIcon.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('AvatarIcon Component', () => {
/>
)

const avatarElement = screen.getByAltText('User Avatar')
const avatarElement = screen.getByAltText('JD')

expect(avatarElement).toBeInTheDocument()
expect(avatarElement).toHaveAttribute('src', mockPhoto)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('AccountIcon test with user role', () => {
})

it('should render click menu icon and open account menu after click on it', () => {
const AccountIconButton = screen.getByAltText('User Avatar')
const AccountIconButton = screen.getByAltText('JD')
expect(AccountIconButton).toBeInTheDocument()

fireEvent.click(AccountIconButton)
Expand Down
Loading