diff --git a/src/CONST.ts b/src/CONST.ts index bc8f627630a3..77ff74b860bc 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -1817,6 +1817,7 @@ const CONST = { XERO_CHECK_CONNECTION: 'xeroCheckConnection', XERO_SYNC_TITLE: 'xeroSyncTitle', }, + SYNC_STAGE_TIMEOUT_MINUTES: 20, }, ACCESS_VARIANTS: { PAID: 'paid', diff --git a/src/libs/actions/connections/index.ts b/src/libs/actions/connections/index.ts index 185cd089d1e9..45a4e4f6819c 100644 --- a/src/libs/actions/connections/index.ts +++ b/src/libs/actions/connections/index.ts @@ -137,6 +137,7 @@ function syncConnection(policyID: string, connectionName: PolicyConnectionName | value: { stageInProgress: isQBOConnection ? CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME.STARTING_IMPORT_QBO : CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME.STARTING_IMPORT_XERO, connectionName, + timestamp: new Date().toISOString(), }, }, ]; diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index ff5e82417ab7..bd7aa5cb4c1a 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -1,4 +1,4 @@ -import {formatDistanceToNow} from 'date-fns'; +import {differenceInMinutes, formatDistanceToNow, isValid, parseISO} from 'date-fns'; import React, {useEffect, useMemo, useRef, useState} from 'react'; import {ActivityIndicator, View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; @@ -117,7 +117,12 @@ function PolicyAccountingPage({policy, connectionSyncProgress}: PolicyAccounting const [datetimeToRelative, setDateTimeToRelative] = useState(''); const threeDotsMenuContainerRef = useRef(null); - const isSyncInProgress = !!connectionSyncProgress?.stageInProgress && connectionSyncProgress.stageInProgress !== CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME.JOB_DONE; + const lastSyncProgressDate = parseISO(connectionSyncProgress?.timestamp ?? ''); + const isSyncInProgress = + !!connectionSyncProgress?.stageInProgress && + connectionSyncProgress.stageInProgress !== CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME.JOB_DONE && + isValid(lastSyncProgressDate) && + differenceInMinutes(new Date(), lastSyncProgressDate) < CONST.POLICY.CONNECTIONS.SYNC_STAGE_TIMEOUT_MINUTES; const accountingIntegrations = Object.values(CONST.POLICY.CONNECTIONS.NAME).filter((name) => !(name === CONST.POLICY.CONNECTIONS.NAME.XERO && !canUseXeroIntegration)); const connectedIntegration = accountingIntegrations.find((integration) => !!policy?.connections?.[integration]) ?? connectionSyncProgress?.connectionName; diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index fc989dcd9783..070803e2e2fd 100644 --- a/src/types/onyx/Policy.ts +++ b/src/types/onyx/Policy.ts @@ -555,6 +555,7 @@ type PolicyConnectionName = ValueOf; type PolicyConnectionSyncProgress = { stageInProgress: PolicyConnectionSyncStage; connectionName: PolicyConnectionName; + timestamp: string; }; export default Policy;