From 37c0566023d29824f6d18eeab80795e386f571e4 Mon Sep 17 00:00:00 2001 From: Yuwen Memon Date: Wed, 24 Jul 2024 16:28:11 -0700 Subject: [PATCH 1/3] Make sure we still show configutation options even when there's a sync error for a connection --- 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 8b41de6b7d37..94862a04c606 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -325,7 +325,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { ), }, ...(isEmptyObject(integrationSpecificMenuItems) || shouldShowSynchronizationError || isEmptyObject(policy?.connections) ? [] : [integrationSpecificMenuItems]), - ...(isEmptyObject(policy?.connections) || shouldShowSynchronizationError + ...(isEmptyObject(policy?.connections) ? [] : [ { From 573fe40e8b5a56589099fee3b0fb447cc368d52c Mon Sep 17 00:00:00 2001 From: Yuwen Memon Date: Wed, 24 Jul 2024 17:01:35 -0700 Subject: [PATCH 2/3] Make sure that we still hide the connection options for not connected connections --- src/libs/actions/connections/index.ts | 12 +++++++++++- .../workspace/accounting/PolicyAccountingPage.tsx | 5 +++-- src/types/onyx/Policy.ts | 6 ++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/connections/index.ts b/src/libs/actions/connections/index.ts index 0701223f6b83..bd337315475d 100644 --- a/src/libs/actions/connections/index.ts +++ b/src/libs/actions/connections/index.ts @@ -269,6 +269,16 @@ function hasSynchronizationError(policy: OnyxEntry, connectionName: Poli return !isSyncInProgress && policy?.connections?.[connectionName]?.lastSync?.isSuccessful === false; } +function isConnectionUnverified(policy: OnyxEntry, connectionName: PolicyConnectionName): boolean { + // A verified connection is one that has been successfully synced at least once + // We'll always err on the side of considering a connection as verified connected even if we can't find a lastSync property saying as such + // i.e. this is a property that is explicitly set to false, not just missing + if (connectionName === CONST.POLICY.CONNECTIONS.NAME.NETSUITE) { + return !(policy?.connections?.[CONST.POLICY.CONNECTIONS.NAME.NETSUITE]?.verified ?? true); + } + return !(policy?.connections?.[connectionName]?.lastSync?.isConnected ?? true); +} + function copyExistingPolicyConnection(connectedPolicyID: string, targetPolicyID: string, connectionName: ConnectionName) { let stageInProgress; switch (connectionName) { @@ -304,4 +314,4 @@ function copyExistingPolicyConnection(connectedPolicyID: string, targetPolicyID: ); } -export {removePolicyConnection, updatePolicyConnectionConfig, updateManyPolicyConnectionConfigs, hasSynchronizationError, syncConnection, copyExistingPolicyConnection}; +export {removePolicyConnection, updatePolicyConnectionConfig, updateManyPolicyConnectionConfigs, hasSynchronizationError, syncConnection, copyExistingPolicyConnection, isConnectionUnverified}; diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index 94862a04c606..7a02875cb129 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -29,7 +29,7 @@ import usePermissions from '@hooks/usePermissions'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; -import {hasSynchronizationError, removePolicyConnection, syncConnection} from '@libs/actions/connections'; +import {hasSynchronizationError, removePolicyConnection, syncConnection, isConnectionUnverified} from '@libs/actions/connections'; import * as PolicyUtils from '@libs/PolicyUtils'; import {findCurrentXeroOrganization, getCurrentSageIntacctEntityName, getCurrentXeroOrganizationName, getIntegrationLastSuccessfulDate, getXeroTenants} from '@libs/PolicyUtils'; import Navigation from '@navigation/Navigation'; @@ -286,6 +286,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { return []; } const shouldShowSynchronizationError = hasSynchronizationError(policy, connectedIntegration, isSyncInProgress); + const shouldHideConfigurationOptions = isConnectionUnverified(policy, connectedIntegration); const integrationData = accountingIntegrationData(connectedIntegration, policyID, translate); const iconProps = integrationData?.icon ? {icon: integrationData.icon, iconType: CONST.ICON_TYPE_AVATAR} : {}; return [ @@ -325,7 +326,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { ), }, ...(isEmptyObject(integrationSpecificMenuItems) || shouldShowSynchronizationError || isEmptyObject(policy?.connections) ? [] : [integrationSpecificMenuItems]), - ...(isEmptyObject(policy?.connections) + ...(isEmptyObject(policy?.connections) || shouldHideConfigurationOptions ? [] : [ { diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index ba26a36638e4..e5e5000b8606 100644 --- a/src/types/onyx/Policy.ts +++ b/src/types/onyx/Policy.ts @@ -183,6 +183,12 @@ type ConnectionLastSync = { /** Where did the connection's last sync job come from */ source: JobSourceValues; + + /** + * Sometimes we'll have a connection that is not connected, but the connection object is still present, so we can + * show an error message + */ + isConnected?: boolean; }; /** Financial account (bank account, debit card, etc) */ From 1e3192155655c28e8294b639b99fa91369eab1dd Mon Sep 17 00:00:00 2001 From: Yuwen Memon Date: Thu, 25 Jul 2024 15:39:11 -0700 Subject: [PATCH 3/3] Prettier --- src/libs/actions/connections/index.ts | 10 +++++++++- .../workspace/accounting/PolicyAccountingPage.tsx | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/connections/index.ts b/src/libs/actions/connections/index.ts index bd337315475d..b421ac7cece5 100644 --- a/src/libs/actions/connections/index.ts +++ b/src/libs/actions/connections/index.ts @@ -314,4 +314,12 @@ function copyExistingPolicyConnection(connectedPolicyID: string, targetPolicyID: ); } -export {removePolicyConnection, updatePolicyConnectionConfig, updateManyPolicyConnectionConfigs, hasSynchronizationError, syncConnection, copyExistingPolicyConnection, isConnectionUnverified}; +export { + removePolicyConnection, + updatePolicyConnectionConfig, + updateManyPolicyConnectionConfigs, + hasSynchronizationError, + syncConnection, + copyExistingPolicyConnection, + isConnectionUnverified, +}; diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index 7a02875cb129..1190637a7c45 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -29,7 +29,7 @@ import usePermissions from '@hooks/usePermissions'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; -import {hasSynchronizationError, removePolicyConnection, syncConnection, isConnectionUnverified} from '@libs/actions/connections'; +import {hasSynchronizationError, isConnectionUnverified, removePolicyConnection, syncConnection} from '@libs/actions/connections'; import * as PolicyUtils from '@libs/PolicyUtils'; import {findCurrentXeroOrganization, getCurrentSageIntacctEntityName, getCurrentXeroOrganizationName, getIntegrationLastSuccessfulDate, getXeroTenants} from '@libs/PolicyUtils'; import Navigation from '@navigation/Navigation';