Skip to content

Commit

Permalink
Merge pull request #20713 from s-alves10/fix/issue-20672
Browse files Browse the repository at this point in the history
fix: avatar not changed in tooltip when updating avatar
(cherry picked from commit f467085)
  • Loading branch information
pecanoro authored and OSBotify committed Jun 14, 2023
1 parent 8c3fb8e commit ddf2e1d
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 25 deletions.
3 changes: 2 additions & 1 deletion src/components/UserDetailsTooltip/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Tooltip from '../Tooltip';
import {propTypes, defaultProps} from './userDetailsTooltipPropTypes';
import styles from '../../styles/styles';
import ONYXKEYS from '../../ONYXKEYS';
import * as UserUtils from '../../libs/UserUtils';

function UserDetailsTooltip(props) {
const userDetails = lodashGet(props.personalDetailsList, props.accountID, props.fallbackUserDetails);
Expand All @@ -18,7 +19,7 @@ function UserDetailsTooltip(props) {
<View style={styles.emptyAvatar}>
<Avatar
containerStyles={[styles.actionAvatar]}
source={userDetails.avatar}
source={UserUtils.getAvatar(userDetails.avatar, userDetails.login)}
/>
</View>

Expand Down
108 changes: 84 additions & 24 deletions src/libs/actions/PersonalDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,48 @@ function updateAvatar(file) {
},
];

const accountID = lodashGet(personalDetails, [currentUserEmail, 'accountID'], '');
if (accountID) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: {
[accountID]: {
avatar: file.uri,
errorFields: {
avatar: null,
},
pendingFields: {
avatar: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
},
},
});
successData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: {
[accountID]: {
pendingFields: {
avatar: null,
},
},
},
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: {
[accountID]: {
avatar: personalDetails[currentUserEmail].avatar,
pendingFields: {
avatar: null,
},
},
},
});
}

API.write('UpdateUserAvatar', {file}, {optimisticData, successData, failureData});
}

Expand All @@ -418,34 +460,52 @@ function deleteAvatar() {
// We want to use the old dot avatar here as this affects both platforms.
const defaultAvatar = UserUtils.getDefaultAvatarURL(currentUserEmail);

API.write(
'DeleteUserAvatar',
{},
const optimisticData = [
{
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS,
value: {
[currentUserEmail]: {
avatar: defaultAvatar,
},
},
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS,
value: {
[currentUserEmail]: {
avatar: defaultAvatar,
},
],
failureData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS,
value: {
[currentUserEmail]: {
avatar: personalDetails[currentUserEmail].avatar,
},
},
},
},
];
const failureData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS,
value: {
[currentUserEmail]: {
avatar: personalDetails[currentUserEmail].avatar,
},
],
},
},
);
];

const accountID = lodashGet(personalDetails, [currentUserEmail, 'accountID'], '');
if (accountID) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: {
[personalDetails[currentUserEmail].accountID]: {
avatar: defaultAvatar,
},
},
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: {
[personalDetails[currentUserEmail].accountID]: {
avatar: personalDetails[currentUserEmail].avatar,
},
},
});
}

API.write('DeleteUserAvatar', {}, {optimisticData, failureData});
}

/**
Expand Down

0 comments on commit ddf2e1d

Please sign in to comment.