diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 4b585da62ba5..231bce5aae0c 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -7,11 +7,13 @@ import {escapeRegExp} from 'lodash'; import * as API from '../API'; import ONYXKEYS from '../../ONYXKEYS'; import CONST from '../../CONST'; +import * as LocalePhoneNumber from '../LocalePhoneNumber'; import * as OptionsListUtils from '../OptionsListUtils'; import * as ErrorUtils from '../ErrorUtils'; import * as ReportUtils from '../ReportUtils'; import Log from '../Log'; import Permissions from '../Permissions'; +import * as UserUtils from '../UserUtils'; const allPolicies = {}; Onyx.connect({ @@ -355,6 +357,24 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs, welcomeNote, policyID, // create onyx data for policy expense chats for each new member const membersChats = createPolicyExpenseChats(policyID, invitedEmailsToAccountIDs, betas); + // Optimistic personal details for the new accounts invited + const optimisticPersonalDetails = _.chain(invitedEmailsToAccountIDs) + .map( + (accountID, memberLogin) => + !_.has(allPersonalDetails, accountID) && [ + accountID, + { + accountID, + avatar: UserUtils.getDefaultAvatarURL(accountID), + displayName: LocalePhoneNumber.formatPhoneNumber(memberLogin), + login: OptionsListUtils.addSMSDomainIfPhoneNumber(memberLogin), + }, + ], + ) + .compact() + .object() + .value(); + const optimisticData = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -364,6 +384,11 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs, welcomeNote, policyID, value: _.object(accountIDs, Array(accountIDs.length).fill({pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD})), }, ...membersChats.onyxOptimisticData, + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.PERSONAL_DETAILS_LIST, + value: optimisticPersonalDetails, + }, ]; const successData = [ @@ -376,6 +401,11 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs, welcomeNote, policyID, value: _.object(accountIDs, Array(accountIDs.length).fill({pendingAction: null, errors: null})), }, ...membersChats.onyxSuccessData, + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.PERSONAL_DETAILS_LIST, + value: _.object(_.keys(optimisticPersonalDetails), Array(_.size(optimisticPersonalDetails)).fill(null)), + }, ]; const failureData = [ @@ -743,6 +773,9 @@ function clearAddMemberError(policyID, accountID) { Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY_MEMBERS}${policyID}`, { [accountID]: null, }); + Onyx.merge(`${ONYXKEYS.PERSONAL_DETAILS_LIST}`, { + [accountID]: null, + }); } /**