@@ -49,6 +49,7 @@ import {
49
49
isReceiptBeingScanned ,
50
50
shouldShowBrokenConnectionViolationForMultipleTransactions ,
51
51
} from '@libs/TransactionUtils' ;
52
+ import type { ExportType } from '@pages/home/report/ReportDetailsExportPage' ;
52
53
import variables from '@styles/variables' ;
53
54
import {
54
55
approveMoneyRequest ,
@@ -146,13 +147,14 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
146
147
const isLoadingHoldUseExplained = isLoadingOnyxValue ( dismissedHoldUseExplanationResult ) ;
147
148
148
149
const isExported = isExportedUtils ( reportActions ) ;
149
- const [ markAsExportedModalVisible , setMarkAsExportedModalVisible ] = useState ( false ) ;
150
150
151
151
const [ downloadErrorModalVisible , setDownloadErrorModalVisible ] = useState ( false ) ;
152
152
const [ isCancelPaymentModalVisible , setIsCancelPaymentModalVisible ] = useState ( false ) ;
153
153
const [ isDeleteModalVisible , setIsDeleteModalVisible ] = useState ( false ) ;
154
154
const [ isUnapproveModalVisible , setIsUnapproveModalVisible ] = useState ( false ) ;
155
155
156
+ const [ exportModalStatus , setExportModalStatus ] = useState < ExportType | null > ( null ) ;
157
+
156
158
const { isPaidAnimationRunning, isApprovedAnimationRunning, startAnimation, stopAnimation, startApprovedAnimation} = usePaymentAnimations ( ) ;
157
159
const styles = useThemeStyles ( ) ;
158
160
const theme = useTheme ( ) ;
@@ -286,14 +288,6 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
286
288
markAsCashAction ( iouTransactionID , reportID ) ;
287
289
} , [ requestParentReportAction , transactionThreadReport ?. reportID ] ) ;
288
290
289
- const confirmManualExport = useCallback ( ( ) => {
290
- if ( ! connectedIntegration || ! moneyRequestReport ) {
291
- throw new Error ( 'Missing data' ) ;
292
- }
293
-
294
- markAsManuallyExported ( moneyRequestReport . reportID , connectedIntegration ) ;
295
- } , [ connectedIntegration , moneyRequestReport ] ) ;
296
-
297
291
const getStatusIcon : ( src : IconAsset ) => React . ReactNode = ( src ) => (
298
292
< Icon
299
293
src = { src }
@@ -363,7 +357,19 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
363
357
return '' ;
364
358
}
365
359
return getReportPrimaryAction ( moneyRequestReport , transactions , violations , policy , reportNameValuePairs ) ;
366
- } , [ isPaidAnimationRunning , moneyRequestReport , policy , reportNameValuePairs , transactions , violations ] ) ;
360
+ } , [ isPaidAnimationRunning , moneyRequestReport , reportNameValuePairs , policy , transactions , violations ] ) ;
361
+
362
+ const confirmExport = useCallback ( ( ) => {
363
+ setExportModalStatus ( null ) ;
364
+ if ( ! moneyRequestReport ?. reportID || ! connectedIntegration ) {
365
+ return ;
366
+ }
367
+ if ( exportModalStatus === CONST . REPORT . EXPORT_OPTIONS . EXPORT_TO_INTEGRATION ) {
368
+ exportToIntegration ( moneyRequestReport ?. reportID , connectedIntegration ) ;
369
+ } else if ( exportModalStatus === CONST . REPORT . EXPORT_OPTIONS . MARK_AS_EXPORTED ) {
370
+ markAsManuallyExported ( moneyRequestReport ?. reportID , connectedIntegration ) ;
371
+ }
372
+ } , [ connectedIntegration , exportModalStatus , moneyRequestReport ?. reportID ] ) ;
367
373
368
374
const primaryActionsImplementation = {
369
375
[ CONST . REPORT . PRIMARY_ACTIONS . SUBMIT ] : (
@@ -417,7 +423,11 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
417
423
if ( ! connectedIntegration || ! moneyRequestReport ) {
418
424
return ;
419
425
}
420
- exportToIntegration ( moneyRequestReport . reportID , connectedIntegration ) ;
426
+ if ( isExported ) {
427
+ setExportModalStatus ( CONST . REPORT . EXPORT_OPTIONS . EXPORT_TO_INTEGRATION ) ;
428
+ return ;
429
+ }
430
+ exportToIntegration ( moneyRequestReport ?. reportID , connectedIntegration ) ;
421
431
} }
422
432
/>
423
433
) ,
@@ -554,22 +564,28 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
554
564
value : CONST . REPORT . SECONDARY_ACTIONS . EXPORT_TO_ACCOUNTING ,
555
565
onSelected : ( ) => {
556
566
if ( ! connectedIntegration || ! moneyRequestReport ) {
557
- throw new Error ( 'Missing data' ) ;
567
+ return ;
558
568
}
559
-
560
- exportToIntegration ( moneyRequestReport . reportID , connectedIntegration ) ;
569
+ if ( isExported ) {
570
+ setExportModalStatus ( CONST . REPORT . EXPORT_OPTIONS . EXPORT_TO_INTEGRATION ) ;
571
+ return ;
572
+ }
573
+ exportToIntegration ( moneyRequestReport ?. reportID , connectedIntegration ) ;
561
574
} ,
562
575
} ,
563
576
[ CONST . REPORT . SECONDARY_ACTIONS . MARK_AS_EXPORTED ] : {
564
577
text : translate ( 'workspace.common.markAsExported' ) ,
565
578
icon : Expensicons . CheckCircle ,
566
579
value : CONST . REPORT . SECONDARY_ACTIONS . MARK_AS_EXPORTED ,
567
580
onSelected : ( ) => {
581
+ if ( ! connectedIntegration || ! moneyRequestReport ) {
582
+ return ;
583
+ }
568
584
if ( isExported ) {
569
- setMarkAsExportedModalVisible ( true ) ;
585
+ setExportModalStatus ( CONST . REPORT . EXPORT_OPTIONS . MARK_AS_EXPORTED ) ;
570
586
return ;
571
587
}
572
- confirmManualExport ( ) ;
588
+ markAsManuallyExported ( moneyRequestReport ?. reportID , connectedIntegration ) ;
573
589
} ,
574
590
} ,
575
591
[ CONST . REPORT . SECONDARY_ACTIONS . HOLD ] : {
@@ -799,19 +815,17 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
799
815
danger
800
816
shouldEnableNewFocusManagement
801
817
/>
802
- < ConfirmModal
803
- title = { translate ( 'workspace.exportAgainModal.title' ) }
804
- onConfirm = { ( ) => {
805
- confirmManualExport ( ) ;
806
- setMarkAsExportedModalVisible ( false ) ;
807
- } }
808
- onCancel = { ( ) => setMarkAsExportedModalVisible ( false ) }
809
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
810
- prompt = { translate ( 'workspace.exportAgainModal.description' , { connectionName : connectedIntegration ! , reportName : moneyRequestReport ?. reportName ?? '' } ) }
811
- confirmText = { translate ( 'workspace.exportAgainModal.confirmText' ) }
812
- cancelText = { translate ( 'workspace.exportAgainModal.cancelText' ) }
813
- isVisible = { markAsExportedModalVisible }
814
- />
818
+ { ! ! connectedIntegration && (
819
+ < ConfirmModal
820
+ title = { translate ( 'workspace.exportAgainModal.title' ) }
821
+ onConfirm = { confirmExport }
822
+ onCancel = { ( ) => setExportModalStatus ( null ) }
823
+ prompt = { translate ( 'workspace.exportAgainModal.description' , { connectionName : connectedIntegration , reportName : moneyRequestReport ?. reportName ?? '' } ) }
824
+ confirmText = { translate ( 'workspace.exportAgainModal.confirmText' ) }
825
+ cancelText = { translate ( 'workspace.exportAgainModal.cancelText' ) }
826
+ isVisible = { ! ! exportModalStatus }
827
+ />
828
+ ) }
815
829
< ConfirmModal
816
830
title = { translate ( 'iou.unapproveReport' ) }
817
831
isVisible = { isUnapproveModalVisible }
0 commit comments