From 270ce3b110c160f271749937b7856688664af2a9 Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Tue, 13 Jun 2023 13:46:02 -0500 Subject: [PATCH 1/6] fix: update PERSONAL_DETAILS_LIST when updating avatar --- src/libs/actions/PersonalDetails.js | 38 +++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/libs/actions/PersonalDetails.js b/src/libs/actions/PersonalDetails.js index b362436def5c..869d7da9b1cc 100644 --- a/src/libs/actions/PersonalDetails.js +++ b/src/libs/actions/PersonalDetails.js @@ -378,6 +378,21 @@ function updateAvatar(file) { }, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.PERSONAL_DETAILS_LIST, + value: { + [personalDetails[currentUserEmail].accountID]: { + avatar: file.uri, + errorFields: { + avatar: null, + }, + pendingFields: { + avatar: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + }, + }, + }, + }, ]; const successData = [ { @@ -391,6 +406,17 @@ function updateAvatar(file) { }, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.PERSONAL_DETAILS_LIST, + value: { + [personalDetails[currentUserEmail].accountID]: { + pendingFields: { + avatar: null, + }, + }, + }, + }, ]; const failureData = [ { @@ -406,6 +432,18 @@ function updateAvatar(file) { }, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.PERSONAL_DETAILS_LIST, + value: { + [personalDetails[currentUserEmail].accountID]: { + avatar: personalDetails[currentUserEmail].avatar, + pendingFields: { + avatar: null, + }, + }, + }, + }, ]; API.write('UpdateUserAvatar', {file}, {optimisticData, successData, failureData}); From 2283c67015d109ab154c271fad06111090992f98 Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Tue, 13 Jun 2023 14:04:30 -0500 Subject: [PATCH 2/6] fix: update avatar when deleting avatar --- src/libs/actions/PersonalDetails.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/libs/actions/PersonalDetails.js b/src/libs/actions/PersonalDetails.js index 869d7da9b1cc..5f2dadb15b8f 100644 --- a/src/libs/actions/PersonalDetails.js +++ b/src/libs/actions/PersonalDetails.js @@ -470,6 +470,15 @@ function deleteAvatar() { }, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.PERSONAL_DETAILS_LIST, + value: { + [personalDetails[currentUserEmail].accountID]: { + avatar: defaultAvatar, + }, + }, + }, ], failureData: [ { @@ -481,6 +490,15 @@ function deleteAvatar() { }, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.PERSONAL_DETAILS_LIST, + value: { + [personalDetails[currentUserEmail].accountID]: { + avatar: personalDetails[currentUserEmail].avatar, + }, + }, + }, ], }, ); From e41f473f29d506d6a20c473987285960827764d4 Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Tue, 13 Jun 2023 15:58:54 -0500 Subject: [PATCH 3/6] fix: remove avatar for NewDot --- src/libs/actions/PersonalDetails.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/PersonalDetails.js b/src/libs/actions/PersonalDetails.js index 5f2dadb15b8f..dd458a3a4f14 100644 --- a/src/libs/actions/PersonalDetails.js +++ b/src/libs/actions/PersonalDetails.js @@ -454,7 +454,7 @@ function updateAvatar(file) { */ function deleteAvatar() { // We want to use the old dot avatar here as this affects both platforms. - const defaultAvatar = UserUtils.getDefaultAvatarURL(currentUserEmail); + const defaultAvatar = UserUtils.getDefaultAvatarURL(currentUserEmail, true); API.write( 'DeleteUserAvatar', From 9676093ae03d1531ddbe500ed66c7ff56a6529a4 Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Tue, 13 Jun 2023 21:54:13 -0500 Subject: [PATCH 4/6] fix: accountID validation added --- src/libs/actions/PersonalDetails.js | 135 ++++++++++++++-------------- 1 file changed, 70 insertions(+), 65 deletions(-) diff --git a/src/libs/actions/PersonalDetails.js b/src/libs/actions/PersonalDetails.js index dd458a3a4f14..9d68797ec5b0 100644 --- a/src/libs/actions/PersonalDetails.js +++ b/src/libs/actions/PersonalDetails.js @@ -378,73 +378,78 @@ function updateAvatar(file) { }, }, }, + ]; + + const successData = [ { onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.PERSONAL_DETAILS_LIST, + key: ONYXKEYS.PERSONAL_DETAILS, value: { - [personalDetails[currentUserEmail].accountID]: { - avatar: file.uri, - errorFields: { - avatar: null, - }, + [currentUserEmail]: { pendingFields: { - avatar: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + avatar: null, }, }, }, }, ]; - const successData = [ + const failureData = [ { onyxMethod: Onyx.METHOD.MERGE, key: ONYXKEYS.PERSONAL_DETAILS, value: { [currentUserEmail]: { + avatar: personalDetails[currentUserEmail].avatar, + avatarThumbnail: personalDetails[currentUserEmail].avatarThumbnail || personalDetails[currentUserEmail].avatar, pendingFields: { avatar: null, }, }, }, }, - { + ]; + + const accountID = lodashGet(personalDetails, [currentUserEmail, 'accountID'], ''); + if (accountID) { + optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, key: ONYXKEYS.PERSONAL_DETAILS_LIST, value: { - [personalDetails[currentUserEmail].accountID]: { - pendingFields: { + [accountID]: { + avatar: file.uri, + errorFields: { avatar: null, }, + pendingFields: { + avatar: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + }, }, }, - }, - ]; - const failureData = [ - { + }); + successData.push({ onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.PERSONAL_DETAILS, + key: ONYXKEYS.PERSONAL_DETAILS_LIST, value: { - [currentUserEmail]: { - avatar: personalDetails[currentUserEmail].avatar, - avatarThumbnail: personalDetails[currentUserEmail].avatarThumbnail || personalDetails[currentUserEmail].avatar, + [accountID]: { pendingFields: { avatar: null, }, }, }, - }, - { + }); + failureData.push({ onyxMethod: Onyx.METHOD.MERGE, key: ONYXKEYS.PERSONAL_DETAILS_LIST, value: { - [personalDetails[currentUserEmail].accountID]: { + [accountID]: { avatar: personalDetails[currentUserEmail].avatar, pendingFields: { avatar: null, }, }, }, - }, - ]; + }); + } API.write('UpdateUserAvatar', {file}, {optimisticData, successData, failureData}); } @@ -456,52 +461,52 @@ function deleteAvatar() { // We want to use the old dot avatar here as this affects both platforms. const defaultAvatar = UserUtils.getDefaultAvatarURL(currentUserEmail, true); - 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, }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.PERSONAL_DETAILS_LIST, - value: { - [personalDetails[currentUserEmail].accountID]: { - avatar: defaultAvatar, - }, - }, + }, + }, + ]; + const failureData = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.PERSONAL_DETAILS, + value: { + [currentUserEmail]: { + avatar: personalDetails[currentUserEmail].avatar, }, - ], - 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, }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.PERSONAL_DETAILS_LIST, - value: { - [personalDetails[currentUserEmail].accountID]: { - avatar: personalDetails[currentUserEmail].avatar, - }, - }, + }, + }); + failureData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.PERSONAL_DETAILS_LIST, + value: { + [personalDetails[currentUserEmail].accountID]: { + avatar: personalDetails[currentUserEmail].avatar, }, - ], - }, - ); + }, + }); + } + + API.write('DeleteUserAvatar', {}, {optimisticData, failureData}); } /** From 14e8999aafbf470f8a9d3091a56260b66c67b57a Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Tue, 13 Jun 2023 22:01:13 -0500 Subject: [PATCH 5/6] fix: lint error --- src/libs/actions/PersonalDetails.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/actions/PersonalDetails.js b/src/libs/actions/PersonalDetails.js index 9d68797ec5b0..67365cf8add3 100644 --- a/src/libs/actions/PersonalDetails.js +++ b/src/libs/actions/PersonalDetails.js @@ -379,7 +379,6 @@ function updateAvatar(file) { }, }, ]; - const successData = [ { onyxMethod: Onyx.METHOD.MERGE, From 1c3a20d35ba17bd3c1c538d0909b6a2c5573c9f3 Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Wed, 14 Jun 2023 12:54:06 -0500 Subject: [PATCH 6/6] fix: use of UserUtils.getAvatar --- src/components/UserDetailsTooltip/index.js | 3 ++- src/libs/actions/PersonalDetails.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/UserDetailsTooltip/index.js b/src/components/UserDetailsTooltip/index.js index 493b40a0a5e1..5dd2fa1c5785 100644 --- a/src/components/UserDetailsTooltip/index.js +++ b/src/components/UserDetailsTooltip/index.js @@ -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); @@ -18,7 +19,7 @@ function UserDetailsTooltip(props) { diff --git a/src/libs/actions/PersonalDetails.js b/src/libs/actions/PersonalDetails.js index 67365cf8add3..9c7dde0c7aa4 100644 --- a/src/libs/actions/PersonalDetails.js +++ b/src/libs/actions/PersonalDetails.js @@ -458,7 +458,7 @@ function updateAvatar(file) { */ function deleteAvatar() { // We want to use the old dot avatar here as this affects both platforms. - const defaultAvatar = UserUtils.getDefaultAvatarURL(currentUserEmail, true); + const defaultAvatar = UserUtils.getDefaultAvatarURL(currentUserEmail); const optimisticData = [ {