diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 55dd2eb4fe39..cec60cb0222f 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -1549,6 +1549,7 @@ function createDistanceRequest( moneyRequestReportID, ); + const activeReportID = isMoneyRequestReport ? report?.reportID ?? '' : chatReport.reportID; const parameters: CreateDistanceRequestParams = { comment, iouReportID: iouReport.reportID, @@ -1569,8 +1570,8 @@ function createDistanceRequest( }; API.write(WRITE_COMMANDS.CREATE_DISTANCE_REQUEST, parameters, onyxData); - Navigation.dismissModal(isMoneyRequestReport ? report?.reportID : chatReport.reportID); - Report.notifyNewAction(chatReport.reportID, userAccountID); + Navigation.dismissModal(activeReportID); + Report.notifyNewAction(activeReportID, userAccountID); } /** diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index 85566b8c5fa0..361cedd56354 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -197,7 +197,8 @@ function ReportActionsList({ const lastActionIndex = sortedVisibleReportActions[0]?.reportActionID; const reportActionSize = useRef(sortedVisibleReportActions.length); const hasNewestReportAction = sortedReportActions?.[0].created === report.lastVisibleActionCreated; - + const hasNewestReportActionRef = useRef(hasNewestReportAction); + hasNewestReportActionRef.current = hasNewestReportAction; const previousLastIndex = useRef(lastActionIndex); const isLastPendingActionIsDelete = sortedReportActions?.[0]?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; @@ -322,14 +323,13 @@ function ReportActionsList({ (isFromCurrentUser: boolean) => { // If a new comment is added and it's from the current user scroll to the bottom otherwise leave the user positioned where // they are now in the list. - if (!isFromCurrentUser || !hasNewestReportAction) { + if (!isFromCurrentUser || !hasNewestReportActionRef.current) { return; } InteractionManager.runAfterInteractions(() => reportScrollManager.scrollToBottom()); }, - [hasNewestReportAction, reportScrollManager], + [reportScrollManager], ); - useEffect(() => { // Why are we doing this, when in the cleanup of the useEffect we are already calling the unsubscribe function? // Answer: On web, when navigating to another report screen, the previous report screen doesn't get unmounted,