1
1
import truncate from 'lodash/truncate' ;
2
- import React , { useMemo } from 'react' ;
2
+ import React , { useMemo , useState } from 'react' ;
3
3
import type { StyleProp , ViewStyle } from 'react-native' ;
4
4
import { View } from 'react-native' ;
5
5
import type { OnyxCollection , OnyxEntry } from 'react-native-onyx' ;
@@ -9,13 +9,16 @@ import Icon from '@components/Icon';
9
9
import * as Expensicons from '@components/Icon/Expensicons' ;
10
10
import OfflineWithFeedback from '@components/OfflineWithFeedback' ;
11
11
import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback' ;
12
+ import ProcessMoneyReportHoldMenu from '@components/ProcessMoneyReportHoldMenu' ;
13
+ import type { ActionHandledType } from '@components/ProcessMoneyReportHoldMenu' ;
12
14
import SettlementButton from '@components/SettlementButton' ;
13
15
import { showContextMenuForReport } from '@components/ShowContextMenuContext' ;
14
16
import Text from '@components/Text' ;
15
17
import useLocalize from '@hooks/useLocalize' ;
16
18
import usePermissions from '@hooks/usePermissions' ;
17
19
import useTheme from '@hooks/useTheme' ;
18
20
import useThemeStyles from '@hooks/useThemeStyles' ;
21
+ import useWindowDimensions from '@hooks/useWindowDimensions' ;
19
22
import ControlSelection from '@libs/ControlSelection' ;
20
23
import * as CurrencyUtils from '@libs/CurrencyUtils' ;
21
24
import * as DeviceCapabilities from '@libs/DeviceCapabilities' ;
@@ -119,6 +122,12 @@ function ReportPreview({
119
122
[ transactions , iouReportID , action ] ,
120
123
) ;
121
124
125
+ const [ isHoldMenuVisible , setIsHoldMenuVisible ] = useState ( false ) ;
126
+ const [ requestType , setRequestType ] = useState < ActionHandledType > ( ) ;
127
+ const [ nonHeldAmount , fullAmount ] = ReportUtils . getNonHeldAndFullAmount ( iouReport , policy ) ;
128
+ const { isSmallScreenWidth} = useWindowDimensions ( ) ;
129
+ const [ paymentType , setPaymentType ] = useState < PaymentMethodType > ( ) ;
130
+
122
131
const managerID = iouReport ?. managerID ?? 0 ;
123
132
const { totalDisplaySpend, reimbursableSpend} = ReportUtils . getMoneyRequestSpendBreakdown ( iouReport ) ;
124
133
@@ -164,6 +173,32 @@ function ReportPreview({
164
173
[ chatReport ?. isOwnPolicyExpenseChat , policy ?. harvesting ?. enabled ] ,
165
174
) ;
166
175
176
+ const confirmPayment = ( type : PaymentMethodType | undefined ) => {
177
+ if ( ! type ) {
178
+ return ;
179
+ }
180
+ setPaymentType ( type ) ;
181
+ setRequestType ( CONST . IOU . REPORT_ACTION_TYPE . PAY ) ;
182
+ if ( ReportUtils . hasHeldExpenses ( iouReport ?. reportID ) ) {
183
+ setIsHoldMenuVisible ( true ) ;
184
+ } else if ( chatReport && iouReport ) {
185
+ if ( ReportUtils . isInvoiceReport ( iouReport ) ) {
186
+ IOU . payInvoice ( type , chatReport , iouReport ) ;
187
+ } else {
188
+ IOU . payMoneyRequest ( type , chatReport , iouReport ) ;
189
+ }
190
+ }
191
+ } ;
192
+
193
+ const confirmApproval = ( ) => {
194
+ setRequestType ( CONST . IOU . REPORT_ACTION_TYPE . APPROVE ) ;
195
+ if ( ReportUtils . hasHeldExpenses ( iouReport ?. reportID ) ) {
196
+ setIsHoldMenuVisible ( true ) ;
197
+ } else {
198
+ IOU . approveMoneyRequest ( iouReport ?? { } , true ) ;
199
+ }
200
+ } ;
201
+
167
202
const getDisplayAmount = ( ) : string => {
168
203
if ( totalDisplaySpend ) {
169
204
return CurrencyUtils . convertToDisplayString ( totalDisplaySpend , iouReport ?. currency ) ;
@@ -282,17 +317,6 @@ function ReportPreview({
282
317
} ;
283
318
} , [ formattedMerchant , formattedDescription , moneyRequestComment , translate , numberOfRequests , numberOfScanningReceipts , numberOfPendingRequests ] ) ;
284
319
285
- const confirmPayment = ( paymentMethodType ?: PaymentMethodType ) => {
286
- if ( ! paymentMethodType || ! chatReport || ! iouReport ) {
287
- return ;
288
- }
289
- if ( ReportUtils . isInvoiceReport ( iouReport ) ) {
290
- IOU . payInvoice ( paymentMethodType , chatReport , iouReport ) ;
291
- } else {
292
- IOU . payMoneyRequest ( paymentMethodType , chatReport , iouReport ) ;
293
- }
294
- } ;
295
-
296
320
return (
297
321
< OfflineWithFeedback
298
322
pendingAction = { iouReport ?. pendingFields ?. preview }
@@ -383,6 +407,7 @@ function ReportPreview({
383
407
chatReportID = { chatReportID }
384
408
iouReport = { iouReport }
385
409
onPress = { confirmPayment }
410
+ confirmApproval = { confirmApproval }
386
411
enablePaymentsRoute = { ROUTES . ENABLE_PAYMENTS }
387
412
addBankAccountRoute = { bankAccountRoute }
388
413
shouldHidePaymentOptions = { ! shouldShowPayButton }
@@ -413,6 +438,19 @@ function ReportPreview({
413
438
</ View >
414
439
</ PressableWithoutFeedback >
415
440
</ View >
441
+ { isHoldMenuVisible && iouReport && requestType !== undefined && (
442
+ < ProcessMoneyReportHoldMenu
443
+ nonHeldAmount = { ! ReportUtils . hasOnlyHeldExpenses ( iouReport ?. reportID ?? '' ) ? nonHeldAmount : undefined }
444
+ requestType = { requestType }
445
+ fullAmount = { fullAmount }
446
+ isSmallScreenWidth = { isSmallScreenWidth }
447
+ onClose = { ( ) => setIsHoldMenuVisible ( false ) }
448
+ isVisible = { isHoldMenuVisible }
449
+ paymentType = { paymentType }
450
+ chatReport = { chatReport }
451
+ moneyRequestReport = { iouReport }
452
+ />
453
+ ) }
416
454
</ OfflineWithFeedback >
417
455
) ;
418
456
}
0 commit comments