Skip to content

Commit

Permalink
Merge pull request Expensify#54105 from bernhardoj/fix/53931-member-a…
Browse files Browse the repository at this point in the history
…dded-offline-doesnt-show-on-approval-flow

Fix new member added while offline doesn't show in approval flow list
  • Loading branch information
AndrewGable authored Dec 20, 2024
2 parents 01c0ad9 + d3e2dfc commit 006a1df
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/libs/actions/Policy/Member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import enhanceParameters from '@libs/Network/enhanceParameters';
import Parser from '@libs/Parser';
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
import * as PhoneNumber from '@libs/PhoneNumber';
import {getDefaultApprover} from '@libs/PolicyUtils';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -637,7 +638,12 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs: InvitedEmailsToAccount
const successMembersState: OnyxCollectionInputValue<PolicyEmployee> = {};
const failureMembersState: OnyxCollectionInputValue<PolicyEmployee> = {};
logins.forEach((email) => {
optimisticMembersState[email] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, role: CONST.POLICY.ROLE.USER};
optimisticMembersState[email] = {
email,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
role: CONST.POLICY.ROLE.USER,
submitsTo: getDefaultApprover(allPolicies?.[policyKey]),
};
successMembersState[email] = {pendingAction: null};
failureMembersState[email] = {
errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.people.error.genericAdd'),
Expand Down
36 changes: 36 additions & 0 deletions tests/actions/PolicyMemberTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,40 @@ describe('actions/PolicyMember', () => {
});
});
});

describe('addMembersToWorkspace', () => {
it('Add a new member to a workspace', async () => {
const policyID = '1';
const defaultApprover = 'approver@gmail.com';
const newUserEmail = 'user@gmail.com';

await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {
...createRandomPolicy(Number(policyID)),
approver: defaultApprover,
});

mockFetch?.pause?.();
Member.addMembersToWorkspace({[newUserEmail]: 1234}, 'Welcome', policyID, []);

await waitForBatchedUpdates();

await new Promise<void>((resolve) => {
const connection = Onyx.connect({
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
waitForCollectionCallback: false,
callback: (policy) => {
Onyx.disconnect(connection);
const newEmployee = policy?.employeeList?.[newUserEmail];
expect(newEmployee).not.toBeUndefined();
expect(newEmployee?.email).toBe(newUserEmail);
expect(newEmployee?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD);
expect(newEmployee?.role).toBe(CONST.POLICY.ROLE.USER);
expect(newEmployee?.submitsTo).toBe(defaultApprover);
resolve();
},
});
});
await mockFetch?.resume?.();
});
});
});

0 comments on commit 006a1df

Please sign in to comment.