Skip to content

Commit

Permalink
Remove the usage of isApprovalModeEnabled
Browse files Browse the repository at this point in the history
  • Loading branch information
mountiny committed Mar 18, 2024
1 parent 17be26d commit 7262520
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
17 changes: 10 additions & 7 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ function setWorkspaceAutoReporting(policyID: string, enabled: boolean, frequency
enabled,
},
autoReportingFrequency: frequency,
pendingFields: {isAutoApprovalEnabled: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE},
pendingFields: {autoReporting: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE},
},
},
];
Expand All @@ -466,7 +466,7 @@ function setWorkspaceAutoReporting(policyID: string, enabled: boolean, frequency
enabled: policy.harvesting?.enabled ?? null,
},
autoReportingFrequency: policy.autoReportingFrequency ?? null,
pendingFields: {isAutoApprovalEnabled: null, harvesting: null},
pendingFields: {autoReporting: null},
},
},
];
Expand All @@ -476,7 +476,7 @@ function setWorkspaceAutoReporting(policyID: string, enabled: boolean, frequency
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
pendingFields: {isAutoApprovalEnabled: null, harvesting: null},
pendingFields: {autoReporting: null},
},
},
];
Expand Down Expand Up @@ -566,13 +566,11 @@ function setWorkspaceAutoReportingMonthlyOffset(policyID: string, autoReportingO
}

function setWorkspaceApprovalMode(policyID: string, approver: string, approvalMode: ValueOf<typeof CONST.POLICY.APPROVAL_MODE>) {
const isAutoApprovalEnabled = approvalMode === CONST.POLICY.APPROVAL_MODE.BASIC;
const policy = ReportUtils.getPolicy(policyID);

const value = {
approver,
approvalMode,
isAutoApprovalEnabled,
};

const optimisticData: OnyxUpdate[] = [
Expand All @@ -593,7 +591,6 @@ function setWorkspaceApprovalMode(policyID: string, approver: string, approvalMo
value: {
approver: policy.approver ?? null,
approvalMode: policy.approvalMode ?? null,
isAutoApprovalEnabled: policy.isAutoApprovalEnabled ?? null,
pendingFields: {approvalMode: null},
},
},
Expand All @@ -609,7 +606,13 @@ function setWorkspaceApprovalMode(policyID: string, approver: string, approvalMo
},
];

const params: SetWorkspaceApprovalModeParams = {policyID, value: JSON.stringify(value)};
const params: SetWorkspaceApprovalModeParams = {
policyID,
value: JSON.stringify({
...value,
isAutoApprovalEnabled: approvalMode === CONST.POLICY.APPROVAL_MODE.BASIC,
}),
};
API.write(WRITE_COMMANDS.SET_WORKSPACE_APPROVAL_MODE, params, {optimisticData, failureData, successData});
}

Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function WorkspaceWorkflowsPage({policy, betas, route, reimbursementAccount, ses
/>
),
isActive: (policy?.harvesting?.enabled && policy.autoReportingFrequency !== CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT) ?? false,
pendingAction: policy?.pendingFields?.isAutoApprovalEnabled,
pendingAction: policy?.pendingFields?.autoReporting,
},
]
: []),
Expand All @@ -134,7 +134,7 @@ function WorkspaceWorkflowsPage({policy, betas, route, reimbursementAccount, ses
hoverAndPressStyle={[styles.mr0, styles.br2]}
/>
),
isActive: policy?.isAutoApprovalEnabled ?? false,
isActive: policy?.approvalMode === CONST.POLICY.APPROVAL_MODE.BASIC,
pendingAction: policy?.pendingFields?.approvalMode,
},
{
Expand Down
3 changes: 0 additions & 3 deletions src/types/onyx/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,6 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback<
/** The approval mode set up on this policy */
approvalMode?: ValueOf<typeof CONST.POLICY.APPROVAL_MODE>;

/** Whether the auto approval is enabled */
isAutoApprovalEnabled?: boolean;

/** Whether transactions should be billable by default */
defaultBillable?: boolean;

Expand Down

0 comments on commit 7262520

Please sign in to comment.