-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Last synced just now does not update #41310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
6fb62d5
4ab21ee
c3e0e4b
ff3397e
8ecfa6e
12d407b
bcaca76
fa426e3
f6e5060
c82b2d9
69a3652
e343f5b
0c8b014
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import React, {useMemo, useRef, useState} from 'react'; | ||
import {formatDistanceToNow} from 'date-fns'; | ||
import React, {useEffect, useMemo, useRef, useState} from 'react'; | ||
import {ActivityIndicator, View} from 'react-native'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import type {OnyxEntry} from 'react-native-onyx'; | ||
|
@@ -34,13 +35,14 @@ | |
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import ROUTES from '@src/ROUTES'; | ||
import type {Policy, PolicyConnectionSyncProgress} from '@src/types/onyx'; | ||
import type {Locale, Policy, PolicyConnectionSyncProgress} from '@src/types/onyx'; | ||
import type {PolicyConnectionName} from '@src/types/onyx/Policy'; | ||
import {isEmptyObject} from '@src/types/utils/EmptyObject'; | ||
import type IconAsset from '@src/types/utils/IconAsset'; | ||
|
||
type PolicyAccountingPageOnyxProps = { | ||
connectionSyncProgress: OnyxEntry<PolicyConnectionSyncProgress>; | ||
preferredLocale: OnyxEntry<Locale>; | ||
}; | ||
|
||
type PolicyAccountingPageProps = WithPolicyProps & | ||
|
@@ -100,7 +102,7 @@ | |
} | ||
} | ||
|
||
function PolicyAccountingPage({policy, connectionSyncProgress}: PolicyAccountingPageProps) { | ||
function PolicyAccountingPage({policy, connectionSyncProgress, preferredLocale}: PolicyAccountingPageProps) { | ||
const theme = useTheme(); | ||
const styles = useThemeStyles(); | ||
const {translate} = useLocalize(); | ||
|
@@ -109,13 +111,16 @@ | |
const {isSmallScreenWidth, windowWidth} = useWindowDimensions(); | ||
const [threeDotsMenuPosition, setThreeDotsMenuPosition] = useState<AnchorPosition>({horizontal: 0, vertical: 0}); | ||
const [isDisconnectModalOpen, setIsDisconnectModalOpen] = useState(false); | ||
const [datetimeToRelative, setDateTimeToRelative] = useState(''); | ||
const threeDotsMenuContainerRef = useRef<View>(null); | ||
|
||
const isSyncInProgress = !!connectionSyncProgress?.stageInProgress && connectionSyncProgress.stageInProgress !== CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME.JOB_DONE; | ||
|
||
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; | ||
const policyID = policy?.id ?? ''; | ||
const successfulDate = policy?.connections?.quickbooksOnline?.lastSync?.successfulDate; | ||
const formattedDate = successfulDate ? new Date(successfulDate) : new Date(); | ||
Check warning on line 123 in src/pages/workspace/accounting/PolicyAccountingPage.tsx
|
||
|
||
const policyConnectedToXero = connectedIntegration === CONST.POLICY.CONNECTIONS.NAME.XERO; | ||
|
||
|
@@ -140,6 +145,17 @@ | |
[translate, policyID, isOffline], | ||
); | ||
|
||
useEffect(() => { | ||
setDateTimeToRelative(formatDistanceToNow(formattedDate, {addSuffix: true})); | ||
const interval = setInterval(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to use setInterval here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we don't use setInterval, we have to refresh page to see the new relativeTime There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't any change in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with Olly, shouldn't this already be handled by the useEffect dependency? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tienifr i dont think this is a requirement @trjExpensify i think its fine to not update the sync date until we get pusher update or user navigates away and back to the page. I dont think there is much value in having the text auto update when user stays on the page There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, agreed. Pretty sure with OldDot we do that too. |
||
setDateTimeToRelative(formatDistanceToNow(formattedDate, {addSuffix: true})); | ||
}, 60 * 1000); | ||
|
||
return () => { | ||
clearInterval(interval); | ||
}; | ||
}, [formattedDate]); | ||
|
||
const connectionsMenuItems: MenuItemProps[] = useMemo(() => { | ||
if (isEmptyObject(policy?.connections) && !isSyncInProgress) { | ||
return accountingIntegrations.map((integration) => { | ||
|
@@ -168,10 +184,7 @@ | |
wrapperStyle: [styles.sectionMenuItemTopDescription], | ||
shouldShowRightComponent: true, | ||
title: integrationData?.title, | ||
|
||
description: isSyncInProgress | ||
? translate('workspace.accounting.connections.syncStageName', connectionSyncProgress.stageInProgress) | ||
: translate('workspace.accounting.lastSync'), | ||
description: isSyncInProgress ? translate('workspace.accounting.connections.syncStageName', connectionSyncProgress.stageInProgress) : datetimeToRelative, | ||
rightComponent: isSyncInProgress ? ( | ||
<ActivityIndicator | ||
style={[styles.popoverMenuIcon]} | ||
|
@@ -257,6 +270,7 @@ | |
theme.spinner, | ||
threeDotsMenuPosition, | ||
translate, | ||
datetimeToRelative, | ||
accountingIntegrations, | ||
]); | ||
|
||
|
@@ -380,5 +394,8 @@ | |
connectionSyncProgress: { | ||
key: (props) => `${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${props.route.params.policyID}`, | ||
}, | ||
preferredLocale: { | ||
key: ONYXKEYS.NVP_PREFERRED_LOCALE, | ||
}, | ||
})(PolicyAccountingPage), | ||
); |
Uh oh!
There was an error while loading. Please reload this page.