1
1
import type { StackScreenProps } from '@react-navigation/stack' ;
2
- import React , { useEffect , useState } from 'react' ;
2
+ import React , { useCallback , useEffect , useState } from 'react' ;
3
3
import { View } from 'react-native' ;
4
4
import Computer from '@assets/images/laptop-with-second-screen-sync.svg' ;
5
+ import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOfflineBlockingView' ;
5
6
import Button from '@components/Button' ;
6
7
import CopyTextToClipboard from '@components/CopyTextToClipboard' ;
7
8
import FixedFooter from '@components/FixedFooter' ;
9
+ import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator' ;
8
10
import HeaderWithBackButton from '@components/HeaderWithBackButton' ;
9
11
import ImageSVG from '@components/ImageSVG' ;
10
12
import ScreenWrapper from '@components/ScreenWrapper' ;
11
13
import Text from '@components/Text' ;
12
14
import useLocalize from '@hooks/useLocalize' ;
15
+ import useNetwork from '@hooks/useNetwork' ;
13
16
import useThemeStyles from '@hooks/useThemeStyles' ;
14
17
import * as QuickbooksDesktop from '@libs/actions/connections/QuickbooksDesktop' ;
15
18
import Navigation from '@libs/Navigation/Navigation' ;
16
19
import type { SettingsNavigatorParamList } from '@libs/Navigation/types' ;
17
- import LoadingPage from '@pages/LoadingPage' ;
18
20
import * as PolicyAction from '@userActions/Policy/Policy' ;
19
21
import ROUTES from '@src/ROUTES' ;
20
22
import type SCREENS from '@src/SCREENS' ;
@@ -28,15 +30,18 @@ function RequireQuickBooksDesktopModal({route}: RequireQuickBooksDesktopModalPro
28
30
const [ isLoading , setIsLoading ] = useState ( true ) ;
29
31
const [ codatSetupLink , setCodatSetupLink ] = useState < string > ( '' ) ;
30
32
31
- useEffect ( ( ) => {
32
- const fetchSetupLink = ( ) => {
33
- // eslint-disable-next-line rulesdir/no-thenable-actions-in-views
34
- QuickbooksDesktop . getQuickbooksDesktopCodatSetupLink ( policyID ) . then ( ( response ) => {
35
- setCodatSetupLink ( String ( response ?. setupUrl ?? '' ) ) ;
36
- setIsLoading ( false ) ;
37
- } ) ;
38
- } ;
33
+ const ContentWrapper = codatSetupLink ? ( { children} : React . PropsWithChildren ) => children : FullPageOfflineBlockingView ;
34
+
35
+ const fetchSetupLink = useCallback ( ( ) => {
36
+ setIsLoading ( true ) ;
37
+ // eslint-disable-next-line rulesdir/no-thenable-actions-in-views
38
+ QuickbooksDesktop . getQuickbooksDesktopCodatSetupLink ( policyID ) . then ( ( response ) => {
39
+ setCodatSetupLink ( String ( response ?. setupUrl ?? '' ) ) ;
40
+ setIsLoading ( false ) ;
41
+ } ) ;
42
+ } , [ policyID ] ) ;
39
43
44
+ useEffect ( ( ) => {
40
45
// Since QBD doesn't support Taxes, we should disable them from the LHN when connecting to QBD
41
46
PolicyAction . enablePolicyTaxes ( policyID , false ) ;
42
47
@@ -45,9 +50,14 @@ function RequireQuickBooksDesktopModal({route}: RequireQuickBooksDesktopModalPro
45
50
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
46
51
} , [ ] ) ;
47
52
48
- if ( isLoading ) {
49
- return < LoadingPage title = { translate ( 'workspace.qbd.qbdSetup' ) } /> ;
50
- }
53
+ useNetwork ( {
54
+ onReconnect : ( ) => {
55
+ if ( codatSetupLink ) {
56
+ return ;
57
+ }
58
+ fetchSetupLink ( ) ;
59
+ } ,
60
+ } ) ;
51
61
52
62
return (
53
63
< ScreenWrapper
@@ -60,29 +70,35 @@ function RequireQuickBooksDesktopModal({route}: RequireQuickBooksDesktopModalPro
60
70
shouldShowBackButton
61
71
onBackButtonPress = { ( ) => Navigation . dismissModal ( ) }
62
72
/>
63
- < View style = { [ styles . flex1 , styles . ph5 ] } >
64
- < View style = { [ styles . alignSelfCenter , styles . computerIllustrationContainer , styles . pv6 ] } >
65
- < ImageSVG src = { Computer } />
66
- </ View >
73
+ < ContentWrapper >
74
+ { isLoading || ! codatSetupLink ? (
75
+ < FullScreenLoadingIndicator style = { [ styles . flex1 , styles . pRelative ] } />
76
+ ) : (
77
+ < View style = { [ styles . flex1 , styles . ph5 ] } >
78
+ < View style = { [ styles . alignSelfCenter , styles . computerIllustrationContainer , styles . pv6 ] } >
79
+ < ImageSVG src = { Computer } />
80
+ </ View >
67
81
68
- < Text style = { [ styles . textHeadlineH1 , styles . pt5 ] } > { translate ( 'workspace.qbd.setupPage.title' ) } </ Text >
69
- < Text style = { [ styles . textSupporting , styles . textNormal , styles . pt4 ] } > { translate ( 'workspace.qbd.setupPage.body' ) } </ Text >
70
- < View style = { [ styles . qbdSetupLinkBox , styles . mt5 ] } >
71
- < CopyTextToClipboard
72
- text = { codatSetupLink }
73
- textStyles = { [ styles . textSupporting ] }
74
- />
75
- </ View >
76
- < FixedFooter style = { [ styles . mtAuto , styles . ph0 ] } >
77
- < Button
78
- success
79
- text = { translate ( 'common.done' ) }
80
- onPress = { ( ) => Navigation . navigate ( ROUTES . POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_TRIGGER_FIRST_SYNC . getRoute ( policyID ) ) }
81
- pressOnEnter
82
- large
83
- />
84
- </ FixedFooter >
85
- </ View >
82
+ < Text style = { [ styles . textHeadlineH1 , styles . pt5 ] } > { translate ( 'workspace.qbd.setupPage.title' ) } </ Text >
83
+ < Text style = { [ styles . textSupporting , styles . textNormal , styles . pt4 ] } > { translate ( 'workspace.qbd.setupPage.body' ) } </ Text >
84
+ < View style = { [ styles . qbdSetupLinkBox , styles . mt5 ] } >
85
+ < CopyTextToClipboard
86
+ text = { codatSetupLink }
87
+ textStyles = { [ styles . textSupporting ] }
88
+ />
89
+ </ View >
90
+ < FixedFooter style = { [ styles . mtAuto , styles . ph0 ] } >
91
+ < Button
92
+ success
93
+ text = { translate ( 'common.done' ) }
94
+ onPress = { ( ) => Navigation . navigate ( ROUTES . POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_TRIGGER_FIRST_SYNC . getRoute ( policyID ) ) }
95
+ pressOnEnter
96
+ large
97
+ />
98
+ </ FixedFooter >
99
+ </ View >
100
+ ) }
101
+ </ ContentWrapper >
86
102
</ ScreenWrapper >
87
103
) ;
88
104
}
0 commit comments