Skip to content

Commit 893ef36

Browse files
authored
Merge pull request #50915 from ZhenjaHorbach/qbd-desktop-modal-offline-mode
[QBD] Offline mode for RequireQuickBooksDesktopModal
2 parents 13f41cb + bd740de commit 893ef36

File tree

1 file changed

+51
-35
lines changed

1 file changed

+51
-35
lines changed

src/pages/workspace/accounting/qbd/QuickBooksDesktopSetupPage.tsx

Lines changed: 51 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
import type {StackScreenProps} from '@react-navigation/stack';
2-
import React, {useEffect, useState} from 'react';
2+
import React, {useCallback, useEffect, useState} from 'react';
33
import {View} from 'react-native';
44
import Computer from '@assets/images/laptop-with-second-screen-sync.svg';
5+
import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOfflineBlockingView';
56
import Button from '@components/Button';
67
import CopyTextToClipboard from '@components/CopyTextToClipboard';
78
import FixedFooter from '@components/FixedFooter';
9+
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
810
import HeaderWithBackButton from '@components/HeaderWithBackButton';
911
import ImageSVG from '@components/ImageSVG';
1012
import ScreenWrapper from '@components/ScreenWrapper';
1113
import Text from '@components/Text';
1214
import useLocalize from '@hooks/useLocalize';
15+
import useNetwork from '@hooks/useNetwork';
1316
import useThemeStyles from '@hooks/useThemeStyles';
1417
import * as QuickbooksDesktop from '@libs/actions/connections/QuickbooksDesktop';
1518
import Navigation from '@libs/Navigation/Navigation';
1619
import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
17-
import LoadingPage from '@pages/LoadingPage';
1820
import * as PolicyAction from '@userActions/Policy/Policy';
1921
import ROUTES from '@src/ROUTES';
2022
import type SCREENS from '@src/SCREENS';
@@ -28,15 +30,18 @@ function RequireQuickBooksDesktopModal({route}: RequireQuickBooksDesktopModalPro
2830
const [isLoading, setIsLoading] = useState(true);
2931
const [codatSetupLink, setCodatSetupLink] = useState<string>('');
3032

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]);
3943

44+
useEffect(() => {
4045
// Since QBD doesn't support Taxes, we should disable them from the LHN when connecting to QBD
4146
PolicyAction.enablePolicyTaxes(policyID, false);
4247

@@ -45,9 +50,14 @@ function RequireQuickBooksDesktopModal({route}: RequireQuickBooksDesktopModalPro
4550
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
4651
}, []);
4752

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+
});
5161

5262
return (
5363
<ScreenWrapper
@@ -60,29 +70,35 @@ function RequireQuickBooksDesktopModal({route}: RequireQuickBooksDesktopModalPro
6070
shouldShowBackButton
6171
onBackButtonPress={() => Navigation.dismissModal()}
6272
/>
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>
6781

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>
86102
</ScreenWrapper>
87103
);
88104
}

0 commit comments

Comments
 (0)