Skip to content

Commit

Permalink
Merge pull request #53383 from abzokhattab/fix-category-approval-fiel…
Browse files Browse the repository at this point in the history
…d-after-removing-workspace-members

Fix categories approval field after removing workspace members
  • Loading branch information
francoisl authored Dec 16, 2024
2 parents 3e99d4d + f8f5c02 commit 0ef6238
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/libs/actions/Policy/Member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 0ef6238

Please sign in to comment.