diff --git a/src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx b/src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx index 4a2eb35278d3..e5129125416e 100644 --- a/src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx +++ b/src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx @@ -619,7 +619,7 @@ function MoneyRequestReportActionsList({onLayout}: MoneyRequestReportListProps) setIsFloatingMessageCounterVisible(false); if (!hasNewestReportAction) { - openReport({reportID, introSelected, betas}); + openReport({reportID, introSelected, betas, hasReportActions: true}); reportScrollManager.scrollToEnd(); return; } diff --git a/src/hooks/useReportActionsScroll.ts b/src/hooks/useReportActionsScroll.ts index f277d6ecff7a..324755e705fd 100644 --- a/src/hooks/useReportActionsScroll.ts +++ b/src/hooks/useReportActionsScroll.ts @@ -334,7 +334,7 @@ function useReportActionsScroll({ if (!Navigation.getReportRHPActiveRoute()) { Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(reportID, undefined, undefined, backTo)); } - openReport({reportID, introSelected, betas}); + openReport({reportID, introSelected, betas, hasReportActions: true}); reportScrollManager.scrollToBottom(); return; } diff --git a/src/libs/actions/Report/index.ts b/src/libs/actions/Report/index.ts index 9b72f3cf5500..254d8827a586 100644 --- a/src/libs/actions/Report/index.ts +++ b/src/libs/actions/Report/index.ts @@ -360,6 +360,9 @@ type OpenReportActionParams = { // TODO: This will be required eventually. Refactor issue: https://github.com/Expensify/App/issues/66424 hasCompletedGuidedSetupFlow?: boolean; + /** Whether the report has report actions or not */ + hasReportActions?: boolean; + /** Beta features list */ betas: OnyxEntry; }; @@ -1482,6 +1485,7 @@ function openReport(params: OpenReportActionParams) { currentUserAccountID, isSelfTourViewed, hasCompletedGuidedSetupFlow, + hasReportActions, } = params; if (!reportID) { return; @@ -1492,7 +1496,7 @@ function openReport(params: OpenReportActionParams) { const participantAccountIDList = participants.map((p) => p.accountID).filter((id): id is number => id !== undefined); const existingReportName = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]?.reportName; const isCreatingNewReport = !isEmptyObject(newReportObject); - const optimisticReport: Partial> = reportActionsExist(reportID) || !existingReportName ? {} : {reportName: existingReportName}; + const optimisticReport: Partial> = (hasReportActions ?? reportActionsExist(reportID)) || !existingReportName ? {} : {reportName: existingReportName}; const optimisticData: Array< OnyxUpdate< diff --git a/src/pages/media/AttachmentModalScreen/routes/TransactionReceiptModalContent.tsx b/src/pages/media/AttachmentModalScreen/routes/TransactionReceiptModalContent.tsx index 3787ce3c11b5..c12c3dfbaa8c 100644 --- a/src/pages/media/AttachmentModalScreen/routes/TransactionReceiptModalContent.tsx +++ b/src/pages/media/AttachmentModalScreen/routes/TransactionReceiptModalContent.tsx @@ -63,6 +63,7 @@ function TransactionReceiptModalContent({navigation, route}: AttachmentModalScre const expensifyIcons = useMemoizedLazyExpensifyIcons(['Camera', 'Download', 'Crop', 'Trashcan', 'Rotate', 'Close', 'Checkmark']); const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`); + const [hasReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, {selector: Boolean}); const allTransactions = useAllTransactions(); const transactionMain = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(transactionID)}`]; const [transactionDraft] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${getNonEmptyStringOnyxID(transactionID)}`); @@ -184,7 +185,7 @@ function TransactionReceiptModalContent({navigation, route}: AttachmentModalScre if ((!!report && !!transaction) || isDraftTransaction) { return; } - openReport({reportID, introSelected, betas}); + openReport({reportID, introSelected, betas, hasReportActions}); // I'm disabling the warning, as it expects to use exhaustive deps, even though we want this useEffect to run only on the first render. // eslint-disable-next-line react-hooks/exhaustive-deps }, []); diff --git a/src/pages/media/AttachmentModalScreen/routes/report/ReportAddAttachmentModalContent/index.tsx b/src/pages/media/AttachmentModalScreen/routes/report/ReportAddAttachmentModalContent/index.tsx index 4f3effad2963..6adf224dc33a 100644 --- a/src/pages/media/AttachmentModalScreen/routes/report/ReportAddAttachmentModalContent/index.tsx +++ b/src/pages/media/AttachmentModalScreen/routes/report/ReportAddAttachmentModalContent/index.tsx @@ -59,13 +59,15 @@ function ReportAddAttachmentModalContent({route, navigation}: AttachmentModalScr // Extract the reportActionID from the attachmentID (format: reportActionID_index) const reportActionID = useMemo(() => attachmentID?.split('_')?.[0], [attachmentID]); + const hasReportActions = !!reportActions; + const shouldFetchReport = useMemo(() => { return isEmptyObject(reportActions?.[reportActionID ?? CONST.DEFAULT_NUMBER_ID]); }, [reportActions, reportActionID]); const fetchReport = useCallback(() => { - openReport({reportID, introSelected, reportActionID, betas}); - }, [reportID, introSelected, reportActionID, betas]); + openReport({reportID, introSelected, reportActionID, betas, hasReportActions}); + }, [reportID, introSelected, reportActionID, betas, hasReportActions]); // Close the modal if user loses write access (e.g., admin switches "Who can post" to Admins only) useEffect(() => { diff --git a/src/pages/media/AttachmentModalScreen/routes/report/ReportAttachmentModalContent.tsx b/src/pages/media/AttachmentModalScreen/routes/report/ReportAttachmentModalContent.tsx index ec2018fe3aa9..cad45c9d1480 100644 --- a/src/pages/media/AttachmentModalScreen/routes/report/ReportAttachmentModalContent.tsx +++ b/src/pages/media/AttachmentModalScreen/routes/report/ReportAttachmentModalContent.tsx @@ -45,6 +45,7 @@ function ReportAttachmentModalContent({route, navigation}: AttachmentModalScreen } = route.params; const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`); + const hasReportActions = !!reportActions; const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED); const [betas] = useOnyx(ONYXKEYS.BETAS); @@ -74,8 +75,8 @@ function ReportAttachmentModalContent({route, navigation}: AttachmentModalScreen return; } - openReport({reportID: reportActionReportID, introSelected, reportActionID, betas}); - }, [reportActionReportID, shouldFetchReport, introSelected, reportActionID, betas]); + openReport({reportID: reportActionReportID, introSelected, reportActionID, betas, hasReportActions}); + }, [reportActionReportID, shouldFetchReport, introSelected, reportActionID, betas, hasReportActions]); const onCarouselAttachmentChange = (attachment: Attachment) => { const routeToNavigate = ROUTES.REPORT_ATTACHMENTS.getRoute({ diff --git a/tests/actions/IOUTest/DeleteMoneyRequestTest.ts b/tests/actions/IOUTest/DeleteMoneyRequestTest.ts index 86661ad5afef..c0cc6cfc5d8c 100644 --- a/tests/actions/IOUTest/DeleteMoneyRequestTest.ts +++ b/tests/actions/IOUTest/DeleteMoneyRequestTest.ts @@ -536,6 +536,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => { })); // When Opening a thread report with the given details openReport({ + hasReportActions: true, reportID: thread.reportID, introSelected: TEST_INTRO_SELECTED, betas: undefined, @@ -644,6 +645,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => { // When Opening a thread report with the given details openReport({ + hasReportActions: true, reportID: thread.reportID, introSelected: TEST_INTRO_SELECTED, betas: undefined, @@ -776,6 +778,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => { accountID: participantAccountIDs.at(index), })); openReport({ + hasReportActions: true, reportID: thread.reportID, introSelected: TEST_INTRO_SELECTED, betas: undefined, @@ -922,6 +925,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => { accountID: participantAccountIDs.at(index), })); openReport({ + hasReportActions: true, reportID: thread.reportID, introSelected: TEST_INTRO_SELECTED, betas: undefined, @@ -1238,6 +1242,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => { accountID: participantAccountIDs.at(index), })); openReport({ + hasReportActions: true, reportID: thread.reportID, introSelected: TEST_INTRO_SELECTED, betas: undefined, @@ -1419,6 +1424,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => { accountID: participantAccountIDs.at(index), })); openReport({ + hasReportActions: true, reportID: thread.reportID, introSelected: TEST_INTRO_SELECTED, betas: undefined, diff --git a/tests/actions/IOUTest/DuplicateTest.ts b/tests/actions/IOUTest/DuplicateTest.ts index bd2a277a0b97..cd4598314943 100644 --- a/tests/actions/IOUTest/DuplicateTest.ts +++ b/tests/actions/IOUTest/DuplicateTest.ts @@ -462,6 +462,7 @@ describe('actions/Duplicate', () => { accountID: participantAccountIDs.at(index), })); openReport({ + hasReportActions: true, reportID: transactionThreadReport1.reportID, introSelected: undefined, personalDetails: allPersonalDetails, @@ -471,6 +472,7 @@ describe('actions/Duplicate', () => { parentReportActionID: iouAction1?.reportActionID, }); openReport({ + hasReportActions: true, reportID: transactionThreadReport2.reportID, introSelected: undefined, personalDetails: allPersonalDetails, diff --git a/tests/actions/IOUTest/TrackExpenseTest.ts b/tests/actions/IOUTest/TrackExpenseTest.ts index fbb7c58dfb5f..c98e2796b425 100644 --- a/tests/actions/IOUTest/TrackExpenseTest.ts +++ b/tests/actions/IOUTest/TrackExpenseTest.ts @@ -2438,6 +2438,7 @@ describe('actions/IOU/TrackExpense', () => { accountID: participantAccountIDs.at(index), })); openReport({ + hasReportActions: true, reportID: thread.reportID, introSelected: TEST_INTRO_SELECTED, betas: undefined, @@ -2549,6 +2550,7 @@ describe('actions/IOU/TrackExpense', () => { accountID: participantAccountIDs.at(index), })); openReport({ + hasReportActions: true, reportID: thread.reportID, introSelected: TEST_INTRO_SELECTED, betas: undefined, diff --git a/tests/actions/MergeTransactionTest.ts b/tests/actions/MergeTransactionTest.ts index 49e53031354b..e6bc58ab9c64 100644 --- a/tests/actions/MergeTransactionTest.ts +++ b/tests/actions/MergeTransactionTest.ts @@ -1145,6 +1145,7 @@ describe('mergeTransactionRequest', () => { accountID: participantAccountIDs.at(index), })); openReport({ + hasReportActions: true, reportID: thread.reportID, introSelected: undefined, participants, @@ -1329,6 +1330,7 @@ describe('mergeTransactionRequest', () => { accountID: participantAccountIDs.at(index), })); openReport({ + hasReportActions: true, reportID: thread.reportID, introSelected: undefined, participants, diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index 2ed6d5702cb0..47e54b481797 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -615,7 +615,7 @@ describe('actions/Report', () => { // When the user visits the report currentTime = DateUtils.getDBTime(); - Report.openReport({reportID: REPORT_ID, introSelected: TEST_INTRO_SELECTED, betas: undefined}); + Report.openReport({hasReportActions: true, reportID: REPORT_ID, introSelected: TEST_INTRO_SELECTED, betas: undefined}); Report.readNewestAction(REPORT_ID, true); waitForBatchedUpdates(); return waitForBatchedUpdates(); @@ -1169,6 +1169,7 @@ describe('actions/Report', () => { for (let i = 0; i < 5; i++) { Report.openReport({ + hasReportActions: true, reportID: REPORT_ID, introSelected: TEST_INTRO_SELECTED, participants: [{login: 'test@user.com'}], @@ -1195,11 +1196,7 @@ describe('actions/Report', () => { setHasRadio(false); await waitForBatchedUpdates(); - Report.openReport({ - reportID: REPORT_ID, - introSelected: undefined, - betas: undefined, - }); + Report.openReport({hasReportActions: true, reportID: REPORT_ID, introSelected: undefined, betas: undefined}); await waitForBatchedUpdates(); const report = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`); @@ -1216,6 +1213,7 @@ describe('actions/Report', () => { await waitForBatchedUpdates(); Report.openReport({ + hasReportActions: true, reportID: REPORT_ID, introSelected: undefined, betas: undefined, @@ -1289,7 +1287,14 @@ describe('actions/Report', () => { const transaction = await getOnyxValue(`${ONYXKEYS.COLLECTION.TRANSACTION}${TXN_ID}` as const); expect(transaction).toBeTruthy(); - Report.openReport({reportID: CHILD_REPORT_ID, introSelected: undefined, betas: undefined, transaction: transaction ?? undefined, parentReportID: SELF_DM_ID}); + Report.openReport({ + hasReportActions: true, + reportID: CHILD_REPORT_ID, + introSelected: undefined, + betas: undefined, + transaction: transaction ?? undefined, + parentReportID: SELF_DM_ID, + }); await waitForBatchedUpdates(); // Validate the correct Onyx key received the new action and existing one is preserved @@ -1335,6 +1340,7 @@ describe('actions/Report', () => { reportID = `${i}`; } Report.openReport({ + hasReportActions: true, reportID, introSelected: TEST_INTRO_SELECTED, participants: [{login: 'test@user.com'}], @@ -2283,6 +2289,7 @@ describe('actions/Report', () => { const reportAction = TestHelper.buildTestReportComment(created, TEST_USER_ACCOUNT_ID, reportActionID); Report.openReport({ + hasReportActions: true, reportID: REPORT_ID, introSelected: TEST_INTRO_SELECTED, participants: [{login: 'test@user.com'}], @@ -4873,7 +4880,7 @@ describe('actions/Report', () => { await Onyx.set(ONYXKEYS.NVP_INTRO_SELECTED, TEST_INTRO_SELECTED); await waitForBatchedUpdates(); - Report.openReport({reportID: REPORT_ID, introSelected: TEST_INTRO_SELECTED, betas: undefined}); + Report.openReport({hasReportActions: true, reportID: REPORT_ID, introSelected: TEST_INTRO_SELECTED, betas: undefined}); await waitForBatchedUpdates(); TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.OPEN_REPORT, 1); @@ -4884,7 +4891,7 @@ describe('actions/Report', () => { const REPORT_ID = '2'; - Report.openReport({reportID: REPORT_ID, introSelected: TEST_INTRO_SELECTED, betas: undefined}); + Report.openReport({hasReportActions: true, reportID: REPORT_ID, introSelected: TEST_INTRO_SELECTED, betas: undefined}); await waitForBatchedUpdates(); TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.OPEN_REPORT, 1); @@ -4895,7 +4902,7 @@ describe('actions/Report', () => { const REPORT_ID = '3'; - Report.openReport({reportID: REPORT_ID, introSelected: undefined, betas: undefined}); + Report.openReport({hasReportActions: true, reportID: REPORT_ID, introSelected: undefined, betas: undefined}); await waitForBatchedUpdates(); TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.OPEN_REPORT, 1);