Skip to content

Commit

Permalink
Merge pull request #38545 from Expensify/vit38445
Browse files Browse the repository at this point in the history
Remove the usage of isApprovalModeEnabled
  • Loading branch information
luacmartins authored Mar 19, 2024
2 parents 7014d47 + e9ab69c commit aa5097f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
18 changes: 11 additions & 7 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,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 @@ -468,7 +468,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 @@ -478,7 +478,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 @@ -568,13 +568,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 @@ -595,7 +593,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 @@ -611,7 +608,14 @@ function setWorkspaceApprovalMode(policyID: string, approver: string, approvalMo
},
];

const params: SetWorkspaceApprovalModeParams = {policyID, value: JSON.stringify(value)};
const params: SetWorkspaceApprovalModeParams = {
policyID,
value: JSON.stringify({
...value,
// 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});
}

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 aa5097f

Please sign in to comment.