From f8f5c02be1809073337d42638f622e3d162aea4a Mon Sep 17 00:00:00 2001 From: abzokhattab Date: Sat, 7 Dec 2024 05:11:09 +0100 Subject: [PATCH] Fixing the approval rules inside the optimistic rules --- src/libs/actions/Policy/Member.ts | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) 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,