From 50c127efabaab0dba4b7aebe52a5624eabb611c7 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Fri, 13 Jun 2025 00:40:26 +0300 Subject: [PATCH 01/17] refactor --- src/libs/ReportUtils.ts | 5 ++--- tests/unit/ReportUtilsTest.ts | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index fb0dc176ab66..ab2390304b4f 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -8702,10 +8702,9 @@ function canEditWriteCapability(report: OnyxEntry, policy: OnyxEntry, policy: OnyxEntry): boolean { +function canEditRoomVisibility(report: OnyxEntry, policy: OnyxEntry, isReportArchived: boolean = false): boolean { // This will get removed as part of https://github.com/Expensify/App/issues/59961 - // eslint-disable-next-line deprecation/deprecation - return isPolicyAdminPolicyUtils(policy) && !isArchivedNonExpenseReport(report, getReportNameValuePairs(report?.reportID)); + return !isReportArchived && isPolicyAdminPolicyUtils(policy) } /** diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index c6ad307cada7..a8c9c37a4bbd 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -23,6 +23,7 @@ import { canDeleteTransaction, canEditReportDescription, canEditWriteCapability, + canEditRoomVisibility, canHoldUnholdReportAction, findLastAccessedReport, getAllAncestorReportActions, @@ -2287,6 +2288,29 @@ describe('ReportUtils', () => { }); }); + describe('canEditRoomVisibility', () => { + it('should return true for policy admins', () => { + const workspaceChat: Report = { + ...createRandomReport(1), + chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, + }; + expect(canEditRoomVisibility(workspaceChat, {...policy, role: CONST.POLICY.ROLE.ADMIN})).toBe(true); + expect(canEditRoomVisibility(workspaceChat, {...policy, role: CONST.POLICY.ROLE.AUDITOR})).toBe(false); + expect(canEditRoomVisibility(workspaceChat, {...policy, role: CONST.POLICY.ROLE.USER})).toBe(false); + }); + + it('should return false if policy expense chat is archived', () => { + const workspaceChat: Report = { + ...createRandomReport(1), + chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, + }; + expect(canEditRoomVisibility(workspaceChat, {...policy, role: CONST.POLICY.ROLE.ADMIN}, true)).toBe(false); + expect(canEditRoomVisibility(workspaceChat, {...policy, role: CONST.POLICY.ROLE.AUDITOR}, true)).toBe(false); + expect(canEditRoomVisibility(workspaceChat, {...policy, role: CONST.POLICY.ROLE.USER}, true)).toBe(false); + + }); + }); + describe('canDeleteReportAction', () => { it('should return false for delete button visibility if transaction is not allowed to be deleted', () => { const parentReport = LHNTestUtils.getFakeReport(); From 9c419b67ab718690dfffdd1b633fdb3bf75d3335 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Fri, 13 Jun 2025 23:01:38 +0300 Subject: [PATCH 02/17] refactoring canEditRoomVisibility params --- src/libs/ReportUtils.ts | 3 ++- .../settings/Report/ReportSettingsPage.tsx | 5 +++-- tests/unit/ReportUtilsTest.ts | 22 ++++++------------- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index f970b9b19f07..6aa8499ae1aa 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -8722,8 +8722,9 @@ function canEditWriteCapability(report: OnyxEntry, policy: OnyxEntry, policy: OnyxEntry, isReportArchived: boolean = false): boolean { +function canEditRoomVisibility(policy: OnyxEntry, isReportArchived: boolean = false): boolean { // This will get removed as part of https://github.com/Expensify/App/issues/59961 return !isReportArchived && isPolicyAdminPolicyUtils(policy) } diff --git a/src/pages/settings/Report/ReportSettingsPage.tsx b/src/pages/settings/Report/ReportSettingsPage.tsx index d1e94b9af7e6..794ad21cbfe1 100644 --- a/src/pages/settings/Report/ReportSettingsPage.tsx +++ b/src/pages/settings/Report/ReportSettingsPage.tsx @@ -9,6 +9,7 @@ import ScrollView from '@components/ScrollView'; import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; +import useReportIsArchived from '@hooks/useReportIsArchived'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import * as ReportUtils from '@libs/ReportUtils'; @@ -32,7 +33,7 @@ function ReportSettingsPage({report, policies, route}: ReportSettingsPageProps) // The workspace the report is on, null if the user isn't a member of the workspace const linkedWorkspace = useMemo(() => Object.values(policies ?? {}).find((policy) => policy && policy.id === report?.policyID), [policies, report?.policyID]); const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); - + const isReportArchived = useReportIsArchived(report?.reportID); const shouldDisableSettings = isEmptyObject(report) || ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs) || ReportUtils.isSelfDM(report); const notificationPreferenceValue = ReportUtils.getReportNotificationPreference(report); const notificationPreference = @@ -43,7 +44,7 @@ function ReportSettingsPage({report, policies, route}: ReportSettingsPageProps) const writeCapabilityText = translate(`writeCapabilityPage.writeCapability.${writeCapability}`); const shouldAllowWriteCapabilityEditing = useMemo(() => ReportUtils.canEditWriteCapability(report, linkedWorkspace), [report, linkedWorkspace]); - const shouldAllowChangeVisibility = useMemo(() => ReportUtils.canEditRoomVisibility(report, linkedWorkspace), [report, linkedWorkspace]); + const shouldAllowChangeVisibility = useMemo(() => ReportUtils.canEditRoomVisibility(linkedWorkspace, isReportArchived), [report, linkedWorkspace]); const shouldShowNotificationPref = !isMoneyRequestReport && !ReportUtils.isHiddenForCurrentUser(notificationPreferenceValue); diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 9768185810a7..8ece4d86fb1d 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -2481,23 +2481,15 @@ describe('ReportUtils', () => { describe('canEditRoomVisibility', () => { it('should return true for policy admins', () => { - const workspaceChat: Report = { - ...createRandomReport(1), - chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, - }; - expect(canEditRoomVisibility(workspaceChat, {...policy, role: CONST.POLICY.ROLE.ADMIN})).toBe(true); - expect(canEditRoomVisibility(workspaceChat, {...policy, role: CONST.POLICY.ROLE.AUDITOR})).toBe(false); - expect(canEditRoomVisibility(workspaceChat, {...policy, role: CONST.POLICY.ROLE.USER})).toBe(false); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN})).toBe(true); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR})).toBe(false); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.USER})).toBe(false); }); - it('should return false if policy expense chat is archived', () => { - const workspaceChat: Report = { - ...createRandomReport(1), - chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, - }; - expect(canEditRoomVisibility(workspaceChat, {...policy, role: CONST.POLICY.ROLE.ADMIN}, true)).toBe(false); - expect(canEditRoomVisibility(workspaceChat, {...policy, role: CONST.POLICY.ROLE.AUDITOR}, true)).toBe(false); - expect(canEditRoomVisibility(workspaceChat, {...policy, role: CONST.POLICY.ROLE.USER}, true)).toBe(false); + it('should return false for policy rooms that are archived', () => { + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, true)).toBe(false); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR}, true)).toBe(false); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.USER}, true)).toBe(false); }); }); From 24317b03621e6fa62548f117423f121163e74f99 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Fri, 13 Jun 2025 23:05:22 +0300 Subject: [PATCH 03/17] comment --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 6aa8499ae1aa..94bc24f69dae 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -8722,7 +8722,7 @@ function canEditWriteCapability(report: OnyxEntry, policy: OnyxEntry, isReportArchived: boolean = false): boolean { // This will get removed as part of https://github.com/Expensify/App/issues/59961 From d864fb80b0af76e48faf9a64bf274ded9f66a491 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Sun, 15 Jun 2025 20:12:54 +0300 Subject: [PATCH 04/17] lint --- src/libs/ReportUtils.ts | 9 ++--- .../settings/Report/ReportSettingsPage.tsx | 37 +++++++++++-------- tests/unit/ReportUtilsTest.ts | 5 +-- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 94bc24f69dae..af38d10ffa06 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -8721,12 +8721,11 @@ function canEditWriteCapability(report: OnyxEntry, policy: OnyxEntry, isReportArchived: boolean = false): boolean { - // This will get removed as part of https://github.com/Expensify/App/issues/59961 - return !isReportArchived && isPolicyAdminPolicyUtils(policy) +function canEditRoomVisibility(policy: OnyxEntry, isReportArchived: boolean): boolean { + return !isReportArchived && isPolicyAdminPolicyUtils(policy); } /** diff --git a/src/pages/settings/Report/ReportSettingsPage.tsx b/src/pages/settings/Report/ReportSettingsPage.tsx index 794ad21cbfe1..940d356857b7 100644 --- a/src/pages/settings/Report/ReportSettingsPage.tsx +++ b/src/pages/settings/Report/ReportSettingsPage.tsx @@ -1,6 +1,5 @@ import React, {useMemo} from 'react'; import {View} from 'react-native'; -import {useOnyx} from 'react-native-onyx'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; @@ -8,16 +7,25 @@ import ScreenWrapper from '@components/ScreenWrapper'; import ScrollView from '@components/ScrollView'; import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; -import useThemeStyles from '@hooks/useThemeStyles'; import useReportIsArchived from '@hooks/useReportIsArchived'; +import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; -import * as ReportUtils from '@libs/ReportUtils'; +import { + canEditRoomVisibility, + canEditWriteCapability, + getReportNotificationPreference, + isAdminRoom, + isHiddenForCurrentUser, + isSelfDM, + isExpenseReport, + isExpenseRequest, + isMoneyRequestReport as isMoneyRequestReportUtils, +} from '@libs/ReportUtils'; import type {ReportSettingsNavigatorParamList} from '@navigation/types'; import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNotFound'; import CONST from '@src/CONST'; -import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; @@ -29,24 +37,23 @@ function ReportSettingsPage({report, policies, route}: ReportSettingsPageProps) const reportID = report?.reportID; const styles = useThemeStyles(); const {translate} = useLocalize(); - const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`); + const isReportArchived = useReportIsArchived(reportID); + const isArchivedNonExpenseReport = isReportArchived && !(isExpenseReport(report) || isExpenseRequest(report)) // The workspace the report is on, null if the user isn't a member of the workspace const linkedWorkspace = useMemo(() => Object.values(policies ?? {}).find((policy) => policy && policy.id === report?.policyID), [policies, report?.policyID]); - const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); - const isReportArchived = useReportIsArchived(report?.reportID); - const shouldDisableSettings = isEmptyObject(report) || ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs) || ReportUtils.isSelfDM(report); - const notificationPreferenceValue = ReportUtils.getReportNotificationPreference(report); + const isMoneyRequestReport = isMoneyRequestReportUtils(report); + const shouldDisableSettings = isEmptyObject(report) || isArchivedNonExpenseReport || isSelfDM(report); + const notificationPreferenceValue = getReportNotificationPreference(report); const notificationPreference = - notificationPreferenceValue && !ReportUtils.isHiddenForCurrentUser(notificationPreferenceValue) + notificationPreferenceValue && !isHiddenForCurrentUser(notificationPreferenceValue) ? translate(`notificationPreferencesPage.notificationPreferences.${notificationPreferenceValue}`) : ''; - const writeCapability = ReportUtils.isAdminRoom(report) ? CONST.REPORT.WRITE_CAPABILITIES.ADMINS : (report?.writeCapability ?? CONST.REPORT.WRITE_CAPABILITIES.ALL); - + const writeCapability = isAdminRoom(report) ? CONST.REPORT.WRITE_CAPABILITIES.ADMINS : (report?.writeCapability ?? CONST.REPORT.WRITE_CAPABILITIES.ALL); const writeCapabilityText = translate(`writeCapabilityPage.writeCapability.${writeCapability}`); - const shouldAllowWriteCapabilityEditing = useMemo(() => ReportUtils.canEditWriteCapability(report, linkedWorkspace), [report, linkedWorkspace]); - const shouldAllowChangeVisibility = useMemo(() => ReportUtils.canEditRoomVisibility(linkedWorkspace, isReportArchived), [report, linkedWorkspace]); + const shouldAllowWriteCapabilityEditing = useMemo(() => canEditWriteCapability(report, linkedWorkspace), [report, linkedWorkspace]); + const shouldAllowChangeVisibility = useMemo(() => canEditRoomVisibility(linkedWorkspace, isReportArchived), [linkedWorkspace, isReportArchived]); - const shouldShowNotificationPref = !isMoneyRequestReport && !ReportUtils.isHiddenForCurrentUser(notificationPreferenceValue); + const shouldShowNotificationPref = !isMoneyRequestReport && !isHiddenForCurrentUser(notificationPreferenceValue); const shouldShowWriteCapability = !isMoneyRequestReport; diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 8ece4d86fb1d..18cec26572ae 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -22,8 +22,8 @@ import { canDeleteReportAction, canDeleteTransaction, canEditReportDescription, - canEditWriteCapability, canEditRoomVisibility, + canEditWriteCapability, canHoldUnholdReportAction, findLastAccessedReport, getAllAncestorReportActions, @@ -2479,7 +2479,7 @@ describe('ReportUtils', () => { }); }); - describe('canEditRoomVisibility', () => { + describe('canEditRoomVisibility', () => { it('should return true for policy admins', () => { expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN})).toBe(true); expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR})).toBe(false); @@ -2490,7 +2490,6 @@ describe('ReportUtils', () => { expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, true)).toBe(false); expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR}, true)).toBe(false); expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.USER}, true)).toBe(false); - }); }); From 42b789b2fe197275175a7706c424322a4c6175ae Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Sun, 15 Jun 2025 20:23:44 +0300 Subject: [PATCH 05/17] prettier --- src/pages/settings/Report/ReportSettingsPage.tsx | 6 +++--- tests/unit/ReportUtilsTest.ts | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/pages/settings/Report/ReportSettingsPage.tsx b/src/pages/settings/Report/ReportSettingsPage.tsx index 940d356857b7..408504dc3c1a 100644 --- a/src/pages/settings/Report/ReportSettingsPage.tsx +++ b/src/pages/settings/Report/ReportSettingsPage.tsx @@ -16,11 +16,11 @@ import { canEditWriteCapability, getReportNotificationPreference, isAdminRoom, - isHiddenForCurrentUser, - isSelfDM, isExpenseReport, isExpenseRequest, + isHiddenForCurrentUser, isMoneyRequestReport as isMoneyRequestReportUtils, + isSelfDM, } from '@libs/ReportUtils'; import type {ReportSettingsNavigatorParamList} from '@navigation/types'; import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; @@ -38,7 +38,7 @@ function ReportSettingsPage({report, policies, route}: ReportSettingsPageProps) const styles = useThemeStyles(); const {translate} = useLocalize(); const isReportArchived = useReportIsArchived(reportID); - const isArchivedNonExpenseReport = isReportArchived && !(isExpenseReport(report) || isExpenseRequest(report)) + const isArchivedNonExpenseReport = isReportArchived && !(isExpenseReport(report) || isExpenseRequest(report)); // The workspace the report is on, null if the user isn't a member of the workspace const linkedWorkspace = useMemo(() => Object.values(policies ?? {}).find((policy) => policy && policy.id === report?.policyID), [policies, report?.policyID]); const isMoneyRequestReport = isMoneyRequestReportUtils(report); diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 18cec26572ae..8faef237c787 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -2480,13 +2480,13 @@ describe('ReportUtils', () => { }); describe('canEditRoomVisibility', () => { - it('should return true for policy admins', () => { - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN})).toBe(true); - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR})).toBe(false); - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.USER})).toBe(false); + it('should return true for policy rooms that are not archived and the user is an admin', () => { + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, false)).toBe(true); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR}, false)).toBe(false); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.USER}, false)).toBe(false); }); - it('should return false for policy rooms that are archived', () => { + it('should return false for policy rooms that are archived regardless of the policy role', () => { expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, true)).toBe(false); expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR}, true)).toBe(false); expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.USER}, true)).toBe(false); From a15b25d3d68c523821130eda534c89b18648083f Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Fri, 20 Jun 2025 23:11:15 +0300 Subject: [PATCH 06/17] changed isArchivedNonExpenseReport second param to accept private_isArchived --- .../HTMLRenderers/ImageRenderer.tsx | 2 +- src/libs/OptionsListUtils.ts | 4 ++-- src/libs/ReportUtils.ts | 22 +++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx index e650df1be650..9f89678dbf22 100644 --- a/src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx +++ b/src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx @@ -120,7 +120,7 @@ function ImageRenderer({tnode}: ImageRendererProps) { return; } return onShowContextMenu(() => - showContextMenuForReport(event, anchor, report?.reportID, action, checkIfContextMenuActive, isArchivedNonExpenseReport(report, reportNameValuePairs)), + showContextMenuForReport(event, anchor, report?.reportID, action, checkIfContextMenuActive, isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived)), ); }} isNested diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 6b15ba58e587..3155d852223f 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -729,7 +729,7 @@ function getLastMessageTextForReport( const lastOriginalReportAction = reportID ? lastReportActions[reportID] : undefined; let lastMessageTextFromReport = ''; - if (isArchivedNonExpenseReport(report, reportNameValuePairs)) { + if (isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived)) { const archiveReason = // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing (isClosedAction(lastOriginalReportAction) && getOriginalMessage(lastOriginalReportAction)?.reason) || CONST.REPORT.ARCHIVE_REASON.DEFAULT; @@ -977,7 +977,7 @@ function createOption(accountIDs: number[], personalDetails: OnyxInputOrEntry, transact * Whether the provided report is an archived room */ // eslint-disable-next-line @typescript-eslint/no-unused-vars -function isArchivedNonExpenseReport(report: OnyxInputOrEntry | SearchReport, reportNameValuePairs?: OnyxInputOrEntry): boolean { - return !(isExpenseReport(report) || isExpenseRequest(report)) && !!reportNameValuePairs?.private_isArchived; +function isArchivedNonExpenseReport(report: OnyxInputOrEntry | SearchReport, isReportArchived?: string): boolean { + return !(isExpenseReport(report) || isExpenseRequest(report)) && !!isReportArchived; } /** @@ -3266,7 +3266,7 @@ function getIcons( const reportNameValuePairs = allReportNameValuePair?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`]; // This will get removed as part of https://github.com/Expensify/App/issues/59961 // eslint-disable-next-line deprecation/deprecation - if (isAdminRoom(report) || isAnnounceRoom(report) || isChatRoom(report) || (isArchivedNonExpenseReport(report, reportNameValuePairs) && !chatIncludesConcierge(report))) { + if (isAdminRoom(report) || isAnnounceRoom(report) || isChatRoom(report) || (isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived) && !chatIncludesConcierge(report))) { return getIconsForPolicyRoom(report, personalDetails, policy, invoiceReceiverPolicy); } if (isPolicyExpenseChat(report)) { @@ -3741,7 +3741,7 @@ function getPolicyExpenseChatName({ // of the account which was merged into the current user's account. Use the name of the policy as the name of the report. // This will get removed as part of https://github.com/Expensify/App/issues/59961 // eslint-disable-next-line deprecation/deprecation - if (isArchivedNonExpenseReport(report, getReportNameValuePairs(report?.reportID))) { + if (isArchivedNonExpenseReport(report, getReportNameValuePairs(report?.reportID)?.private_isArchived )) { const lastAction = getLastVisibleActionReportActionsUtils(report?.reportID); const archiveReason = isClosedAction(lastAction) ? getOriginalMessage(lastAction)?.reason : CONST.REPORT.ARCHIVE_REASON.DEFAULT; if (archiveReason === CONST.REPORT.ARCHIVE_REASON.ACCOUNT_MERGED && policyExpenseChatRole !== CONST.POLICY.ROLE.ADMIN) { @@ -5033,7 +5033,7 @@ function getReportNameInternal({ const parentReportActionMessage = getReportActionMessageReportUtils(parentReportAction); const isArchivedNonExpense = isArchivedNonExpenseReport( report, - reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? String(CONST.DEFAULT_NUMBER_ID)}`], + reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? String(CONST.DEFAULT_NUMBER_ID)}`]?.private_isArchived , ); if ( @@ -5366,7 +5366,7 @@ function getParentNavigationSubtitle(report: OnyxEntry, invoiceReceiverP // This will get removed as part of https://github.com/Expensify/App/issues/59961 // eslint-disable-next-line deprecation/deprecation - if (isArchivedNonExpenseReport(parentReport, getReportNameValuePairs(parentReport?.reportID))) { + if (isArchivedNonExpenseReport(parentReport, getReportNameValuePairs(parentReport?.reportID)?.private_isArchived )) { reportName += ` (${translateLocal('common.archived')})`; } @@ -7836,7 +7836,7 @@ function canSeeDefaultRoom(report: OnyxEntry, policies: OnyxCollection

, rep canFlagReportAction(reportAction, report?.reportID) && // This will get removed as part of https://github.com/Expensify/App/issues/59961 // eslint-disable-next-line deprecation/deprecation - !isArchivedNonExpenseReport(report, getReportNameValuePairs(report?.reportID)) && + !isArchivedNonExpenseReport(report, getReportNameValuePairs(report?.reportID)?.private_isArchived) && !chatIncludesChronos(report) && !isConciergeChatReport(report) && reportAction?.actorAccountID !== CONST.ACCOUNT_ID.CONCIERGE @@ -8742,7 +8742,7 @@ function getWhisperDisplayNames(participantAccountIDs?: number[]): string | unde function shouldReportShowSubscript(report: OnyxEntry): boolean { // This will get removed as part of https://github.com/Expensify/App/issues/59961 // eslint-disable-next-line deprecation/deprecation - if (isArchivedNonExpenseReport(report, getReportNameValuePairs(report?.reportID)) && !isWorkspaceThread(report)) { + if (isArchivedNonExpenseReport(report, getReportNameValuePairs(report?.reportID)?.private_isArchived) && !isWorkspaceThread(report)) { return false; } @@ -8861,7 +8861,7 @@ function canUserPerformWriteAction(report: OnyxEntry) { // This will get removed as part of https://github.com/Expensify/App/issues/59961 // eslint-disable-next-line deprecation/deprecation const reportNameValuePairs = getReportNameValuePairs(report?.reportID); - return !isArchivedNonExpenseReport(report, reportNameValuePairs) && isEmptyObject(reportErrors) && report && isAllowedToComment(report) && !isAnonymousUser && canWriteInReport(report); + return !isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived) && isEmptyObject(reportErrors) && report && isAllowedToComment(report) && !isAnonymousUser && canWriteInReport(report); } /** From 592fa8aa1886ad8c6e8cfa0ec60197728ca2faec Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Fri, 20 Jun 2025 23:58:57 +0300 Subject: [PATCH 07/17] typecheck --- .../BaseAnchorForAttachmentsOnly.tsx | 9 ++++++- .../HTMLRenderers/ImageRenderer.tsx | 9 ++++++- .../HTMLRenderers/MentionUserRenderer.tsx | 9 ++++++- .../HTMLRenderers/PreRenderer.tsx | 9 ++++++- src/components/ReportWelcomeText.tsx | 2 +- .../VideoPlayerThumbnail.tsx | 9 ++++++- src/libs/ReportUtils.ts | 26 ++++++++++++++----- src/libs/SidebarUtils.ts | 2 +- src/pages/ReportDetailsPage.tsx | 2 +- src/pages/ReportParticipantsPage.tsx | 2 +- .../BaseReportActionContextMenu.tsx | 5 +++- .../home/report/PureReportActionItem.tsx | 3 ++- src/pages/home/report/ReportActionsList.tsx | 4 +-- src/pages/home/report/ReportFooter.tsx | 2 +- .../Report/NotificationPreferencePage.tsx | 2 +- .../settings/Report/ReportSettingsPage.tsx | 14 +++++----- src/pages/settings/Report/VisibilityPage.tsx | 2 +- 17 files changed, 81 insertions(+), 30 deletions(-) diff --git a/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx b/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx index 57213dc1d3d2..f49fcea993d7 100644 --- a/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx +++ b/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx @@ -51,7 +51,14 @@ function BaseAnchorForAttachmentsOnly({style, source = '', displayName = '', onP if (isDisabled || !shouldDisplayContextMenu) { return; } - showContextMenuForReport(event, anchor, report?.reportID, action, checkIfContextMenuActive, ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs)); + showContextMenuForReport( + event, + anchor, + report?.reportID, + action, + checkIfContextMenuActive, + ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived), + ); }} shouldUseHapticsOnLongPress accessibilityLabel={displayName} diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx index 9f89678dbf22..7be94d00d6b0 100644 --- a/src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx +++ b/src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx @@ -120,7 +120,14 @@ function ImageRenderer({tnode}: ImageRendererProps) { return; } return onShowContextMenu(() => - showContextMenuForReport(event, anchor, report?.reportID, action, checkIfContextMenuActive, isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived)), + showContextMenuForReport( + event, + anchor, + report?.reportID, + action, + checkIfContextMenuActive, + isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived), + ), ); }} isNested diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx index 71e711a93dcb..7c49fe871180 100644 --- a/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx +++ b/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx @@ -78,7 +78,14 @@ function MentionUserRenderer({style, tnode, TDefaultRenderer, currentUserPersona return; } return onShowContextMenu(() => - showContextMenuForReport(event, anchor, report?.reportID, action, checkIfContextMenuActive, isArchivedNonExpenseReport(report, reportNameValuePairs)), + showContextMenuForReport( + event, + anchor, + report?.reportID, + action, + checkIfContextMenuActive, + isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived), + ), ); }} onPress={(event) => { diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/PreRenderer.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/PreRenderer.tsx index 88b614365012..33e123daf9d3 100644 --- a/src/components/HTMLEngineProvider/HTMLRenderers/PreRenderer.tsx +++ b/src/components/HTMLEngineProvider/HTMLRenderers/PreRenderer.tsx @@ -62,7 +62,14 @@ function PreRenderer({TDefaultRenderer, onPressIn, onPressOut, onLongPress, ...d if (isDisabled || !shouldDisplayContextMenu) { return; } - return showContextMenuForReport(event, anchor, report?.reportID, action, checkIfContextMenuActive, isArchivedNonExpenseReport(report, reportNameValuePairs)); + return showContextMenuForReport( + event, + anchor, + report?.reportID, + action, + checkIfContextMenuActive, + isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived), + ); }); }} shouldUseHapticsOnLongPress diff --git a/src/components/ReportWelcomeText.tsx b/src/components/ReportWelcomeText.tsx index 04d661131488..df3b63d57d86 100644 --- a/src/components/ReportWelcomeText.tsx +++ b/src/components/ReportWelcomeText.tsx @@ -52,7 +52,7 @@ function ReportWelcomeText({report, policy}: ReportWelcomeTextProps) { const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID || undefined}`, {canBeMissing: false}); // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report?.reportID || undefined}`, {canBeMissing: true}); - const isArchivedRoom = isArchivedNonExpenseReport(report, reportNameValuePairs); + const isArchivedRoom = isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived); const isChatRoom = isChatRoomReportUtils(report); const isSelfDM = isSelfDMReportUtils(report); const isInvoiceRoom = isInvoiceRoomReportUtils(report); diff --git a/src/components/VideoPlayerPreview/VideoPlayerThumbnail.tsx b/src/components/VideoPlayerPreview/VideoPlayerThumbnail.tsx index d7115921f58a..d56b6d25ac42 100644 --- a/src/components/VideoPlayerPreview/VideoPlayerThumbnail.tsx +++ b/src/components/VideoPlayerPreview/VideoPlayerThumbnail.tsx @@ -58,7 +58,14 @@ function VideoPlayerThumbnail({thumbnailUrl, onPress, accessibilityLabel, isDele return; } onShowContextMenu(() => { - showContextMenuForReport(event, anchor, report?.reportID, action, checkIfContextMenuActive, isArchivedNonExpenseReport(report, reportNameValuePairs)); + showContextMenuForReport( + event, + anchor, + report?.reportID, + action, + checkIfContextMenuActive, + isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived), + ); }); }} shouldUseHapticsOnLongPress diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index a2cbc71b24e9..a7bdd46eaf76 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3266,7 +3266,12 @@ function getIcons( const reportNameValuePairs = allReportNameValuePair?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`]; // This will get removed as part of https://github.com/Expensify/App/issues/59961 // eslint-disable-next-line deprecation/deprecation - if (isAdminRoom(report) || isAnnounceRoom(report) || isChatRoom(report) || (isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived) && !chatIncludesConcierge(report))) { + if ( + isAdminRoom(report) || + isAnnounceRoom(report) || + isChatRoom(report) || + (isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived) && !chatIncludesConcierge(report)) + ) { return getIconsForPolicyRoom(report, personalDetails, policy, invoiceReceiverPolicy); } if (isPolicyExpenseChat(report)) { @@ -3741,7 +3746,7 @@ function getPolicyExpenseChatName({ // of the account which was merged into the current user's account. Use the name of the policy as the name of the report. // This will get removed as part of https://github.com/Expensify/App/issues/59961 // eslint-disable-next-line deprecation/deprecation - if (isArchivedNonExpenseReport(report, getReportNameValuePairs(report?.reportID)?.private_isArchived )) { + if (isArchivedNonExpenseReport(report, getReportNameValuePairs(report?.reportID)?.private_isArchived)) { const lastAction = getLastVisibleActionReportActionsUtils(report?.reportID); const archiveReason = isClosedAction(lastAction) ? getOriginalMessage(lastAction)?.reason : CONST.REPORT.ARCHIVE_REASON.DEFAULT; if (archiveReason === CONST.REPORT.ARCHIVE_REASON.ACCOUNT_MERGED && policyExpenseChatRole !== CONST.POLICY.ROLE.ADMIN) { @@ -5033,7 +5038,7 @@ function getReportNameInternal({ const parentReportActionMessage = getReportActionMessageReportUtils(parentReportAction); const isArchivedNonExpense = isArchivedNonExpenseReport( report, - reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? String(CONST.DEFAULT_NUMBER_ID)}`]?.private_isArchived , + reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? String(CONST.DEFAULT_NUMBER_ID)}`]?.private_isArchived, ); if ( @@ -5366,7 +5371,7 @@ function getParentNavigationSubtitle(report: OnyxEntry, invoiceReceiverP // This will get removed as part of https://github.com/Expensify/App/issues/59961 // eslint-disable-next-line deprecation/deprecation - if (isArchivedNonExpenseReport(parentReport, getReportNameValuePairs(parentReport?.reportID)?.private_isArchived )) { + if (isArchivedNonExpenseReport(parentReport, getReportNameValuePairs(parentReport?.reportID)?.private_isArchived)) { reportName += ` (${translateLocal('common.archived')})`; } @@ -7836,7 +7841,7 @@ function canSeeDefaultRoom(report: OnyxEntry, policies: OnyxCollection

) { // This will get removed as part of https://github.com/Expensify/App/issues/59961 // eslint-disable-next-line deprecation/deprecation const reportNameValuePairs = getReportNameValuePairs(report?.reportID); - return !isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived) && isEmptyObject(reportErrors) && report && isAllowedToComment(report) && !isAnonymousUser && canWriteInReport(report); + return ( + !isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived) && + isEmptyObject(reportErrors) && + report && + isAllowedToComment(report) && + !isAnonymousUser && + canWriteInReport(report) + ); } /** diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 9e39a9704f20..a651ba492617 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -394,7 +394,7 @@ function sortReportsToDisplayInLHN( errorReports.push(miniReport); } else if (hasValidDraftComment(report?.reportID)) { draftReports.push(miniReport); - } else if (isArchivedNonExpenseReport(report, rNVPs)) { + } else if (isArchivedNonExpenseReport(report, rNVPs?.private_isArchived)) { archivedReports.push(miniReport); } else { nonArchivedReports.push(miniReport); diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index 6f02b73a378b..f5f426d40247 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -179,7 +179,7 @@ function ReportDetailsPage({policies, report, route, reportMetadata}: ReportDeta const isUserCreatedPolicyRoom = useMemo(() => isUserCreatedPolicyRoomUtil(report), [report]); const isDefaultRoom = useMemo(() => isDefaultRoomUtil(report), [report]); const isChatThread = useMemo(() => isChatThreadUtil(report), [report]); - const isArchivedRoom = useMemo(() => isArchivedNonExpenseReport(report, reportNameValuePairs), [report, reportNameValuePairs]); + const isArchivedRoom = useMemo(() => isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived), [report, reportNameValuePairs]); const isMoneyRequestReport = useMemo(() => isMoneyRequestReportUtil(report), [report]); const isMoneyRequest = useMemo(() => isMoneyRequestUtil(report), [report]); const isInvoiceReport = useMemo(() => isInvoiceReportUtil(report), [report]); diff --git a/src/pages/ReportParticipantsPage.tsx b/src/pages/ReportParticipantsPage.tsx index 82333a6c1349..db1d7288a3ea 100755 --- a/src/pages/ReportParticipantsPage.tsx +++ b/src/pages/ReportParticipantsPage.tsx @@ -396,7 +396,7 @@ function ReportParticipantsPage({report, route}: ReportParticipantsPageProps) { style={[styles.defaultModalContainer]} testID={ReportParticipantsPage.displayName} > - + { diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx index 6713eaa615f2..06d794ce4398 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx @@ -203,7 +203,10 @@ function BaseReportActionContextMenu({ const areHoldRequirementsMet = !isInvoiceReport && isMoneyRequestOrReport && - !isArchivedNonExpenseReport(transactionThreadReportID ? childReport : parentReport, transactionThreadReportID ? childReportNameValuePairs : parentReportNameValuePairs); + !isArchivedNonExpenseReport( + transactionThreadReportID ? childReport : parentReport, + transactionThreadReportID ? childReportNameValuePairs?.private_isArchived : parentReportNameValuePairs?.private_isArchived, + ); const shouldEnableArrowNavigation = !isMini && (isVisible || shouldKeepOpen); let filteredContextMenuActions = ContextMenuActions.filter( diff --git a/src/pages/home/report/PureReportActionItem.tsx b/src/pages/home/report/PureReportActionItem.tsx index ad124bbc20f4..f907bf357b28 100644 --- a/src/pages/home/report/PureReportActionItem.tsx +++ b/src/pages/home/report/PureReportActionItem.tsx @@ -1230,7 +1230,8 @@ function PureReportActionItem({ index={index} ref={composerTextInputRef} shouldDisableEmojiPicker={ - (chatIncludesConcierge(report) && isBlockedFromConcierge(blockedFromConcierge)) || isArchivedNonExpenseReport(report, reportNameValuePairs) + (chatIncludesConcierge(report) && isBlockedFromConcierge(blockedFromConcierge)) || + isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived) } isGroupPolicyReport={!!report?.policyID && report.policyID !== CONST.POLICY.ID_FAKE} /> diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index 8fb3a5d1d17b..afb1b7bda581 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -550,7 +550,7 @@ function ReportActionsList({ const newMessageTimeReference = lastMessageTime.current && report.lastReadTime && lastMessageTime.current > report.lastReadTime ? userActiveSince.current : report.lastReadTime; lastMessageTime.current = null; - const isArchivedReport = isArchivedNonExpenseReport(report, reportNameValuePairs); + const isArchivedReport = isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived); const hasNewMessagesInView = scrollingVerticalOffset.current < CONST.REPORT.ACTIONS.ACTION_VISIBLE_THRESHOLD; const hasUnreadReportAction = sortedVisibleReportActions.some( (reportAction) => @@ -619,7 +619,7 @@ function ReportActionsList({ // Native mobile does not render updates flatlist the changes even though component did update called. // To notify there something changes we can use extraData prop to flatlist const extraData = useMemo( - () => [shouldUseNarrowLayout ? unreadMarkerReportActionID : undefined, isArchivedNonExpenseReport(report, reportNameValuePairs)], + () => [shouldUseNarrowLayout ? unreadMarkerReportActionID : undefined, isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived)], [unreadMarkerReportActionID, shouldUseNarrowLayout, report, reportNameValuePairs], ); const hideComposer = !canUserPerformWriteAction(report); diff --git a/src/pages/home/report/ReportFooter.tsx b/src/pages/home/report/ReportFooter.tsx index 03fcea1e72e6..b60686649b93 100644 --- a/src/pages/home/report/ReportFooter.tsx +++ b/src/pages/home/report/ReportFooter.tsx @@ -105,7 +105,7 @@ function ReportFooter({ const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`, {canBeMissing: true}); const chatFooterStyles = {...styles.chatFooter, minHeight: !isOffline ? CONST.CHAT_FOOTER_MIN_HEIGHT : 0}; - const isArchivedRoom = isArchivedNonExpenseReport(report, reportNameValuePairs); + const isArchivedRoom = isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived); const isSmallSizeLayout = windowWidth - (shouldUseNarrowLayout ? 0 : variables.sideBarWithLHBWidth) < variables.anonymousReportFooterBreakpoint; diff --git a/src/pages/settings/Report/NotificationPreferencePage.tsx b/src/pages/settings/Report/NotificationPreferencePage.tsx index 434505ad473e..6f7f1125b449 100644 --- a/src/pages/settings/Report/NotificationPreferencePage.tsx +++ b/src/pages/settings/Report/NotificationPreferencePage.tsx @@ -27,7 +27,7 @@ function NotificationPreferencePage({report}: NotificationPreferencePageProps) { const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); const currentNotificationPreference = ReportUtils.getReportNotificationPreference(report); const shouldDisableNotificationPreferences = - ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs) || + ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived) || ReportUtils.isSelfDM(report) || (!isMoneyRequestReport && ReportUtils.isHiddenForCurrentUser(currentNotificationPreference)); const notificationPreferenceOptions = Object.values(CONST.REPORT.NOTIFICATION_PREFERENCE) diff --git a/src/pages/settings/Report/ReportSettingsPage.tsx b/src/pages/settings/Report/ReportSettingsPage.tsx index 408504dc3c1a..15722c3928cd 100644 --- a/src/pages/settings/Report/ReportSettingsPage.tsx +++ b/src/pages/settings/Report/ReportSettingsPage.tsx @@ -7,7 +7,7 @@ import ScreenWrapper from '@components/ScreenWrapper'; import ScrollView from '@components/ScrollView'; import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; -import useReportIsArchived from '@hooks/useReportIsArchived'; +import useOnyx from '@hooks/useOnyx'; import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; @@ -16,8 +16,7 @@ import { canEditWriteCapability, getReportNotificationPreference, isAdminRoom, - isExpenseReport, - isExpenseRequest, + isArchivedNonExpenseReport as isArchivedNonExpenseReportUtils, isHiddenForCurrentUser, isMoneyRequestReport as isMoneyRequestReportUtils, isSelfDM, @@ -26,6 +25,7 @@ import type {ReportSettingsNavigatorParamList} from '@navigation/types'; import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNotFound'; import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; @@ -37,12 +37,12 @@ function ReportSettingsPage({report, policies, route}: ReportSettingsPageProps) const reportID = report?.reportID; const styles = useThemeStyles(); const {translate} = useLocalize(); - const isReportArchived = useReportIsArchived(reportID); - const isArchivedNonExpenseReport = isReportArchived && !(isExpenseReport(report) || isExpenseRequest(report)); + const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`); + const isArchivedNonExpenseReport = isArchivedNonExpenseReportUtils(report, reportNameValuePairs?.private_isArchived); // The workspace the report is on, null if the user isn't a member of the workspace const linkedWorkspace = useMemo(() => Object.values(policies ?? {}).find((policy) => policy && policy.id === report?.policyID), [policies, report?.policyID]); const isMoneyRequestReport = isMoneyRequestReportUtils(report); - const shouldDisableSettings = isEmptyObject(report) || isArchivedNonExpenseReport || isSelfDM(report); + const shouldDisableSettings = isArchivedNonExpenseReport || isEmptyObject(report) || isSelfDM(report); const notificationPreferenceValue = getReportNotificationPreference(report); const notificationPreference = notificationPreferenceValue && !isHiddenForCurrentUser(notificationPreferenceValue) @@ -51,7 +51,7 @@ function ReportSettingsPage({report, policies, route}: ReportSettingsPageProps) const writeCapability = isAdminRoom(report) ? CONST.REPORT.WRITE_CAPABILITIES.ADMINS : (report?.writeCapability ?? CONST.REPORT.WRITE_CAPABILITIES.ALL); const writeCapabilityText = translate(`writeCapabilityPage.writeCapability.${writeCapability}`); const shouldAllowWriteCapabilityEditing = useMemo(() => canEditWriteCapability(report, linkedWorkspace), [report, linkedWorkspace]); - const shouldAllowChangeVisibility = useMemo(() => canEditRoomVisibility(linkedWorkspace, isReportArchived), [linkedWorkspace, isReportArchived]); + const shouldAllowChangeVisibility = useMemo(() => canEditRoomVisibility(linkedWorkspace, isArchivedNonExpenseReport), [linkedWorkspace, isArchivedNonExpenseReport]); const shouldShowNotificationPref = !isMoneyRequestReport && !isHiddenForCurrentUser(notificationPreferenceValue); diff --git a/src/pages/settings/Report/VisibilityPage.tsx b/src/pages/settings/Report/VisibilityPage.tsx index 560b96383a57..7224cbc4510e 100644 --- a/src/pages/settings/Report/VisibilityPage.tsx +++ b/src/pages/settings/Report/VisibilityPage.tsx @@ -27,7 +27,7 @@ function VisibilityPage({report}: VisibilityProps) { const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID || undefined}`); const shouldGoBackToDetailsPage = useRef(false); - const shouldDisableVisibility = ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs); + const shouldDisableVisibility = ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived); const {translate} = useLocalize(); const visibilityOptions = useMemo( From 0815356b1487236a46bd9eec83b67e01f03c63a9 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Sat, 21 Jun 2025 00:49:21 +0300 Subject: [PATCH 08/17] lint errors --- .../BaseAnchorForAttachmentsOnly.tsx | 12 ++++----- .../Report/NotificationPreferencePage.tsx | 25 +++++++++++-------- .../settings/Report/ReportSettingsPage.tsx | 2 +- src/pages/settings/Report/VisibilityPage.tsx | 10 ++++---- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx b/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx index f49fcea993d7..63b6c67c38da 100644 --- a/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx +++ b/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx @@ -6,10 +6,10 @@ import {ShowContextMenuContext, showContextMenuForReport} from '@components/Show import useNetwork from '@hooks/useNetwork'; import useThemeStyles from '@hooks/useThemeStyles'; import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL'; -import * as Browser from '@libs/Browser'; +import {isMobileSafari} from '@libs/Browser'; import fileDownload from '@libs/fileDownload'; -import * as ReportUtils from '@libs/ReportUtils'; -import * as Download from '@userActions/Download'; +import {isArchivedNonExpenseReport} from '@libs/ReportUtils'; +import {setDownload} from '@userActions/Download'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type AnchorForAttachmentsOnlyProps from './types'; @@ -42,8 +42,8 @@ function BaseAnchorForAttachmentsOnly({style, source = '', displayName = '', onP if (isDownloading || isOffline || !sourceID) { return; } - Download.setDownload(sourceID, true); - fileDownload(sourceURLWithAuth, displayName, '', Browser.isMobileSafari()).then(() => Download.setDownload(sourceID, false)); + setDownload(sourceID, true); + fileDownload(sourceURLWithAuth, displayName, '', isMobileSafari()).then(() => setDownload(sourceID, false)); }} onPressIn={onPressIn} onPressOut={onPressOut} @@ -57,7 +57,7 @@ function BaseAnchorForAttachmentsOnly({style, source = '', displayName = '', onP report?.reportID, action, checkIfContextMenuActive, - ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived), + isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived), ); }} shouldUseHapticsOnLongPress diff --git a/src/pages/settings/Report/NotificationPreferencePage.tsx b/src/pages/settings/Report/NotificationPreferencePage.tsx index 6f7f1125b449..237eb26778a2 100644 --- a/src/pages/settings/Report/NotificationPreferencePage.tsx +++ b/src/pages/settings/Report/NotificationPreferencePage.tsx @@ -9,11 +9,18 @@ import SelectionList from '@components/SelectionList'; import RadioListItem from '@components/SelectionList/RadioListItem'; import useLocalize from '@hooks/useLocalize'; import type {PlatformStackRouteProp, PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; -import * as ReportUtils from '@libs/ReportUtils'; +import { + getReportNotificationPreference, + goBackToDetailsPage, + isArchivedNonExpenseReport, + isHiddenForCurrentUser, + isMoneyRequestReport as isMoneyRequestReportUtils, + isSelfDM, +} from '@libs/ReportUtils'; import type {ReportSettingsNavigatorParamList} from '@navigation/types'; import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNotFound'; -import * as ReportActions from '@userActions/Report'; +import {updateNotificationPreference as updateNotificationPreferenceReportActionUtils} from '@userActions/Report'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; @@ -24,14 +31,12 @@ function NotificationPreferencePage({report}: NotificationPreferencePageProps) { const route = useRoute>(); const {translate} = useLocalize(); const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID || undefined}`); - const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); - const currentNotificationPreference = ReportUtils.getReportNotificationPreference(report); + const isMoneyRequestReport = isMoneyRequestReportUtils(report); + const currentNotificationPreference = getReportNotificationPreference(report); const shouldDisableNotificationPreferences = - ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived) || - ReportUtils.isSelfDM(report) || - (!isMoneyRequestReport && ReportUtils.isHiddenForCurrentUser(currentNotificationPreference)); + isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived) || isSelfDM(report) || (!isMoneyRequestReport && isHiddenForCurrentUser(currentNotificationPreference)); const notificationPreferenceOptions = Object.values(CONST.REPORT.NOTIFICATION_PREFERENCE) - .filter((pref) => !ReportUtils.isHiddenForCurrentUser(pref)) + .filter((pref) => !isHiddenForCurrentUser(pref)) .map((preference) => ({ value: preference, text: translate(`notificationPreferencesPage.notificationPreferences.${preference}`), @@ -40,12 +45,12 @@ function NotificationPreferencePage({report}: NotificationPreferencePageProps) { })); const goBack = useCallback(() => { - ReportUtils.goBackToDetailsPage(report, route.params.backTo); + goBackToDetailsPage(report, route.params.backTo); }, [report, route.params.backTo]); const updateNotificationPreference = useCallback( (value: ValueOf) => { - ReportActions.updateNotificationPreference(report.reportID, currentNotificationPreference, value, undefined, undefined); + updateNotificationPreferenceReportActionUtils(report.reportID, currentNotificationPreference, value, undefined, undefined); goBack(); }, [report.reportID, currentNotificationPreference, goBack], diff --git a/src/pages/settings/Report/ReportSettingsPage.tsx b/src/pages/settings/Report/ReportSettingsPage.tsx index 15722c3928cd..16460d976f31 100644 --- a/src/pages/settings/Report/ReportSettingsPage.tsx +++ b/src/pages/settings/Report/ReportSettingsPage.tsx @@ -37,7 +37,7 @@ function ReportSettingsPage({report, policies, route}: ReportSettingsPageProps) const reportID = report?.reportID; const styles = useThemeStyles(); const {translate} = useLocalize(); - const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`); + const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`, {canBeMissing: true}); const isArchivedNonExpenseReport = isArchivedNonExpenseReportUtils(report, reportNameValuePairs?.private_isArchived); // The workspace the report is on, null if the user isn't a member of the workspace const linkedWorkspace = useMemo(() => Object.values(policies ?? {}).find((policy) => policy && policy.id === report?.policyID), [policies, report?.policyID]); diff --git a/src/pages/settings/Report/VisibilityPage.tsx b/src/pages/settings/Report/VisibilityPage.tsx index 7224cbc4510e..e01277e53e4f 100644 --- a/src/pages/settings/Report/VisibilityPage.tsx +++ b/src/pages/settings/Report/VisibilityPage.tsx @@ -10,10 +10,10 @@ import RadioListItem from '@components/SelectionList/RadioListItem'; import useLocalize from '@hooks/useLocalize'; import type {PlatformStackRouteProp, PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import type {ReportSettingsNavigatorParamList} from '@libs/Navigation/types'; -import * as ReportUtils from '@libs/ReportUtils'; +import {goBackToDetailsPage, isArchivedNonExpenseReport} from '@libs/ReportUtils'; import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNotFound'; import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; -import * as ReportActions from '@userActions/Report'; +import {updateRoomVisibility} from '@userActions/Report'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; @@ -27,7 +27,7 @@ function VisibilityPage({report}: VisibilityProps) { const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID || undefined}`); const shouldGoBackToDetailsPage = useRef(false); - const shouldDisableVisibility = ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived); + const shouldDisableVisibility = isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived, {canBeMissing: true}); const {translate} = useLocalize(); const visibilityOptions = useMemo( @@ -45,7 +45,7 @@ function VisibilityPage({report}: VisibilityProps) { ); const goBack = useCallback(() => { - ReportUtils.goBackToDetailsPage(report, route.params.backTo); + goBackToDetailsPage(report, route.params.backTo); }, [report, route.params.backTo]); const changeVisibility = useCallback( @@ -53,7 +53,7 @@ function VisibilityPage({report}: VisibilityProps) { if (!report) { return; } - ReportActions.updateRoomVisibility(report.reportID, report.visibility, newVisibility); + updateRoomVisibility(report.reportID, report.visibility, newVisibility); if (showConfirmModal) { shouldGoBackToDetailsPage.current = true; } else { From 19cb2ae5a418612e89a5d15fcf9978d0bb4aea99 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Sat, 21 Jun 2025 00:58:03 +0300 Subject: [PATCH 09/17] prettier --- .../AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx | 4 ++-- src/pages/settings/Report/NotificationPreferencePage.tsx | 2 +- src/pages/settings/Report/VisibilityPage.tsx | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx b/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx index 63b6c67c38da..2ba5156d84be 100644 --- a/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx +++ b/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx @@ -9,7 +9,7 @@ import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL'; import {isMobileSafari} from '@libs/Browser'; import fileDownload from '@libs/fileDownload'; import {isArchivedNonExpenseReport} from '@libs/ReportUtils'; -import {setDownload} from '@userActions/Download'; +import {setDownload} from '@userActions/Download'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type AnchorForAttachmentsOnlyProps from './types'; @@ -26,7 +26,7 @@ function BaseAnchorForAttachmentsOnly({style, source = '', displayName = '', onP const sourceURLWithAuth = addEncryptedAuthTokenToURL(source); const sourceID = (source.match(CONST.REGEX.ATTACHMENT_ID) ?? [])[1]; - const [download] = useOnyx(`${ONYXKEYS.COLLECTION.DOWNLOAD}${sourceID}`); + const [download] = useOnyx(`${ONYXKEYS.COLLECTION.DOWNLOAD}${sourceID}`, {canBeMissing: true}); const {isOffline} = useNetwork(); const styles = useThemeStyles(); diff --git a/src/pages/settings/Report/NotificationPreferencePage.tsx b/src/pages/settings/Report/NotificationPreferencePage.tsx index 237eb26778a2..bf36a89880d3 100644 --- a/src/pages/settings/Report/NotificationPreferencePage.tsx +++ b/src/pages/settings/Report/NotificationPreferencePage.tsx @@ -30,7 +30,7 @@ type NotificationPreferencePageProps = WithReportOrNotFoundProps & PlatformStack function NotificationPreferencePage({report}: NotificationPreferencePageProps) { const route = useRoute>(); const {translate} = useLocalize(); - const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID || undefined}`); + const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID || undefined}`, {canBeMissing: true}); const isMoneyRequestReport = isMoneyRequestReportUtils(report); const currentNotificationPreference = getReportNotificationPreference(report); const shouldDisableNotificationPreferences = diff --git a/src/pages/settings/Report/VisibilityPage.tsx b/src/pages/settings/Report/VisibilityPage.tsx index e01277e53e4f..5b76693477ea 100644 --- a/src/pages/settings/Report/VisibilityPage.tsx +++ b/src/pages/settings/Report/VisibilityPage.tsx @@ -24,10 +24,10 @@ type VisibilityProps = WithReportOrNotFoundProps & PlatformStackScreenProps>(); const [showConfirmModal, setShowConfirmModal] = useState(false); - const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID || undefined}`); + const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID || undefined}`, {canBeMissing: true}); const shouldGoBackToDetailsPage = useRef(false); - const shouldDisableVisibility = isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived, {canBeMissing: true}); + const shouldDisableVisibility = isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived); const {translate} = useLocalize(); const visibilityOptions = useMemo( From b286f5e7e5ad23851bfb457bd6f377fe68d26979 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Tue, 24 Jun 2025 03:03:14 +0300 Subject: [PATCH 10/17] refactoring --- .../BaseAnchorForAttachmentsOnly.tsx | 2 +- .../HTMLRenderers/ImageRenderer.tsx | 2 +- .../HTMLRenderers/MentionUserRenderer.tsx | 2 +- .../HTMLRenderers/PreRenderer.tsx | 2 +- src/components/ReportWelcomeText.tsx | 4 +-- .../VideoPlayerThumbnail.tsx | 2 +- src/libs/OptionsListUtils.ts | 4 +-- src/libs/ReportUtils.ts | 20 +++++------ src/libs/SidebarUtils.ts | 2 +- src/pages/ReportDetailsPage.tsx | 3 +- src/pages/ReportParticipantsPage.tsx | 5 +-- .../BaseReportActionContextMenu.tsx | 2 +- .../home/report/PureReportActionItem.tsx | 2 +- src/pages/home/report/ReportActionsList.tsx | 9 ++--- src/pages/home/report/ReportFooter.tsx | 6 ++-- .../Report/NotificationPreferencePage.tsx | 7 ++-- .../settings/Report/ReportSettingsPage.tsx | 7 ++-- src/pages/settings/Report/VisibilityPage.tsx | 8 ++--- tests/unit/ReportUtilsTest.ts | 34 +++++++++++++++---- 19 files changed, 70 insertions(+), 53 deletions(-) diff --git a/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx b/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx index 2ba5156d84be..c4bff718a887 100644 --- a/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx +++ b/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx @@ -57,7 +57,7 @@ function BaseAnchorForAttachmentsOnly({style, source = '', displayName = '', onP report?.reportID, action, checkIfContextMenuActive, - isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived), + isArchivedNonExpenseReport(report, !!reportNameValuePairs?.private_isArchived), ); }} shouldUseHapticsOnLongPress diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx index 7be94d00d6b0..d26bb0abffe3 100644 --- a/src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx +++ b/src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx @@ -126,7 +126,7 @@ function ImageRenderer({tnode}: ImageRendererProps) { report?.reportID, action, checkIfContextMenuActive, - isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived), + isArchivedNonExpenseReport(report, !!reportNameValuePairs?.private_isArchived), ), ); }} diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx index 7c49fe871180..f2ab2cf62ca7 100644 --- a/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx +++ b/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx @@ -84,7 +84,7 @@ function MentionUserRenderer({style, tnode, TDefaultRenderer, currentUserPersona report?.reportID, action, checkIfContextMenuActive, - isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived), + isArchivedNonExpenseReport(report, !!reportNameValuePairs?.private_isArchived), ), ); }} diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/PreRenderer.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/PreRenderer.tsx index 33e123daf9d3..cfaa6598b325 100644 --- a/src/components/HTMLEngineProvider/HTMLRenderers/PreRenderer.tsx +++ b/src/components/HTMLEngineProvider/HTMLRenderers/PreRenderer.tsx @@ -68,7 +68,7 @@ function PreRenderer({TDefaultRenderer, onPressIn, onPressOut, onLongPress, ...d report?.reportID, action, checkIfContextMenuActive, - isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived), + isArchivedNonExpenseReport(report, !!reportNameValuePairs?.private_isArchived), ); }); }} diff --git a/src/components/ReportWelcomeText.tsx b/src/components/ReportWelcomeText.tsx index df3b63d57d86..82882b486eb2 100644 --- a/src/components/ReportWelcomeText.tsx +++ b/src/components/ReportWelcomeText.tsx @@ -49,10 +49,7 @@ function ReportWelcomeText({report, policy}: ReportWelcomeTextProps) { const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {canBeMissing: false}); const isPolicyExpenseChat = isPolicyExpenseChatReportUtils(report); // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID || undefined}`, {canBeMissing: false}); - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report?.reportID || undefined}`, {canBeMissing: true}); - const isArchivedRoom = isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived); const isChatRoom = isChatRoomReportUtils(report); const isSelfDM = isSelfDMReportUtils(report); const isInvoiceRoom = isInvoiceRoomReportUtils(report); @@ -64,6 +61,7 @@ function ReportWelcomeText({report, policy}: ReportWelcomeTextProps) { const displayNamesWithTooltips = getDisplayNamesWithTooltips(getPersonalDetailsForAccountIDs(participantAccountIDs, personalDetails), isMultipleParticipant); const isReportArchived = useReportIsArchived(report?.reportID); const welcomeMessage = SidebarUtils.getWelcomeMessage(report, policy, isReportArchived); + const isArchivedRoom = isArchivedNonExpenseReport(report, isReportArchived); const moneyRequestOptions = temporary_getMoneyRequestOptions(report, policy, participantAccountIDs); const policyName = getPolicyName({report}); diff --git a/src/components/VideoPlayerPreview/VideoPlayerThumbnail.tsx b/src/components/VideoPlayerPreview/VideoPlayerThumbnail.tsx index d56b6d25ac42..03b5e9340a9c 100644 --- a/src/components/VideoPlayerPreview/VideoPlayerThumbnail.tsx +++ b/src/components/VideoPlayerPreview/VideoPlayerThumbnail.tsx @@ -64,7 +64,7 @@ function VideoPlayerThumbnail({thumbnailUrl, onPress, accessibilityLabel, isDele report?.reportID, action, checkIfContextMenuActive, - isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived), + isArchivedNonExpenseReport(report, !!reportNameValuePairs?.private_isArchived), ); }); }} diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 3155d852223f..90890d5fa69d 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -729,7 +729,7 @@ function getLastMessageTextForReport( const lastOriginalReportAction = reportID ? lastReportActions[reportID] : undefined; let lastMessageTextFromReport = ''; - if (isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived)) { + if (isArchivedNonExpenseReport(report, !!reportNameValuePairs?.private_isArchived)) { const archiveReason = // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing (isClosedAction(lastOriginalReportAction) && getOriginalMessage(lastOriginalReportAction)?.reason) || CONST.REPORT.ARCHIVE_REASON.DEFAULT; @@ -977,7 +977,7 @@ function createOption(accountIDs: number[], personalDetails: OnyxInputOrEntry, transact * Whether the provided report is an archived room */ // eslint-disable-next-line @typescript-eslint/no-unused-vars -function isArchivedNonExpenseReport(report: OnyxInputOrEntry | SearchReport, isReportArchived?: string): boolean { +function isArchivedNonExpenseReport(report: OnyxInputOrEntry | SearchReport, isReportArchived?: boolean): boolean { return !(isExpenseReport(report) || isExpenseRequest(report)) && !!isReportArchived; } @@ -3277,7 +3277,7 @@ function getIcons( isAdminRoom(report) || isAnnounceRoom(report) || isChatRoom(report) || - (isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived) && !chatIncludesConcierge(report)) + (isArchivedNonExpenseReport(report, !!reportNameValuePairs?.private_isArchived) && !chatIncludesConcierge(report)) ) { return getIconsForPolicyRoom(report, personalDetails, policy, invoiceReceiverPolicy); } @@ -3753,7 +3753,7 @@ function getPolicyExpenseChatName({ // of the account which was merged into the current user's account. Use the name of the policy as the name of the report. // This will get removed as part of https://github.com/Expensify/App/issues/59961 // eslint-disable-next-line deprecation/deprecation - if (isArchivedNonExpenseReport(report, getReportNameValuePairs(report?.reportID)?.private_isArchived)) { + if (isArchivedNonExpenseReport(report, !!getReportNameValuePairs(report?.reportID)?.private_isArchived)) { const lastAction = getLastVisibleActionReportActionsUtils(report?.reportID); const archiveReason = isClosedAction(lastAction) ? getOriginalMessage(lastAction)?.reason : CONST.REPORT.ARCHIVE_REASON.DEFAULT; if (archiveReason === CONST.REPORT.ARCHIVE_REASON.ACCOUNT_MERGED && policyExpenseChatRole !== CONST.POLICY.ROLE.ADMIN) { @@ -5049,7 +5049,7 @@ function getReportNameInternal({ const parentReportActionMessage = getReportActionMessageReportUtils(parentReportAction); const isArchivedNonExpense = isArchivedNonExpenseReport( report, - reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? String(CONST.DEFAULT_NUMBER_ID)}`]?.private_isArchived, + !!reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? String(CONST.DEFAULT_NUMBER_ID)}`]?.private_isArchived, ); if ( @@ -5382,7 +5382,7 @@ function getParentNavigationSubtitle(report: OnyxEntry, invoiceReceiverP // This will get removed as part of https://github.com/Expensify/App/issues/59961 // eslint-disable-next-line deprecation/deprecation - if (isArchivedNonExpenseReport(parentReport, getReportNameValuePairs(parentReport?.reportID)?.private_isArchived)) { + if (isArchivedNonExpenseReport(parentReport, !!getReportNameValuePairs(parentReport?.reportID)?.private_isArchived)) { reportName += ` (${translateLocal('common.archived')})`; } @@ -7853,7 +7853,7 @@ function canSeeDefaultRoom(report: OnyxEntry, policies: OnyxCollection

, rep canFlagReportAction(reportAction, report?.reportID) && // This will get removed as part of https://github.com/Expensify/App/issues/59961 // eslint-disable-next-line deprecation/deprecation - !isArchivedNonExpenseReport(report, getReportNameValuePairs(report?.reportID)?.private_isArchived) && + !isArchivedNonExpenseReport(report, !!getReportNameValuePairs(report?.reportID)?.private_isArchived) && !chatIncludesChronos(report) && !isConciergeChatReport(report) && reportAction?.actorAccountID !== CONST.ACCOUNT_ID.CONCIERGE @@ -8759,7 +8759,7 @@ function getWhisperDisplayNames(participantAccountIDs?: number[]): string | unde function shouldReportShowSubscript(report: OnyxEntry): boolean { // This will get removed as part of https://github.com/Expensify/App/issues/59961 // eslint-disable-next-line deprecation/deprecation - if (isArchivedNonExpenseReport(report, getReportNameValuePairs(report?.reportID)?.private_isArchived) && !isWorkspaceThread(report)) { + if (isArchivedNonExpenseReport(report, !!getReportNameValuePairs(report?.reportID)?.private_isArchived) && !isWorkspaceThread(report)) { return false; } @@ -8879,7 +8879,7 @@ function canUserPerformWriteAction(report: OnyxEntry) { // eslint-disable-next-line deprecation/deprecation const reportNameValuePairs = getReportNameValuePairs(report?.reportID); return ( - !isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived) && + !isArchivedNonExpenseReport(report, !!reportNameValuePairs?.private_isArchived) && isEmptyObject(reportErrors) && report && isAllowedToComment(report) && diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index a651ba492617..c32fd93a9b71 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -394,7 +394,7 @@ function sortReportsToDisplayInLHN( errorReports.push(miniReport); } else if (hasValidDraftComment(report?.reportID)) { draftReports.push(miniReport); - } else if (isArchivedNonExpenseReport(report, rNVPs?.private_isArchived)) { + } else if (isArchivedNonExpenseReport(report, !!rNVPs?.private_isArchived)) { archivedReports.push(miniReport); } else { nonArchivedReports.push(miniReport); diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index f5f426d40247..6006268e06d0 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -167,7 +167,6 @@ function ReportDetailsPage({policies, report, route, reportMetadata}: ReportDeta const [isDebugModeEnabled] = useOnyx(ONYXKEYS.ACCOUNT, {selector: (account) => !!account?.isDebugModeEnabled, canBeMissing: false}); const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {canBeMissing: false}); const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false}); - const [isLastMemberLeavingGroupModalVisible, setIsLastMemberLeavingGroupModalVisible] = useState(false); const [isDeleteModalVisible, setIsDeleteModalVisible] = useState(false); const policy = useMemo(() => policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`], [policies, report?.policyID]); @@ -179,7 +178,6 @@ function ReportDetailsPage({policies, report, route, reportMetadata}: ReportDeta const isUserCreatedPolicyRoom = useMemo(() => isUserCreatedPolicyRoomUtil(report), [report]); const isDefaultRoom = useMemo(() => isDefaultRoomUtil(report), [report]); const isChatThread = useMemo(() => isChatThreadUtil(report), [report]); - const isArchivedRoom = useMemo(() => isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived), [report, reportNameValuePairs]); const isMoneyRequestReport = useMemo(() => isMoneyRequestReportUtil(report), [report]); const isMoneyRequest = useMemo(() => isMoneyRequestUtil(report), [report]); const isInvoiceReport = useMemo(() => isInvoiceReportUtil(report), [report]); @@ -198,6 +196,7 @@ function ReportDetailsPage({policies, report, route, reportMetadata}: ReportDeta const isSingleTransactionView = isMoneyRequest || isTrackExpenseReport; const isSelfDMTrackExpenseReport = isTrackExpenseReport && isSelfDMUtil(parentReport); const isReportArchived = useReportIsArchived(report?.reportID); + const isArchivedRoom = useMemo(() => isArchivedNonExpenseReport(report, isReportArchived), [report, isReportArchived]); const shouldDisableRename = useMemo(() => shouldDisableRenameUtil(report, isReportArchived), [report, isReportArchived]); const parentNavigationSubtitleData = getParentNavigationSubtitle(report); const base62ReportID = getBase62ReportID(Number(report.reportID)); diff --git a/src/pages/ReportParticipantsPage.tsx b/src/pages/ReportParticipantsPage.tsx index db1d7288a3ea..5ff92c2bc1ed 100755 --- a/src/pages/ReportParticipantsPage.tsx +++ b/src/pages/ReportParticipantsPage.tsx @@ -21,6 +21,7 @@ import useFilteredSelection from '@hooks/useFilteredSelection'; import useLocalize from '@hooks/useLocalize'; import useMobileSelectionMode from '@hooks/useMobileSelectionMode'; import useNetwork from '@hooks/useNetwork'; +import useReportIsArchived from '@hooks/useReportIsArchived'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useSearchBackPress from '@hooks/useSearchBackPress'; import useStyleUtils from '@hooks/useStyleUtils'; @@ -71,7 +72,6 @@ function ReportParticipantsPage({report, route}: ReportParticipantsPageProps) { const selectionListRef = useRef(null); const textInputRef = useRef(null); const [userSearchPhrase] = useOnyx(ONYXKEYS.ROOM_MEMBERS_USER_SEARCH_PHRASE, {canBeMissing: true}); - const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`, {canBeMissing: false}); const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report?.reportID}`, {canBeMissing: false}); const [reportAttributes] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {selector: (attributes) => attributes?.reports, canBeMissing: false}); const {selectionMode} = useMobileSelectionMode(); @@ -84,6 +84,7 @@ function ReportParticipantsPage({report, route}: ReportParticipantsPageProps) { const {isOffline} = useNetwork(); const canSelectMultiple = isGroupChat && isCurrentUserAdmin && (isSmallScreenWidth ? selectionMode?.isEnabled : true); const [searchValue, setSearchValue] = useState(''); + const isReportArchived = useReportIsArchived(report?.reportID); const {chatParticipants, personalDetailsParticipants} = useMemo( () => getReportPersonalDetailsParticipants(report, personalDetails, reportMetadata), @@ -396,7 +397,7 @@ function ReportParticipantsPage({report, route}: ReportParticipantsPageProps) { style={[styles.defaultModalContainer]} testID={ReportParticipantsPage.displayName} > - + { diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx index 397fb43c758e..09fc2a881969 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx @@ -205,7 +205,7 @@ function BaseReportActionContextMenu({ isMoneyRequestOrReport && !isArchivedNonExpenseReport( transactionThreadReportID ? childReport : parentReport, - transactionThreadReportID ? childReportNameValuePairs?.private_isArchived : parentReportNameValuePairs?.private_isArchived, + transactionThreadReportID ? !!childReportNameValuePairs?.private_isArchived : !!parentReportNameValuePairs?.private_isArchived, ); const shouldEnableArrowNavigation = !isMini && (isVisible || shouldKeepOpen); diff --git a/src/pages/home/report/PureReportActionItem.tsx b/src/pages/home/report/PureReportActionItem.tsx index f907bf357b28..a7ccf23b9958 100644 --- a/src/pages/home/report/PureReportActionItem.tsx +++ b/src/pages/home/report/PureReportActionItem.tsx @@ -1231,7 +1231,7 @@ function PureReportActionItem({ ref={composerTextInputRef} shouldDisableEmojiPicker={ (chatIncludesConcierge(report) && isBlockedFromConcierge(blockedFromConcierge)) || - isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived) + isArchivedNonExpenseReport(report, !!reportNameValuePairs?.private_isArchived) } isGroupPolicyReport={!!report?.policyID && report.policyID !== CONST.POLICY.ID_FAKE} /> diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index 200cc4d82ad4..9e5f6e71505b 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -14,6 +14,7 @@ import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails' import useLocalize from '@hooks/useLocalize'; import useNetworkWithOfflineStatus from '@hooks/useNetworkWithOfflineStatus'; import usePrevious from '@hooks/usePrevious'; +import useReportIsArchived from '@hooks/useReportIsArchived'; import useReportScrollManager from '@hooks/useReportScrollManager'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; @@ -167,9 +168,9 @@ function ReportActionsList({ const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: false}); const [transactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {canBeMissing: true}); - const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`, {canBeMissing: true}); const [accountID] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session?.accountID, canBeMissing: true}); const participantsContext = useContext(PersonalDetailsContext); + const isReportArchived = useReportIsArchived(report?.reportID); const [isScrollToBottomEnabled, setIsScrollToBottomEnabled] = useState(false); @@ -551,7 +552,7 @@ function ReportActionsList({ const newMessageTimeReference = lastMessageTime.current && report.lastReadTime && lastMessageTime.current > report.lastReadTime ? userActiveSince.current : report.lastReadTime; lastMessageTime.current = null; - const isArchivedReport = isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived); + const isArchivedReport = isArchivedNonExpenseReport(report, isReportArchived); const hasNewMessagesInView = scrollingVerticalOffset.current < CONST.REPORT.ACTIONS.ACTION_VISIBLE_THRESHOLD; const hasUnreadReportAction = sortedVisibleReportActions.some( (reportAction) => @@ -622,8 +623,8 @@ function ReportActionsList({ // Native mobile does not render updates flatlist the changes even though component did update called. // To notify there something changes we can use extraData prop to flatlist const extraData = useMemo( - () => [shouldUseNarrowLayout ? unreadMarkerReportActionID : undefined, isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived)], - [unreadMarkerReportActionID, shouldUseNarrowLayout, report, reportNameValuePairs], + () => [shouldUseNarrowLayout ? unreadMarkerReportActionID : undefined, isArchivedNonExpenseReport(report, isReportArchived)], + [unreadMarkerReportActionID, shouldUseNarrowLayout, report, isReportArchived], ); const hideComposer = !canUserPerformWriteAction(report); const shouldShowReportRecipientLocalTime = canShowReportRecipientLocalTime(personalDetailsList, report, currentUserPersonalDetails.accountID) && !isComposerFullSize; diff --git a/src/pages/home/report/ReportFooter.tsx b/src/pages/home/report/ReportFooter.tsx index b60686649b93..320c6688ab8a 100644 --- a/src/pages/home/report/ReportFooter.tsx +++ b/src/pages/home/report/ReportFooter.tsx @@ -14,6 +14,7 @@ import {usePersonalDetails} from '@components/OnyxProvider'; import SwipeableView from '@components/SwipeableView'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; +import useReportIsArchived from '@hooks/useReportIsArchived'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; @@ -102,10 +103,9 @@ function ReportFooter({ }, canBeMissing: true, }); - const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`, {canBeMissing: true}); - + const isReportArchived = useReportIsArchived(report?.reportID); const chatFooterStyles = {...styles.chatFooter, minHeight: !isOffline ? CONST.CHAT_FOOTER_MIN_HEIGHT : 0}; - const isArchivedRoom = isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived); + const isArchivedRoom = isArchivedNonExpenseReport(report, isReportArchived); const isSmallSizeLayout = windowWidth - (shouldUseNarrowLayout ? 0 : variables.sideBarWithLHBWidth) < variables.anonymousReportFooterBreakpoint; diff --git a/src/pages/settings/Report/NotificationPreferencePage.tsx b/src/pages/settings/Report/NotificationPreferencePage.tsx index bf36a89880d3..62df62907ccd 100644 --- a/src/pages/settings/Report/NotificationPreferencePage.tsx +++ b/src/pages/settings/Report/NotificationPreferencePage.tsx @@ -1,6 +1,5 @@ import {useRoute} from '@react-navigation/native'; import React, {useCallback} from 'react'; -import {useOnyx} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; @@ -8,6 +7,7 @@ import ScreenWrapper from '@components/ScreenWrapper'; import SelectionList from '@components/SelectionList'; import RadioListItem from '@components/SelectionList/RadioListItem'; import useLocalize from '@hooks/useLocalize'; +import useReportIsArchived from '@hooks/useReportIsArchived'; import type {PlatformStackRouteProp, PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import { getReportNotificationPreference, @@ -22,7 +22,6 @@ import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNotFound'; import {updateNotificationPreference as updateNotificationPreferenceReportActionUtils} from '@userActions/Report'; import CONST from '@src/CONST'; -import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; type NotificationPreferencePageProps = WithReportOrNotFoundProps & PlatformStackScreenProps; @@ -30,11 +29,11 @@ type NotificationPreferencePageProps = WithReportOrNotFoundProps & PlatformStack function NotificationPreferencePage({report}: NotificationPreferencePageProps) { const route = useRoute>(); const {translate} = useLocalize(); - const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID || undefined}`, {canBeMissing: true}); const isMoneyRequestReport = isMoneyRequestReportUtils(report); const currentNotificationPreference = getReportNotificationPreference(report); + const isReportArchived = useReportIsArchived(report?.reportID); const shouldDisableNotificationPreferences = - isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived) || isSelfDM(report) || (!isMoneyRequestReport && isHiddenForCurrentUser(currentNotificationPreference)); + isArchivedNonExpenseReport(report, isReportArchived) || isSelfDM(report) || (!isMoneyRequestReport && isHiddenForCurrentUser(currentNotificationPreference)); const notificationPreferenceOptions = Object.values(CONST.REPORT.NOTIFICATION_PREFERENCE) .filter((pref) => !isHiddenForCurrentUser(pref)) .map((preference) => ({ diff --git a/src/pages/settings/Report/ReportSettingsPage.tsx b/src/pages/settings/Report/ReportSettingsPage.tsx index 16460d976f31..c97bd619a4c4 100644 --- a/src/pages/settings/Report/ReportSettingsPage.tsx +++ b/src/pages/settings/Report/ReportSettingsPage.tsx @@ -7,7 +7,7 @@ import ScreenWrapper from '@components/ScreenWrapper'; import ScrollView from '@components/ScrollView'; import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; -import useOnyx from '@hooks/useOnyx'; +import useReportIsArchived from '@hooks/useReportIsArchived'; import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; @@ -25,7 +25,6 @@ import type {ReportSettingsNavigatorParamList} from '@navigation/types'; import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNotFound'; import CONST from '@src/CONST'; -import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; @@ -37,8 +36,8 @@ function ReportSettingsPage({report, policies, route}: ReportSettingsPageProps) const reportID = report?.reportID; const styles = useThemeStyles(); const {translate} = useLocalize(); - const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`, {canBeMissing: true}); - const isArchivedNonExpenseReport = isArchivedNonExpenseReportUtils(report, reportNameValuePairs?.private_isArchived); + const isReportArchived = useReportIsArchived(reportID); + const isArchivedNonExpenseReport = isArchivedNonExpenseReportUtils(report, isReportArchived); // The workspace the report is on, null if the user isn't a member of the workspace const linkedWorkspace = useMemo(() => Object.values(policies ?? {}).find((policy) => policy && policy.id === report?.policyID), [policies, report?.policyID]); const isMoneyRequestReport = isMoneyRequestReportUtils(report); diff --git a/src/pages/settings/Report/VisibilityPage.tsx b/src/pages/settings/Report/VisibilityPage.tsx index 5b76693477ea..d6ba63bc29ed 100644 --- a/src/pages/settings/Report/VisibilityPage.tsx +++ b/src/pages/settings/Report/VisibilityPage.tsx @@ -1,6 +1,5 @@ import {useRoute} from '@react-navigation/native'; import React, {useCallback, useMemo, useRef, useState} from 'react'; -import {useOnyx} from 'react-native-onyx'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; import ConfirmModal from '@components/ConfirmModal'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; @@ -8,6 +7,7 @@ import ScreenWrapper from '@components/ScreenWrapper'; import SelectionList from '@components/SelectionList'; import RadioListItem from '@components/SelectionList/RadioListItem'; import useLocalize from '@hooks/useLocalize'; +import useReportIsArchived from '@hooks/useReportIsArchived'; import type {PlatformStackRouteProp, PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import type {ReportSettingsNavigatorParamList} from '@libs/Navigation/types'; import {goBackToDetailsPage, isArchivedNonExpenseReport} from '@libs/ReportUtils'; @@ -15,7 +15,6 @@ import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNot import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; import {updateRoomVisibility} from '@userActions/Report'; import CONST from '@src/CONST'; -import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; import type {RoomVisibility} from '@src/types/onyx/Report'; @@ -24,10 +23,11 @@ type VisibilityProps = WithReportOrNotFoundProps & PlatformStackScreenProps>(); const [showConfirmModal, setShowConfirmModal] = useState(false); - const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID || undefined}`, {canBeMissing: true}); const shouldGoBackToDetailsPage = useRef(false); - const shouldDisableVisibility = isArchivedNonExpenseReport(report, reportNameValuePairs?.private_isArchived); + const isReportArchived = useReportIsArchived(report?.reportID); + const shouldDisableVisibility = isArchivedNonExpenseReport(report, isReportArchived); + const {translate} = useLocalize(); const visibilityOptions = useMemo( diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index b0ce1386ffd2..23e172ae71b9 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -2477,16 +2477,36 @@ describe('ReportUtils', () => { }); describe('canEditRoomVisibility', () => { + const policyRoomReport: Report = { + ...LHNTestUtils.getFakeReport(), + chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, + reportID: '1', + }; + it('should return true for policy rooms that are not archived and the user is an admin', () => { - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, false)).toBe(true); - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR}, false)).toBe(false); - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.USER}, false)).toBe(false); + const {result: isReportArchived} = renderHook(() => useReportIsArchived(policyRoomReport?.reportID)); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, isReportArchived.current)).toBeTruthy(); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR}, isReportArchived.current)).toBeFalsy(); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.USER}, isReportArchived.current)).toBeFalsy(); + }); + + it('should return false for policy rooms that are archived regardless of the policy role', async () => { + const reportNameValuePairs = { + type: 'chat', + private_isArchived: DateUtils.getDBTime(), + }; + + // Archiving the workspace + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${policyRoomReport.reportID}`, reportNameValuePairs); + const {result: isReportArchived} = renderHook(() => useReportIsArchived(policyRoomReport?.reportID)); + + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, isReportArchived.current)).toBeFalsy(); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR}, isReportArchived.current)).toBeFalsy(); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.USER}, isReportArchived.current)).toBeFalsy(); }); - it('should return false for policy rooms that are archived regardless of the policy role', () => { - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, true)).toBe(false); - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR}, true)).toBe(false); - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.USER}, true)).toBe(false); + afterAll(async () => { + await Onyx.clear(); }); }); From 79ca8804c527bade690d2300fb4114eb6c350cfc Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Wed, 25 Jun 2025 02:13:19 +0300 Subject: [PATCH 11/17] defaulting to false for isArchivedNonExpenseReport --- src/libs/ReportUtils.ts | 4 ++-- tests/unit/ReportUtilsTest.ts | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 27372ec3f881..a029bca0f3ac 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2054,8 +2054,8 @@ function isClosedExpenseReportWithNoExpenses(report: OnyxEntry, transact * Whether the provided report is an archived room */ // eslint-disable-next-line @typescript-eslint/no-unused-vars -function isArchivedNonExpenseReport(report: OnyxInputOrEntry | SearchReport, isReportArchived?: boolean): boolean { - return !(isExpenseReport(report) || isExpenseRequest(report)) && !!isReportArchived; +function isArchivedNonExpenseReport(report: OnyxInputOrEntry | SearchReport, isReportArchived = false): boolean { + return isReportArchived && !(isExpenseReport(report) || isExpenseRequest(report)) } /** diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 0d09dc1434fd..b9d2dd5a89fc 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -46,8 +46,9 @@ import { getWorkspaceNameUpdatedMessage, hasReceiptError, isAllowedToApproveExpenseReport, - isArchivedNonExpenseReportWithID, isArchivedReport, + isArchivedNonExpenseReport as isArchivedNonExpenseReportUtils, + isArchivedNonExpenseReportWithID, isChatUsedForOnboarding, isPayer, isReportOutstanding, @@ -2577,9 +2578,10 @@ describe('ReportUtils', () => { it('should return true for policy rooms that are not archived and the user is an admin', () => { const {result: isReportArchived} = renderHook(() => useReportIsArchived(policyRoomReport?.reportID)); - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, isReportArchived.current)).toBeTruthy(); - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR}, isReportArchived.current)).toBeFalsy(); - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.USER}, isReportArchived.current)).toBeFalsy(); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, isArchivedNonExpenseReportUtils(policyRoomReport, isReportArchived.current))).toBeTruthy(); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, isArchivedNonExpenseReportUtils(policyRoomReport, isReportArchived.current))).toBeTruthy(); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR}, isArchivedNonExpenseReportUtils(policyRoomReport, isReportArchived.current))).toBeFalsy(); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.USER}, isArchivedNonExpenseReportUtils(policyRoomReport, isReportArchived.current))).toBeFalsy(); }); it('should return false for policy rooms that are archived regardless of the policy role', async () => { @@ -2588,13 +2590,12 @@ describe('ReportUtils', () => { private_isArchived: DateUtils.getDBTime(), }; - // Archiving the workspace await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${policyRoomReport.reportID}`, reportNameValuePairs); const {result: isReportArchived} = renderHook(() => useReportIsArchived(policyRoomReport?.reportID)); - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, isReportArchived.current)).toBeFalsy(); - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR}, isReportArchived.current)).toBeFalsy(); - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.USER}, isReportArchived.current)).toBeFalsy(); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, isArchivedNonExpenseReportUtils(policyRoomReport, isReportArchived.current))).toBeFalsy(); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR}, isArchivedNonExpenseReportUtils(policyRoomReport, isReportArchived.current))).toBeFalsy(); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.USER}, isArchivedNonExpenseReportUtils(policyRoomReport, isReportArchived.current))).toBeFalsy(); }); afterAll(async () => { From 7023bc4993561323e0bf023f14c08602eb012b89 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Wed, 25 Jun 2025 02:33:01 +0300 Subject: [PATCH 12/17] lint --- src/libs/ReportUtils.ts | 2 +- .../settings/Report/ReportSettingsPage.tsx | 2 +- tests/unit/ReportUtilsTest.ts | 18 ++++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index a029bca0f3ac..2d1701fbc794 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2055,7 +2055,7 @@ function isClosedExpenseReportWithNoExpenses(report: OnyxEntry, transact */ // eslint-disable-next-line @typescript-eslint/no-unused-vars function isArchivedNonExpenseReport(report: OnyxInputOrEntry | SearchReport, isReportArchived = false): boolean { - return isReportArchived && !(isExpenseReport(report) || isExpenseRequest(report)) + return isReportArchived && !(isExpenseReport(report) || isExpenseRequest(report)); } /** diff --git a/src/pages/settings/Report/ReportSettingsPage.tsx b/src/pages/settings/Report/ReportSettingsPage.tsx index 6af86ea13e7d..990137714eb8 100644 --- a/src/pages/settings/Report/ReportSettingsPage.tsx +++ b/src/pages/settings/Report/ReportSettingsPage.tsx @@ -39,7 +39,7 @@ function ReportSettingsPage({report, policy, route}: ReportSettingsPageProps) { const isReportArchived = useReportIsArchived(reportID); const isArchivedNonExpenseReport = isArchivedNonExpenseReportUtils(report, isReportArchived); // The workspace the report is on, null if the user isn't a member of the workspace - const linkedWorkspace = useMemo(() => Object.values(policies ?? {}).find((policy) => policy && policy.id === report?.policyID), [policies, report?.policyID]); + const linkedWorkspace = useMemo(() => (report?.policyID && policy?.id === report?.policyID ? policy : undefined), [policy, report?.policyID]); const isMoneyRequestReport = isMoneyRequestReportUtils(report); const shouldDisableSettings = isArchivedNonExpenseReport || isEmptyObject(report) || isSelfDM(report); const notificationPreferenceValue = getReportNotificationPreference(report); diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index b9d2dd5a89fc..c5c7cf32a68f 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -46,9 +46,9 @@ import { getWorkspaceNameUpdatedMessage, hasReceiptError, isAllowedToApproveExpenseReport, - isArchivedReport, isArchivedNonExpenseReport as isArchivedNonExpenseReportUtils, isArchivedNonExpenseReportWithID, + isArchivedReport, isChatUsedForOnboarding, isPayer, isReportOutstanding, @@ -2578,10 +2578,11 @@ describe('ReportUtils', () => { it('should return true for policy rooms that are not archived and the user is an admin', () => { const {result: isReportArchived} = renderHook(() => useReportIsArchived(policyRoomReport?.reportID)); - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, isArchivedNonExpenseReportUtils(policyRoomReport, isReportArchived.current))).toBeTruthy(); - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, isArchivedNonExpenseReportUtils(policyRoomReport, isReportArchived.current))).toBeTruthy(); - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR}, isArchivedNonExpenseReportUtils(policyRoomReport, isReportArchived.current))).toBeFalsy(); - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.USER}, isArchivedNonExpenseReportUtils(policyRoomReport, isReportArchived.current))).toBeFalsy(); + const isArchivedNonExpenseReport = isArchivedNonExpenseReportUtils(policyRoomReport, isReportArchived.current) + + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, isArchivedNonExpenseReport)).toBeTruthy(); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR}, isArchivedNonExpenseReport)).toBeFalsy(); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.USER}, isArchivedNonExpenseReport)).toBeFalsy(); }); it('should return false for policy rooms that are archived regardless of the policy role', async () => { @@ -2592,10 +2593,11 @@ describe('ReportUtils', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${policyRoomReport.reportID}`, reportNameValuePairs); const {result: isReportArchived} = renderHook(() => useReportIsArchived(policyRoomReport?.reportID)); + const isArchivedNonExpenseReport = isArchivedNonExpenseReportUtils(policyRoomReport, isReportArchived.current) - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, isArchivedNonExpenseReportUtils(policyRoomReport, isReportArchived.current))).toBeFalsy(); - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR}, isArchivedNonExpenseReportUtils(policyRoomReport, isReportArchived.current))).toBeFalsy(); - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.USER}, isArchivedNonExpenseReportUtils(policyRoomReport, isReportArchived.current))).toBeFalsy(); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, isArchivedNonExpenseReport)).toBeFalsy(); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR}, isArchivedNonExpenseReport)).toBeFalsy(); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.USER}, isArchivedNonExpenseReport)).toBeFalsy(); }); afterAll(async () => { From 87aefdf56236a4ad28e99ff2967fd24e4730850d Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Wed, 25 Jun 2025 02:42:11 +0300 Subject: [PATCH 13/17] prettier --- tests/unit/ReportUtilsTest.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index c5c7cf32a68f..e24f9a857246 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -2576,9 +2576,13 @@ describe('ReportUtils', () => { reportID: '1', }; + beforeAll(async () => { + await Onyx.clear(); + }); + it('should return true for policy rooms that are not archived and the user is an admin', () => { const {result: isReportArchived} = renderHook(() => useReportIsArchived(policyRoomReport?.reportID)); - const isArchivedNonExpenseReport = isArchivedNonExpenseReportUtils(policyRoomReport, isReportArchived.current) + const isArchivedNonExpenseReport = isArchivedNonExpenseReportUtils(policyRoomReport, isReportArchived.current); expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, isArchivedNonExpenseReport)).toBeTruthy(); expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR}, isArchivedNonExpenseReport)).toBeFalsy(); @@ -2593,7 +2597,7 @@ describe('ReportUtils', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${policyRoomReport.reportID}`, reportNameValuePairs); const {result: isReportArchived} = renderHook(() => useReportIsArchived(policyRoomReport?.reportID)); - const isArchivedNonExpenseReport = isArchivedNonExpenseReportUtils(policyRoomReport, isReportArchived.current) + const isArchivedNonExpenseReport = isArchivedNonExpenseReportUtils(policyRoomReport, isReportArchived.current); expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, isArchivedNonExpenseReport)).toBeFalsy(); expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR}, isArchivedNonExpenseReport)).toBeFalsy(); From 5a220f535d0474aba61dfa8fa5177375629c1a31 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Thu, 26 Jun 2025 16:31:44 +0300 Subject: [PATCH 14/17] revert --- .../settings/Report/ReportSettingsPage.tsx | 2 +- tests/unit/ReportUtilsTest.ts | 24 +++++-------------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/pages/settings/Report/ReportSettingsPage.tsx b/src/pages/settings/Report/ReportSettingsPage.tsx index 990137714eb8..082e6211571d 100644 --- a/src/pages/settings/Report/ReportSettingsPage.tsx +++ b/src/pages/settings/Report/ReportSettingsPage.tsx @@ -49,7 +49,7 @@ function ReportSettingsPage({report, policy, route}: ReportSettingsPageProps) { : ''; const writeCapability = isAdminRoom(report) ? CONST.REPORT.WRITE_CAPABILITIES.ADMINS : (report?.writeCapability ?? CONST.REPORT.WRITE_CAPABILITIES.ALL); const writeCapabilityText = translate(`writeCapabilityPage.writeCapability.${writeCapability}`); - const shouldAllowWriteCapabilityEditing = useMemo(() => canEditWriteCapability(report, linkedWorkspace), [report, linkedWorkspace]); + const shouldAllowWriteCapabilityEditing = useMemo(() => canEditWriteCapability(report, linkedWorkspace, isReportArchived), [report, linkedWorkspace, isReportArchived]); const shouldAllowChangeVisibility = useMemo(() => canEditRoomVisibility(linkedWorkspace, isArchivedNonExpenseReport), [linkedWorkspace, isArchivedNonExpenseReport]); const shouldShowNotificationPref = !isMoneyRequestReport && !isHiddenForCurrentUser(notificationPreferenceValue); diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index e24f9a857246..fd0673d88522 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -2581,27 +2581,15 @@ describe('ReportUtils', () => { }); it('should return true for policy rooms that are not archived and the user is an admin', () => { - const {result: isReportArchived} = renderHook(() => useReportIsArchived(policyRoomReport?.reportID)); - const isArchivedNonExpenseReport = isArchivedNonExpenseReportUtils(policyRoomReport, isReportArchived.current); - - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, isArchivedNonExpenseReport)).toBeTruthy(); - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR}, isArchivedNonExpenseReport)).toBeFalsy(); - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.USER}, isArchivedNonExpenseReport)).toBeFalsy(); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, false)).toBeTruthy(); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR}, false)).toBeFalsy(); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.USER}, false)).toBeFalsy(); }); it('should return false for policy rooms that are archived regardless of the policy role', async () => { - const reportNameValuePairs = { - type: 'chat', - private_isArchived: DateUtils.getDBTime(), - }; - - await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${policyRoomReport.reportID}`, reportNameValuePairs); - const {result: isReportArchived} = renderHook(() => useReportIsArchived(policyRoomReport?.reportID)); - const isArchivedNonExpenseReport = isArchivedNonExpenseReportUtils(policyRoomReport, isReportArchived.current); - - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, isArchivedNonExpenseReport)).toBeFalsy(); - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR}, isArchivedNonExpenseReport)).toBeFalsy(); - expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.USER}, isArchivedNonExpenseReport)).toBeFalsy(); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, true)).toBeFalsy(); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR}, true)).toBeFalsy(); + expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.USER}, true)).toBeFalsy(); }); afterAll(async () => { From 5e2a5d53eeedfb4f531cadfb11863bcd85846fd4 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Thu, 26 Jun 2025 16:33:27 +0300 Subject: [PATCH 15/17] lint --- tests/unit/ReportUtilsTest.ts | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index fd0673d88522..65261f746e70 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -2570,16 +2570,6 @@ describe('ReportUtils', () => { }); describe('canEditRoomVisibility', () => { - const policyRoomReport: Report = { - ...LHNTestUtils.getFakeReport(), - chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, - reportID: '1', - }; - - beforeAll(async () => { - await Onyx.clear(); - }); - it('should return true for policy rooms that are not archived and the user is an admin', () => { expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, false)).toBeTruthy(); expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR}, false)).toBeFalsy(); @@ -2591,10 +2581,6 @@ describe('ReportUtils', () => { expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR}, true)).toBeFalsy(); expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.USER}, true)).toBeFalsy(); }); - - afterAll(async () => { - await Onyx.clear(); - }); }); describe('canDeleteReportAction', () => { From 9b3219a13f5df8bf01087b8e937b997037733ba1 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Thu, 26 Jun 2025 16:51:47 +0300 Subject: [PATCH 16/17] lint --- tests/unit/ReportUtilsTest.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 65261f746e70..30912baae97b 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -46,7 +46,6 @@ import { getWorkspaceNameUpdatedMessage, hasReceiptError, isAllowedToApproveExpenseReport, - isArchivedNonExpenseReport as isArchivedNonExpenseReportUtils, isArchivedNonExpenseReportWithID, isArchivedReport, isChatUsedForOnboarding, From 2313b8d76754a878166011452552fcf130e2555a Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Thu, 26 Jun 2025 16:58:28 +0300 Subject: [PATCH 17/17] removing async --- tests/unit/ReportUtilsTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 30912baae97b..a93aca1944b9 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -2575,7 +2575,7 @@ describe('ReportUtils', () => { expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.USER}, false)).toBeFalsy(); }); - it('should return false for policy rooms that are archived regardless of the policy role', async () => { + it('should return false for policy rooms that are archived regardless of the policy role', () => { expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.ADMIN}, true)).toBeFalsy(); expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.AUDITOR}, true)).toBeFalsy(); expect(canEditRoomVisibility({...policy, role: CONST.POLICY.ROLE.USER}, true)).toBeFalsy();