11import { findFocusedRoute } from '@react-navigation/native' ;
22import React , { useEffect , useMemo } from 'react' ;
3- import type { OnyxEntry } from 'react-native-onyx' ;
43import PrevNextButtons from '@components/PrevNextButtons' ;
54import useOnyx from '@hooks/useOnyx' ;
6- import { clearActiveTransactionIDs } from '@libs/actions/TransactionThreadNavigation' ;
7- import { getIOUActionForTransactionID } from '@libs/ReportActionsUtils' ;
8- import { generateReportID } from '@libs/ReportUtils' ;
5+ import { clearActiveTransactionThreadIDs } from '@libs/actions/TransactionThreadNavigation' ;
96import Navigation from '@navigation/Navigation' ;
107import navigationRef from '@navigation/navigationRef' ;
118import ONYXKEYS from '@src/ONYXKEYS' ;
129import ROUTES from '@src/ROUTES' ;
1310import SCREENS from '@src/SCREENS' ;
14- import type { Report } from '@src/types/onyx' ;
1511import getEmptyArray from '@src/types/utils/getEmptyArray' ;
1612
1713type MoneyRequestReportRHPNavigationButtonsProps = {
18- currentTransactionID : string ;
19- parentReport : OnyxEntry < Report > ;
14+ currentReportID : string ;
2015} ;
2116
22- function MoneyRequestReportTransactionsNavigation ( { currentTransactionID , parentReport } : MoneyRequestReportRHPNavigationButtonsProps ) {
23- const [ transactionIDsList = getEmptyArray < string > ( ) ] = useOnyx ( ONYXKEYS . TRANSACTION_THREAD_NAVIGATION_TRANSACTION_IDS , {
17+ function MoneyRequestReportTransactionsNavigation ( { currentReportID } : MoneyRequestReportRHPNavigationButtonsProps ) {
18+ const [ reportIDsList = getEmptyArray < string > ( ) ] = useOnyx ( ONYXKEYS . TRANSACTION_THREAD_NAVIGATION_REPORT_IDS , {
2419 canBeMissing : true ,
2520 } ) ;
26- const [ reportActions ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ parentReport ?. reportID } ` , { canEvict : false , canBeMissing : true } ) ;
27- const reportActionsArray = Object . values ( reportActions ?? { } ) ;
2821
29- const { prevTransactionID , nextTransactionID } = useMemo ( ( ) => {
30- if ( ! transactionIDsList || transactionIDsList . length < 2 ) {
22+ const { prevReportID , nextReportID } = useMemo ( ( ) => {
23+ if ( ! reportIDsList || reportIDsList . length < 2 ) {
3124 return { prevReportID : undefined , nextReportID : undefined } ;
3225 }
3326
34- const currentReportIndex = transactionIDsList . findIndex ( ( id ) => id === currentTransactionID ) ;
27+ const currentReportIndex = reportIDsList . findIndex ( ( id ) => id === currentReportID ) ;
3528
36- const prevID = currentReportIndex > 0 ? transactionIDsList . at ( currentReportIndex - 1 ) : undefined ;
37- const nextID = currentReportIndex <= transactionIDsList . length - 1 ? transactionIDsList . at ( currentReportIndex + 1 ) : undefined ;
29+ const prevID = currentReportIndex > 0 ? reportIDsList . at ( currentReportIndex - 1 ) : undefined ;
30+ const nextID = currentReportIndex <= reportIDsList . length - 1 ? reportIDsList . at ( currentReportIndex + 1 ) : undefined ;
3831
39- return { prevTransactionID : prevID , nextTransactionID : nextID } ;
40- } , [ currentTransactionID , transactionIDsList ] ) ;
32+ return { prevReportID : prevID , nextReportID : nextID } ;
33+ } , [ currentReportID , reportIDsList ] ) ;
4134
4235 /**
4336 * We clear the sibling transactionThreadIDs when unmounting this component
@@ -49,49 +42,27 @@ function MoneyRequestReportTransactionsNavigation({currentTransactionID, parentR
4942 if ( focusedRoute ?. name === SCREENS . SEARCH . REPORT_RHP ) {
5043 return ;
5144 }
52- clearActiveTransactionIDs ( ) ;
45+ clearActiveTransactionThreadIDs ( ) ;
5346 } ;
5447 } , [ ] ) ;
5548
56- if ( transactionIDsList . length < 2 ) {
49+ if ( reportIDsList . length < 2 ) {
5750 return ;
5851 }
5952
60- const navigateToReportByTransactionID = ( transactionID : string | undefined ) => {
61- if ( ! transactionID ) {
62- return ;
63- }
64-
65- const backTo = Navigation . getActiveRoute ( ) ;
66- const action = getIOUActionForTransactionID ( Object . values ( reportActionsArray ) , transactionID ) ;
67-
68- if ( action ?. childReportID ) {
69- Navigation . navigate ( ROUTES . SEARCH_REPORT . getRoute ( { reportID : action . childReportID , backTo} ) , { forceReplace : true } ) ;
70- } else {
71- const transactionThreadReportID = generateReportID ( ) ;
72- Navigation . navigate (
73- ROUTES . SEARCH_REPORT . getRoute ( {
74- reportID : transactionThreadReportID ,
75- backTo,
76- moneyRequestReportActionID : action ?. reportActionID ,
77- transactionID,
78- iouReportID : parentReport ?. reportID ,
79- } ) ,
80- ) ;
81- }
82- } ;
83-
8453 return (
8554 < PrevNextButtons
86- isPrevButtonDisabled = { ! prevTransactionID }
87- isNextButtonDisabled = { ! nextTransactionID }
55+ isPrevButtonDisabled = { ! prevReportID }
56+ isNextButtonDisabled = { ! nextReportID }
8857 onNext = { ( e ) => {
58+ const backTo = Navigation . getActiveRoute ( ) ;
8959 e ?. preventDefault ( ) ;
90- navigateToReportByTransactionID ( nextTransactionID ) ;
60+ Navigation . navigate ( ROUTES . SEARCH_REPORT . getRoute ( { reportID : nextReportID , backTo } ) , { forceReplace : true } ) ;
9161 } }
9262 onPrevious = { ( e ) => {
63+ const backTo = Navigation . getActiveRoute ( ) ;
9364 e ?. preventDefault ( ) ;
94- navigateToReportByTransactionID ( prevTransactionID ) ;
65+ Navigation . navigate ( ROUTES . SEARCH_REPORT . getRoute ( { reportID : prevReportID , backTo } ) , { forceReplace : true } ) ;
9566 } }
9667 />
9768 ) ;
0 commit comments