From dd690ee394a9f719d12114f35004e64867a2410b Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Sat, 16 Mar 2024 10:38:00 +0700 Subject: [PATCH 1/3] fix add optimistic data once disable workflow --- src/libs/actions/Policy.ts | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 9df73f970195..180527786a32 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -3562,8 +3562,25 @@ function enablePolicyWorkflows(policyID: string, enabled: boolean) { 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 + ? { + autoReporting: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + harvesting: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + reimbursementChoice: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + } + : {}), }, }, }, @@ -3575,6 +3592,13 @@ function enablePolicyWorkflows(policyID: string, enabled: boolean) { value: { pendingFields: { areWorkflowsEnabled: null, + ...(!enabled + ? { + autoReporting: null, + harvesting: null, + reimbursementChoice: null, + } + : {}), }, }, }, @@ -3585,8 +3609,25 @@ function enablePolicyWorkflows(policyID: string, enabled: boolean) { 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: null, + ...(!enabled + ? { + autoReporting: null, + harvesting: null, + reimbursementChoice: null, + } + : {}), }, }, }, From b2eb8c47e8106717f6b3e75c578307e8b9ba8f74 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Sat, 16 Mar 2024 10:51:53 +0700 Subject: [PATCH 2/3] fix failure data --- src/libs/actions/Policy.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 180527786a32..dee59578c0c9 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -3555,6 +3555,7 @@ function enablePolicyTaxes(policyID: string, enabled: boolean) { } function enablePolicyWorkflows(policyID: string, enabled: boolean) { + const policy = ReportUtils.getPolicy(policyID); const onyxData: OnyxData = { optimisticData: [ { @@ -3611,12 +3612,10 @@ function enablePolicyWorkflows(policyID: string, enabled: boolean) { areWorkflowsEnabled: !enabled, ...(!enabled ? { - approvalMode: CONST.POLICY.APPROVAL_MODE.OPTIONAL, - autoReporting: false, - harvesting: { - enabled: false, - }, - reimbursementChoice: CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_NO, + approvalMode: policy.approvalMode, + autoReporting: policy.autoReporting, + harvesting: policy.harvesting, + reimbursementChoice: policy.reimbursementChoice, } : {}), pendingFields: { From cd4b87bf0bf8eaf050ede429b2154ab552bfcf6b Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Sat, 16 Mar 2024 10:55:43 +0700 Subject: [PATCH 3/3] fix update pendingField --- src/libs/actions/Policy.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index dee59578c0c9..b304a85cc27a 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -3577,6 +3577,7 @@ function enablePolicyWorkflows(policyID: string, enabled: boolean) { 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, @@ -3595,6 +3596,7 @@ function enablePolicyWorkflows(policyID: string, enabled: boolean) { areWorkflowsEnabled: null, ...(!enabled ? { + approvalMode: null, autoReporting: null, harvesting: null, reimbursementChoice: null, @@ -3622,6 +3624,7 @@ function enablePolicyWorkflows(policyID: string, enabled: boolean) { areWorkflowsEnabled: null, ...(!enabled ? { + approvalMode: null, autoReporting: null, harvesting: null, reimbursementChoice: null,