From 7262520417930c9fdb8dd730fe29a910e6aeefb8 Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Mon, 18 Mar 2024 22:56:09 +0000 Subject: [PATCH 1/2] Remove the usage of isApprovalModeEnabled --- src/libs/actions/Policy.ts | 17 ++++++++++------- .../workflows/WorkspaceWorkflowsPage.tsx | 4 ++-- src/types/onyx/Policy.ts | 3 --- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index dbbb94b82a1a..dd3fabfcc656 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -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}, }, }, ]; @@ -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}, }, }, ]; @@ -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}, }, }, ]; @@ -566,13 +566,11 @@ function setWorkspaceAutoReportingMonthlyOffset(policyID: string, autoReportingO } function setWorkspaceApprovalMode(policyID: string, approver: string, approvalMode: ValueOf) { - const isAutoApprovalEnabled = approvalMode === CONST.POLICY.APPROVAL_MODE.BASIC; const policy = ReportUtils.getPolicy(policyID); const value = { approver, approvalMode, - isAutoApprovalEnabled, }; const optimisticData: OnyxUpdate[] = [ @@ -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}, }, }, @@ -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}); } diff --git a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx index c6ace2b0856e..af91eeb3aef6 100644 --- a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx +++ b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx @@ -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, }, ] : []), @@ -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, }, { diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index 84ac101a7d7a..e8e17bbdff4b 100644 --- a/src/types/onyx/Policy.ts +++ b/src/types/onyx/Policy.ts @@ -292,9 +292,6 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback< /** The approval mode set up on this policy */ approvalMode?: ValueOf; - /** Whether the auto approval is enabled */ - isAutoApprovalEnabled?: boolean; - /** Whether transactions should be billable by default */ defaultBillable?: boolean; From e9ab69ce9102d5be47b4ee37539a41ff5af6483c Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Mon, 18 Mar 2024 23:41:44 +0000 Subject: [PATCH 2/2] Make sure the autoApproval is off for Collect --- src/libs/actions/Policy.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index dd3fabfcc656..8df84965b08c 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -610,7 +610,8 @@ function setWorkspaceApprovalMode(policyID: string, approver: string, approvalMo policyID, value: JSON.stringify({ ...value, - isAutoApprovalEnabled: approvalMode === CONST.POLICY.APPROVAL_MODE.BASIC, + // This property should now be set to false for all Collect policies + isAutoApprovalEnabled: false, }), }; API.write(WRITE_COMMANDS.SET_WORKSPACE_APPROVAL_MODE, params, {optimisticData, failureData, successData});