diff --git a/src/libs/actions/Policy/Member.ts b/src/libs/actions/Policy/Member.ts index 81dea1c828e7..e6bf5bd434b5 100644 --- a/src/libs/actions/Policy/Member.ts +++ b/src/libs/actions/Policy/Member.ts @@ -296,17 +296,7 @@ function removeMembers(accountIDs: number[], policyID: string) { failureMembersState[email] = {errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.people.error.genericRemove')}; }); - const approvalRules: ApprovalRule[] = policy?.rules?.approvalRules ?? []; - const optimisticApprovalRules: ApprovalRule[] = []; - Object.keys(policy?.employeeList ?? {}).forEach((employeeEmail) => { - approvalRules.forEach((rule) => { - if (employeeEmail === rule?.approver) { - return; - } - optimisticApprovalRules.push(rule); - }); - const employee = policy?.employeeList?.[employeeEmail]; optimisticMembersState[employeeEmail] = optimisticMembersState[employeeEmail] ?? {}; failureMembersState[employeeEmail] = failureMembersState[employeeEmail] ?? {}; @@ -342,6 +332,9 @@ function removeMembers(accountIDs: number[], policyID: string) { } }); + const approvalRules: ApprovalRule[] = policy?.rules?.approvalRules ?? []; + const optimisticApprovalRules = approvalRules.filter((rule) => !emailList.includes(rule?.approver ?? '')); + const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE,