diff --git a/src/ROUTES.ts b/src/ROUTES.ts index cca81f999da4..c3110273dc87 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -707,7 +707,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/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index ea99f3c46b5f..6174561f2c89 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,52 @@ 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), + }, + ]; + + if (!canUseWorkspaceFeeds || !policy?.areExpensifyCardsEnabled) { + configurationOptions.splice(2, 1); + } + return [ { ...iconProps, @@ -387,55 +436,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 +448,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { styles.pb0, styles.mt5, styles.popoverMenuIcon, + canUseWorkspaceFeeds, connectionSyncProgress?.stageInProgress, datetimeToRelative, theme.spinner, 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) => {