diff --git a/src/pages/workspace/accounting/qbd/QuickBooksDesktopSetupPage.tsx b/src/pages/workspace/accounting/qbd/QuickBooksDesktopSetupPage.tsx index 1aa80231fc7d..559cdc0c7377 100644 --- a/src/pages/workspace/accounting/qbd/QuickBooksDesktopSetupPage.tsx +++ b/src/pages/workspace/accounting/qbd/QuickBooksDesktopSetupPage.tsx @@ -1,20 +1,22 @@ import type {StackScreenProps} from '@react-navigation/stack'; -import React, {useEffect, useState} from 'react'; +import React, {useCallback, useEffect, useState} from 'react'; import {View} from 'react-native'; import Computer from '@assets/images/laptop-with-second-screen-sync.svg'; +import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOfflineBlockingView'; import Button from '@components/Button'; import CopyTextToClipboard from '@components/CopyTextToClipboard'; import FixedFooter from '@components/FixedFooter'; +import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ImageSVG from '@components/ImageSVG'; import ScreenWrapper from '@components/ScreenWrapper'; import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; +import useNetwork from '@hooks/useNetwork'; import useThemeStyles from '@hooks/useThemeStyles'; import * as QuickbooksDesktop from '@libs/actions/connections/QuickbooksDesktop'; import Navigation from '@libs/Navigation/Navigation'; import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; -import LoadingPage from '@pages/LoadingPage'; import * as PolicyAction from '@userActions/Policy/Policy'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; @@ -28,15 +30,18 @@ function RequireQuickBooksDesktopModal({route}: RequireQuickBooksDesktopModalPro const [isLoading, setIsLoading] = useState(true); const [codatSetupLink, setCodatSetupLink] = useState(''); - useEffect(() => { - const fetchSetupLink = () => { - // eslint-disable-next-line rulesdir/no-thenable-actions-in-views - QuickbooksDesktop.getQuickbooksDesktopCodatSetupLink(policyID).then((response) => { - setCodatSetupLink(String(response?.setupUrl ?? '')); - setIsLoading(false); - }); - }; + const ContentWrapper = codatSetupLink ? ({children}: React.PropsWithChildren) => children : FullPageOfflineBlockingView; + + const fetchSetupLink = useCallback(() => { + setIsLoading(true); + // eslint-disable-next-line rulesdir/no-thenable-actions-in-views + QuickbooksDesktop.getQuickbooksDesktopCodatSetupLink(policyID).then((response) => { + setCodatSetupLink(String(response?.setupUrl ?? '')); + setIsLoading(false); + }); + }, [policyID]); + useEffect(() => { // Since QBD doesn't support Taxes, we should disable them from the LHN when connecting to QBD PolicyAction.enablePolicyTaxes(policyID, false); @@ -45,9 +50,14 @@ function RequireQuickBooksDesktopModal({route}: RequireQuickBooksDesktopModalPro // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps }, []); - if (isLoading) { - return ; - } + useNetwork({ + onReconnect: () => { + if (codatSetupLink) { + return; + } + fetchSetupLink(); + }, + }); return ( Navigation.dismissModal()} /> - - - - + + {isLoading || !codatSetupLink ? ( + + ) : ( + + + + - {translate('workspace.qbd.setupPage.title')} - {translate('workspace.qbd.setupPage.body')} - - - - -