Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure we still show configuration options even when there's a sync error for a connection #46155

Merged
merged 4 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading