Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the usage of isApprovalModeEnabled #38545

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 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,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,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed this and we actually want the autoapproval to be off for Collect policies

}),
};
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;
Comment on lines -295 to -296
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This property is right now, never returned from the backend to the client so we can remove it from the type


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

Expand Down
Loading