11import React , { useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
22import { InteractionManager } from 'react-native' ;
33import type { OnyxCollection } from 'react-native-onyx' ;
4+ import Button from '@components/Button' ;
45import EmptyStateComponent from '@components/EmptyStateComponent' ;
56import FormHelpMessage from '@components/FormHelpMessage' ;
67import HeaderWithBackButton from '@components/HeaderWithBackButton' ;
@@ -110,8 +111,13 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {
110111
111112 const styles = useThemeStyles ( ) ;
112113 const selectionListRef = useRef < SelectionListHandle > ( null ) ;
114+
115+ const shouldShowTextInput = useMemo ( ( ) => {
116+ return transactions . length >= CONST . SEARCH_ITEM_LIMIT ;
117+ } , [ transactions . length ] ) ;
118+
113119 const filteredTransactions = useMemo ( ( ) => {
114- if ( ! debouncedSearchValue . trim ( ) ) {
120+ if ( ! debouncedSearchValue . trim ( ) || ! shouldShowTextInput ) {
115121 return transactions ;
116122 }
117123
@@ -135,13 +141,58 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {
135141
136142 return searchableFields ;
137143 } ) ;
138- } , [ transactions , debouncedSearchValue ] ) ;
144+ } , [ debouncedSearchValue , shouldShowTextInput , transactions ] ) ;
139145
140146 const sections : Array < SectionListDataType < Transaction & ListItem > > = useMemo ( ( ) => createUnreportedExpenseSections ( filteredTransactions ) , [ filteredTransactions ] ) ;
141147
142- const shouldShowTextInput = useMemo ( ( ) => {
143- return transactions . length >= CONST . SEARCH_ITEM_LIMIT ;
144- } , [ transactions . length ] ) ;
148+ const handleConfirm = useCallback ( ( ) => {
149+ if ( selectedIds . size === 0 ) {
150+ setErrorMessage ( translate ( 'iou.selectUnreportedExpense' ) ) ;
151+ return ;
152+ }
153+ Navigation . dismissModal ( ) ;
154+ // eslint-disable-next-line deprecation/deprecation
155+ InteractionManager . runAfterInteractions ( ( ) => {
156+ if ( report && isIOUReport ( report ) ) {
157+ convertBulkTrackedExpensesToIOU ( [ ...selectedIds ] , report . reportID ) ;
158+ } else {
159+ changeTransactionsReport (
160+ [ ...selectedIds ] ,
161+ report ?. reportID ?? CONST . REPORT . UNREPORTED_REPORT_ID ,
162+ isASAPSubmitBetaEnabled ,
163+ session ?. accountID ?? CONST . DEFAULT_NUMBER_ID ,
164+ session ?. email ?? '' ,
165+ policy ,
166+ reportNextStep ,
167+ policyCategories ,
168+ ) ;
169+ }
170+ } ) ;
171+ setErrorMessage ( '' ) ;
172+ } , [ selectedIds , translate , report , isASAPSubmitBetaEnabled , session ?. accountID , session ?. email , policy , reportNextStep , policyCategories ] ) ;
173+
174+ const footerContent = useMemo ( ( ) => {
175+ return (
176+ < >
177+ { ! ! errorMessage && (
178+ < FormHelpMessage
179+ style = { [ styles . ph1 , styles . mb2 ] }
180+ isError
181+ message = { errorMessage }
182+ />
183+ ) }
184+ < Button
185+ success
186+ large
187+ style = { [ styles . w100 , styles . justifyContentCenter ] }
188+ text = { translate ( 'iou.addUnreportedExpenseConfirm' ) }
189+ onPress = { handleConfirm }
190+ pressOnEnter
191+ enterKeyEventListenerPriority = { 1 }
192+ />
193+ </ >
194+ ) ;
195+ } , [ errorMessage , styles , translate , handleConfirm ] ) ;
145196
146197 const headerMessage = useMemo ( ( ) => {
147198 if ( debouncedSearchValue . trim ( ) && sections . at ( 0 ) ?. data . length === 0 ) {
@@ -217,9 +268,11 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {
217268
218269 return (
219270 < ScreenWrapper
220- shouldEnableKeyboardAvoidingView = { false }
271+ shouldEnableKeyboardAvoidingView
221272 includeSafeAreaPaddingBottom
222273 shouldEnablePickerAvoiding = { false }
274+ shouldEnableMaxHeight
275+ enableEdgeToEdgeBottomSafeAreaPadding
223276 testID = { NewChatSelectorPage . displayName }
224277 focusTrapSettings = { { active : false } }
225278 >
@@ -253,46 +306,12 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {
253306 canSelectMultiple
254307 sections = { sections }
255308 ListItem = { UnreportedExpenseListItem }
256- confirmButtonStyles = { [ styles . justifyContentCenter ] }
257- showConfirmButton
258- confirmButtonText = { translate ( 'iou.addUnreportedExpenseConfirm' ) }
259- onConfirm = { ( ) => {
260- if ( selectedIds . size === 0 ) {
261- setErrorMessage ( translate ( 'iou.selectUnreportedExpense' ) ) ;
262- return ;
263- }
264- Navigation . dismissModal ( ) ;
265- // eslint-disable-next-line deprecation/deprecation
266- InteractionManager . runAfterInteractions ( ( ) => {
267- if ( report && isIOUReport ( report ) ) {
268- convertBulkTrackedExpensesToIOU ( [ ...selectedIds ] , report . reportID ) ;
269- } else {
270- changeTransactionsReport (
271- [ ...selectedIds ] ,
272- report ?. reportID ?? CONST . REPORT . UNREPORTED_REPORT_ID ,
273- isASAPSubmitBetaEnabled ,
274- session ?. accountID ?? CONST . DEFAULT_NUMBER_ID ,
275- session ?. email ?? '' ,
276- policy ,
277- reportNextStep ,
278- policyCategories ,
279- ) ;
280- }
281- } ) ;
282- setErrorMessage ( '' ) ;
283- } }
284309 onEndReached = { fetchMoreUnreportedTransactions }
285310 onEndReachedThreshold = { 0.75 }
311+ addBottomSafeAreaPadding
286312 listFooterContent = { shouldShowUnreportedTransactionsSkeletons ? < UnreportedExpensesSkeleton fixedNumberOfItems = { 3 } /> : undefined }
287- >
288- { ! ! errorMessage && (
289- < FormHelpMessage
290- style = { [ styles . mb2 , styles . ph4 ] }
291- isError
292- message = { errorMessage }
293- />
294- ) }
295- </ SelectionList >
313+ footerContent = { footerContent }
314+ />
296315 </ ScreenWrapper >
297316 ) ;
298317}
0 commit comments