diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 142b319240f..9a2c3089e62 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4097,8 +4097,17 @@ function buildOptimisticInvoiceReport(chatReportID: string, policyID: string, re * @param total - Amount in cents * @param currency * @param reimbursable – Whether the expense is reimbursable + * @param parentReportActionID – The parent ReportActionID of the PolicyExpenseChat */ -function buildOptimisticExpenseReport(chatReportID: string, policyID: string, payeeAccountID: number, total: number, currency: string, reimbursable = true): OptimisticExpenseReport { +function buildOptimisticExpenseReport( + chatReportID: string, + policyID: string, + payeeAccountID: number, + total: number, + currency: string, + reimbursable = true, + parentReportActionID?: string, +): OptimisticExpenseReport { // The amount for Expense reports are stored as negative value in the database const storedTotal = total * -1; const policyName = getPolicyName(ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`]); @@ -4126,6 +4135,7 @@ function buildOptimisticExpenseReport(chatReportID: string, policyID: string, pa notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, parentReportID: chatReportID, lastVisibleActionCreated: DateUtils.getDBTime(), + parentReportActionID, }; // Get the approver/manager for this report to properly display the optimistic data @@ -4472,6 +4482,7 @@ function buildOptimisticSubmittedReportAction(amount: number, currency: string, * @param iouReport * @param [comment] - User comment for the IOU. * @param [transaction] - optimistic first transaction of preview + * @param reportActionID */ function buildOptimisticReportPreview( chatReport: OnyxInputOrEntry, @@ -4479,12 +4490,13 @@ function buildOptimisticReportPreview( comment = '', transaction: OnyxInputOrEntry = null, childReportID?: string, + reportActionID?: string, ): ReportAction { const hasReceipt = TransactionUtils.hasReceipt(transaction); const message = getReportPreviewMessage(iouReport); const created = DateUtils.getDBTime(); return { - reportActionID: NumberUtils.rand64(), + reportActionID: reportActionID ?? NumberUtils.rand64(), reportID: chatReport?.reportID, actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index f6eac67a86f..e6320445255 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -6249,6 +6249,7 @@ function getReportFromHoldRequestsOnyxData( } { const {holdReportActions, holdTransactions} = getHoldReportActionsAndTransactions(iouReport.reportID); const firstHoldTransaction = holdTransactions[0]; + const newParentReportActionID = rand64(); const optimisticExpenseReport = ReportUtils.buildOptimisticExpenseReport( chatReport.reportID, @@ -6257,8 +6258,16 @@ function getReportFromHoldRequestsOnyxData( (firstHoldTransaction?.amount ?? 0) * -1, getCurrency(firstHoldTransaction), false, + newParentReportActionID, + ); + const optimisticExpenseReportPreview = ReportUtils.buildOptimisticReportPreview( + chatReport, + optimisticExpenseReport, + '', + firstHoldTransaction, + optimisticExpenseReport.reportID, + newParentReportActionID, ); - const optimisticExpenseReportPreview = ReportUtils.buildOptimisticReportPreview(chatReport, optimisticExpenseReport, '', firstHoldTransaction, optimisticExpenseReport.reportID); const updateHeldReports: Record> = {}; const addHoldReportActions: OnyxTypes.ReportActions = {};