diff --git a/src/libs/actions/Policy/Member.ts b/src/libs/actions/Policy/Member.ts index 3bd87683b085..00acd397c557 100644 --- a/src/libs/actions/Policy/Member.ts +++ b/src/libs/actions/Policy/Member.ts @@ -26,7 +26,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {InvitedEmailsToAccountIDs, PersonalDetailsList, Policy, PolicyEmployee, PolicyOwnershipChangeChecks, Report, ReportAction} from '@src/types/onyx'; import type {PendingAction} from '@src/types/onyx/OnyxCommon'; import type {JoinWorkspaceResolution} from '@src/types/onyx/OriginalMessage'; -import type {Attributes, Rate} from '@src/types/onyx/Policy'; +import type {ApprovalRule, Attributes, Rate} from '@src/types/onyx/Policy'; import type {OnyxData} from '@src/types/onyx/Request'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import {createPolicyExpenseChats} from './Policy'; @@ -332,11 +332,21 @@ 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, key: policyKey, - value: {employeeList: optimisticMembersState, approver: emailList.includes(policy?.approver ?? '') ? policy?.owner : policy?.approver}, + value: { + employeeList: optimisticMembersState, + approver: emailList.includes(policy?.approver ?? '') ? policy?.owner : policy?.approver, + rules: { + ...(policy?.rules ?? {}), + approvalRules: optimisticApprovalRules, + }, + }, }, ]; optimisticData.push(...announceRoomMembers.onyxOptimisticData); @@ -354,7 +364,7 @@ function removeMembers(accountIDs: number[], policyID: string) { { onyxMethod: Onyx.METHOD.MERGE, key: policyKey, - value: {employeeList: failureMembersState, approver: policy?.approver}, + value: {employeeList: failureMembersState, approver: policy?.approver, rules: policy?.rules}, }, ]; failureData.push(...announceRoomMembers.onyxFailureData);