From e7b824973be3a2508174f0d11f5fbd3916e3df38 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 13 Mar 2024 18:21:58 +0700 Subject: [PATCH 1/4] update optimistic data --- src/libs/actions/Policy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 48b9948fc1ff..6d0cc2fd156d 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -440,7 +440,7 @@ function setWorkspaceAutoReporting(policyID: string, enabled: boolean, frequency value: { autoReporting: enabled, harvesting: { - enabled: true, + enabled, }, autoReportingFrequency: frequency, pendingFields: {isAutoApprovalEnabled: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}, From ef571f71d3448431a58353e97fb2f4cea1e7b36f Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 13 Mar 2024 22:22:44 +0700 Subject: [PATCH 2/4] update failure data --- src/libs/actions/Policy.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 6d0cc2fd156d..fee836404fd5 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -433,6 +433,7 @@ function buildAnnounceRoomMembersOnyxData(policyID: string, accountIDs: number[] } function setWorkspaceAutoReporting(policyID: string, enabled: boolean, frequency: ValueOf) { + const policy = ReportUtils.getPolicy(policyID); const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -453,7 +454,9 @@ function setWorkspaceAutoReporting(policyID: string, enabled: boolean, frequency onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { - autoReporting: !enabled, + autoReporting: policy.autoReporting, + harvesting: policy.harvesting, + autoReportingFrequency: policy.autoReportingFrequency, pendingFields: {isAutoApprovalEnabled: null, harvesting: null}, }, }, @@ -475,6 +478,8 @@ function setWorkspaceAutoReporting(policyID: string, enabled: boolean, frequency } function setWorkspaceAutoReportingFrequency(policyID: string, frequency: ValueOf) { + const policy = ReportUtils.getPolicy(policyID); + const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -491,6 +496,7 @@ function setWorkspaceAutoReportingFrequency(policyID: string, frequency: ValueOf onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { + autoReportingFrequency: policy.autoReportingFrequency, pendingFields: {autoReportingFrequency: null}, }, }, @@ -512,6 +518,7 @@ function setWorkspaceAutoReportingFrequency(policyID: string, frequency: ValueOf function setWorkspaceAutoReportingMonthlyOffset(policyID: string, autoReportingOffset: number | ValueOf) { const value = JSON.stringify({autoReportingOffset: autoReportingOffset.toString()}); + const policy = ReportUtils.getPolicy(policyID); const optimisticData: OnyxUpdate[] = [ { @@ -529,6 +536,7 @@ function setWorkspaceAutoReportingMonthlyOffset(policyID: string, autoReportingO onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { + autoReportingOffset: policy.autoReportingOffset, pendingFields: {autoReportingOffset: null}, }, }, @@ -550,6 +558,7 @@ function setWorkspaceAutoReportingMonthlyOffset(policyID: string, autoReportingO function setWorkspaceApprovalMode(policyID: string, approver: string, approvalMode: ValueOf) { const isAutoApprovalEnabled = approvalMode === CONST.POLICY.APPROVAL_MODE.BASIC; + const policy = ReportUtils.getPolicy(policyID); const value = { approver, @@ -573,6 +582,9 @@ function setWorkspaceApprovalMode(policyID: string, approver: string, approvalMo onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { + approver: policy.approver, + approvalMode: policy.approvalMode, + isAutoApprovalEnabled: policy.isAutoApprovalEnabled, pendingFields: {approvalMode: null}, }, }, From 750ca3fc04625e363663a668574f99b4b27e5606 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Thu, 14 Mar 2024 00:28:48 +0700 Subject: [PATCH 3/4] add null value as a fallback --- src/libs/actions/Policy.ts | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index a2bb039971d7..d7cc3aba9322 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -457,9 +457,11 @@ function setWorkspaceAutoReporting(policyID: string, enabled: boolean, frequency onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { - autoReporting: policy.autoReporting, - harvesting: policy.harvesting, - autoReportingFrequency: policy.autoReportingFrequency, + autoReporting: policy.autoReporting ?? null, + harvesting: { + enabled: policy?.harvesting?.enabled ?? null, + }, + autoReportingFrequency: policy.autoReportingFrequency ?? null, pendingFields: {isAutoApprovalEnabled: null, harvesting: null}, }, }, @@ -499,7 +501,7 @@ function setWorkspaceAutoReportingFrequency(policyID: string, frequency: ValueOf onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { - autoReportingFrequency: policy.autoReportingFrequency, + autoReportingFrequency: policy.autoReportingFrequency ?? null, pendingFields: {autoReportingFrequency: null}, }, }, @@ -539,7 +541,7 @@ function setWorkspaceAutoReportingMonthlyOffset(policyID: string, autoReportingO onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { - autoReportingOffset: policy.autoReportingOffset, + autoReportingOffset: policy.autoReportingOffset ?? null, pendingFields: {autoReportingOffset: null}, }, }, @@ -585,9 +587,9 @@ function setWorkspaceApprovalMode(policyID: string, approver: string, approvalMo onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { - approver: policy.approver, - approvalMode: policy.approvalMode, - isAutoApprovalEnabled: policy.isAutoApprovalEnabled, + approver: policy.approver ?? null, + approvalMode: policy.approvalMode ?? null, + isAutoApprovalEnabled: policy.isAutoApprovalEnabled ?? null, pendingFields: {approvalMode: null}, }, }, @@ -639,8 +641,8 @@ function setWorkspacePayer(policyID: string, reimburserEmail: string, reimburser onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { - reimburserEmail: policy.reimburserEmail, - reimburserAccountID: policy.reimburserAccountID, + reimburserEmail: policy.reimburserEmail ?? null, + reimburserAccountID: policy.reimburserAccountID ?? null, errorFields: {reimburserEmail: ErrorUtils.getMicroSecondOnyxError('workflowsPayerPage.genericErrorMessage')}, pendingFields: {reimburserEmail: null}, }, @@ -689,9 +691,9 @@ function setWorkspaceReimbursement(policyID: string, reimbursementChoice: ValueO onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { - reimbursementChoice: policy.reimbursementChoice, - reimburserAccountID: policy.reimburserAccountID, - reimburserEmail: policy.reimburserEmail, + reimbursementChoice: policy.reimbursementChoice ?? null, + reimburserAccountID: policy.reimburserAccountID ?? null, + reimburserEmail: policy.reimburserEmail ?? null, errorFields: {reimbursementChoice: ErrorUtils.getMicroSecondOnyxError('common.genericErrorMessage')}, pendingFields: {reimbursementChoice: null}, }, From 1fa0d917bea633db625f08559c52d1f62473bbdb Mon Sep 17 00:00:00 2001 From: DylanDylann <141406735+DylanDylann@users.noreply.github.com> Date: Thu, 14 Mar 2024 10:02:50 +0700 Subject: [PATCH 4/4] Update src/libs/actions/Policy.ts Co-authored-by: Carlos Martins --- src/libs/actions/Policy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index d7cc3aba9322..d69594548218 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -459,7 +459,7 @@ function setWorkspaceAutoReporting(policyID: string, enabled: boolean, frequency value: { autoReporting: policy.autoReporting ?? null, harvesting: { - enabled: policy?.harvesting?.enabled ?? null, + enabled: policy.harvesting?.enabled ?? null, }, autoReportingFrequency: policy.autoReportingFrequency ?? null, pendingFields: {isAutoApprovalEnabled: null, harvesting: null},