Skip to content
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
6 changes: 6 additions & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3041,6 +3041,12 @@ const CONST = {
NETSUITE: 'netsuite',
SAGE_INTACCT: 'intacct',
},
SUPPORTED_ONLY_ON_OLDDOT: {
FINANCIALFORCE: 'financialForce',
},
UNSUPPORTED_NAMES: {
GENERIC_INDIRECT_CONNECTION: 'generic_indirect_connection',
},
ROUTE: {
QBO: 'quickbooks-online',
XERO: 'xero',
Expand Down
15 changes: 11 additions & 4 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

let allPolicies: OnyxCollection<Policy>;

Onyx.connect({

Check warning on line 60 in src/libs/PolicyUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => (allPolicies = value),
Expand Down Expand Up @@ -594,10 +594,12 @@
}

/**
* Whether the policy has active accounting integration connections
* Whether the policy has active accounting integration connections.
* `getCurrentConnectionName` only returns connections supported in NewDot.
* `hasSupportedOnlyOnOldDotIntegration` detects connections that are supported only on OldDot.
*/
function hasAccountingConnections(policy: OnyxEntry<Policy>) {
return !isEmptyObject(policy?.connections);
return !!getCurrentConnectionName(policy) || hasSupportedOnlyOnOldDotIntegration(policy);
}

function getPolicyEmployeeListByIdWithoutCurrentUser(policies: OnyxCollection<Pick<Policy, 'employeeList'>>, currentPolicyID?: string, currentUserAccountID?: number) {
Expand Down Expand Up @@ -1274,8 +1276,12 @@
return (connectedIntegration && policy?.connections?.[connectedIntegration]?.config?.autoSync?.enabled) ?? false;
}

function hasUnsupportedIntegration(policy: Policy | undefined, accountingIntegrations?: ConnectionName[]) {
return !(accountingIntegrations ?? Object.values(CONST.POLICY.CONNECTIONS.NAME)).some((integration) => !!policy?.connections?.[integration]);
function hasUnsupportedIntegration(policy: Policy | undefined) {
return Object.values(CONST.POLICY.CONNECTIONS.UNSUPPORTED_NAMES).some((integration) => !!(policy?.connections as Record<string, unknown>)?.[integration]);
}

function hasSupportedOnlyOnOldDotIntegration(policy: Policy | undefined) {
return Object.values(CONST.POLICY.CONNECTIONS.SUPPORTED_ONLY_ON_OLDDOT).some((integration) => !!(policy?.connections as Record<string, unknown>)?.[integration]);
}

function getCurrentConnectionName(policy: Policy | undefined): string | undefined {
Expand Down Expand Up @@ -1636,6 +1642,7 @@
getTagApproverRule,
getDomainNameForPolicy,
hasUnsupportedIntegration,
hasSupportedOnlyOnOldDotIntegration,
getWorkflowApprovalsUnavailable,
getNetSuiteImportCustomFieldLabel,
getUserFriendlyWorkspaceType,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/WorkspaceMoreFeaturesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {getLatestErrorField} from '@libs/ErrorUtils';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {WorkspaceSplitNavigatorParamList} from '@libs/Navigation/types';
import {getDistanceRateCustomUnit, getPerDiemCustomUnit, isControlPolicy} from '@libs/PolicyUtils';
import {getDistanceRateCustomUnit, getPerDiemCustomUnit, hasAccountingConnections, isControlPolicy} from '@libs/PolicyUtils';
import {enablePolicyCategories} from '@userActions/Policy/Category';
import {enablePolicyDistanceRates} from '@userActions/Policy/DistanceRate';
import {enablePerDiem} from '@userActions/Policy/PerDiem';
Expand Down Expand Up @@ -80,7 +80,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
const {shouldUseNarrowLayout} = useResponsiveLayout();
const {translate} = useLocalize();
const {isBetaEnabled} = usePermissions();
const hasAccountingConnection = !isEmptyObject(policy?.connections);
const hasAccountingConnection = hasAccountingConnections(policy);
const isAccountingEnabled = !!policy?.areConnectionsEnabled || !isEmptyObject(policy?.connections);
const isSyncTaxEnabled =
!!policy?.connections?.quickbooksOnline?.config?.syncTax ||
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/accounting/PolicyAccountingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
getIntegrationLastSuccessfulDate,
getXeroTenants,
hasAccountingConnections,
hasUnsupportedIntegration,
hasSupportedOnlyOnOldDotIntegration,
isControlPolicy,
settingsPendingAction,
shouldShowSyncError,
Expand Down Expand Up @@ -102,7 +102,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) {
);

const hasSyncError = shouldShowSyncError(policy, isSyncInProgress);
const hasUnsupportedNDIntegration = !isEmptyObject(policy?.connections) && hasUnsupportedIntegration(policy, accountingIntegrations);
const hasUnsupportedNDIntegration = !isEmptyObject(policy?.connections) && hasSupportedOnlyOnOldDotIntegration(policy);

const tenants = useMemo(() => getXeroTenants(policy), [policy]);
const currentXeroOrganization = findCurrentXeroOrganization(tenants, policy?.connections?.xero?.config?.tenantID);
Expand Down
14 changes: 6 additions & 8 deletions src/pages/workspace/reports/WorkspaceReportsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {getLatestErrorField} from '@libs/ErrorUtils';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {WorkspaceSplitNavigatorParamList} from '@libs/Navigation/types';
import {getConnectedIntegration, getCurrentConnectionName, hasAccountingConnections, isControlPolicy, shouldShowSyncError} from '@libs/PolicyUtils';
import {getConnectedIntegration, getCurrentConnectionName, hasAccountingConnections as hasAccountingConnectionsPolicyUtils, isControlPolicy, shouldShowSyncError} from '@libs/PolicyUtils';
import {getReportFieldTypeTranslationKey} from '@libs/WorkspaceReportFieldUtils';
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
import ToggleSettingOptionRow from '@pages/workspace/workflows/ToggleSettingsOptionRow';
Expand All @@ -40,7 +40,6 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

type ReportFieldForList = ListItem & {
fieldID: string;
Expand Down Expand Up @@ -73,23 +72,22 @@ function WorkspaceReportFieldsPage({
const connectedIntegration = getConnectedIntegration(policy) ?? connectionSyncProgress?.connectionName;
const isConnectionVerified = connectedIntegration && !isConnectionUnverified(policy, connectedIntegration);
const currentConnectionName = getCurrentConnectionName(policy);
const hasReportAccountingConnections = hasAccountingConnections(policy);
const hasAccountingConnections = hasAccountingConnectionsPolicyUtils(policy);
const filteredPolicyFieldList = useMemo(() => {
if (!policy?.fieldList) {
return {};
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
return Object.fromEntries(Object.entries(policy.fieldList).filter(([_, value]) => value.fieldID !== 'text_title'));
}, [policy]);
const hasAccountingConnection = !isEmptyObject(policy?.connections);
const [isOrganizeWarningModalOpen, setIsOrganizeWarningModalOpen] = useState(false);

const onDisabledOrganizeSwitchPress = useCallback(() => {
if (!hasAccountingConnection) {
if (!hasAccountingConnections) {
return;
}
setIsOrganizeWarningModalOpen(true);
}, [hasAccountingConnection]);
}, [hasAccountingConnections]);

const fetchReportFields = useCallback(() => {
openPolicyReportFieldsPage(policyID);
Expand Down Expand Up @@ -269,7 +267,7 @@ function WorkspaceReportFieldsPage({
}
enablePolicyReportFields(policyID, isEnabled);
}}
disabled={hasAccountingConnection}
disabled={hasAccountingConnections}
disabledAction={onDisabledOrganizeSwitchPress}
subMenuItems={
!!policy?.areReportFieldsEnabled && (
Expand All @@ -282,7 +280,7 @@ function WorkspaceReportFieldsPage({
keyExtractor={keyExtractor}
/>
</View>
{!hasReportAccountingConnections && (
{!hasAccountingConnections && (
<MenuItem
onPress={() => Navigation.navigate(ROUTES.WORKSPACE_CREATE_REPORT_FIELD.getRoute(policyID))}
title={translate('workspace.reportFields.addField')}
Expand Down
Loading