diff --git a/src/libs/actions/connections/index.ts b/src/libs/actions/connections/index.ts index 01dca61cdfe9..b611a37faf64 100644 --- a/src/libs/actions/connections/index.ts +++ b/src/libs/actions/connections/index.ts @@ -371,6 +371,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) { @@ -414,4 +424,5 @@ export { hasSynchronizationError, syncConnection, copyExistingPolicyConnection, + isConnectionUnverified, }; diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index 2da483c884df..89bbfd75d538 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -30,7 +30,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; 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, isConnectionUnverified, removePolicyConnection, syncConnection} from '@libs/actions/connections'; import { areXeroSettingsInErrorFields, findCurrentXeroOrganization, @@ -315,6 +315,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { return []; } const shouldShowSynchronizationError = hasSynchronizationError(policy, connectedIntegration, isSyncInProgress); + const shouldHideConfigurationOptions = isConnectionUnverified(policy, connectedIntegration); const integrationData = accountingIntegrationData(connectedIntegration, policyID, translate, undefined, undefined, policy); const iconProps = integrationData?.icon ? {icon: integrationData.icon, iconType: CONST.ICON_TYPE_AVATAR} : {}; return [ @@ -354,7 +355,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { ), }, ...(isEmptyObject(integrationSpecificMenuItems) || shouldShowSynchronizationError || isEmptyObject(policy?.connections) ? [] : [integrationSpecificMenuItems]), - ...(isEmptyObject(policy?.connections) || shouldShowSynchronizationError + ...(isEmptyObject(policy?.connections) || shouldHideConfigurationOptions ? [] : [ { diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index 10e5fe71ba66..4a3576c7f099 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) */