Skip to content

Commit

Permalink
Merge pull request #46155 from Expensify/yuwen-connErr
Browse files Browse the repository at this point in the history
Make sure we still show configuration options even when there's a sync error for a connection
  • Loading branch information
NikkiWines authored Jul 29, 2024
2 parents c16efbc + 1a3c334 commit eeafe76
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/libs/actions/connections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,16 @@ function hasSynchronizationError(policy: OnyxEntry<Policy>, connectionName: Poli
return !isSyncInProgress && policy?.connections?.[connectionName]?.lastSync?.isSuccessful === false;
}

function isConnectionUnverified(policy: OnyxEntry<Policy>, 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) {
Expand Down Expand Up @@ -414,4 +424,5 @@ export {
hasSynchronizationError,
syncConnection,
copyExistingPolicyConnection,
isConnectionUnverified,
};
5 changes: 3 additions & 2 deletions src/pages/workspace/accounting/PolicyAccountingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 [
Expand Down Expand Up @@ -354,7 +355,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) {
),
},
...(isEmptyObject(integrationSpecificMenuItems) || shouldShowSynchronizationError || isEmptyObject(policy?.connections) ? [] : [integrationSpecificMenuItems]),
...(isEmptyObject(policy?.connections) || shouldShowSynchronizationError
...(isEmptyObject(policy?.connections) || shouldHideConfigurationOptions
? []
: [
{
Expand Down
6 changes: 6 additions & 0 deletions src/types/onyx/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Expand Down

0 comments on commit eeafe76

Please sign in to comment.