Skip to content

Commit

Permalink
Fix categories approval field after removing workspace members
Browse files Browse the repository at this point in the history
  • Loading branch information
abzokhattab committed Dec 2, 2024
1 parent 5b884db commit 6a7b207
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 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 @@ -296,7 +296,17 @@ 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] ?? {};
Expand Down Expand Up @@ -336,7 +346,14 @@ function removeMembers(accountIDs: number[], policyID: string) {
{
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 +371,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 6a7b207

Please sign in to comment.