Skip to content

Commit

Permalink
add members optimistic and success actions changed
Browse files Browse the repository at this point in the history
  • Loading branch information
burczu committed Apr 3, 2024
1 parent 80e2473 commit ae9a8a5
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,10 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs: InvitedEmailsToAccount
const optimisticMembersState: OnyxCollection<PolicyMember> = {};
const failureMembersState: OnyxCollection<PolicyMember> = {};
accountIDs.forEach((accountID) => {
optimisticMembersState[accountID] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD};
optimisticMembersState[accountID] = {
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
role: CONST.POLICY.ROLE.USER,
};
failureMembersState[accountID] = {
errors: ErrorUtils.getMicroSecondOnyxError('workspace.people.error.genericAdd'),
};
Expand All @@ -1318,12 +1321,11 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs: InvitedEmailsToAccount
// Convert to object with each key clearing pendingAction, when it is an existing account.
// Remove the object, when it is a newly created account.
value: accountIDs.reduce((accountIDsWithClearedPendingAction, accountID) => {
let value = null;
const accountAlreadyExists = !isEmptyObject(allPersonalDetails?.[accountID]);

if (accountAlreadyExists) {
value = {pendingAction: null, errors: null};
}
const value = {
...allPolicyMembers?.[accountID],
pendingAction: null,
errors: null
};

return {...accountIDsWithClearedPendingAction, [accountID]: value};
}, {}),
Expand Down

0 comments on commit ae9a8a5

Please sign in to comment.