Skip to content

Commit

Permalink
Merge pull request #38432 from nkdengineer/fix/38250
Browse files Browse the repository at this point in the history
fix: add optimistic data once disable workflow
  • Loading branch information
mountiny authored Mar 16, 2024
2 parents f84219f + cd4b87b commit e40fba1
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3555,15 +3555,34 @@ function enablePolicyTaxes(policyID: string, enabled: boolean) {
}

function enablePolicyWorkflows(policyID: string, enabled: boolean) {
const policy = ReportUtils.getPolicy(policyID);
const onyxData: OnyxData = {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
areWorkflowsEnabled: enabled,
...(!enabled
? {
approvalMode: CONST.POLICY.APPROVAL_MODE.OPTIONAL,
autoReporting: false,
harvesting: {
enabled: false,
},
reimbursementChoice: CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_NO,
}
: {}),
pendingFields: {
areWorkflowsEnabled: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
...(!enabled
? {
approvalMode: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
autoReporting: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
harvesting: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
reimbursementChoice: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
}
: {}),
},
},
},
Expand All @@ -3575,6 +3594,14 @@ function enablePolicyWorkflows(policyID: string, enabled: boolean) {
value: {
pendingFields: {
areWorkflowsEnabled: null,
...(!enabled
? {
approvalMode: null,
autoReporting: null,
harvesting: null,
reimbursementChoice: null,
}
: {}),
},
},
},
Expand All @@ -3585,8 +3612,24 @@ function enablePolicyWorkflows(policyID: string, enabled: boolean) {
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
areWorkflowsEnabled: !enabled,
...(!enabled
? {
approvalMode: policy.approvalMode,
autoReporting: policy.autoReporting,
harvesting: policy.harvesting,
reimbursementChoice: policy.reimbursementChoice,
}
: {}),
pendingFields: {
areWorkflowsEnabled: null,
...(!enabled
? {
approvalMode: null,
autoReporting: null,
harvesting: null,
reimbursementChoice: null,
}
: {}),
},
},
},
Expand Down

0 comments on commit e40fba1

Please sign in to comment.