diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index b3a240091c3e..0d9e3d93b53a 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5505,7 +5505,7 @@ function buildOptimisticExpenseReport( return expenseReport; } -function buildOptimisticEmptyReport(reportID: string, accountID: number, parentReport: OnyxEntry, policy: OnyxEntry, timeOfCreation: string) { +function buildOptimisticEmptyReport(reportID: string, accountID: number, parentReport: OnyxEntry, parentReportActionID: string, policy: OnyxEntry, timeOfCreation: string) { const {stateNum, statusNum} = getExpenseReportStateAndStatus(policy); const titleReportField = getTitleReportField(getReportFieldsByPolicyID(policy?.id) ?? {}); const optimisticEmptyReport: OptimisticNewReport = { @@ -5523,6 +5523,7 @@ function buildOptimisticEmptyReport(reportID: string, accountID: number, parentR lastVisibleActionCreated: timeOfCreation, pendingFields: {createReport: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}, parentReportID: parentReport?.reportID, + parentReportActionID, chatReportID: parentReport?.reportID, managerID: getSubmitToAccountID(policy, undefined), }; diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index c87f5d029a83..367b946a686f 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2509,7 +2509,7 @@ function buildNewReportOptimisticData(policy: OnyxEntry, reportID: strin const {accountID, login} = creatorPersonalDetails; const timeOfCreation = DateUtils.getDBTime(); const parentReport = getPolicyExpenseChat(accountID, policy?.id); - const optimisticReportData = buildOptimisticEmptyReport(reportID, accountID, parentReport, policy, timeOfCreation); + const optimisticReportData = buildOptimisticEmptyReport(reportID, accountID, parentReport, reportPreviewReportActionID, policy, timeOfCreation); const optimisticCreateAction = { action: CONST.REPORT.ACTIONS.TYPE.CREATED, @@ -2549,6 +2549,9 @@ function buildNewReportOptimisticData(policy: OnyxEntry, reportID: strin isAttachmentOnly: false, reportActionID: reportPreviewReportActionID, message: createReportActionMessage, + originalMessage: { + linkedReportID: reportID, + }, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, }; diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index 1ab229171215..e7c4271c1488 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -8,6 +8,7 @@ import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; import OnyxUtils from 'react-native-onyx/dist/OnyxUtils'; import {WRITE_COMMANDS} from '@libs/API/types'; import HttpUtils from '@libs/HttpUtils'; +import {getOriginalMessage} from '@libs/ReportActionsUtils'; import initOnyxDerivedValues from '@userActions/OnyxDerived'; import CONST from '@src/CONST'; import OnyxUpdateManager from '@src/libs/actions/OnyxUpdateManager'; @@ -1529,7 +1530,22 @@ describe('actions/Report', () => { }); it('should create new report and "create report" quick action, when createNewReport gets called', async () => { - const reportID = Report.createNewReport({accountID: 1234}, '5678'); + const accountID = 1234; + const policyID = '5678'; + const reportID = Report.createNewReport({accountID}, policyID); + const parentReport = ReportUtils.getPolicyExpenseChat(accountID, policyID); + const reportPreviewAction = await new Promise>>((resolve) => { + const connection = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReport?.reportID}`, + callback: (reportActions) => { + Onyx.disconnect(connection); + const action = Object.values(reportActions ?? {}).at(0); + resolve(action as OnyxTypes.ReportAction); + }, + }); + }); + expect(getOriginalMessage(reportPreviewAction)?.linkedReportID).toBe(reportID); + await new Promise((resolve) => { const connection = Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT, @@ -1541,6 +1557,7 @@ describe('actions/Report', () => { // assert correctness of crucial onyx data expect(createdReport?.reportID).toBe(reportID); expect(createdReport?.total).toBe(0); + expect(createdReport?.parentReportActionID).toBe(reportPreviewAction?.reportActionID); resolve(); }, diff --git a/tests/unit/NextStepUtilsTest.ts b/tests/unit/NextStepUtilsTest.ts index cd50848fbdca..0ffe9e650110 100644 --- a/tests/unit/NextStepUtilsTest.ts +++ b/tests/unit/NextStepUtilsTest.ts @@ -77,7 +77,14 @@ describe('libs/NextStepUtils', () => { describe('it generates and optimistic nextStep once a report has been created', () => { test('Correct next steps message', () => { - const emptyReport = buildOptimisticEmptyReport('fake-empty-report-id-2', currentUserAccountID, {reportID: 'fake-parent-report-id-3'}, policy, '2025-03-31 13:23:11'); + const emptyReport = buildOptimisticEmptyReport( + 'fake-empty-report-id-2', + currentUserAccountID, + {reportID: 'fake-parent-report-id-3'}, + 'fake-parent-report-action-id-4', + policy, + '2025-03-31 13:23:11', + ); optimisticNextStep.message = [ {