From 38c538b310ce71499911b77133bebcc0902063b8 Mon Sep 17 00:00:00 2001 From: Nicolay Arefyeu Date: Tue, 31 Dec 2024 16:37:20 +0200 Subject: [PATCH] add logic for check not available account options for company cards --- .../accounting/intacct/export/SageIntacctExportPage.tsx | 4 ++-- .../netsuite/export/NetSuiteExportConfigurationPage.tsx | 7 ++++++- .../qbo/export/QuickbooksExportConfigurationPage.tsx | 4 +++- .../accounting/xero/export/XeroExportConfigurationPage.tsx | 3 ++- src/pages/workspace/companyCards/utils.tsx | 4 ++-- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/pages/workspace/accounting/intacct/export/SageIntacctExportPage.tsx b/src/pages/workspace/accounting/intacct/export/SageIntacctExportPage.tsx index b9fad924a974..9384cf785e9c 100644 --- a/src/pages/workspace/accounting/intacct/export/SageIntacctExportPage.tsx +++ b/src/pages/workspace/accounting/intacct/export/SageIntacctExportPage.tsx @@ -23,6 +23,7 @@ function SageIntacctExportPage({policy}: WithPolicyProps) { const route = useRoute>(); const backTo = route?.params?.backTo; const {export: exportConfig, pendingFields, errorFields} = policy?.connections?.intacct?.config ?? {}; + const isConnectionShouldBeRemovedFromCompanyCard = exportConfig?.reimbursable === CONST.SAGE_INTACCT_REIMBURSABLE_EXPENSE_TYPE.EXPENSE_REPORT && backTo; const sections = useMemo( () => [ @@ -72,8 +73,7 @@ function SageIntacctExportPage({policy}: WithPolicyProps) { title="workspace.sageIntacct.exportDescription" accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.PAID]} policyID={policyID} - // TODO here we should check - if export account is not supported by company card - we will navigate to card details page instead of go back - onBackButtonPress={!backTo ? undefined : () => Navigation.navigate(backTo)} + onBackButtonPress={isConnectionShouldBeRemovedFromCompanyCard ? () => Navigation.navigate(backTo) : undefined} featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED} contentContainerStyle={styles.pb2} titleStyle={styles.ph5} diff --git a/src/pages/workspace/accounting/netsuite/export/NetSuiteExportConfigurationPage.tsx b/src/pages/workspace/accounting/netsuite/export/NetSuiteExportConfigurationPage.tsx index 56b35d51380a..1535c713db60 100644 --- a/src/pages/workspace/accounting/netsuite/export/NetSuiteExportConfigurationPage.tsx +++ b/src/pages/workspace/accounting/netsuite/export/NetSuiteExportConfigurationPage.tsx @@ -50,6 +50,11 @@ function NetSuiteExportConfigurationPage({policy}: WithPolicyConnectionsProps) { const {canUseNetSuiteUSATax} = usePermissions(); const config = policy?.connections?.netsuite?.options.config; + const isConnectionShouldBeRemovedFromCompanyCard = + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + (config?.reimbursableExpensesExportDestination === CONST.NETSUITE_EXPORT_DESTINATION.EXPENSE_REPORT || + config?.nonreimbursableExpensesExportDestination === CONST.NETSUITE_EXPORT_DESTINATION.EXPENSE_REPORT) && + backTo; const {subsidiaryList, receivableList, taxAccountsList, items} = policy?.connections?.netsuite?.options?.data ?? {}; const selectedSubsidiary = useMemo(() => (subsidiaryList ?? []).find((subsidiary) => subsidiary.internalID === config?.subsidiaryID), [subsidiaryList, config?.subsidiaryID]); @@ -200,7 +205,7 @@ function NetSuiteExportConfigurationPage({policy}: WithPolicyConnectionsProps) { title="workspace.netsuite.exportDescription" accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN]} policyID={policyID} - onBackButtonPress={!backTo ? undefined : () => Navigation.navigate(backTo)} + onBackButtonPress={isConnectionShouldBeRemovedFromCompanyCard ? () => Navigation.navigate(backTo) : undefined} featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED} contentContainerStyle={styles.pb2} titleStyle={styles.ph5} diff --git a/src/pages/workspace/accounting/qbo/export/QuickbooksExportConfigurationPage.tsx b/src/pages/workspace/accounting/qbo/export/QuickbooksExportConfigurationPage.tsx index 23d95b6d9194..dcfce5d70b95 100644 --- a/src/pages/workspace/accounting/qbo/export/QuickbooksExportConfigurationPage.tsx +++ b/src/pages/workspace/accounting/qbo/export/QuickbooksExportConfigurationPage.tsx @@ -32,6 +32,8 @@ function QuickbooksExportConfigurationPage({policy}: WithPolicyConnectionsProps) () => qboConfig?.nonReimbursableExpensesExportDestination === CONST.QUICKBOOKS_NON_REIMBURSABLE_EXPORT_ACCOUNT_TYPE.VENDOR_BILL, [qboConfig?.nonReimbursableExpensesExportDestination], ); + const isConnectionShouldBeRemovedFromCompanyCard = shouldShowVendorMenuItems && backTo; + const menuItems = [ { description: translate('workspace.accounting.preferredExporter'), @@ -84,7 +86,7 @@ function QuickbooksExportConfigurationPage({policy}: WithPolicyConnectionsProps) title="workspace.qbo.exportDescription" accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN]} policyID={policyID} - onBackButtonPress={!backTo ? undefined : () => Navigation.navigate(backTo)} + onBackButtonPress={isConnectionShouldBeRemovedFromCompanyCard ? () => Navigation.navigate(backTo) : undefined} featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED} contentContainerStyle={styles.pb2} titleStyle={styles.ph5} diff --git a/src/pages/workspace/accounting/xero/export/XeroExportConfigurationPage.tsx b/src/pages/workspace/accounting/xero/export/XeroExportConfigurationPage.tsx index 3d47de23aba6..69b6375f2856 100644 --- a/src/pages/workspace/accounting/xero/export/XeroExportConfigurationPage.tsx +++ b/src/pages/workspace/accounting/xero/export/XeroExportConfigurationPage.tsx @@ -25,6 +25,7 @@ function XeroExportConfigurationPage({policy}: WithPolicyConnectionsProps) { const policyOwner = policy?.owner ?? ''; const {export: exportConfiguration, errorFields, pendingFields} = policy?.connections?.xero?.config ?? {}; + const isConnectionShouldBeRemovedFromCompanyCard = !exportConfiguration?.nonReimbursableAccount && backTo; const {bankAccounts} = policy?.connections?.xero?.data ?? {}; const selectedBankAccountName = useMemo(() => { @@ -94,7 +95,7 @@ function XeroExportConfigurationPage({policy}: WithPolicyConnectionsProps) { title="workspace.xero.exportDescription" accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN]} policyID={policyID} - onBackButtonPress={!backTo ? undefined : () => Navigation.navigate(backTo)} + onBackButtonPress={isConnectionShouldBeRemovedFromCompanyCard ? () => Navigation.navigate(backTo) : undefined} featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED} contentContainerStyle={styles.pb2} titleStyle={styles.ph5} diff --git a/src/pages/workspace/companyCards/utils.tsx b/src/pages/workspace/companyCards/utils.tsx index c7abf0fab037..f0c2305f1d3b 100644 --- a/src/pages/workspace/companyCards/utils.tsx +++ b/src/pages/workspace/companyCards/utils.tsx @@ -115,7 +115,7 @@ function getExportMenuItem( return { description, exportType, - shouldShowMenuItem: true, + shouldShowMenuItem: !!exportConfiguration?.nonReimbursableAccount, title: isDefaultTitle ? defaultCard : selectedAccount?.name, onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_XERO_EXPORT.getRoute(policyID, backTo)), data: (resultData ?? []).map((card) => { @@ -274,7 +274,7 @@ function getExportMenuItem( shouldShowMenuItem, exportType, title, - onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_EXPORT.getRoute(policyID, backTo)), + onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_EXPORT.getRoute(policyID, backTo)), data, }; }