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

Add delegate avatar component #48564

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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 */
Copy link
Contributor

@dangrous dangrous Sep 5, 2024

Choose a reason for hiding this comment

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

Suggested change
/** Emoji status */
/** Original account of delegate */

Copy link
Contributor

Choose a reason for hiding this comment

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

@DylanDylann is off for the night, i guess you can force push this commit @dangrous ? lets get the ball rolling imo

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I won't be able to merge if I do that unfortunately, a little wonky but @allgandalf can you add it into your PR? I'll go ahead and merge this as is.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes sure!

delegateEmail: string;

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

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

Choose a reason for hiding this comment

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

perhaps put this one under useCallback or something which will trigger a re-render

Copy link
Contributor

@allgandalf allgandalf Sep 4, 2024

Choose a reason for hiding this comment

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

Seems like both of those have something to do with not correctly loading personal details?

@dangrous
I consoled logged the vairable which stores the personal details, it show undefined unless we refresh page:

Screenshot 2024-09-05 at 12 22 38 AM

const personalDetail = PersonalDetailsUtils.getPersonalDetailByEmail(delegateEmail);

Is not working as expected for the first load

Copy link
Contributor

@allgandalf allgandalf Sep 4, 2024

Choose a reason for hiding this comment

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

Oh i get it, we are calling the wrong util, that util gives us the cache, when we switch account there is none

Screenshot 2024-09-05 at 12 26 38 AM

@DylanDylann can you update the util please

Copy link
Contributor

@dangrous dangrous Sep 4, 2024

Choose a reason for hiding this comment

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

oh nice find. Alternately, is there a way we can preserve the personal details of the delegate account in the cache when we switch accounts (and past reload)? Trying to avoid unnecessary calls to the backend if we already have that info

Copy link
Member

Choose a reason for hiding this comment

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

We have to use useOnyx. Otherwise the variable won't update when underlying data changes


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: 13 additions & 1 deletion 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,7 +41,14 @@ function BottomTabAvatar({isCreateMenuOpen = false, isSelected = false}: BottomT

let children;

if (emojiStatus) {
if (delegateEmail) {
children = (
<AvatarWithDelegateAvatar
delegateEmail={delegateEmail}
isSelected={isSelected}
/>
);
} else if (emojiStatus) {
children = (
<AvatarWithOptionalStatus
emojiStatus={emojiStatus}
Expand Down
Loading