From d7b8835d364b91337eff276cac7eba254d597b85 Mon Sep 17 00:00:00 2001 From: Hans Date: Thu, 15 Aug 2024 14:22:31 +0700 Subject: [PATCH 01/17] only show error message if isSuccessful is false --- src/libs/actions/connections/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/connections/index.ts b/src/libs/actions/connections/index.ts index c47c57d57466..cfce7442efed 100644 --- a/src/libs/actions/connections/index.ts +++ b/src/libs/actions/connections/index.ts @@ -379,7 +379,8 @@ function getSynchronizationErrorMessage(policy: OnyxEntry, connectionNam } const connection = policy?.connections?.[connectionName]; - if (isSyncInProgress || connection?.lastSync?.isSuccessful) { + + if (isSyncInProgress || connection?.lastSync?.isSuccessful !== false) { return; } return `${syncError} ("${connection?.lastSync?.errorMessage}")`; From 5a9bf323e844fcc026a69cf28e5fb332d53142ec Mon Sep 17 00:00:00 2001 From: Hans Date: Mon, 19 Aug 2024 17:53:19 +0700 Subject: [PATCH 02/17] introduce allConnectionProgreses Onyx data --- src/components/Indicator.tsx | 11 +++++++++-- src/libs/WorkspacesSettingsUtils.ts | 11 ++++++++--- src/libs/actions/connections/index.ts | 18 +++++++++++++++++- src/pages/home/sidebar/AllSettingsScreen.tsx | 5 +++-- src/pages/settings/InitialSettingsPage.tsx | 5 +++-- .../accounting/PolicyAccountingPage.tsx | 9 ++------- 6 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/components/Indicator.tsx b/src/components/Indicator.tsx index 5ae227d1de70..e0d8ec95738f 100644 --- a/src/components/Indicator.tsx +++ b/src/components/Indicator.tsx @@ -1,9 +1,10 @@ import React from 'react'; import {StyleSheet, View} from 'react-native'; import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; -import {withOnyx} from 'react-native-onyx'; +import {useOnyx, withOnyx} from 'react-native-onyx'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; +import {isConnectionInProgress} from '@libs/actions/connections'; import * as PolicyUtils from '@libs/PolicyUtils'; import * as SubscriptionUtils from '@libs/SubscriptionUtils'; import * as UserUtils from '@libs/UserUtils'; @@ -41,6 +42,7 @@ type IndicatorProps = IndicatorOnyxProps; function Indicator({reimbursementAccount, policies, bankAccountList, fundList, userWallet, walletTerms, loginList}: IndicatorOnyxProps) { const theme = useTheme(); const styles = useThemeStyles(); + const [allConnectionSyncProgresses] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}`); // If a policy was just deleted from Onyx, then Onyx will pass a null value to the props, and // those should be cleaned out before doing any error checking @@ -55,7 +57,12 @@ function Indicator({reimbursementAccount, policies, bankAccountList, fundList, u () => Object.values(cleanPolicies).some(PolicyUtils.hasPolicyError), () => Object.values(cleanPolicies).some(PolicyUtils.hasCustomUnitsError), () => Object.values(cleanPolicies).some(PolicyUtils.hasEmployeeListError), - () => Object.values(cleanPolicies).some(PolicyUtils.hasSyncError), + () => + Object.values(cleanPolicies).some( + (cleanPolicy) => + PolicyUtils.hasSyncError(cleanPolicy) && + !isConnectionInProgress(allConnectionSyncProgresses?.[`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${cleanPolicy?.id}}`], cleanPolicy), + ), () => SubscriptionUtils.hasSubscriptionRedDotError(), () => Object.keys(reimbursementAccount?.errors ?? {}).length > 0, () => !!loginList && UserUtils.hasLoginListError(loginList), diff --git a/src/libs/WorkspacesSettingsUtils.ts b/src/libs/WorkspacesSettingsUtils.ts index 9b96c8404bf6..7224b5ae2f9c 100644 --- a/src/libs/WorkspacesSettingsUtils.ts +++ b/src/libs/WorkspacesSettingsUtils.ts @@ -5,7 +5,8 @@ import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Policy, ReimbursementAccount, Report, ReportAction, ReportActions, TransactionViolations} from '@src/types/onyx'; -import type {Unit} from '@src/types/onyx/Policy'; +import type {PolicyConnectionSyncProgress, Unit} from '@src/types/onyx/Policy'; +import {isConnectionInProgress} from './actions/connections'; import * as CurrencyUtils from './CurrencyUtils'; import type {Phrase, PhraseParameters} from './Localize'; import * as OptionsListUtils from './OptionsListUtils'; @@ -100,7 +101,7 @@ const getBrickRoadForPolicy = (report: Report, altReportActions?: OnyxCollection return shouldShowGreenDotIndicator ? CONST.BRICK_ROAD_INDICATOR_STATUS.INFO : undefined; }; -function hasGlobalWorkspaceSettingsRBR(policies: OnyxCollection) { +function hasGlobalWorkspaceSettingsRBR(policies: OnyxCollection, allConnectionProgresses: OnyxCollection) { // When attempting to open a policy with an invalid policyID, the policy collection is updated to include policy objects with error information. // Only policies displayed on the policy list page should be verified. Otherwise, the user will encounter an RBR unrelated to any policies on the list. const cleanPolicies = Object.fromEntries(Object.entries(policies ?? {}).filter(([, policy]) => policy?.id)); @@ -110,7 +111,11 @@ function hasGlobalWorkspaceSettingsRBR(policies: OnyxCollection) { () => Object.values(cleanPolicies).some(hasCustomUnitsError), () => Object.values(cleanPolicies).some(hasTaxRateError), () => Object.values(cleanPolicies).some(hasEmployeeListError), - () => Object.values(cleanPolicies).some(hasSyncError), + () => + Object.values(cleanPolicies).some( + (cleanPolicy) => + hasSyncError(cleanPolicy) && !isConnectionInProgress(allConnectionProgresses?.[`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${cleanPolicy?.id}`], cleanPolicy), + ), () => Object.keys(reimbursementAccount?.errors ?? {}).length > 0, ]; diff --git a/src/libs/actions/connections/index.ts b/src/libs/actions/connections/index.ts index cfce7442efed..1d13fe90d349 100644 --- a/src/libs/actions/connections/index.ts +++ b/src/libs/actions/connections/index.ts @@ -1,3 +1,4 @@ +import {differenceInMinutes, isValid, parseISO} from 'date-fns'; import isObject from 'lodash/isObject'; import type {OnyxEntry, OnyxUpdate} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; @@ -9,7 +10,7 @@ import * as Localize from '@libs/Localize'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type * as OnyxCommon from '@src/types/onyx/OnyxCommon'; -import type {ConnectionName, Connections, PolicyConnectionName} from '@src/types/onyx/Policy'; +import type {ConnectionName, Connections, PolicyConnectionName, PolicyConnectionSyncProgress} from '@src/types/onyx/Policy'; import type Policy from '@src/types/onyx/Policy'; type ConnectionNameExceptNetSuite = Exclude; @@ -431,6 +432,20 @@ function copyExistingPolicyConnection(connectedPolicyID: string, targetPolicyID: ); } +function isConnectionInProgress(connectionSyncProgress?: OnyxEntry, policy?: OnyxEntry): boolean | undefined { + if (!policy || !connectionSyncProgress) { + return false; + } + + const lastSyncProgressDate = parseISO(connectionSyncProgress?.timestamp ?? ''); + return ( + !!connectionSyncProgress?.stageInProgress && + (connectionSyncProgress.stageInProgress !== CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME.JOB_DONE || !policy?.connections?.[connectionSyncProgress.connectionName]) && + isValid(lastSyncProgressDate) && + differenceInMinutes(new Date(), lastSyncProgressDate) < CONST.POLICY.CONNECTIONS.SYNC_STAGE_TIMEOUT_MINUTES + ); +} + export { removePolicyConnection, updatePolicyConnectionConfig, @@ -440,4 +455,5 @@ export { syncConnection, copyExistingPolicyConnection, isConnectionUnverified, + isConnectionInProgress, }; diff --git a/src/pages/home/sidebar/AllSettingsScreen.tsx b/src/pages/home/sidebar/AllSettingsScreen.tsx index dc969cb98622..c0322fc0fcf7 100644 --- a/src/pages/home/sidebar/AllSettingsScreen.tsx +++ b/src/pages/home/sidebar/AllSettingsScreen.tsx @@ -30,6 +30,7 @@ function AllSettingsScreen({policies}: AllSettingsScreenProps) { const waitForNavigate = useWaitForNavigation(); const {translate} = useLocalize(); const {shouldUseNarrowLayout} = useResponsiveLayout(); + const [allConnectionSyncProgresses] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}`); const [privateSubscription] = useOnyx(ONYXKEYS.NVP_PRIVATE_SUBSCRIPTION); @@ -48,7 +49,7 @@ function AllSettingsScreen({policies}: AllSettingsScreenProps) { })(); }, focused: !shouldUseNarrowLayout, - brickRoadIndicator: hasGlobalWorkspaceSettingsRBR(policies) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined, + brickRoadIndicator: hasGlobalWorkspaceSettingsRBR(policies, allConnectionSyncProgresses) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined, }, ...(privateSubscription ? [ @@ -90,7 +91,7 @@ function AllSettingsScreen({policies}: AllSettingsScreenProps) { hoverAndPressStyle: styles.hoveredComponentBG, brickRoadIndicator: item.brickRoadIndicator, })); - }, [shouldUseNarrowLayout, policies, privateSubscription, waitForNavigate, translate, styles]); + }, [shouldUseNarrowLayout, policies, privateSubscription, waitForNavigate, translate, styles, allConnectionSyncProgresses]); return ( (null); const {canUseWorkspaceFeeds} = usePermissions(); - const lastSyncProgressDate = parseISO(connectionSyncProgress?.timestamp ?? ''); - const isSyncInProgress = - !!connectionSyncProgress?.stageInProgress && - (connectionSyncProgress.stageInProgress !== CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME.JOB_DONE || !policy.connections?.[connectionSyncProgress.connectionName]) && - isValid(lastSyncProgressDate) && - differenceInMinutes(new Date(), lastSyncProgressDate) < CONST.POLICY.CONNECTIONS.SYNC_STAGE_TIMEOUT_MINUTES; + const isSyncInProgress = isConnectionInProgress(connectionSyncProgress, policy); const accountingIntegrations = Object.values(CONST.POLICY.CONNECTIONS.NAME); const connectedIntegration = getConnectedIntegration(policy, accountingIntegrations) ?? connectionSyncProgress?.connectionName; From c1c7d634de100933ca8566ffc28d2dd01bfee2e3 Mon Sep 17 00:00:00 2001 From: Hans Date: Mon, 19 Aug 2024 18:03:33 +0700 Subject: [PATCH 03/17] fix linting --- src/languages/en.ts | 4 ++-- src/languages/es.ts | 4 ++-- src/pages/workspace/accounting/PolicyAccountingPage.tsx | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 1684ed3057da..a9c1dd2305f9 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -3189,9 +3189,9 @@ export default { : 'this integration'; return `Are you sure you want to disconnect ${integrationName}?`; }, - connectPrompt: (integrationToConnect: ConnectionName): string => + connectPrompt: (integrationToConnect?: ConnectionName): string => `Are you sure you want to connect ${ - CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY[integrationToConnect] ?? 'this accounting integration' + integrationToConnect ? CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY[integrationToConnect] : 'this accounting integration' }? This will remove any existing acounting connections.`, enterCredentials: 'Enter your credentials', connections: { diff --git a/src/languages/es.ts b/src/languages/es.ts index b4d071ba4a08..f7ddcb8e954c 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -3171,9 +3171,9 @@ export default { currentIntegration && CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY[currentIntegration] ? CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY[currentIntegration] : 'integración'; return `¿Estás seguro de que quieres desconectar ${integrationName}?`; }, - connectPrompt: (integrationToConnect: ConnectionName): string => + connectPrompt: (integrationToConnect?: ConnectionName): string => `¿Estás seguro de que quieres conectar a ${ - CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY[integrationToConnect] ?? 'esta integración contable' + integrationToConnect ? CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY[integrationToConnect] : 'esta integración contable' }? Esto eliminará cualquier conexión contable existente.`, enterCredentials: 'Ingresa tus credenciales', connections: { diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index 909d86c185e0..d7ea0f486e41 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -344,7 +344,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { if (!connectedIntegration) { return []; } - const synchronizationError = getSynchronizationErrorMessage(policy, connectedIntegration, isSyncInProgress); + const synchronizationError = getSynchronizationErrorMessage(policy, connectedIntegration, !!isSyncInProgress); const shouldShowSynchronizationError = !!synchronizationError; const shouldHideConfigurationOptions = isConnectionUnverified(policy, connectedIntegration); const integrationData = accountingIntegrationData(connectedIntegration, policyID, translate, undefined, undefined, policy); @@ -406,7 +406,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { errorTextStyle: [styles.mt5], shouldShowRedDotIndicator: true, description: isSyncInProgress - ? translate('workspace.accounting.connections.syncStageName', connectionSyncProgress.stageInProgress) + ? translate('workspace.accounting.connections.syncStageName', connectionSyncProgress?.stageInProgress) : translate('workspace.accounting.lastSync', datetimeToRelative), rightComponent: isSyncInProgress ? ( Date: Mon, 19 Aug 2024 18:14:21 +0700 Subject: [PATCH 04/17] fix lint --- src/languages/en.ts | 4 ++-- src/languages/es.ts | 4 ++-- src/libs/actions/connections/index.ts | 2 +- src/pages/workspace/accounting/PolicyAccountingPage.tsx | 7 ++++--- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index a9c1dd2305f9..1684ed3057da 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -3189,9 +3189,9 @@ export default { : 'this integration'; return `Are you sure you want to disconnect ${integrationName}?`; }, - connectPrompt: (integrationToConnect?: ConnectionName): string => + connectPrompt: (integrationToConnect: ConnectionName): string => `Are you sure you want to connect ${ - integrationToConnect ? CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY[integrationToConnect] : 'this accounting integration' + CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY[integrationToConnect] ?? 'this accounting integration' }? This will remove any existing acounting connections.`, enterCredentials: 'Enter your credentials', connections: { diff --git a/src/languages/es.ts b/src/languages/es.ts index f7ddcb8e954c..b4d071ba4a08 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -3171,9 +3171,9 @@ export default { currentIntegration && CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY[currentIntegration] ? CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY[currentIntegration] : 'integración'; return `¿Estás seguro de que quieres desconectar ${integrationName}?`; }, - connectPrompt: (integrationToConnect?: ConnectionName): string => + connectPrompt: (integrationToConnect: ConnectionName): string => `¿Estás seguro de que quieres conectar a ${ - integrationToConnect ? CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY[integrationToConnect] : 'esta integración contable' + CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY[integrationToConnect] ?? 'esta integración contable' }? Esto eliminará cualquier conexión contable existente.`, enterCredentials: 'Ingresa tus credenciales', connections: { diff --git a/src/libs/actions/connections/index.ts b/src/libs/actions/connections/index.ts index 1d13fe90d349..8cb7afbd1144 100644 --- a/src/libs/actions/connections/index.ts +++ b/src/libs/actions/connections/index.ts @@ -432,7 +432,7 @@ function copyExistingPolicyConnection(connectedPolicyID: string, targetPolicyID: ); } -function isConnectionInProgress(connectionSyncProgress?: OnyxEntry, policy?: OnyxEntry): boolean | undefined { +function isConnectionInProgress(connectionSyncProgress: OnyxEntry, policy?: OnyxEntry): boolean | undefined { if (!policy || !connectionSyncProgress) { return false; } diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index d7ea0f486e41..6ffd57f982c3 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -405,9 +405,10 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { errorText: synchronizationError, errorTextStyle: [styles.mt5], shouldShowRedDotIndicator: true, - description: isSyncInProgress - ? translate('workspace.accounting.connections.syncStageName', connectionSyncProgress?.stageInProgress) - : translate('workspace.accounting.lastSync', datetimeToRelative), + description: + isSyncInProgress && connectionSyncProgress?.stageInProgress + ? translate('workspace.accounting.connections.syncStageName', connectionSyncProgress.stageInProgress) + : translate('workspace.accounting.lastSync', datetimeToRelative), rightComponent: isSyncInProgress ? ( Date: Mon, 19 Aug 2024 18:14:53 +0700 Subject: [PATCH 05/17] remove unused import --- src/pages/workspace/accounting/PolicyAccountingPage.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index 6ffd57f982c3..07e1ba4d1b0a 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -1,4 +1,3 @@ -import {differenceInMinutes, isValid, parseISO} from 'date-fns'; import React, {useEffect, useMemo, useRef, useState} from 'react'; import {ActivityIndicator, View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; From 5cf0bfd612b1e5f278510605261ecf13ea8f9709 Mon Sep 17 00:00:00 2001 From: Hans Date: Mon, 19 Aug 2024 18:17:33 +0700 Subject: [PATCH 06/17] update return value --- src/libs/actions/connections/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/connections/index.ts b/src/libs/actions/connections/index.ts index 8cb7afbd1144..c782f659fd05 100644 --- a/src/libs/actions/connections/index.ts +++ b/src/libs/actions/connections/index.ts @@ -432,7 +432,7 @@ function copyExistingPolicyConnection(connectedPolicyID: string, targetPolicyID: ); } -function isConnectionInProgress(connectionSyncProgress: OnyxEntry, policy?: OnyxEntry): boolean | undefined { +function isConnectionInProgress(connectionSyncProgress: OnyxEntry, policy?: OnyxEntry): boolean { if (!policy || !connectionSyncProgress) { return false; } From c1e7e9c8e8a3925473a5435fa89c5ca05519d354 Mon Sep 17 00:00:00 2001 From: Hans Date: Mon, 19 Aug 2024 18:22:47 +0700 Subject: [PATCH 07/17] update accounting page --- src/pages/workspace/WorkspaceInitialPage.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/WorkspaceInitialPage.tsx b/src/pages/workspace/WorkspaceInitialPage.tsx index 115a24691838..1937e757666f 100644 --- a/src/pages/workspace/WorkspaceInitialPage.tsx +++ b/src/pages/workspace/WorkspaceInitialPage.tsx @@ -3,7 +3,7 @@ import type {StackScreenProps} from '@react-navigation/stack'; import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; -import {withOnyx} from 'react-native-onyx'; +import {useOnyx, withOnyx} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; import ConfirmModal from '@components/ConfirmModal'; @@ -41,6 +41,7 @@ import {isEmptyObject} from '@src/types/utils/EmptyObject'; import type IconAsset from '@src/types/utils/IconAsset'; import type {WithPolicyAndFullscreenLoadingProps} from './withPolicyAndFullscreenLoading'; import withPolicyAndFullscreenLoading from './withPolicyAndFullscreenLoading'; +import { isConnectionInProgress } from '@libs/actions/connections'; type WorkspaceMenuItem = { translationKey: TranslationPaths; @@ -93,7 +94,8 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAcc const policy = policyDraft?.id ? policyDraft : policyProp; const [isCurrencyModalOpen, setIsCurrencyModalOpen] = useState(false); const hasPolicyCreationError = !!(policy?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD && !isEmptyObject(policy.errors)); - const hasSyncError = PolicyUtils.hasSyncError(policy); + const [connectionSyncProgress] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${policy?.id}`); + const hasSyncError = PolicyUtils.hasSyncError(policy) && !isConnectionInProgress(connectionSyncProgress, policy); const waitForNavigate = useWaitForNavigation(); const {singleExecution, isExecuting} = useSingleExecution(); const activeRoute = useNavigationState(getTopmostRouteName); From 5613c04a3ce9c5094126d08ab2e42ae6f3098afc Mon Sep 17 00:00:00 2001 From: Hans Date: Mon, 19 Aug 2024 21:55:46 +0700 Subject: [PATCH 08/17] refactor hasSync logic --- src/components/Indicator.tsx | 10 ++++++---- src/libs/PolicyUtils.ts | 8 ++++---- src/libs/WorkspacesSettingsUtils.ts | 19 ++----------------- src/pages/workspace/WorkspaceInitialPage.tsx | 7 ++++--- 4 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/components/Indicator.tsx b/src/components/Indicator.tsx index e0d8ec95738f..a051399681f5 100644 --- a/src/components/Indicator.tsx +++ b/src/components/Indicator.tsx @@ -12,6 +12,7 @@ import * as PaymentMethods from '@userActions/PaymentMethods'; import ONYXKEYS from '@src/ONYXKEYS'; import type {BankAccountList, FundList, LoginList, Policy, ReimbursementAccount, UserWallet, WalletTerms} from '@src/types/onyx'; + type CheckingMethod = () => boolean; type IndicatorOnyxProps = { @@ -58,10 +59,11 @@ function Indicator({reimbursementAccount, policies, bankAccountList, fundList, u () => Object.values(cleanPolicies).some(PolicyUtils.hasCustomUnitsError), () => Object.values(cleanPolicies).some(PolicyUtils.hasEmployeeListError), () => - Object.values(cleanPolicies).some( - (cleanPolicy) => - PolicyUtils.hasSyncError(cleanPolicy) && - !isConnectionInProgress(allConnectionSyncProgresses?.[`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${cleanPolicy?.id}}`], cleanPolicy), + Object.values(cleanPolicies).some((cleanPolicy) => + PolicyUtils.hasSyncError( + cleanPolicy, + isConnectionInProgress(allConnectionSyncProgresses?.[`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${cleanPolicy?.id}}`], cleanPolicy), + ), ), () => SubscriptionUtils.hasSubscriptionRedDotError(), () => Object.keys(reimbursementAccount?.errors ?? {}).length > 0, diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 3f3a2a96a1e1..a240dfe01f66 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -89,8 +89,8 @@ function hasPolicyCategoriesError(policyCategories: OnyxEntry) /** * Checks if the policy had a sync error. */ -function hasSyncError(policy: OnyxEntry): boolean { - return (Object.keys(policy?.connections ?? {}) as ConnectionName[]).some((connection) => !!getSynchronizationErrorMessage(policy, connection, false)); +function hasSyncError(policy: OnyxEntry, isSyncInProgress: boolean): boolean { + return (Object.keys(policy?.connections ?? {}) as ConnectionName[]).some((connection) => !!getSynchronizationErrorMessage(policy, connection, isSyncInProgress)); } /** @@ -152,8 +152,8 @@ function getUnitRateValue(toLocaleDigit: (arg: string) => string, customUnitRate /** * Get the brick road indicator status for a policy. The policy has an error status if there is a policy member error, a custom unit error or a field error. */ -function getPolicyBrickRoadIndicatorStatus(policy: OnyxEntry): ValueOf | undefined { - if (hasEmployeeListError(policy) || hasCustomUnitsError(policy) || hasPolicyErrorFields(policy) || hasSyncError(policy)) { +function getPolicyBrickRoadIndicatorStatus(policy: OnyxEntry, isConnectionInProgress: boolean): ValueOf | undefined { + if (hasEmployeeListError(policy) || hasCustomUnitsError(policy) || hasPolicyErrorFields(policy) || hasSyncError(policy, isConnectionInProgress)) { return CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR; } return undefined; diff --git a/src/libs/WorkspacesSettingsUtils.ts b/src/libs/WorkspacesSettingsUtils.ts index 7224b5ae2f9c..9c1ace6cc8c9 100644 --- a/src/libs/WorkspacesSettingsUtils.ts +++ b/src/libs/WorkspacesSettingsUtils.ts @@ -112,9 +112,8 @@ function hasGlobalWorkspaceSettingsRBR(policies: OnyxCollection, allConn () => Object.values(cleanPolicies).some(hasTaxRateError), () => Object.values(cleanPolicies).some(hasEmployeeListError), () => - Object.values(cleanPolicies).some( - (cleanPolicy) => - hasSyncError(cleanPolicy) && !isConnectionInProgress(allConnectionProgresses?.[`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${cleanPolicy?.id}`], cleanPolicy), + Object.values(cleanPolicies).some((cleanPolicy) => + hasSyncError(cleanPolicy, isConnectionInProgress(allConnectionProgresses?.[`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${cleanPolicy?.id}`], cleanPolicy)), ), () => Object.keys(reimbursementAccount?.errors ?? {}).length > 0, ]; @@ -159,19 +158,6 @@ function getChatTabBrickRoad(policyID?: string): BrickRoad | undefined { return undefined; } -function checkIfWorkspaceSettingsTabHasRBR(policyID?: string) { - if (!policyID) { - return hasGlobalWorkspaceSettingsRBR(allPolicies); - } - const policy = allPolicies ? allPolicies[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`] : null; - - if (!policy) { - return false; - } - - return hasWorkspaceSettingsRBR(policy); -} - /** * @returns a map where the keys are policyIDs and the values are BrickRoads for each policy */ @@ -323,7 +309,6 @@ export { getWorkspacesBrickRoads, getWorkspacesUnreadStatuses, hasGlobalWorkspaceSettingsRBR, - checkIfWorkspaceSettingsTabHasRBR, hasWorkspaceSettingsRBR, getChatTabBrickRoad, getUnitTranslationKey, diff --git a/src/pages/workspace/WorkspaceInitialPage.tsx b/src/pages/workspace/WorkspaceInitialPage.tsx index 1937e757666f..044cea2bbbfa 100644 --- a/src/pages/workspace/WorkspaceInitialPage.tsx +++ b/src/pages/workspace/WorkspaceInitialPage.tsx @@ -20,6 +20,7 @@ import usePrevious from '@hooks/usePrevious'; import useSingleExecution from '@hooks/useSingleExecution'; import useThemeStyles from '@hooks/useThemeStyles'; import useWaitForNavigation from '@hooks/useWaitForNavigation'; +import {isConnectionInProgress} from '@libs/actions/connections'; import getTopmostRouteName from '@libs/Navigation/getTopmostRouteName'; import Navigation from '@libs/Navigation/Navigation'; import * as PolicyUtils from '@libs/PolicyUtils'; @@ -41,7 +42,7 @@ import {isEmptyObject} from '@src/types/utils/EmptyObject'; import type IconAsset from '@src/types/utils/IconAsset'; import type {WithPolicyAndFullscreenLoadingProps} from './withPolicyAndFullscreenLoading'; import withPolicyAndFullscreenLoading from './withPolicyAndFullscreenLoading'; -import { isConnectionInProgress } from '@libs/actions/connections'; + type WorkspaceMenuItem = { translationKey: TranslationPaths; @@ -95,7 +96,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAcc const [isCurrencyModalOpen, setIsCurrencyModalOpen] = useState(false); const hasPolicyCreationError = !!(policy?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD && !isEmptyObject(policy.errors)); const [connectionSyncProgress] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${policy?.id}`); - const hasSyncError = PolicyUtils.hasSyncError(policy) && !isConnectionInProgress(connectionSyncProgress, policy); + const hasSyncError = PolicyUtils.hasSyncError(policy, isConnectionInProgress(connectionSyncProgress, policy)); const waitForNavigate = useWaitForNavigation(); const {singleExecution, isExecuting} = useSingleExecution(); const activeRoute = useNavigationState(getTopmostRouteName); @@ -468,4 +469,4 @@ export default withPolicyAndFullscreenLoading( key: ({route}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${route.params?.policyID ?? '-1'}`, }, })(WorkspaceInitialPage), -); +); \ No newline at end of file From 6abc5e9e1f50b3a17c7fc2e3ebaba908e21572c3 Mon Sep 17 00:00:00 2001 From: Hans Date: Mon, 19 Aug 2024 22:07:51 +0700 Subject: [PATCH 09/17] update the workspacelist logic --- src/components/Indicator.tsx | 1 - src/pages/workspace/WorkspacesListPage.tsx | 11 +++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/components/Indicator.tsx b/src/components/Indicator.tsx index a051399681f5..edf1cb231291 100644 --- a/src/components/Indicator.tsx +++ b/src/components/Indicator.tsx @@ -12,7 +12,6 @@ import * as PaymentMethods from '@userActions/PaymentMethods'; import ONYXKEYS from '@src/ONYXKEYS'; import type {BankAccountList, FundList, LoginList, Policy, ReimbursementAccount, UserWallet, WalletTerms} from '@src/types/onyx'; - type CheckingMethod = () => boolean; type IndicatorOnyxProps = { diff --git a/src/pages/workspace/WorkspacesListPage.tsx b/src/pages/workspace/WorkspacesListPage.tsx index 94fb454c4a2d..6d4aa82f3931 100755 --- a/src/pages/workspace/WorkspacesListPage.tsx +++ b/src/pages/workspace/WorkspacesListPage.tsx @@ -1,6 +1,6 @@ import React, {useCallback, useMemo, useState} from 'react'; import {FlatList, View} from 'react-native'; -import {withOnyx} from 'react-native-onyx'; +import {useOnyx, withOnyx} from 'react-native-onyx'; import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import Button from '@components/Button'; @@ -42,6 +42,7 @@ import type {Policy as PolicyType, ReimbursementAccount, Report, Session as Sess import type * as OnyxCommon from '@src/types/onyx/OnyxCommon'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import WorkspacesListRow from './WorkspacesListRow'; +import { isConnectionInProgress } from '@libs/actions/connections'; type WorkspaceItem = Required> & Pick & @@ -123,6 +124,7 @@ function WorkspacesListPage({policies, reimbursementAccount, reports, session}: const {translate} = useLocalize(); const {isOffline} = useNetwork(); const {shouldUseNarrowLayout, isMediumScreenWidth} = useResponsiveLayout(); + const [allConnectionSyncProgresses] = useOnyx(ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS); const {activeWorkspaceID, setActiveWorkspaceID} = useActiveWorkspace(); @@ -338,7 +340,12 @@ function WorkspacesListPage({policies, reimbursementAccount, reports, session}: title: policy.name, icon: policy.avatarURL ? policy.avatarURL : ReportUtils.getDefaultWorkspaceAvatar(policy.name), action: () => Navigation.navigate(ROUTES.WORKSPACE_INITIAL.getRoute(policy.id)), - brickRoadIndicator: reimbursementAccountBrickRoadIndicator ?? PolicyUtils.getPolicyBrickRoadIndicatorStatus(policy), + brickRoadIndicator: + reimbursementAccountBrickRoadIndicator ?? + PolicyUtils.getPolicyBrickRoadIndicatorStatus( + policy, + isConnectionInProgress(allConnectionSyncProgresses?.[`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${policy.id}`], policy), + ), pendingAction: policy.pendingAction, errors: policy.errors, dismissError: () => dismissWorkspaceError(policy.id, policy.pendingAction), From 5bf86d5fc46e0c44fcfcb73ea447d34e039a336a Mon Sep 17 00:00:00 2001 From: Hans Date: Mon, 19 Aug 2024 22:19:28 +0700 Subject: [PATCH 10/17] fix linting --- src/pages/workspace/WorkspacesListPage.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/workspace/WorkspacesListPage.tsx b/src/pages/workspace/WorkspacesListPage.tsx index 6d4aa82f3931..a388fd73269d 100755 --- a/src/pages/workspace/WorkspacesListPage.tsx +++ b/src/pages/workspace/WorkspacesListPage.tsx @@ -42,7 +42,6 @@ import type {Policy as PolicyType, ReimbursementAccount, Report, Session as Sess import type * as OnyxCommon from '@src/types/onyx/OnyxCommon'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import WorkspacesListRow from './WorkspacesListRow'; -import { isConnectionInProgress } from '@libs/actions/connections'; type WorkspaceItem = Required> & Pick & From 266526d0b5c178992b7820fbb7b020fe88b3495e Mon Sep 17 00:00:00 2001 From: Hans Date: Mon, 19 Aug 2024 22:26:37 +0700 Subject: [PATCH 11/17] add import connection for list page --- src/pages/workspace/WorkspacesListPage.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pages/workspace/WorkspacesListPage.tsx b/src/pages/workspace/WorkspacesListPage.tsx index a388fd73269d..751acab415ac 100755 --- a/src/pages/workspace/WorkspacesListPage.tsx +++ b/src/pages/workspace/WorkspacesListPage.tsx @@ -24,6 +24,7 @@ import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useTheme from '@hooks/useTheme'; +import {isConnectionInProgress} from '@libs/actions/connections'; import useThemeStyles from '@hooks/useThemeStyles'; import interceptAnonymousUser from '@libs/interceptAnonymousUser'; import localeCompare from '@libs/LocaleCompare'; @@ -43,6 +44,7 @@ import type * as OnyxCommon from '@src/types/onyx/OnyxCommon'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import WorkspacesListRow from './WorkspacesListRow'; + type WorkspaceItem = Required> & Pick & Pick & From 2f0d0fa8fdc8be833e90617287e485931104af0a Mon Sep 17 00:00:00 2001 From: Hans Date: Mon, 19 Aug 2024 23:08:04 +0700 Subject: [PATCH 12/17] fix lint --- src/pages/workspace/WorkspacesListPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/WorkspacesListPage.tsx b/src/pages/workspace/WorkspacesListPage.tsx index 751acab415ac..7540b41bb021 100755 --- a/src/pages/workspace/WorkspacesListPage.tsx +++ b/src/pages/workspace/WorkspacesListPage.tsx @@ -363,7 +363,7 @@ function WorkspacesListPage({policies, reimbursementAccount, reports, session}: }; }) .sort((a, b) => localeCompare(a.title, b.title)); - }, [reimbursementAccount?.errors, policies, isOffline, theme.textLight, policyRooms]); + }, [reimbursementAccount?.errors, policies, isOffline, theme.textLight, policyRooms, allConnectionSyncProgresses]); const getHeaderButton = () => (