Skip to content

Commit

Permalink
Merge pull request #42498 from Expensify/yuwen-connectionTimestamp
Browse files Browse the repository at this point in the history
Make sure that the connection sync progress times out after 20 minutes using timestamp
  • Loading branch information
aldo-expensify authored Jun 5, 2024
2 parents 70ecf7d + 90c63f5 commit afe64e5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1817,6 +1817,7 @@ const CONST = {
XERO_CHECK_CONNECTION: 'xeroCheckConnection',
XERO_SYNC_TITLE: 'xeroSyncTitle',
},
SYNC_STAGE_TIMEOUT_MINUTES: 20,
},
ACCESS_VARIANTS: {
PAID: 'paid',
Expand Down
1 change: 1 addition & 0 deletions src/libs/actions/connections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
},
];
Expand Down
9 changes: 7 additions & 2 deletions src/pages/workspace/accounting/PolicyAccountingPage.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -117,7 +117,12 @@ function PolicyAccountingPage({policy, connectionSyncProgress}: PolicyAccounting
const [datetimeToRelative, setDateTimeToRelative] = useState('');
const threeDotsMenuContainerRef = useRef<View>(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;
Expand Down
1 change: 1 addition & 0 deletions src/types/onyx/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ type PolicyConnectionName = ValueOf<typeof CONST.POLICY.CONNECTIONS.NAME>;
type PolicyConnectionSyncProgress = {
stageInProgress: PolicyConnectionSyncStage;
connectionName: PolicyConnectionName;
timestamp: string;
};

export default Policy;
Expand Down

0 comments on commit afe64e5

Please sign in to comment.