diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index f501244a725d..3b3e24867a4f 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -5,9 +5,9 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {PolicyTagList, ReportAction} from '@src/types/onyx'; import * as CurrencyUtils from './CurrencyUtils'; import DateUtils from './DateUtils'; +import getReportPolicyID from './getReportPolicyID'; import * as Localize from './Localize'; import * as PolicyUtils from './PolicyUtils'; -import * as ReportUtils from './ReportUtils'; import type {ExpenseOriginalMessage} from './ReportUtils'; import * as TransactionUtils from './TransactionUtils'; @@ -97,12 +97,12 @@ function getForDistanceRequest(newDistance: string, oldDistance: string, newAmou * ModifiedExpense::getNewDotComment in Web-Expensify should match this. * If we change this function be sure to update the backend as well. */ -function getForReportAction(reportID: string | undefined, reportAction: OnyxEntry): string { +function getForReportAction(reportID: string | undefined, reportAction: OnyxEntry | ReportAction | Record): string { if (reportAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE) { return ''; } const reportActionOriginalMessage = reportAction?.originalMessage as ExpenseOriginalMessage | undefined; - const policyID = ReportUtils.getReportPolicyID(reportID) ?? ''; + const policyID = getReportPolicyID(reportID) ?? ''; const removalFragments: string[] = []; const setFragments: string[] = []; diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 1df59508257a..64bac4f46b5a 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -135,7 +135,7 @@ function isReportPreviewAction(reportAction: OnyxEntry): boolean { return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW; } -function isModifiedExpenseAction(reportAction: OnyxEntry): boolean { +function isModifiedExpenseAction(reportAction: OnyxEntry | ReportAction | Record): boolean { return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE; } diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index e7a6af8c6f3a..aca25f4926a8 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -55,11 +55,13 @@ import * as store from './actions/ReimbursementAccount/store'; import * as CollectionUtils from './CollectionUtils'; import * as CurrencyUtils from './CurrencyUtils'; import DateUtils from './DateUtils'; +import originalGetReportPolicyID from './getReportPolicyID'; import isReportMessageAttachment from './isReportMessageAttachment'; import localeCompare from './LocaleCompare'; import * as LocalePhoneNumber from './LocalePhoneNumber'; import * as Localize from './Localize'; import {isEmailPublicDomain} from './LoginUtils'; +import ModifiedExpenseMessage from './ModifiedExpenseMessage'; import linkingConfig from './Navigation/linkingConfig'; import Navigation from './Navigation/Navigation'; import * as NumberUtils from './NumberUtils'; @@ -2772,6 +2774,9 @@ function getReportName(report: OnyxEntry, policy: OnyxEntry = nu if (parentReportActionMessage && isArchivedRoom(report)) { return `${parentReportActionMessage} (${Localize.translateLocal('common.archived')})`; } + if (ReportActionsUtils.isModifiedExpenseAction(parentReportAction)) { + return ModifiedExpenseMessage.getForReportAction(report?.reportID, parentReportAction); + } return parentReportActionMessage; } @@ -4619,7 +4624,7 @@ function getReportIDFromLink(url: string | null): string { * Get the report policyID given a reportID */ function getReportPolicyID(reportID?: string): string | undefined { - return getReport(reportID)?.policyID; + return originalGetReportPolicyID(reportID); } /** diff --git a/src/libs/getReportPolicyID.ts b/src/libs/getReportPolicyID.ts new file mode 100644 index 000000000000..12124f24fbe7 --- /dev/null +++ b/src/libs/getReportPolicyID.ts @@ -0,0 +1,33 @@ +import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; +import Onyx from 'react-native-onyx'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type {Report} from '@src/types/onyx'; +import type {EmptyObject} from '@src/types/utils/EmptyObject'; + +let allReports: OnyxCollection; +Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (value) => (allReports = value), +}); + +/** + * Get the report given a reportID + */ +function getReport(reportID: string | undefined): OnyxEntry | EmptyObject { + if (!allReports) { + return {}; + } + + return allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] ?? {}; +} + +/** + * Get the report policyID given a reportID. + * We need to define this method in a separate file to avoid cyclic dependency. + */ +function getReportPolicyID(reportID?: string): string | undefined { + return getReport(reportID)?.policyID; +} + +export default getReportPolicyID;