Skip to content

Commit

Permalink
Merge pull request Expensify#23157 from tienifr/fix/22359-can-not-rem…
Browse files Browse the repository at this point in the history
…ove-rbr-invite-workspace-member

Fix: Cannot remove RBR when invite an invalid member to workspace
  • Loading branch information
NikkiWines authored Jul 26, 2023
2 parents 0d98268 + 9eba1dd commit 1205a74
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ 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 * as PersonalDetailsUtils from '../PersonalDetailsUtils';
import Log from '../Log';
import Permissions from '../Permissions';
import * as UserUtils from '../UserUtils';

const allPolicies = {};
Onyx.connect({
Expand Down Expand Up @@ -358,6 +360,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,
Expand All @@ -368,6 +388,11 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs, welcomeNote, policyID,
},
...newPersonalDetailsOnyxData.optimisticData,
...membersChats.onyxOptimisticData,
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: optimisticPersonalDetails,
},
];

const successData = [
Expand All @@ -381,6 +406,11 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs, welcomeNote, policyID,
},
...newPersonalDetailsOnyxData.successData,
...membersChats.onyxSuccessData,
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: _.object(_.keys(optimisticPersonalDetails), Array(_.size(optimisticPersonalDetails)).fill(null)),
},
];

const failureData = [
Expand Down Expand Up @@ -748,6 +778,9 @@ function clearAddMemberError(policyID, accountID) {
Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY_MEMBERS}${policyID}`, {
[accountID]: null,
});
Onyx.merge(`${ONYXKEYS.PERSONAL_DETAILS_LIST}`, {
[accountID]: null,
});
}

/**
Expand Down

0 comments on commit 1205a74

Please sign in to comment.