diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index ace8f547b75c..0f07ca1927ec 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1286,12 +1286,9 @@ function isClosedExpenseReportWithNoExpenses(report: OnyxEntry): boolean /** * Whether the provided report is an archived room */ +// eslint-disable-next-line @typescript-eslint/no-unused-vars function isArchivedRoom(report: OnyxInputOrEntry, reportNameValuePairs?: OnyxInputOrEntry): boolean { - if (reportNameValuePairs) { - return reportNameValuePairs.private_isArchived; - } - - return report?.statusNum === CONST.REPORT.STATUS_NUM.CLOSED && report?.stateNum === CONST.REPORT.STATE_NUM.APPROVED; + return !!report?.private_isArchived; } /** diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index e6d2e35dd8c1..c5be4b6074a7 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -260,6 +260,7 @@ function deleteWorkspace(policyID: string, policyName: string) { (report) => report?.policyID === policyID && (ReportUtils.isChatRoom(report) || ReportUtils.isPolicyExpenseChat(report) || ReportUtils.isTaskReport(report)), ); const finallyData: OnyxUpdate[] = []; + const currentTime = DateUtils.getDBTime(); reportsToArchive.forEach((report) => { const {reportID, ownerAccountID} = report ?? {}; optimisticData.push({ @@ -270,6 +271,8 @@ function deleteWorkspace(policyID: string, policyName: string) { statusNum: CONST.REPORT.STATUS_NUM.CLOSED, oldPolicyName: allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]?.name ?? '', policyName: '', + // eslint-disable-next-line @typescript-eslint/naming-convention + private_isArchived: currentTime, }, }); diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index 49897928ffe9..0af6a4387adf 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -203,6 +203,8 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro visibility: reportOnyx?.visibility, oldPolicyName: reportOnyx?.oldPolicyName, policyName: reportOnyx?.policyName, + // eslint-disable-next-line @typescript-eslint/naming-convention + private_isArchived: reportOnyx?.private_isArchived, isOptimisticReport: reportOnyx?.isOptimisticReport, lastMentionedTime: reportOnyx?.lastMentionedTime, avatarUrl: reportOnyx?.avatarUrl, @@ -244,6 +246,7 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro reportOnyx?.visibility, reportOnyx?.oldPolicyName, reportOnyx?.policyName, + reportOnyx?.private_isArchived, reportOnyx?.isOptimisticReport, reportOnyx?.lastMentionedTime, reportOnyx?.avatarUrl, diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index b5d0a0a15d13..14fd2bd3ac81 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -289,6 +289,10 @@ type Report = OnyxCommon.OnyxValueWithOfflineFeedback< /** The trip ID in spotnana */ tripID: string; }; + + /** Whether the report is archived */ + // eslint-disable-next-line @typescript-eslint/naming-convention + private_isArchived?: string; }, PolicyReportField['fieldID'] >; diff --git a/tests/unit/OptionsListUtilsTest.ts b/tests/unit/OptionsListUtilsTest.ts index 4a1171658f4d..79f19649f337 100644 --- a/tests/unit/OptionsListUtilsTest.ts +++ b/tests/unit/OptionsListUtilsTest.ts @@ -2,6 +2,7 @@ import type {OnyxCollection} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import type {SelectedTagOption} from '@components/TagPicker'; +import DateUtils from '@libs/DateUtils'; import CONST from '@src/CONST'; import * as OptionsListUtils from '@src/libs/OptionsListUtils'; import * as ReportUtils from '@src/libs/ReportUtils'; @@ -153,6 +154,8 @@ describe('OptionsListUtils', () => { // This indicates that the report is archived stateNum: 2, statusNum: 2, + // eslint-disable-next-line @typescript-eslint/naming-convention + private_isArchived: DateUtils.getDBTime(), }, }; diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 34a9a923bd61..14c710c6ddf2 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -2,6 +2,7 @@ import {addDays, format as formatDate, subDays} from 'date-fns'; import type {OnyxEntry} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; +import DateUtils from '@libs/DateUtils'; import * as ReportUtils from '@libs/ReportUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -166,6 +167,8 @@ describe('ReportUtils', () => { ...baseAdminsRoom, statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, + // eslint-disable-next-line @typescript-eslint/naming-convention + private_isArchived: DateUtils.getDBTime(), }; expect(ReportUtils.getReportName(archivedAdminsRoom)).toBe('#admins (archived)'); @@ -190,6 +193,8 @@ describe('ReportUtils', () => { ...baseUserCreatedRoom, statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, + // eslint-disable-next-line @typescript-eslint/naming-convention + private_isArchived: DateUtils.getDBTime(), }; expect(ReportUtils.getReportName(archivedPolicyRoom)).toBe('#VikingsChat (archived)'); @@ -234,6 +239,8 @@ describe('ReportUtils', () => { oldPolicyName: policy.name, statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, + // eslint-disable-next-line @typescript-eslint/naming-convention + private_isArchived: DateUtils.getDBTime(), }; test('as member', () => { diff --git a/tests/unit/SidebarOrderTest.ts b/tests/unit/SidebarOrderTest.ts index 41e85c4fdd78..c8b885f98205 100644 --- a/tests/unit/SidebarOrderTest.ts +++ b/tests/unit/SidebarOrderTest.ts @@ -812,6 +812,8 @@ describe('Sidebar', () => { chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, + // eslint-disable-next-line @typescript-eslint/naming-convention + private_isArchived: DateUtils.getDBTime(), }; const report2 = LHNTestUtils.getFakeReport([3, 4]); const report3 = LHNTestUtils.getFakeReport([5, 6]); @@ -919,6 +921,8 @@ describe('Sidebar', () => { statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, lastMessageText: 'test', + // eslint-disable-next-line @typescript-eslint/naming-convention + private_isArchived: DateUtils.getDBTime(), }; const report2 = { ...LHNTestUtils.getFakeReport([3, 4], 2, true), diff --git a/tests/unit/SidebarTest.ts b/tests/unit/SidebarTest.ts index 4c585f29bc61..f9b258228937 100644 --- a/tests/unit/SidebarTest.ts +++ b/tests/unit/SidebarTest.ts @@ -1,5 +1,6 @@ import {screen} from '@testing-library/react-native'; import Onyx from 'react-native-onyx'; +import DateUtils from '@libs/DateUtils'; import CONST from '@src/CONST'; import * as Localize from '@src/libs/Localize'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -42,6 +43,8 @@ describe('Sidebar', () => { chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, + // eslint-disable-next-line @typescript-eslint/naming-convention + private_isArchived: DateUtils.getDBTime(), lastMessageText: 'test', }; @@ -95,6 +98,8 @@ describe('Sidebar', () => { chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, + // eslint-disable-next-line @typescript-eslint/naming-convention + private_isArchived: DateUtils.getDBTime(), lastMessageText: 'test', }; const action = {