From 3ff4201b649afb228dfcc6d1be5cb082a3988f1f Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Wed, 7 Aug 2024 16:35:09 +0200 Subject: [PATCH 1/4] fix: hide Card reconciliation for beta --- .../accounting/PolicyAccountingPage.tsx | 101 +++++++++--------- 1 file changed, 52 insertions(+), 49 deletions(-) diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index ea99f3c46b5f..c35e9e689c91 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -25,6 +25,7 @@ import ThreeDotsMenu from '@components/ThreeDotsMenu'; import type ThreeDotsMenuProps from '@components/ThreeDotsMenu/types'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; +import usePermissions from '@hooks/usePermissions'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; @@ -82,6 +83,7 @@ type AccountingIntegration = { pendingFields?: PendingFields; errorFields?: ErrorFields; }; + function accountingIntegrationData( connectionName: PolicyConnectionName, policyID: string, @@ -214,6 +216,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { const [isDisconnectModalOpen, setIsDisconnectModalOpen] = useState(false); const [datetimeToRelative, setDateTimeToRelative] = useState(''); const threeDotsMenuContainerRef = useRef(null); + const {canUseWorkspaceFeeds} = usePermissions(); const lastSyncProgressDate = parseISO(connectionSyncProgress?.timestamp ?? ''); const isSyncInProgress = @@ -350,6 +353,53 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { 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} : {}; + + const configurationOptions = [ + { + icon: Expensicons.Pencil, + iconRight: Expensicons.ArrowRight, + shouldShowRightIcon: true, + title: translate('workspace.accounting.import'), + wrapperStyle: [styles.sectionMenuItemTopDescription], + onPress: integrationData?.onImportPagePress, + brickRoadIndicator: areSettingsInErrorFields(integrationData?.subscribedImportSettings, integrationData?.errorFields) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined, + pendingAction: settingsPendingAction(integrationData?.subscribedImportSettings, integrationData?.pendingFields), + }, + { + icon: Expensicons.Send, + iconRight: Expensicons.ArrowRight, + shouldShowRightIcon: true, + title: translate('workspace.accounting.export'), + wrapperStyle: [styles.sectionMenuItemTopDescription], + onPress: integrationData?.onExportPagePress, + brickRoadIndicator: areSettingsInErrorFields(integrationData?.subscribedExportSettings, integrationData?.errorFields) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined, + pendingAction: settingsPendingAction(integrationData?.subscribedExportSettings, integrationData?.pendingFields), + }, + { + icon: Expensicons.ExpensifyCard, + iconRight: Expensicons.ArrowRight, + shouldShowRightIcon: true, + title: translate('workspace.accounting.cardReconciliation'), + wrapperStyle: [styles.sectionMenuItemTopDescription], + onPress: integrationData?.onCardReconciliationPagePress, + }, + { + icon: Expensicons.Gear, + iconRight: Expensicons.ArrowRight, + shouldShowRightIcon: true, + title: translate('workspace.accounting.advanced'), + wrapperStyle: [styles.sectionMenuItemTopDescription], + onPress: integrationData?.onAdvancedPagePress, + brickRoadIndicator: areSettingsInErrorFields(integrationData?.subscribedAdvancedSettings, integrationData?.errorFields) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined, + pendingAction: settingsPendingAction(integrationData?.subscribedAdvancedSettings, integrationData?.pendingFields), + }, + ]; + + // TODO: remove after this beta feature is released + if (!canUseWorkspaceFeeds) { + configurationOptions.splice(2, 1); + } + return [ { ...iconProps, @@ -387,55 +437,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { ), }, ...(isEmptyObject(integrationSpecificMenuItems) || shouldShowSynchronizationError || isEmptyObject(policy?.connections) ? [] : [integrationSpecificMenuItems]), - ...(isEmptyObject(policy?.connections) || shouldHideConfigurationOptions - ? [] - : [ - { - icon: Expensicons.Pencil, - iconRight: Expensicons.ArrowRight, - shouldShowRightIcon: true, - title: translate('workspace.accounting.import'), - wrapperStyle: [styles.sectionMenuItemTopDescription], - onPress: integrationData?.onImportPagePress, - brickRoadIndicator: areSettingsInErrorFields(integrationData?.subscribedImportSettings, integrationData?.errorFields) - ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR - : undefined, - pendingAction: settingsPendingAction(integrationData?.subscribedImportSettings, integrationData?.pendingFields), - }, - { - icon: Expensicons.Send, - iconRight: Expensicons.ArrowRight, - shouldShowRightIcon: true, - title: translate('workspace.accounting.export'), - wrapperStyle: [styles.sectionMenuItemTopDescription], - onPress: integrationData?.onExportPagePress, - brickRoadIndicator: areSettingsInErrorFields(integrationData?.subscribedExportSettings, integrationData?.errorFields) - ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR - : undefined, - pendingAction: settingsPendingAction(integrationData?.subscribedExportSettings, integrationData?.pendingFields), - }, - { - icon: Expensicons.ExpensifyCard, - iconRight: Expensicons.ArrowRight, - shouldShowRightIcon: true, - title: translate('workspace.accounting.cardReconciliation'), - wrapperStyle: [styles.sectionMenuItemTopDescription], - onPress: integrationData?.onCardReconciliationPagePress, - }, - - { - icon: Expensicons.Gear, - iconRight: Expensicons.ArrowRight, - shouldShowRightIcon: true, - title: translate('workspace.accounting.advanced'), - wrapperStyle: [styles.sectionMenuItemTopDescription], - onPress: integrationData?.onAdvancedPagePress, - brickRoadIndicator: areSettingsInErrorFields(integrationData?.subscribedAdvancedSettings, integrationData?.errorFields) - ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR - : undefined, - pendingAction: settingsPendingAction(integrationData?.subscribedAdvancedSettings, integrationData?.pendingFields), - }, - ]), + ...(isEmptyObject(policy?.connections) || shouldHideConfigurationOptions ? [] : configurationOptions), ]; }, [ policy, @@ -447,6 +449,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { styles.pb0, styles.mt5, styles.popoverMenuIcon, + canUseWorkspaceFeeds, connectionSyncProgress?.stageInProgress, datetimeToRelative, theme.spinner, From 36994e29437b0b5fc2fa407a58346d3a890dbf80 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Wed, 7 Aug 2024 16:51:43 +0200 Subject: [PATCH 2/4] fix: do not show the link when reconciliation is not enabled --- src/ROUTES.ts | 2 +- .../WorkspaceSettlementAccountPage.tsx | 15 ++++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 8e69e06a3105..220033b81234 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -714,7 +714,7 @@ const ROUTES = { }, WORKSPACE_ACCOUNTING_RECONCILIATION_ACCOUNT_SETTINGS: { route: 'settings/workspaces/:policyID/accounting/:connection/card-reconciliation/account', - getRoute: (policyID: string, connection: ValueOf) => + getRoute: (policyID: string, connection?: ValueOf) => `settings/workspaces/${policyID}/accounting/${connection}/card-reconciliation/account` as const, }, WORKSPACE_CATEGORIES: { diff --git a/src/pages/workspace/expensifyCard/WorkspaceSettlementAccountPage.tsx b/src/pages/workspace/expensifyCard/WorkspaceSettlementAccountPage.tsx index 12eecbb0b0ed..785297aecb45 100644 --- a/src/pages/workspace/expensifyCard/WorkspaceSettlementAccountPage.tsx +++ b/src/pages/workspace/expensifyCard/WorkspaceSettlementAccountPage.tsx @@ -13,8 +13,8 @@ import Text from '@components/Text'; import TextLink from '@components/TextLink'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; -// import * as CardUtils from '@libs/CardUtils'; import {getLastFourDigits} from '@libs/BankAccountUtils'; +import * as CardUtils from '@libs/CardUtils'; import Navigation from '@navigation/Navigation'; import type {SettingsNavigatorParamList} from '@navigation/types'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; @@ -33,20 +33,13 @@ function WorkspaceSettlementAccountPage({route}: WorkspaceSettlementAccountPageP const policyID = route.params?.policyID ?? '-1'; const [bankAccountsList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST); const [cardSettings] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policyID}`); - // TODO: uncomment after integration with the BE - // const [isUsedContinuousReconciliation] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION}${policyID}`); - // const [reconciliationConnection] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_EXPENSIFY_CARD_CONTINUOUS_RECONCILIATION_CONNECTION}${policyID}`); - - // TODO: remove after integration with the BE - const isUsedContinuousReconciliation = true; - const reconciliationConnection = CONST.POLICY.CONNECTIONS.NAME.QBO; + const [isUsedContinuousReconciliation] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION}${policyID}`); + const [reconciliationConnection] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_EXPENSIFY_CARD_CONTINUOUS_RECONCILIATION_CONNECTION}${policyID}`); const paymentBankAccountID = cardSettings?.paymentBankAccountID ?? ''; const paymentBankAccountNumber = bankAccountsList?.[paymentBankAccountID]?.accountData?.accountNumber ?? ''; - // TODO: for now not filtering the accounts for easier testing - // const eligibleBankAccounts = CardUtils.getEligibleBankAccountsForCard(bankAccountsList ?? {}); - const eligibleBankAccounts = Object.values(bankAccountsList ?? {}); + const eligibleBankAccounts = CardUtils.getEligibleBankAccountsForCard(bankAccountsList ?? {}); const data = useMemo(() => { const options = eligibleBankAccounts.map((bankAccount) => { From 08ffbd5596319919f2945987daf4c9c2ef0494c9 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Wed, 7 Aug 2024 17:16:33 +0200 Subject: [PATCH 3/4] fix: remove unnecessary comment --- src/pages/workspace/accounting/PolicyAccountingPage.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index c35e9e689c91..4bde1662f9be 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -395,7 +395,6 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { }, ]; - // TODO: remove after this beta feature is released if (!canUseWorkspaceFeeds) { configurationOptions.splice(2, 1); } From 0469cd048cbc6e678978bffac25aea6b6ea42f22 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Wed, 7 Aug 2024 18:00:00 +0200 Subject: [PATCH 4/4] fix: hide cardReconciliation button when cards not enabled --- src/pages/workspace/accounting/PolicyAccountingPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index 4bde1662f9be..6174561f2c89 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -395,7 +395,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { }, ]; - if (!canUseWorkspaceFeeds) { + if (!canUseWorkspaceFeeds || !policy?.areExpensifyCardsEnabled) { configurationOptions.splice(2, 1); }