From fc5e522fa2a891bcadb5bf1291227c4f5b3bd4fe Mon Sep 17 00:00:00 2001
From: Abdelrahman Khattab <abzokhattab@gmail.com>
Date: Thu, 15 Aug 2024 06:58:35 +0300
Subject: [PATCH 1/6] Fix/Delay submissions option is not grayed when clicking
 offline

---
 src/CONST.ts                                  |  1 -
 src/libs/PolicyUtils.ts                       |  2 +-
 src/libs/actions/Policy/Policy.ts             | 28 ++++++++-----------
 .../workflows/WorkspaceWorkflowsPage.tsx      |  8 +++---
 src/types/onyx/Policy.ts                      |  3 --
 5 files changed, 16 insertions(+), 26 deletions(-)

diff --git a/src/CONST.ts b/src/CONST.ts
index f1e4a3bb46d5..ca9e4ea1bfcc 100755
--- a/src/CONST.ts
+++ b/src/CONST.ts
@@ -2117,7 +2117,6 @@ const CONST = {
             REIMBURSER: 'reimburser',
             REIMBURSEMENT_CHOICE: 'reimbursementChoice',
             APPROVAL_MODE: 'approvalMode',
-            AUTOREPORTING: 'autoReporting',
             AUTOREPORTING_FREQUENCY: 'autoReportingFrequency',
             AUTOREPORTING_OFFSET: 'autoReportingOffset',
             GENERAL_SETTINGS: 'generalSettings',
diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts
index 3f3a2a96a1e1..77a084305978 100644
--- a/src/libs/PolicyUtils.ts
+++ b/src/libs/PolicyUtils.ts
@@ -361,7 +361,7 @@ function isTaxTrackingEnabled(isPolicyExpenseChat: boolean, policy: OnyxEntry<Po
  * Note: Free policies have "instant" submit always enabled.
  */
 function isInstantSubmitEnabled(policy: OnyxInputOrEntry<Policy>): boolean {
-    return policy?.type === CONST.POLICY.TYPE.FREE || (policy?.autoReporting === true && policy?.autoReportingFrequency === CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT);
+    return policy?.type === CONST.POLICY.TYPE.FREE || policy?.autoReportingFrequency === CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT;
 }
 
 /**
diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts
index d914e47e5204..4de784cb6e38 100644
--- a/src/libs/actions/Policy/Policy.ts
+++ b/src/libs/actions/Policy/Policy.ts
@@ -1504,7 +1504,6 @@ function createDraftInitialWorkspace(policyOwnerEmail = '', policyName = '', pol
                 pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
                 customUnits,
                 makeMeAdmin,
-                autoReporting: true,
                 autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT,
                 employeeList: {
                     [sessionEmail]: {
@@ -1517,7 +1516,7 @@ function createDraftInitialWorkspace(policyOwnerEmail = '', policyName = '', pol
                     enabled: true,
                 },
                 pendingFields: {
-                    autoReporting: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
+                    autoReportingFrequency: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
                     approvalMode: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
                     reimbursementChoice: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
                 },
@@ -1573,7 +1572,6 @@ function buildPolicyData(policyOwnerEmail = '', makeMeAdmin = false, policyName
                 isPolicyExpenseChatEnabled: true,
                 outputCurrency,
                 pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
-                autoReporting: true,
                 autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT,
                 approvalMode: CONST.POLICY.APPROVAL_MODE.OPTIONAL,
                 harvesting: {
@@ -1594,7 +1592,7 @@ function buildPolicyData(policyOwnerEmail = '', makeMeAdmin = false, policyName
                 },
                 chatReportIDAdmins: makeMeAdmin ? Number(adminsChatReportID) : undefined,
                 pendingFields: {
-                    autoReporting: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
+                    autoReportingFrequency: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
                     approvalMode: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
                     reimbursementChoice: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
                     generalSettings: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
@@ -1671,7 +1669,7 @@ function buildPolicyData(policyOwnerEmail = '', makeMeAdmin = false, policyName
             value: {
                 pendingAction: null,
                 pendingFields: {
-                    autoReporting: null,
+                    autoReportingFrequency: null,
                     approvalMode: null,
                     reimbursementChoice: null,
                 },
@@ -1851,7 +1849,6 @@ function createDraftWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policy
                 isPolicyExpenseChatEnabled: true,
                 outputCurrency,
                 pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
-                autoReporting: true,
                 autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT,
                 approvalMode: CONST.POLICY.APPROVAL_MODE.OPTIONAL,
                 harvesting: {
@@ -1872,7 +1869,7 @@ function createDraftWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policy
                 },
                 chatReportIDAdmins: makeMeAdmin ? Number(adminsChatReportID) : undefined,
                 pendingFields: {
-                    autoReporting: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
+                    autoReportingFrequency: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
                     approvalMode: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
                     reimbursementChoice: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
                 },
@@ -2193,7 +2190,6 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry<Report>): WorkspaceF
         // Setting the currency to USD as we can only add the VBBA for this policy currency right now
         outputCurrency: CONST.CURRENCY.USD,
         pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
-        autoReporting: true,
         autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT,
         approvalMode: CONST.POLICY.APPROVAL_MODE.OPTIONAL,
         harvesting: {
@@ -2217,7 +2213,7 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry<Report>): WorkspaceF
             },
         },
         pendingFields: {
-            autoReporting: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
+            autoReportingFrequency: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
             approvalMode: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
             reimbursementChoice: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
         },
@@ -2294,7 +2290,7 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry<Report>): WorkspaceF
             value: {
                 pendingAction: null,
                 pendingFields: {
-                    autoReporting: null,
+                    autoReportingFrequency: null,
                     approvalMode: null,
                     reimbursementChoice: null,
                 },
@@ -2858,7 +2854,7 @@ function enablePolicyWorkflows(policyID: string, enabled: boolean) {
                     ...(!enabled
                         ? {
                               approvalMode: CONST.POLICY.APPROVAL_MODE.OPTIONAL,
-                              autoReporting: false,
+                              autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT,
                               harvesting: {
                                   enabled: false,
                               },
@@ -2870,7 +2866,7 @@ function enablePolicyWorkflows(policyID: string, enabled: boolean) {
                         ...(!enabled
                             ? {
                                   approvalMode: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
-                                  autoReporting: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
+                                  autoReportingFrequency: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
                                   harvesting: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
                                   reimbursementChoice: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
                               }
@@ -2889,7 +2885,7 @@ function enablePolicyWorkflows(policyID: string, enabled: boolean) {
                         ...(!enabled
                             ? {
                                   approvalMode: null,
-                                  autoReporting: null,
+                                  autoReportingFrequency: null,
                                   harvesting: null,
                                   reimbursementChoice: null,
                               }
@@ -2907,7 +2903,7 @@ function enablePolicyWorkflows(policyID: string, enabled: boolean) {
                     ...(!enabled
                         ? {
                               approvalMode: policy?.approvalMode,
-                              autoReporting: policy?.autoReporting,
+                              autoReportingFrequency: policy?.autoReportingFrequency,
                               harvesting: policy?.harvesting,
                               reimbursementChoice: policy?.reimbursementChoice,
                           }
@@ -2917,7 +2913,7 @@ function enablePolicyWorkflows(policyID: string, enabled: boolean) {
                         ...(!enabled
                             ? {
                                   approvalMode: null,
-                                  autoReporting: null,
+                                  autoReportingFrequency: null,
                                   harvesting: null,
                                   reimbursementChoice: null,
                               }
@@ -3237,7 +3233,6 @@ function upgradeToCorporate(policyID: string, featureName: string) {
                 maxExpenseAmountNoReceipt: CONST.POLICY.DEFAULT_MAX_AMOUNT_NO_RECEIPT,
                 glCodes: true,
                 ...(PolicyUtils.isInstantSubmitEnabled(policy) && {
-                    autoReporting: true,
                     autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.IMMEDIATE,
                 }),
                 harvesting: {
@@ -3268,7 +3263,6 @@ function upgradeToCorporate(policyID: string, featureName: string) {
                 maxExpenseAmount: policy?.maxExpenseAmount ?? null,
                 maxExpenseAmountNoReceipt: policy?.maxExpenseAmountNoReceipt ?? null,
                 glCodes: policy?.glCodes ?? null,
-                autoReporting: policy?.autoReporting ?? null,
                 autoReportingFrequency: policy?.autoReportingFrequency ?? null,
                 harvesting: policy?.harvesting ?? null,
             },
diff --git a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx
index 18b1314c9b1e..05461277115b 100644
--- a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx
+++ b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx
@@ -127,7 +127,7 @@ function WorkspaceWorkflowsPage({policy, betas, route}: WorkspaceWorkflowsPagePr
         }
         const hasReimburserError = !!policy?.errorFields?.reimburser;
         const hasApprovalError = !!policy?.errorFields?.approvalMode;
-        const hasDelayedSubmissionError = !!policy?.errorFields?.autoReporting;
+        const hasDelayedSubmissionError = !!policy?.errorFields?.autoReportingFrequency;
 
         return [
             {
@@ -158,9 +158,9 @@ function WorkspaceWorkflowsPage({policy, betas, route}: WorkspaceWorkflowsPagePr
                     />
                 ),
                 isActive: (policy?.autoReportingFrequency !== CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT && !hasDelayedSubmissionError) ?? false,
-                pendingAction: policy?.pendingFields?.autoReporting,
-                errors: ErrorUtils.getLatestErrorField(policy ?? {}, CONST.POLICY.COLLECTION_KEYS.AUTOREPORTING),
-                onCloseError: () => Policy.clearPolicyErrorField(route.params.policyID, CONST.POLICY.COLLECTION_KEYS.AUTOREPORTING),
+                pendingAction: policy?.pendingFields?.autoReportingFrequency,
+                errors: ErrorUtils.getLatestErrorField(policy ?? {}, CONST.POLICY.COLLECTION_KEYS.AUTOREPORTING_FREQUENCY),
+                onCloseError: () => Policy.clearPolicyErrorField(route.params.policyID, CONST.POLICY.COLLECTION_KEYS.AUTOREPORTING_FREQUENCY),
             },
             {
                 title: translate('workflowsPage.addApprovalsTitle'),
diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts
index 8f48205d8749..a3c468795958 100644
--- a/src/types/onyx/Policy.ts
+++ b/src/types/onyx/Policy.ts
@@ -1391,9 +1391,6 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback<
         /** Whether policy expense chats can be created and used on this policy. Enabled manually by CQ/JS snippet. Always true for free policies. */
         isPolicyExpenseChatEnabled: boolean;
 
-        /** Whether the auto reporting is enabled */
-        autoReporting?: boolean;
-
         /**
          * The scheduled submit frequency set up on this policy.
          * Note that manual does not exist in the DB and thus should not exist in Onyx, only as a param for the API.

From 6a85eaf51172916d626b728a9b9b9dab173b5e9e Mon Sep 17 00:00:00 2001
From: Abdelrahman Khattab <abzokhattab@gmail.com>
Date: Thu, 15 Aug 2024 07:04:31 +0300
Subject: [PATCH 2/6] ts fix

---
 tests/unit/ReportUtilsTest.ts       | 1 -
 tests/utils/LHNTestUtils.tsx        | 1 -
 tests/utils/collections/policies.ts | 1 -
 3 files changed, 3 deletions(-)

diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts
index 12bcabc92b19..cdaa0b84a633 100644
--- a/tests/unit/ReportUtilsTest.ts
+++ b/tests/unit/ReportUtilsTest.ts
@@ -656,7 +656,6 @@ describe('ReportUtils', () => {
                 const paidPolicy: Policy = {
                     id: 'ef72dfeb',
                     type: CONST.POLICY.TYPE.TEAM,
-                    autoReporting: true,
                     autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT,
                     name: '',
                     role: 'user',
diff --git a/tests/utils/LHNTestUtils.tsx b/tests/utils/LHNTestUtils.tsx
index 7197529cd43c..e2c83b8e234c 100644
--- a/tests/utils/LHNTestUtils.tsx
+++ b/tests/utils/LHNTestUtils.tsx
@@ -214,7 +214,6 @@ function getFakePolicy(id = '1', name = 'Workspace-Test-001'): Policy {
         employeeList: {},
         isPolicyExpenseChatEnabled: true,
         lastModified: '1697323926777105',
-        autoReporting: true,
         autoReportingFrequency: 'immediate',
         harvesting: {
             enabled: true,
diff --git a/tests/utils/collections/policies.ts b/tests/utils/collections/policies.ts
index 47bf996afb7e..b8fb3aa3c12e 100644
--- a/tests/utils/collections/policies.ts
+++ b/tests/utils/collections/policies.ts
@@ -8,7 +8,6 @@ export default function createRandomPolicy(index: number): Policy {
         id: index.toString(),
         name: randWord(),
         type: rand(Object.values(CONST.POLICY.TYPE)),
-        autoReporting: randBoolean(),
         isPolicyExpenseChatEnabled: randBoolean(),
         autoReportingFrequency: rand(
             Object.values(CONST.POLICY.AUTO_REPORTING_FREQUENCIES).filter(

From 520cde45afd813eff9703d50fcb95b7198c67e8c Mon Sep 17 00:00:00 2001
From: Abdelrahman Khattab <abzokhattab@gmail.com>
Date: Sun, 18 Aug 2024 05:12:20 +0300
Subject: [PATCH 3/6] Revert "Fix/Delay submissions option is not grayed when
 clicking offline"

This reverts commit fc5e522fa2a891bcadb5bf1291227c4f5b3bd4fe.
---
 src/CONST.ts                                  |  1 +
 src/libs/PolicyUtils.ts                       |  2 +-
 src/libs/actions/Policy/Policy.ts             | 28 +++++++++++--------
 .../workflows/WorkspaceWorkflowsPage.tsx      |  8 +++---
 src/types/onyx/Policy.ts                      |  3 ++
 5 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/src/CONST.ts b/src/CONST.ts
index ca9e4ea1bfcc..f1e4a3bb46d5 100755
--- a/src/CONST.ts
+++ b/src/CONST.ts
@@ -2117,6 +2117,7 @@ const CONST = {
             REIMBURSER: 'reimburser',
             REIMBURSEMENT_CHOICE: 'reimbursementChoice',
             APPROVAL_MODE: 'approvalMode',
+            AUTOREPORTING: 'autoReporting',
             AUTOREPORTING_FREQUENCY: 'autoReportingFrequency',
             AUTOREPORTING_OFFSET: 'autoReportingOffset',
             GENERAL_SETTINGS: 'generalSettings',
diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts
index 77a084305978..3f3a2a96a1e1 100644
--- a/src/libs/PolicyUtils.ts
+++ b/src/libs/PolicyUtils.ts
@@ -361,7 +361,7 @@ function isTaxTrackingEnabled(isPolicyExpenseChat: boolean, policy: OnyxEntry<Po
  * Note: Free policies have "instant" submit always enabled.
  */
 function isInstantSubmitEnabled(policy: OnyxInputOrEntry<Policy>): boolean {
-    return policy?.type === CONST.POLICY.TYPE.FREE || policy?.autoReportingFrequency === CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT;
+    return policy?.type === CONST.POLICY.TYPE.FREE || (policy?.autoReporting === true && policy?.autoReportingFrequency === CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT);
 }
 
 /**
diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts
index 4de784cb6e38..d914e47e5204 100644
--- a/src/libs/actions/Policy/Policy.ts
+++ b/src/libs/actions/Policy/Policy.ts
@@ -1504,6 +1504,7 @@ function createDraftInitialWorkspace(policyOwnerEmail = '', policyName = '', pol
                 pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
                 customUnits,
                 makeMeAdmin,
+                autoReporting: true,
                 autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT,
                 employeeList: {
                     [sessionEmail]: {
@@ -1516,7 +1517,7 @@ function createDraftInitialWorkspace(policyOwnerEmail = '', policyName = '', pol
                     enabled: true,
                 },
                 pendingFields: {
-                    autoReportingFrequency: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
+                    autoReporting: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
                     approvalMode: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
                     reimbursementChoice: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
                 },
@@ -1572,6 +1573,7 @@ function buildPolicyData(policyOwnerEmail = '', makeMeAdmin = false, policyName
                 isPolicyExpenseChatEnabled: true,
                 outputCurrency,
                 pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
+                autoReporting: true,
                 autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT,
                 approvalMode: CONST.POLICY.APPROVAL_MODE.OPTIONAL,
                 harvesting: {
@@ -1592,7 +1594,7 @@ function buildPolicyData(policyOwnerEmail = '', makeMeAdmin = false, policyName
                 },
                 chatReportIDAdmins: makeMeAdmin ? Number(adminsChatReportID) : undefined,
                 pendingFields: {
-                    autoReportingFrequency: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
+                    autoReporting: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
                     approvalMode: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
                     reimbursementChoice: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
                     generalSettings: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
@@ -1669,7 +1671,7 @@ function buildPolicyData(policyOwnerEmail = '', makeMeAdmin = false, policyName
             value: {
                 pendingAction: null,
                 pendingFields: {
-                    autoReportingFrequency: null,
+                    autoReporting: null,
                     approvalMode: null,
                     reimbursementChoice: null,
                 },
@@ -1849,6 +1851,7 @@ function createDraftWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policy
                 isPolicyExpenseChatEnabled: true,
                 outputCurrency,
                 pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
+                autoReporting: true,
                 autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT,
                 approvalMode: CONST.POLICY.APPROVAL_MODE.OPTIONAL,
                 harvesting: {
@@ -1869,7 +1872,7 @@ function createDraftWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policy
                 },
                 chatReportIDAdmins: makeMeAdmin ? Number(adminsChatReportID) : undefined,
                 pendingFields: {
-                    autoReportingFrequency: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
+                    autoReporting: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
                     approvalMode: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
                     reimbursementChoice: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
                 },
@@ -2190,6 +2193,7 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry<Report>): WorkspaceF
         // Setting the currency to USD as we can only add the VBBA for this policy currency right now
         outputCurrency: CONST.CURRENCY.USD,
         pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
+        autoReporting: true,
         autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT,
         approvalMode: CONST.POLICY.APPROVAL_MODE.OPTIONAL,
         harvesting: {
@@ -2213,7 +2217,7 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry<Report>): WorkspaceF
             },
         },
         pendingFields: {
-            autoReportingFrequency: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
+            autoReporting: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
             approvalMode: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
             reimbursementChoice: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
         },
@@ -2290,7 +2294,7 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry<Report>): WorkspaceF
             value: {
                 pendingAction: null,
                 pendingFields: {
-                    autoReportingFrequency: null,
+                    autoReporting: null,
                     approvalMode: null,
                     reimbursementChoice: null,
                 },
@@ -2854,7 +2858,7 @@ function enablePolicyWorkflows(policyID: string, enabled: boolean) {
                     ...(!enabled
                         ? {
                               approvalMode: CONST.POLICY.APPROVAL_MODE.OPTIONAL,
-                              autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT,
+                              autoReporting: false,
                               harvesting: {
                                   enabled: false,
                               },
@@ -2866,7 +2870,7 @@ function enablePolicyWorkflows(policyID: string, enabled: boolean) {
                         ...(!enabled
                             ? {
                                   approvalMode: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
-                                  autoReportingFrequency: 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,
                               }
@@ -2885,7 +2889,7 @@ function enablePolicyWorkflows(policyID: string, enabled: boolean) {
                         ...(!enabled
                             ? {
                                   approvalMode: null,
-                                  autoReportingFrequency: null,
+                                  autoReporting: null,
                                   harvesting: null,
                                   reimbursementChoice: null,
                               }
@@ -2903,7 +2907,7 @@ function enablePolicyWorkflows(policyID: string, enabled: boolean) {
                     ...(!enabled
                         ? {
                               approvalMode: policy?.approvalMode,
-                              autoReportingFrequency: policy?.autoReportingFrequency,
+                              autoReporting: policy?.autoReporting,
                               harvesting: policy?.harvesting,
                               reimbursementChoice: policy?.reimbursementChoice,
                           }
@@ -2913,7 +2917,7 @@ function enablePolicyWorkflows(policyID: string, enabled: boolean) {
                         ...(!enabled
                             ? {
                                   approvalMode: null,
-                                  autoReportingFrequency: null,
+                                  autoReporting: null,
                                   harvesting: null,
                                   reimbursementChoice: null,
                               }
@@ -3233,6 +3237,7 @@ function upgradeToCorporate(policyID: string, featureName: string) {
                 maxExpenseAmountNoReceipt: CONST.POLICY.DEFAULT_MAX_AMOUNT_NO_RECEIPT,
                 glCodes: true,
                 ...(PolicyUtils.isInstantSubmitEnabled(policy) && {
+                    autoReporting: true,
                     autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.IMMEDIATE,
                 }),
                 harvesting: {
@@ -3263,6 +3268,7 @@ function upgradeToCorporate(policyID: string, featureName: string) {
                 maxExpenseAmount: policy?.maxExpenseAmount ?? null,
                 maxExpenseAmountNoReceipt: policy?.maxExpenseAmountNoReceipt ?? null,
                 glCodes: policy?.glCodes ?? null,
+                autoReporting: policy?.autoReporting ?? null,
                 autoReportingFrequency: policy?.autoReportingFrequency ?? null,
                 harvesting: policy?.harvesting ?? null,
             },
diff --git a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx
index 05461277115b..18b1314c9b1e 100644
--- a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx
+++ b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx
@@ -127,7 +127,7 @@ function WorkspaceWorkflowsPage({policy, betas, route}: WorkspaceWorkflowsPagePr
         }
         const hasReimburserError = !!policy?.errorFields?.reimburser;
         const hasApprovalError = !!policy?.errorFields?.approvalMode;
-        const hasDelayedSubmissionError = !!policy?.errorFields?.autoReportingFrequency;
+        const hasDelayedSubmissionError = !!policy?.errorFields?.autoReporting;
 
         return [
             {
@@ -158,9 +158,9 @@ function WorkspaceWorkflowsPage({policy, betas, route}: WorkspaceWorkflowsPagePr
                     />
                 ),
                 isActive: (policy?.autoReportingFrequency !== CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT && !hasDelayedSubmissionError) ?? false,
-                pendingAction: policy?.pendingFields?.autoReportingFrequency,
-                errors: ErrorUtils.getLatestErrorField(policy ?? {}, CONST.POLICY.COLLECTION_KEYS.AUTOREPORTING_FREQUENCY),
-                onCloseError: () => Policy.clearPolicyErrorField(route.params.policyID, CONST.POLICY.COLLECTION_KEYS.AUTOREPORTING_FREQUENCY),
+                pendingAction: policy?.pendingFields?.autoReporting,
+                errors: ErrorUtils.getLatestErrorField(policy ?? {}, CONST.POLICY.COLLECTION_KEYS.AUTOREPORTING),
+                onCloseError: () => Policy.clearPolicyErrorField(route.params.policyID, CONST.POLICY.COLLECTION_KEYS.AUTOREPORTING),
             },
             {
                 title: translate('workflowsPage.addApprovalsTitle'),
diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts
index a3c468795958..8f48205d8749 100644
--- a/src/types/onyx/Policy.ts
+++ b/src/types/onyx/Policy.ts
@@ -1391,6 +1391,9 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback<
         /** Whether policy expense chats can be created and used on this policy. Enabled manually by CQ/JS snippet. Always true for free policies. */
         isPolicyExpenseChatEnabled: boolean;
 
+        /** Whether the auto reporting is enabled */
+        autoReporting?: boolean;
+
         /**
          * The scheduled submit frequency set up on this policy.
          * Note that manual does not exist in the DB and thus should not exist in Onyx, only as a param for the API.

From 81463760c332ba28e1156bc37fd685fb9bb4871d Mon Sep 17 00:00:00 2001
From: Abdelrahman Khattab <abzokhattab@gmail.com>
Date: Sun, 18 Aug 2024 05:12:27 +0300
Subject: [PATCH 4/6] Revert "ts fix"

This reverts commit 6a85eaf51172916d626b728a9b9b9dab173b5e9e.
---
 tests/unit/ReportUtilsTest.ts       | 1 +
 tests/utils/LHNTestUtils.tsx        | 1 +
 tests/utils/collections/policies.ts | 1 +
 3 files changed, 3 insertions(+)

diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts
index cdaa0b84a633..12bcabc92b19 100644
--- a/tests/unit/ReportUtilsTest.ts
+++ b/tests/unit/ReportUtilsTest.ts
@@ -656,6 +656,7 @@ describe('ReportUtils', () => {
                 const paidPolicy: Policy = {
                     id: 'ef72dfeb',
                     type: CONST.POLICY.TYPE.TEAM,
+                    autoReporting: true,
                     autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT,
                     name: '',
                     role: 'user',
diff --git a/tests/utils/LHNTestUtils.tsx b/tests/utils/LHNTestUtils.tsx
index e2c83b8e234c..7197529cd43c 100644
--- a/tests/utils/LHNTestUtils.tsx
+++ b/tests/utils/LHNTestUtils.tsx
@@ -214,6 +214,7 @@ function getFakePolicy(id = '1', name = 'Workspace-Test-001'): Policy {
         employeeList: {},
         isPolicyExpenseChatEnabled: true,
         lastModified: '1697323926777105',
+        autoReporting: true,
         autoReportingFrequency: 'immediate',
         harvesting: {
             enabled: true,
diff --git a/tests/utils/collections/policies.ts b/tests/utils/collections/policies.ts
index b8fb3aa3c12e..47bf996afb7e 100644
--- a/tests/utils/collections/policies.ts
+++ b/tests/utils/collections/policies.ts
@@ -8,6 +8,7 @@ export default function createRandomPolicy(index: number): Policy {
         id: index.toString(),
         name: randWord(),
         type: rand(Object.values(CONST.POLICY.TYPE)),
+        autoReporting: randBoolean(),
         isPolicyExpenseChatEnabled: randBoolean(),
         autoReportingFrequency: rand(
             Object.values(CONST.POLICY.AUTO_REPORTING_FREQUENCIES).filter(

From fc8b460893862270ba023e565e6ed3b140006451 Mon Sep 17 00:00:00 2001
From: Abdelrahman Khattab <abzokhattab@gmail.com>
Date: Sun, 18 Aug 2024 05:19:08 +0300
Subject: [PATCH 5/6] adding the autoReportingFrequency as a fallback for the
 pending action check

---
 Gemfile.lock                                  | 26 ++++++++++++-------
 .../workflows/WorkspaceWorkflowsPage.tsx      |  4 +--
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/Gemfile.lock b/Gemfile.lock
index 12cae5d0eb21..bf724be4edf9 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -5,11 +5,12 @@ GEM
       base64
       nkf
       rexml
-    activesupport (7.0.8.4)
+    activesupport (6.1.7.8)
       concurrent-ruby (~> 1.0, >= 1.0.2)
       i18n (>= 1.6, < 2)
       minitest (>= 5.1)
       tzinfo (~> 2.0)
+      zeitwerk (~> 2.3)
     addressable (2.8.7)
       public_suffix (>= 2.0.2, < 7.0)
     algoliasearch (1.27.5)
@@ -83,13 +84,14 @@ GEM
     declarative (0.0.20)
     digest-crc (0.6.5)
       rake (>= 12.0.0, < 14.0.0)
-    domain_name (0.6.20240107)
+    domain_name (0.5.20190701)
+      unf (>= 0.0.5, < 1.0.0)
     dotenv (2.8.1)
     emoji_regex (3.2.3)
     escape (0.0.4)
     ethon (0.16.0)
       ffi (>= 1.15.0)
-    excon (0.111.0)
+    excon (0.109.0)
     faraday (1.10.3)
       faraday-em_http (~> 1.0)
       faraday-em_synchrony (~> 1.0)
@@ -185,19 +187,19 @@ GEM
       google-apis-core (>= 0.11.0, < 2.a)
     google-apis-playcustomapp_v1 (0.13.0)
       google-apis-core (>= 0.11.0, < 2.a)
-    google-apis-storage_v1 (0.31.0)
+    google-apis-storage_v1 (0.32.0)
       google-apis-core (>= 0.11.0, < 2.a)
-    google-cloud-core (1.7.0)
+    google-cloud-core (1.6.1)
       google-cloud-env (>= 1.0, < 3.a)
       google-cloud-errors (~> 1.0)
     google-cloud-env (1.6.0)
       faraday (>= 0.17.3, < 3.0)
-    google-cloud-errors (1.4.0)
-    google-cloud-storage (1.47.0)
+    google-cloud-errors (1.3.1)
+    google-cloud-storage (1.37.0)
       addressable (~> 2.8)
       digest-crc (~> 0.4)
       google-apis-iamcredentials_v1 (~> 0.1)
-      google-apis-storage_v1 (~> 0.31.0)
+      google-apis-storage_v1 (~> 0.1)
       google-cloud-core (~> 1.6)
       googleauth (>= 0.16.2, < 2.a)
       mini_mime (~> 1.0)
@@ -248,7 +250,7 @@ GEM
     ruby2_keywords (0.0.5)
     rubyzip (2.3.2)
     security (0.1.5)
-    signet (0.19.0)
+    signet (0.18.0)
       addressable (~> 2.8)
       faraday (>= 0.17.5, < 3.a)
       jwt (>= 1.5, < 3.0)
@@ -270,6 +272,9 @@ GEM
     tzinfo (2.0.6)
       concurrent-ruby (~> 1.0)
     uber (0.1.0)
+    unf (0.1.4)
+      unf_ext
+    unf_ext (0.0.9.1)
     unicode-display_width (2.5.0)
     word_wrap (1.0.0)
     xcodeproj (1.24.0)
@@ -283,6 +288,7 @@ GEM
       rouge (~> 2.0.7)
     xcpretty-travis-formatter (1.0.1)
       xcpretty (~> 0.2, >= 0.0.7)
+    zeitwerk (2.6.17)
 
 PLATFORMS
   arm64-darwin-21
@@ -302,4 +308,4 @@ RUBY VERSION
    ruby 2.6.10p210
 
 BUNDLED WITH
-   2.4.14
+   2.4.19
diff --git a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx
index 18b1314c9b1e..23f341d308e2 100644
--- a/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx
+++ b/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx
@@ -127,7 +127,7 @@ function WorkspaceWorkflowsPage({policy, betas, route}: WorkspaceWorkflowsPagePr
         }
         const hasReimburserError = !!policy?.errorFields?.reimburser;
         const hasApprovalError = !!policy?.errorFields?.approvalMode;
-        const hasDelayedSubmissionError = !!policy?.errorFields?.autoReporting;
+        const hasDelayedSubmissionError = !!policy?.errorFields?.autoReporting ?? !!policy?.errorFields?.autoReportingFrequency;
 
         return [
             {
@@ -158,7 +158,7 @@ function WorkspaceWorkflowsPage({policy, betas, route}: WorkspaceWorkflowsPagePr
                     />
                 ),
                 isActive: (policy?.autoReportingFrequency !== CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT && !hasDelayedSubmissionError) ?? false,
-                pendingAction: policy?.pendingFields?.autoReporting,
+                pendingAction: policy?.pendingFields?.autoReporting ?? policy?.pendingFields?.autoReportingFrequency,
                 errors: ErrorUtils.getLatestErrorField(policy ?? {}, CONST.POLICY.COLLECTION_KEYS.AUTOREPORTING),
                 onCloseError: () => Policy.clearPolicyErrorField(route.params.policyID, CONST.POLICY.COLLECTION_KEYS.AUTOREPORTING),
             },

From f99d098f0588e68ddbbd81d4ff8d4a7b376b96ba Mon Sep 17 00:00:00 2001
From: Abdelrahman Khattab <59809993+abzokhattab@users.noreply.github.com>
Date: Wed, 21 Aug 2024 21:36:18 +0200
Subject: [PATCH 6/6] R Gemfile.lock

---
 Gemfile.lock | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/Gemfile.lock b/Gemfile.lock
index bf724be4edf9..12cae5d0eb21 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -5,12 +5,11 @@ GEM
       base64
       nkf
       rexml
-    activesupport (6.1.7.8)
+    activesupport (7.0.8.4)
       concurrent-ruby (~> 1.0, >= 1.0.2)
       i18n (>= 1.6, < 2)
       minitest (>= 5.1)
       tzinfo (~> 2.0)
-      zeitwerk (~> 2.3)
     addressable (2.8.7)
       public_suffix (>= 2.0.2, < 7.0)
     algoliasearch (1.27.5)
@@ -84,14 +83,13 @@ GEM
     declarative (0.0.20)
     digest-crc (0.6.5)
       rake (>= 12.0.0, < 14.0.0)
-    domain_name (0.5.20190701)
-      unf (>= 0.0.5, < 1.0.0)
+    domain_name (0.6.20240107)
     dotenv (2.8.1)
     emoji_regex (3.2.3)
     escape (0.0.4)
     ethon (0.16.0)
       ffi (>= 1.15.0)
-    excon (0.109.0)
+    excon (0.111.0)
     faraday (1.10.3)
       faraday-em_http (~> 1.0)
       faraday-em_synchrony (~> 1.0)
@@ -187,19 +185,19 @@ GEM
       google-apis-core (>= 0.11.0, < 2.a)
     google-apis-playcustomapp_v1 (0.13.0)
       google-apis-core (>= 0.11.0, < 2.a)
-    google-apis-storage_v1 (0.32.0)
+    google-apis-storage_v1 (0.31.0)
       google-apis-core (>= 0.11.0, < 2.a)
-    google-cloud-core (1.6.1)
+    google-cloud-core (1.7.0)
       google-cloud-env (>= 1.0, < 3.a)
       google-cloud-errors (~> 1.0)
     google-cloud-env (1.6.0)
       faraday (>= 0.17.3, < 3.0)
-    google-cloud-errors (1.3.1)
-    google-cloud-storage (1.37.0)
+    google-cloud-errors (1.4.0)
+    google-cloud-storage (1.47.0)
       addressable (~> 2.8)
       digest-crc (~> 0.4)
       google-apis-iamcredentials_v1 (~> 0.1)
-      google-apis-storage_v1 (~> 0.1)
+      google-apis-storage_v1 (~> 0.31.0)
       google-cloud-core (~> 1.6)
       googleauth (>= 0.16.2, < 2.a)
       mini_mime (~> 1.0)
@@ -250,7 +248,7 @@ GEM
     ruby2_keywords (0.0.5)
     rubyzip (2.3.2)
     security (0.1.5)
-    signet (0.18.0)
+    signet (0.19.0)
       addressable (~> 2.8)
       faraday (>= 0.17.5, < 3.a)
       jwt (>= 1.5, < 3.0)
@@ -272,9 +270,6 @@ GEM
     tzinfo (2.0.6)
       concurrent-ruby (~> 1.0)
     uber (0.1.0)
-    unf (0.1.4)
-      unf_ext
-    unf_ext (0.0.9.1)
     unicode-display_width (2.5.0)
     word_wrap (1.0.0)
     xcodeproj (1.24.0)
@@ -288,7 +283,6 @@ GEM
       rouge (~> 2.0.7)
     xcpretty-travis-formatter (1.0.1)
       xcpretty (~> 0.2, >= 0.0.7)
-    zeitwerk (2.6.17)
 
 PLATFORMS
   arm64-darwin-21
@@ -308,4 +302,4 @@ RUBY VERSION
    ruby 2.6.10p210
 
 BUNDLED WITH
-   2.4.19
+   2.4.14
