Skip to content

Commit afe64e5

Browse files
Merge pull request #42498 from Expensify/yuwen-connectionTimestamp
Make sure that the connection sync progress times out after 20 minutes using timestamp
2 parents 70ecf7d + 90c63f5 commit afe64e5

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

src/CONST.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1817,6 +1817,7 @@ const CONST = {
18171817
XERO_CHECK_CONNECTION: 'xeroCheckConnection',
18181818
XERO_SYNC_TITLE: 'xeroSyncTitle',
18191819
},
1820+
SYNC_STAGE_TIMEOUT_MINUTES: 20,
18201821
},
18211822
ACCESS_VARIANTS: {
18221823
PAID: 'paid',

src/libs/actions/connections/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ function syncConnection(policyID: string, connectionName: PolicyConnectionName |
137137
value: {
138138
stageInProgress: isQBOConnection ? CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME.STARTING_IMPORT_QBO : CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME.STARTING_IMPORT_XERO,
139139
connectionName,
140+
timestamp: new Date().toISOString(),
140141
},
141142
},
142143
];

src/pages/workspace/accounting/PolicyAccountingPage.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {formatDistanceToNow} from 'date-fns';
1+
import {differenceInMinutes, formatDistanceToNow, isValid, parseISO} from 'date-fns';
22
import React, {useEffect, useMemo, useRef, useState} from 'react';
33
import {ActivityIndicator, View} from 'react-native';
44
import {withOnyx} from 'react-native-onyx';
@@ -117,7 +117,12 @@ function PolicyAccountingPage({policy, connectionSyncProgress}: PolicyAccounting
117117
const [datetimeToRelative, setDateTimeToRelative] = useState('');
118118
const threeDotsMenuContainerRef = useRef<View>(null);
119119

120-
const isSyncInProgress = !!connectionSyncProgress?.stageInProgress && connectionSyncProgress.stageInProgress !== CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME.JOB_DONE;
120+
const lastSyncProgressDate = parseISO(connectionSyncProgress?.timestamp ?? '');
121+
const isSyncInProgress =
122+
!!connectionSyncProgress?.stageInProgress &&
123+
connectionSyncProgress.stageInProgress !== CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME.JOB_DONE &&
124+
isValid(lastSyncProgressDate) &&
125+
differenceInMinutes(new Date(), lastSyncProgressDate) < CONST.POLICY.CONNECTIONS.SYNC_STAGE_TIMEOUT_MINUTES;
121126

122127
const accountingIntegrations = Object.values(CONST.POLICY.CONNECTIONS.NAME).filter((name) => !(name === CONST.POLICY.CONNECTIONS.NAME.XERO && !canUseXeroIntegration));
123128
const connectedIntegration = accountingIntegrations.find((integration) => !!policy?.connections?.[integration]) ?? connectionSyncProgress?.connectionName;

src/types/onyx/Policy.ts

+1
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ type PolicyConnectionName = ValueOf<typeof CONST.POLICY.CONNECTIONS.NAME>;
555555
type PolicyConnectionSyncProgress = {
556556
stageInProgress: PolicyConnectionSyncStage;
557557
connectionName: PolicyConnectionName;
558+
timestamp: string;
558559
};
559560

560561
export default Policy;

0 commit comments

Comments
 (0)