diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index f4c125b79ba2..1b4cd65de03f 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, @@ -417,37 +416,6 @@ Onyx.connect({ callback: (value) => (allReportDraftComments = 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, @@ -5374,7 +5342,7 @@ function moveIOUReportToPolicyAndInviteSubmitter( role, email: submitterLogin, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - submitsTo: getDefaultApprover(allPolicies?.[policyKey]), + submitsTo: getDefaultApprover(policy), }, };