From e02bff8e761ee70e5fe6f75cc4d1bceb17c4aeba Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Tue, 1 Oct 2024 15:46:50 +0700 Subject: [PATCH 1/6] fix: categories subtitle shows undefeind settings when there is sync error --- src/CONST.ts | 5 +++++ src/libs/PolicyUtils.ts | 5 ++++- .../accounting/PolicyAccountingPage.tsx | 21 +++++++++++++++---- .../categories/WorkspaceCategoriesPage.tsx | 8 +++++-- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 70db2e661056..3b50331b3264 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -2374,6 +2374,11 @@ const CONST = { }, SYNC_STAGE_TIMEOUT_MINUTES: 20, }, + UNSUPPORTED_CONNECTIONS: { + NAME: { + QBO: 'quickbooksDesktop', + }, + }, ACCESS_VARIANTS: { PAID: 'paid', ADMIN: 'admin', diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 8cdb34991cb7..0cad2aadd03d 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -965,8 +965,11 @@ function hasUnsupportedIntegration(policy: Policy | undefined, accountingIntegra return !(accountingIntegrations ?? Object.values(CONST.POLICY.CONNECTIONS.NAME)).some((integration) => !!policy?.connections?.[integration]); } -function getCurrentConnectionName(policy: Policy | undefined): string | undefined { +function getCurrentConnectionName(policy: Policy | undefined, includeUnsupportedConnection = false): string | undefined { const accountingIntegrations = Object.values(CONST.POLICY.CONNECTIONS.NAME); + if (includeUnsupportedConnection) { + accountingIntegrations.push(...Object.values(CONST.POLICY.UNSUPPORTED_CONNECTIONS.NAME)); + } const connectionKey = accountingIntegrations.find((integration) => !!policy?.connections?.[integration]); return connectionKey ? CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY[connectionKey] : undefined; } diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index 591641020480..a7631b9599fe 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -97,7 +97,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { ); const hasSyncError = PolicyUtils.hasSyncError(policy, isSyncInProgress); - const hasUnsupportedNDIntegration = PolicyUtils.hasUnsupportedIntegration(policy, accountingIntegrations); + const hasUnsupportedNDIntegration = !isEmptyObject(policy?.connections) && PolicyUtils.hasUnsupportedIntegration(policy, accountingIntegrations); const tenants = useMemo(() => getXeroTenants(policy), [policy]); const currentXeroOrganization = findCurrentXeroOrganization(tenants, policy?.connections?.xero?.config?.tenantID); @@ -377,7 +377,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { ]); const otherIntegrationsItems = useMemo(() => { - if (isEmptyObject(policy?.connections) && !isSyncInProgress && !(hasUnsupportedNDIntegration && hasSyncError)) { + if (isEmptyObject(policy?.connections) && !isSyncInProgress) { return; } const otherIntegrations = accountingIntegrations.filter( @@ -459,7 +459,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { titleStyles={styles.accountSettingsSectionTitle} childrenStyles={styles.pt5} > - {!(hasUnsupportedNDIntegration && hasSyncError) && + {!hasUnsupportedNDIntegration && connectionsMenuItems.map((menuItem) => ( @@ -493,6 +492,20 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { )} + {hasUnsupportedNDIntegration && !hasSyncError && ( + + + { + // Go to Expensify Classic. + Link.openOldDotLink(CONST.OLDDOT_URLS.POLICY_CONNECTIONS_URL(policyID)); + }} + > + {'Go to Expensify Classic to manage your settings'} + + + + )} {otherIntegrationsItems && ( 0; - const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy); + const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy, true); const canSelectMultiple = shouldUseNarrowLayout ? selectionMode?.isEnabled : true; @@ -284,7 +288,7 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) { const getHeaderText = () => ( - {isConnectedToAccounting ? ( + {!hasSyncError && isConnectedToAccounting ? ( {`${translate('workspace.categories.importedFromAccountingSoftware')} `} Date: Tue, 1 Oct 2024 15:54:13 +0700 Subject: [PATCH 2/6] update copy --- src/languages/en.ts | 1 + src/languages/es.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/languages/en.ts b/src/languages/en.ts index a3dc0e4c2ed3..6b680d013040 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -3431,6 +3431,7 @@ const translations = { }, errorODIntegration: "There's an error with a connection that's been set up in Expensify Classic. ", goToODToFix: 'Go to Expensify Classic to fix this issue.', + goToODToSettings: 'Go to Expensify Classic to manage your settings.', setup: 'Connect', lastSync: ({relativeDate}: LastSyncAccountingParams) => `Last synced ${relativeDate}`, import: 'Import', diff --git a/src/languages/es.ts b/src/languages/es.ts index de333859cdf3..1f521c0438e9 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -3435,6 +3435,7 @@ const translations = { }, errorODIntegration: 'Hay un error con una conexión que se ha configurado en Expensify Classic. ', goToODToFix: 'Ve a Expensify Classic para solucionar este problema.', + goToODToSettings: 'Ve a Expensify Classic para gestionar tus configuraciones.', setup: 'Configurar', lastSync: ({relativeDate}: LastSyncAccountingParams) => `Recién sincronizado ${relativeDate}`, import: 'Importar', From 568191be67c2f93f91ef5467c0f5ca7cddf0c71f Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Tue, 1 Oct 2024 15:54:47 +0700 Subject: [PATCH 3/6] update copy --- src/pages/workspace/accounting/PolicyAccountingPage.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index a7631b9599fe..2609ad5525e8 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -428,8 +428,6 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { isOffline, startIntegrationFlow, popoverAnchorRefs, - hasUnsupportedNDIntegration, - hasSyncError, ]); return ( @@ -501,7 +499,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { Link.openOldDotLink(CONST.OLDDOT_URLS.POLICY_CONNECTIONS_URL(policyID)); }} > - {'Go to Expensify Classic to manage your settings'} + {translate('workspace.accounting.goToODToSettings')} From 279f98d30a8520a4b1f3d38b511454490ffd69e2 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Thu, 3 Oct 2024 22:38:28 +0700 Subject: [PATCH 4/6] fix type error --- src/libs/PolicyUtils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 0cad2aadd03d..9ec14902f800 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -966,12 +966,12 @@ function hasUnsupportedIntegration(policy: Policy | undefined, accountingIntegra } function getCurrentConnectionName(policy: Policy | undefined, includeUnsupportedConnection = false): string | undefined { - const accountingIntegrations = Object.values(CONST.POLICY.CONNECTIONS.NAME); + const accountingIntegrations: string[] = [...Object.values(CONST.POLICY.CONNECTIONS.NAME)]; if (includeUnsupportedConnection) { accountingIntegrations.push(...Object.values(CONST.POLICY.UNSUPPORTED_CONNECTIONS.NAME)); } - const connectionKey = accountingIntegrations.find((integration) => !!policy?.connections?.[integration]); - return connectionKey ? CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY[connectionKey] : undefined; + const connectionKey = accountingIntegrations.find((integration) => policy?.connections && integration in policy.connections); + return connectionKey ? CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY[connectionKey as keyof typeof CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY] : undefined; } /** From e5a9a9e88b8c24f6a14414334bc80e0c9611925f Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Thu, 10 Oct 2024 18:21:51 +0700 Subject: [PATCH 5/6] apple changes to other tabs --- .../reportFields/WorkspaceReportFieldsPage.tsx | 10 ++++++++-- src/pages/workspace/tags/WorkspaceTagsPage.tsx | 8 ++++++-- src/pages/workspace/taxes/WorkspaceTaxesPage.tsx | 10 ++++++++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/pages/workspace/reportFields/WorkspaceReportFieldsPage.tsx b/src/pages/workspace/reportFields/WorkspaceReportFieldsPage.tsx index 603e610b6f5d..994f0c308d54 100644 --- a/src/pages/workspace/reportFields/WorkspaceReportFieldsPage.tsx +++ b/src/pages/workspace/reportFields/WorkspaceReportFieldsPage.tsx @@ -3,6 +3,7 @@ import type {StackScreenProps} from '@react-navigation/stack'; import {Str} from 'expensify-common'; import React, {useCallback, useEffect, useMemo, useState} from 'react'; import {ActivityIndicator, View} from 'react-native'; +import {useOnyx} from 'react-native-onyx'; import Button from '@components/Button'; import ButtonWithDropdownMenu from '@components/ButtonWithDropdownMenu'; import type {DropdownOption} from '@components/ButtonWithDropdownMenu/types'; @@ -29,6 +30,7 @@ import usePolicy from '@hooks/usePolicy'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; +import {isConnectionInProgress} from '@libs/actions/connections'; import {turnOffMobileSelectionMode} from '@libs/actions/MobileSelectionMode'; import * as DeviceCapabilities from '@libs/DeviceCapabilities'; import localeCompare from '@libs/LocaleCompare'; @@ -40,6 +42,7 @@ import * as WorkspaceReportFieldUtils from '@libs/WorkspaceReportFieldUtils'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; import * as ReportField from '@userActions/Policy/ReportField'; import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import type {PolicyReportField} from '@src/types/onyx/Policy'; @@ -76,8 +79,11 @@ function WorkspaceReportFieldsPage({ const [selectedReportFields, setSelectedReportFields] = useState([]); const [deleteReportFieldsConfirmModalVisible, setDeleteReportFieldsConfirmModalVisible] = useState(false); const hasAccountingConnections = PolicyUtils.hasAccountingConnections(policy); + const [connectionSyncProgress] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${policy?.id}`); + const isSyncInProgress = isConnectionInProgress(connectionSyncProgress, policy); + const hasSyncError = PolicyUtils.hasSyncError(policy, isSyncInProgress); const isConnectedToAccounting = Object.keys(policy?.connections ?? {}).length > 0; - const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy); + const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy, true); const canSelectMultiple = !hasAccountingConnections && (isSmallScreenWidth ? selectionMode?.isEnabled : true); @@ -220,7 +226,7 @@ function WorkspaceReportFieldsPage({ const getHeaderText = () => ( - {isConnectedToAccounting ? ( + {!hasSyncError && isConnectedToAccounting ? ( {`${translate('workspace.reportFields.importedFromAccountingSoftware')} `} 0; - const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy); + const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy, true); const [policyTagLists, isMultiLevelTags] = useMemo(() => [PolicyUtils.getTagLists(policyTags), PolicyUtils.isMultiLevelTags(policyTags)], [policyTags]); const canSelectMultiple = !isMultiLevelTags && (shouldUseNarrowLayout ? selectionMode?.isEnabled : true); @@ -332,7 +336,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) { const getHeaderText = () => ( - {isConnectedToAccounting ? ( + {!hasSyncError && isConnectedToAccounting ? ( {`${translate('workspace.tags.importedFromAccountingSoftware')} `} 0; - const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy); + const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy, true); const canSelectMultiple = shouldUseNarrowLayout ? selectionMode?.isEnabled : true; const fetchTaxes = useCallback(() => { @@ -251,7 +257,7 @@ function WorkspaceTaxesPage({ const getHeaderText = () => ( - {isConnectedToAccounting ? ( + {!hasSyncError && isConnectedToAccounting ? ( {`${translate('workspace.taxes.importedFromAccountingSoftware')} `} Date: Wed, 16 Oct 2024 10:18:15 +0700 Subject: [PATCH 6/6] revert: unsupported connection name --- src/CONST.ts | 5 ----- src/libs/PolicyUtils.ts | 11 ++++------- .../workspace/categories/WorkspaceCategoriesPage.tsx | 2 +- .../reportFields/WorkspaceReportFieldsPage.tsx | 2 +- src/pages/workspace/tags/WorkspaceTagsPage.tsx | 2 +- src/pages/workspace/taxes/WorkspaceTaxesPage.tsx | 2 +- 6 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index cf0a21bb75b4..17cc92998fc1 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -2435,11 +2435,6 @@ const CONST = { }, SYNC_STAGE_TIMEOUT_MINUTES: 20, }, - UNSUPPORTED_CONNECTIONS: { - NAME: { - QBO: 'quickbooksDesktop', - }, - }, ACCESS_VARIANTS: { PAID: 'paid', ADMIN: 'admin', diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 673726300a60..6a1a61afa05d 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -985,13 +985,10 @@ function hasUnsupportedIntegration(policy: Policy | undefined, accountingIntegra return !(accountingIntegrations ?? Object.values(CONST.POLICY.CONNECTIONS.NAME)).some((integration) => !!policy?.connections?.[integration]); } -function getCurrentConnectionName(policy: Policy | undefined, includeUnsupportedConnection = false): string | undefined { - const accountingIntegrations: string[] = [...Object.values(CONST.POLICY.CONNECTIONS.NAME)]; - if (includeUnsupportedConnection) { - accountingIntegrations.push(...Object.values(CONST.POLICY.UNSUPPORTED_CONNECTIONS.NAME)); - } - const connectionKey = accountingIntegrations.find((integration) => policy?.connections && integration in policy.connections); - return connectionKey ? CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY[connectionKey as keyof typeof CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY] : undefined; +function getCurrentConnectionName(policy: Policy | undefined): string | undefined { + const accountingIntegrations = Object.values(CONST.POLICY.CONNECTIONS.NAME); + const connectionKey = accountingIntegrations.find((integration) => !!policy?.connections?.[integration]); + return connectionKey ? CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY[connectionKey] : undefined; } /** diff --git a/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx b/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx index 01103870c28f..366f30d2fd73 100644 --- a/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx +++ b/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx @@ -78,7 +78,7 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) { const isSyncInProgress = isConnectionInProgress(connectionSyncProgress, policy); const hasSyncError = PolicyUtils.hasSyncError(policy, isSyncInProgress); const isConnectedToAccounting = Object.keys(policy?.connections ?? {}).length > 0; - const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy, true); + const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy); const canSelectMultiple = shouldUseNarrowLayout ? selectionMode?.isEnabled : true; diff --git a/src/pages/workspace/reportFields/WorkspaceReportFieldsPage.tsx b/src/pages/workspace/reportFields/WorkspaceReportFieldsPage.tsx index 994f0c308d54..730b5010a221 100644 --- a/src/pages/workspace/reportFields/WorkspaceReportFieldsPage.tsx +++ b/src/pages/workspace/reportFields/WorkspaceReportFieldsPage.tsx @@ -83,7 +83,7 @@ function WorkspaceReportFieldsPage({ const isSyncInProgress = isConnectionInProgress(connectionSyncProgress, policy); const hasSyncError = PolicyUtils.hasSyncError(policy, isSyncInProgress); const isConnectedToAccounting = Object.keys(policy?.connections ?? {}).length > 0; - const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy, true); + const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy); const canSelectMultiple = !hasAccountingConnections && (isSmallScreenWidth ? selectionMode?.isEnabled : true); diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index 5fb7d93990ea..4369004b7a28 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -71,7 +71,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) { const isSyncInProgress = isConnectionInProgress(connectionSyncProgress, policy); const hasSyncError = PolicyUtils.hasSyncError(policy, isSyncInProgress); const isConnectedToAccounting = Object.keys(policy?.connections ?? {}).length > 0; - const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy, true); + const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy); const [policyTagLists, isMultiLevelTags] = useMemo(() => [PolicyUtils.getTagLists(policyTags), PolicyUtils.isMultiLevelTags(policyTags)], [policyTags]); const canSelectMultiple = !isMultiLevelTags && (shouldUseNarrowLayout ? selectionMode?.isEnabled : true); diff --git a/src/pages/workspace/taxes/WorkspaceTaxesPage.tsx b/src/pages/workspace/taxes/WorkspaceTaxesPage.tsx index 761d9cb5b9f0..44919dd09324 100644 --- a/src/pages/workspace/taxes/WorkspaceTaxesPage.tsx +++ b/src/pages/workspace/taxes/WorkspaceTaxesPage.tsx @@ -67,7 +67,7 @@ function WorkspaceTaxesPage({ const hasSyncError = PolicyUtils.hasSyncError(policy, isSyncInProgress); const isConnectedToAccounting = Object.keys(policy?.connections ?? {}).length > 0; - const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy, true); + const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy); const canSelectMultiple = shouldUseNarrowLayout ? selectionMode?.isEnabled : true; const fetchTaxes = useCallback(() => {