From f34f1abd17cdeb1b80084aaadb9a6656182f169c Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Tue, 28 Oct 2025 23:28:58 +0530 Subject: [PATCH] Refactored moveIOUReportToPolicyAndInviteSubmitter to pure function --- src/libs/actions/Report.ts | 34 +--------------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 2e688ea78a95..6ae0a10ae48b 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -121,7 +121,6 @@ import { findSelfDMReportID, formatReportLastMessageText, generateReportID, - getAllPolicyReports, getChatByParticipants, getChildReportNotificationPreference, getDefaultNotificationPreferenceForReport, @@ -425,37 +424,6 @@ Onyx.connect({ callback: (value) => (nvpDismissedProductTraining = value), }); -const allPolicies: OnyxCollection = {}; -Onyx.connect({ - key: ONYXKEYS.COLLECTION.POLICY, - callback: (val, key) => { - if (!key) { - return; - } - if (val === null || val === undefined) { - // If we are deleting a policy, we have to check every report linked to that policy - // and unset the draft indicator (pencil icon) alongside removing any draft comments. Clearing these values will keep the newly archived chats from being displayed in the LHN. - // More info: https://github.com/Expensify/App/issues/14260 - const policyID = key.replace(ONYXKEYS.COLLECTION.POLICY, ''); - const policyReports = getAllPolicyReports(policyID); - const cleanUpSetQueries: Record<`${typeof ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${string}` | `${typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${string}`, null> = {}; - policyReports.forEach((policyReport) => { - if (!policyReport) { - return; - } - const {reportID} = policyReport; - cleanUpSetQueries[`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`] = null; - cleanUpSetQueries[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${reportID}`] = null; - }); - Onyx.multiSet(cleanUpSetQueries); - delete allPolicies[key]; - return; - } - - allPolicies[key] = val; - }, -}); - let allTransactions: OnyxCollection = {}; Onyx.connect({ key: ONYXKEYS.COLLECTION.TRANSACTION, @@ -5381,7 +5349,7 @@ function moveIOUReportToPolicyAndInviteSubmitter( role, email: submitterLogin, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - submitsTo: getDefaultApprover(allPolicies?.[policyKey]), + submitsTo: getDefaultApprover(policy), }, };