Skip to content

Commit

Permalink
Simplify logic for autoReimbursement
Browse files Browse the repository at this point in the history
  • Loading branch information
marcaaron committed Sep 17, 2024
1 parent f5d39d8 commit 054221c
Showing 1 changed file with 7 additions and 23 deletions.
30 changes: 7 additions & 23 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4327,17 +4327,8 @@ function enableAutoApprovalOptions(policyID: string, enabled: boolean) {
return;
}

const autoApprovalCleanupValues = !enabled
? {
pendingFields: {
limit: null,
auditRate: null,
},
}
: {};
const autoApprovalValues = !enabled ? {auditRate: CONST.POLICY.RANDOM_AUDIT_DEFAULT_PERCENTAGE, limit: CONST.POLICY.AUTO_APPROVE_REPORTS_UNDER_DEFAULT_CENTS} : {};
const autoApprovalFailureValues = !enabled ? {autoApproval: {limit: policy?.autoApproval?.limit, auditRate: policy?.autoApproval?.auditRate, ...autoApprovalCleanupValues}} : {};

const autoApprovalValues = {auditRate: CONST.POLICY.RANDOM_AUDIT_DEFAULT_PERCENTAGE, limit: CONST.POLICY.AUTO_APPROVE_REPORTS_UNDER_DEFAULT_CENTS};
const autoApprovalFailureValues = {autoApproval: {limit: policy?.autoApproval?.limit, auditRate: policy?.autoApproval?.auditRate, pendingFields: null}};
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -4363,7 +4354,7 @@ function enableAutoApprovalOptions(policyID: string, enabled: boolean) {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
autoApproval: {...autoApprovalCleanupValues},
autoApproval: {pendingFields: null},
pendingFields: {
shouldShowAutoApprovalOptions: null,
},
Expand Down Expand Up @@ -4469,6 +4460,7 @@ function setPolicyAutoReimbursementLimit(policyID: string, limit: string) {

/**
* Call the API to enable auto-payment for the reports in the given policy
*
* @param policyID - id of the policy to apply the limit to
* @param enabled - whether auto-payment for the reports is enabled in the given policy
*/
Expand All @@ -4479,16 +4471,8 @@ function enablePolicyAutoReimbursementLimit(policyID: string, enabled: boolean)
return;
}

const autoReimbursementCleanupValues = !enabled
? {
pendingFields: {
limit: null,
},
}
: {};
const autoReimbursementFailureValues = !enabled ? {autoReimbursement: {limit: policy?.autoReimbursement?.limit, ...autoReimbursementCleanupValues}} : {};
const autoReimbursementValues = !enabled ? {limit: CONST.POLICY.AUTO_REIMBURSEMENT_DEFAULT_LIMIT_CENTS} : {};

const autoReimbursementFailureValues = {autoReimbursement: {limit: policy?.autoReimbursement?.limit, pendingFields: null}};
const autoReimbursementValues = {limit: CONST.POLICY.AUTO_REIMBURSEMENT_DEFAULT_LIMIT_CENTS};
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -4513,7 +4497,7 @@ function enablePolicyAutoReimbursementLimit(policyID: string, enabled: boolean)
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
autoReimbursement: {...autoReimbursementCleanupValues},
autoReimbursement: {pendingFields: null},
pendingFields: {
shouldShowAutoReimbursementLimitOption: null,
},
Expand Down

0 comments on commit 054221c

Please sign in to comment.