From 6fb62d5a74eb65674542ee5ebee13bb210c19bfa Mon Sep 17 00:00:00 2001 From: tienifr Date: Tue, 30 Apr 2024 17:05:48 +0700 Subject: [PATCH 1/7] Last synced just now doesnt update --- .../accounting/PolicyAccountingPage.tsx | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index 4fd8ea019370..286bed15ab6d 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -1,4 +1,4 @@ -import React, {useMemo, useRef, useState} from 'react'; +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'; @@ -24,6 +24,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import {removePolicyConnection} from '@libs/actions/connections'; import {syncConnection} from '@libs/actions/connections/QuickBooksOnline'; +import DateUtils from '@libs/DateUtils'; import Navigation from '@navigation/Navigation'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; import type {WithPolicyProps} from '@pages/workspace/withPolicy'; @@ -32,13 +33,14 @@ import type {AnchorPosition} from '@styles/index'; 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 {Policy, PolicyConnectionSyncProgress,Locale} 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; + preferredLocale: OnyxEntry; }; type PolicyAccountingPageProps = WithPolicyProps & @@ -100,7 +102,7 @@ function accountingIntegrationData( } } -function PolicyAccountingPage({policy, connectionSyncProgress}: PolicyAccountingPageProps) { +function PolicyAccountingPage({policy, connectionSyncProgress, preferredLocale}: PolicyAccountingPageProps) { const theme = useTheme(); const styles = useThemeStyles(); const {translate} = useLocalize(); @@ -108,11 +110,13 @@ function PolicyAccountingPage({policy, connectionSyncProgress}: PolicyAccounting const {isSmallScreenWidth, windowWidth} = useWindowDimensions(); const [threeDotsMenuPosition, setThreeDotsMenuPosition] = useState({horizontal: 0, vertical: 0}); const [isDisconnectModalOpen, setIsDisconnectModalOpen] = useState(false); + const [datetimeToRelative, setDateTimeToRelative] = useState(''); const threeDotsMenuContainerRef = useRef(null); const isSyncInProgress = !!connectionSyncProgress?.stageInProgress && connectionSyncProgress.stageInProgress !== CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME.JOB_DONE; const connectedIntegration = accountingIntegrations.find((integration) => !!policy?.connections?.[integration]) ?? connectionSyncProgress?.connectionName; const policyID = policy?.id ?? ''; + const datetime = policy?.connections?.quickbooksOnline?.lastSync?.successfulDate ?? ''; const overflowMenu: ThreeDotsMenuProps['menuItems'] = useMemo( () => [ @@ -131,6 +135,18 @@ function PolicyAccountingPage({policy, connectionSyncProgress}: PolicyAccounting [translate, policyID, isOffline], ); + useEffect(() => { + const locale = preferredLocale ?? CONST.LOCALES.DEFAULT; + setDateTimeToRelative(DateUtils.datetimeToRelative(locale, datetime)); + const interval = setInterval(() => { + setDateTimeToRelative(DateUtils.datetimeToRelative(locale, datetime)); + }, 60 * 1000); + + return () => { + clearInterval(interval); + }; + }, [datetime, preferredLocale]); + const connectionsMenuItems: MenuItemProps[] = useMemo(() => { if (isEmptyObject(policy?.connections) && !isSyncInProgress) { return accountingIntegrations.map((integration) => { @@ -159,9 +175,7 @@ function PolicyAccountingPage({policy, connectionSyncProgress}: PolicyAccounting 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 ? ( { @@ -336,5 +351,8 @@ export default withPolicyConnections( connectionSyncProgress: { key: (props) => `${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${props.route.params.policyID}`, }, + preferredLocale: { + key: ONYXKEYS.NVP_PREFERRED_LOCALE, + }, })(PolicyAccountingPage), ); From c3e0e4ba3bcc70bbabb0e03d7866512873051b4f Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 1 May 2024 15:09:39 +0700 Subject: [PATCH 2/7] lint fix --- src/pages/workspace/accounting/PolicyAccountingPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index 286bed15ab6d..8f5e669d914b 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -33,7 +33,7 @@ import type {AnchorPosition} from '@styles/index'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import type {Policy, PolicyConnectionSyncProgress,Locale} 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'; From 8ecfa6e57205bb1dd892e0e69881418507994ed8 Mon Sep 17 00:00:00 2001 From: tienifr Date: Tue, 7 May 2024 16:04:20 +0700 Subject: [PATCH 3/7] fix: formate date --- src/pages/workspace/accounting/PolicyAccountingPage.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index 2907a5590546..32f5a14d5d1c 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -119,7 +119,8 @@ function PolicyAccountingPage({policy, connectionSyncProgress, preferredLocale}: 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 datetime = policy?.connections?.quickbooksOnline?.lastSync?.successfulDate ?? ''; + const successfulDate = policy?.connections?.quickbooksOnline?.lastSync?.successfulDate; + const formatedDate = successfulDate ? new Date(successfulDate).toString() : ''; const policyConnectedToXero = connectedIntegration === CONST.POLICY.CONNECTIONS.NAME.XERO; @@ -146,15 +147,15 @@ function PolicyAccountingPage({policy, connectionSyncProgress, preferredLocale}: useEffect(() => { const locale = preferredLocale ?? CONST.LOCALES.DEFAULT; - setDateTimeToRelative(DateUtils.datetimeToRelative(locale, datetime)); + setDateTimeToRelative(DateUtils.datetimeToRelative(locale, formatedDate)); const interval = setInterval(() => { - setDateTimeToRelative(DateUtils.datetimeToRelative(locale, datetime)); + setDateTimeToRelative(DateUtils.datetimeToRelative(locale, formatedDate)); }, 60 * 1000); return () => { clearInterval(interval); }; - }, [datetime, preferredLocale]); + }, [formatedDate, preferredLocale]); const connectionsMenuItems: MenuItemProps[] = useMemo(() => { if (isEmptyObject(policy?.connections) && !isSyncInProgress) { From bcaca76912018e1b8f05499d49a3dc7981c137e7 Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 8 May 2024 16:04:20 +0700 Subject: [PATCH 4/7] fix: typo word --- src/pages/workspace/accounting/PolicyAccountingPage.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index 70bb4900c2d8..f98c557de2d8 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -120,7 +120,7 @@ function PolicyAccountingPage({policy, connectionSyncProgress, preferredLocale}: const connectedIntegration = accountingIntegrations.find((integration) => !!policy?.connections?.[integration]) ?? connectionSyncProgress?.connectionName; const policyID = policy?.id ?? ''; const successfulDate = policy?.connections?.quickbooksOnline?.lastSync?.successfulDate; - const formatedDate = successfulDate ? new Date(successfulDate).toString() : ''; + const formattedDate = successfulDate ? new Date(successfulDate).toString() : ''; const policyConnectedToXero = connectedIntegration === CONST.POLICY.CONNECTIONS.NAME.XERO; @@ -147,15 +147,15 @@ function PolicyAccountingPage({policy, connectionSyncProgress, preferredLocale}: useEffect(() => { const locale = preferredLocale ?? CONST.LOCALES.DEFAULT; - setDateTimeToRelative(DateUtils.datetimeToRelative(locale, formatedDate)); + setDateTimeToRelative(DateUtils.datetimeToRelative(locale, formattedDate)); const interval = setInterval(() => { - setDateTimeToRelative(DateUtils.datetimeToRelative(locale, formatedDate)); + setDateTimeToRelative(DateUtils.datetimeToRelative(locale, formattedDate)); }, 60 * 1000); return () => { clearInterval(interval); }; - }, [formatedDate, preferredLocale]); + }, [formattedDate, preferredLocale]); const connectionsMenuItems: MenuItemProps[] = useMemo(() => { if (isEmptyObject(policy?.connections) && !isSyncInProgress) { From f6e50607f75d2921a40e1e96c91f6e8793077c40 Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 10 May 2024 15:38:47 +0700 Subject: [PATCH 5/7] convert date to string --- src/pages/workspace/accounting/PolicyAccountingPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index f98c557de2d8..8f627d100b0c 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -120,7 +120,7 @@ function PolicyAccountingPage({policy, connectionSyncProgress, preferredLocale}: 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).toString() : ''; + const formattedDate = successfulDate ? new Date(successfulDate).toISOString().replace('Z', '') : ''; const policyConnectedToXero = connectedIntegration === CONST.POLICY.CONNECTIONS.NAME.XERO; From 69a3652d78e4ce28e53c1f98acc80893d3273865 Mon Sep 17 00:00:00 2001 From: tienifr Date: Mon, 13 May 2024 17:05:35 +0700 Subject: [PATCH 6/7] fix timeone error --- .../workspace/accounting/PolicyAccountingPage.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index 8f627d100b0c..b205a88945f0 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -1,3 +1,4 @@ +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'; @@ -25,7 +26,6 @@ import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import {removePolicyConnection} from '@libs/actions/connections'; import {syncConnection} from '@libs/actions/connections/QuickBooksOnline'; -import DateUtils from '@libs/DateUtils'; import {findCurrentXeroOrganization, getXeroTenants} from '@libs/PolicyUtils'; import Navigation from '@navigation/Navigation'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; @@ -120,7 +120,7 @@ function PolicyAccountingPage({policy, connectionSyncProgress, preferredLocale}: 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).toISOString().replace('Z', '') : ''; + const formattedDate = successfulDate ? new Date(successfulDate) : new Date(); const policyConnectedToXero = connectedIntegration === CONST.POLICY.CONNECTIONS.NAME.XERO; @@ -146,16 +146,15 @@ function PolicyAccountingPage({policy, connectionSyncProgress, preferredLocale}: ); useEffect(() => { - const locale = preferredLocale ?? CONST.LOCALES.DEFAULT; - setDateTimeToRelative(DateUtils.datetimeToRelative(locale, formattedDate)); + setDateTimeToRelative(formatDistanceToNow(formattedDate, {addSuffix: true})); const interval = setInterval(() => { - setDateTimeToRelative(DateUtils.datetimeToRelative(locale, formattedDate)); + setDateTimeToRelative(formatDistanceToNow(formattedDate, {addSuffix: true})); }, 60 * 1000); return () => { clearInterval(interval); }; - }, [formattedDate, preferredLocale]); + }, [formattedDate]); const connectionsMenuItems: MenuItemProps[] = useMemo(() => { if (isEmptyObject(policy?.connections) && !isSyncInProgress) { From 0c8b01483988ef87c0911b76c97152b5fef36409 Mon Sep 17 00:00:00 2001 From: tienifr Date: Tue, 14 May 2024 15:16:30 +0700 Subject: [PATCH 7/7] remove setinterval --- .../accounting/PolicyAccountingPage.tsx | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index b205a88945f0..1c3bc66a3f42 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -35,14 +35,13 @@ import type {AnchorPosition} from '@styles/index'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import type {Locale, Policy, PolicyConnectionSyncProgress} from '@src/types/onyx'; +import type {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; - preferredLocale: OnyxEntry; }; type PolicyAccountingPageProps = WithPolicyProps & @@ -102,7 +101,7 @@ function accountingIntegrationData( } } -function PolicyAccountingPage({policy, connectionSyncProgress, preferredLocale}: PolicyAccountingPageProps) { +function PolicyAccountingPage({policy, connectionSyncProgress}: PolicyAccountingPageProps) { const theme = useTheme(); const styles = useThemeStyles(); const {translate} = useLocalize(); @@ -120,7 +119,7 @@ function PolicyAccountingPage({policy, connectionSyncProgress, preferredLocale}: 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(); + const formattedDate = useMemo(() => (successfulDate ? new Date(successfulDate) : new Date()), [successfulDate]); const policyConnectedToXero = connectedIntegration === CONST.POLICY.CONNECTIONS.NAME.XERO; @@ -147,13 +146,6 @@ function PolicyAccountingPage({policy, connectionSyncProgress, preferredLocale}: useEffect(() => { setDateTimeToRelative(formatDistanceToNow(formattedDate, {addSuffix: true})); - const interval = setInterval(() => { - setDateTimeToRelative(formatDistanceToNow(formattedDate, {addSuffix: true})); - }, 60 * 1000); - - return () => { - clearInterval(interval); - }; }, [formattedDate]); const connectionsMenuItems: MenuItemProps[] = useMemo(() => { @@ -394,8 +386,5 @@ export default withPolicyConnections( connectionSyncProgress: { key: (props) => `${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${props.route.params.policyID}`, }, - preferredLocale: { - key: ONYXKEYS.NVP_PREFERRED_LOCALE, - }, })(PolicyAccountingPage), );