@@ -8,8 +8,8 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton';
88import LottieAnimations from '@components/LottieAnimations' ;
99import { useSession } from '@components/OnyxListItemProvider' ;
1010import ScreenWrapper from '@components/ScreenWrapper' ;
11- import SelectionList from '@components/SelectionListWithSections ' ;
12- import type { ListItem , SectionListDataType , SelectionListHandle } from '@components/SelectionListWithSections /types' ;
11+ import SelectionList from '@components/SelectionList ' ;
12+ import type { ListItem , SelectionListHandle } from '@components/SelectionList /types' ;
1313import UnreportedExpensesSkeleton from '@components/Skeletons/UnreportedExpensesSkeleton' ;
1414import useDebouncedState from '@hooks/useDebouncedState' ;
1515import useLocalize from '@hooks/useLocalize' ;
@@ -27,7 +27,7 @@ import {canSubmitPerDiemExpenseFromWorkspace, getPerDiemCustomUnit} from '@libs/
2727import { getTransactionDetails , isIOUReport } from '@libs/ReportUtils' ;
2828import { shouldRestrictUserBillableActions } from '@libs/SubscriptionUtils' ;
2929import tokenizedSearch from '@libs/tokenizedSearch' ;
30- import { createUnreportedExpenseSections , getAmount , getCurrency , getDescription , getMerchant , isPerDiemRequest } from '@libs/TransactionUtils' ;
30+ import { createUnreportedExpenses , getAmount , getCurrency , getDescription , getMerchant , isPerDiemRequest } from '@libs/TransactionUtils' ;
3131import Navigation from '@navigation/Navigation' ;
3232import type { PlatformStackScreenProps } from '@navigation/PlatformStackNavigation/types' ;
3333import { convertBulkTrackedExpensesToIOU , startMoneyRequest } from '@userActions/IOU' ;
@@ -153,7 +153,12 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {
153153 } ) ;
154154 } , [ debouncedSearchValue , shouldShowTextInput , transactions ] ) ;
155155
156- const sections : Array < SectionListDataType < Transaction & ListItem > > = useMemo ( ( ) => createUnreportedExpenseSections ( filteredTransactions ) , [ filteredTransactions ] ) ;
156+ const unreportedExpenses = useMemo ( ( ) => {
157+ return createUnreportedExpenses ( filteredTransactions ) . map ( ( item ) => ( {
158+ ...item ,
159+ isSelected : selectedIds . has ( item . transactionID ) ,
160+ } ) ) ;
161+ } , [ filteredTransactions , selectedIds ] ) ;
157162
158163 const handleConfirm = useCallback ( ( ) => {
159164 if ( selectedIds . size === 0 ) {
@@ -212,11 +217,39 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {
212217 } , [ errorMessage , styles , translate , handleConfirm ] ) ;
213218
214219 const headerMessage = useMemo ( ( ) => {
215- if ( debouncedSearchValue . trim ( ) && sections . at ( 0 ) ?. data . length === 0 ) {
220+ if ( debouncedSearchValue . trim ( ) && unreportedExpenses ? .length === 0 ) {
216221 return translate ( 'common.noResultsFound' ) ;
217222 }
218223 return '' ;
219- } , [ debouncedSearchValue , sections , translate ] ) ;
224+ } , [ debouncedSearchValue , unreportedExpenses ?. length , translate ] ) ;
225+
226+ const textInputOptions = useMemo (
227+ ( ) => ( {
228+ value : searchValue ,
229+ label : shouldShowTextInput ? translate ( 'iou.findExpense' ) : undefined ,
230+ onChangeText : setSearchValue ,
231+ headerMessage,
232+ } ) ,
233+ [ searchValue , shouldShowTextInput , translate , setSearchValue , headerMessage ] ,
234+ ) ;
235+
236+ const onSelectRow = useCallback (
237+ ( item : { transactionID : string } ) => {
238+ setSelectedIds ( ( prevIds ) => {
239+ const newIds = new Set ( prevIds ) ;
240+ if ( newIds . has ( item . transactionID ) ) {
241+ newIds . delete ( item . transactionID ) ;
242+ } else {
243+ newIds . add ( item . transactionID ) ;
244+ if ( errorMessage ) {
245+ setErrorMessage ( '' ) ;
246+ }
247+ }
248+ return newIds ;
249+ } ) ;
250+ } ,
251+ [ errorMessage ] ,
252+ ) ;
220253
221254 const hasSearchTerm = debouncedSearchValue . trim ( ) . length > 0 ;
222255 const isShowingEmptyState = ! hasSearchTerm && transactions . length === 0 ;
@@ -298,36 +331,19 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {
298331 onBackButtonPress = { Navigation . goBack }
299332 />
300333 < SelectionList < Transaction & ListItem >
334+ data = { unreportedExpenses }
301335 ref = { selectionListRef }
302- onSelectRow = { ( item ) => {
303- setSelectedIds ( ( prevIds ) => {
304- const newIds = new Set ( prevIds ) ;
305- if ( newIds . has ( item . transactionID ) ) {
306- newIds . delete ( item . transactionID ) ;
307- } else {
308- newIds . add ( item . transactionID ) ;
309- if ( errorMessage ) {
310- setErrorMessage ( '' ) ;
311- }
312- }
313-
314- return newIds ;
315- } ) ;
316- } }
317- isSelected = { ( item ) => selectedIds . has ( item . transactionID ) }
336+ onSelectRow = { onSelectRow }
337+ textInputOptions = { textInputOptions }
318338 shouldShowTextInput = { shouldShowTextInput }
319- textInputValue = { searchValue }
320- textInputLabel = { shouldShowTextInput ? translate ( 'iou.findExpense' ) : undefined }
321- onChangeText = { setSearchValue }
322- headerMessage = { headerMessage }
323339 canSelectMultiple
324- sections = { sections }
325340 ListItem = { UnreportedExpenseListItem }
326341 onEndReached = { fetchMoreUnreportedTransactions }
327342 onEndReachedThreshold = { 0.75 }
328343 addBottomSafeAreaPadding
329344 listFooterContent = { shouldShowUnreportedTransactionsSkeletons ? < UnreportedExpensesSkeleton fixedNumberOfItems = { 3 } /> : undefined }
330345 footerContent = { footerContent }
346+ disableMaintainingScrollPosition
331347 />
332348 </ ScreenWrapper >
333349 ) ;
0 commit comments