Skip to content

Commit

Permalink
add delegate avatar component
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanDylann committed Sep 4, 2024
1 parent 562d7b4 commit 531033a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/pages/home/sidebar/AvatarWithDelegateAvatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';
import {View} from 'react-native';
import Avatar from '@components/Avatar';
import useThemeStyles from '@hooks/useThemeStyles';
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
import * as UserUtils from '@libs/UserUtils';
import CONST from '@src/CONST';
import ProfileAvatarWithIndicator from './ProfileAvatarWithIndicator';

type AvatarWithDelegateAvatarProps = {
/** Emoji status */
delegateEmail: string;

/** Whether the avatar is selected */
isSelected?: boolean;
};

function AvatarWithDelegateAvatar({delegateEmail, isSelected = false}: AvatarWithDelegateAvatarProps) {
const styles = useThemeStyles();
const personalDetail = PersonalDetailsUtils.getPersonalDetailByEmail(delegateEmail);

return (
<View style={styles.sidebarStatusAvatarContainer}>
<ProfileAvatarWithIndicator isSelected={isSelected} />
<View style={[styles.sidebarStatusAvatar]}>
<View style={styles.emojiStatusLHN}>
<Avatar
size={CONST.AVATAR_SIZE.SMALL}
source={UserUtils.getSmallSizeAvatar(personalDetail?.avatar, personalDetail?.accountID)}
fallbackIcon={personalDetail?.fallbackIcon}
type={CONST.ICON_TYPE_AVATAR}
/>
</View>
</View>
</View>
);
}

AvatarWithDelegateAvatar.displayName = 'AvatarWithDelegateAvatar';

export default AvatarWithDelegateAvatar;
14 changes: 14 additions & 0 deletions src/pages/home/sidebar/BottomTabAvatar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {useCallback} from 'react';
import {useOnyx} from 'react-native-onyx';
import {PressableWithFeedback} from '@components/Pressable';
import Tooltip from '@components/Tooltip';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
Expand All @@ -7,7 +8,9 @@ import useThemeStyles from '@hooks/useThemeStyles';
import interceptAnonymousUser from '@libs/interceptAnonymousUser';
import Navigation from '@libs/Navigation/Navigation';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import AvatarWithDelegateAvatar from './AvatarWithDelegateAvatar';
import AvatarWithOptionalStatus from './AvatarWithOptionalStatus';
import ProfileAvatarWithIndicator from './ProfileAvatarWithIndicator';

Expand All @@ -22,6 +25,8 @@ type BottomTabAvatarProps = {
function BottomTabAvatar({isCreateMenuOpen = false, isSelected = false}: BottomTabAvatarProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const [account] = useOnyx(ONYXKEYS.ACCOUNT);
const delegateEmail = account?.delegatedAccess?.delegate ?? '';
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const emojiStatus = currentUserPersonalDetails?.status?.emojiCode ?? '';

Expand All @@ -36,6 +41,15 @@ function BottomTabAvatar({isCreateMenuOpen = false, isSelected = false}: BottomT

let children;

if (delegateEmail) {
children = (
<AvatarWithDelegateAvatar
delegateEmail={delegateEmail}
isSelected={isSelected}
/>
);
}

if (emojiStatus) {
children = (
<AvatarWithOptionalStatus
Expand Down

0 comments on commit 531033a

Please sign in to comment.