From 44d74b0123cbeeaf6c6a7640bece45a03c1181d6 Mon Sep 17 00:00:00 2001 From: Nicolay Arefyeu Date: Thu, 14 Nov 2024 16:50:09 +0200 Subject: [PATCH 1/9] Add Default Card view - if something pre-selected in Export Account flow --- src/CONST.ts | 1 + src/libs/PolicyUtils.ts | 39 +++-- src/pages/workspace/companyCards/utils.tsx | 172 +++++++++++++++++---- 3 files changed, 166 insertions(+), 46 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 4b2b66ab5a2d..22b62263b824 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -2811,6 +2811,7 @@ const CONST = { ALLOW: 'personal', }, CARD_LIST_THRESHOLD: 8, + EXPORT_DEFAULT_CARD: 'Default Card', EXPORT_CARD_TYPES: { /** * Name of Card NVP for QBO custom export accounts diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 4592500e9250..6e876f762516 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -12,22 +12,23 @@ import type {OnyxInputOrEntry, Policy, PolicyCategories, PolicyEmployeeList, Pol import type {CardFeedData} from '@src/types/onyx/CardFeeds'; import type {ErrorFields, PendingAction, PendingFields} from '@src/types/onyx/OnyxCommon'; import type { - ConnectionLastSync, - ConnectionName, - Connections, - CustomUnit, - InvoiceItem, - NetSuiteAccount, - NetSuiteConnection, - NetSuiteCustomList, - NetSuiteCustomSegment, - NetSuiteTaxAccount, - NetSuiteVendor, - PolicyConnectionSyncProgress, - PolicyFeatureName, - Rate, - Tenant, -} from '@src/types/onyx/Policy'; + ConnectionLastSync, + ConnectionName, + Connections, + CustomUnit, + InvoiceItem, + NetSuiteAccount, + NetSuiteConnection, + NetSuiteCustomList, + NetSuiteCustomSegment, + NetSuiteTaxAccount, + NetSuiteVendor, + PolicyConnectionSyncProgress, + PolicyFeatureName, + Rate, SageIntacctDataElement, + SageIntacctDataElementWithValue, + Tenant +} from "@src/types/onyx/Policy"; import type PolicyEmployee from '@src/types/onyx/PolicyEmployee'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import {hasSynchronizationErrorMessage} from './actions/connections'; @@ -710,6 +711,11 @@ function findSelectedVendorWithDefaultSelect(vendors: NetSuiteVendor[] | undefin return selectedVendor ?? vendors?.[0] ?? undefined; } +function findSelectedSageVendorWithDefaultSelect(vendors: SageIntacctDataElementWithValue[] | SageIntacctDataElement[] | undefined, selectedVendorId: string | undefined) { + const selectedVendor = (vendors ?? []).find(({id}) => id === selectedVendorId); + return selectedVendor ?? vendors?.[0] ?? undefined; +} + function findSelectedBankAccountWithDefaultSelect(accounts: NetSuiteAccount[] | undefined, selectedBankAccountId: string | undefined) { const selectedBankAccount = (accounts ?? []).find(({id}) => id === selectedBankAccountId); return selectedBankAccount ?? accounts?.[0] ?? undefined; @@ -1176,6 +1182,7 @@ export { findSelectedBankAccountWithDefaultSelect, findSelectedInvoiceItemWithDefaultSelect, findSelectedTaxAccountWithDefaultSelect, + findSelectedSageVendorWithDefaultSelect, getNetSuiteVendorOptions, canUseTaxNetSuite, canUseProvincialTaxNetSuite, diff --git a/src/pages/workspace/companyCards/utils.tsx b/src/pages/workspace/companyCards/utils.tsx index 38189ebac525..0da76866688a 100644 --- a/src/pages/workspace/companyCards/utils.tsx +++ b/src/pages/workspace/companyCards/utils.tsx @@ -2,14 +2,6 @@ import type {ValueOf} from 'type-fest'; import type {LocaleContextProps} from '@components/LocaleContextProvider'; import type {SelectorType} from '@components/SelectionScreen'; import * as PolicyUtils from '@libs/PolicyUtils'; -import { - getNetSuitePayableAccountOptions, - getNetSuiteVendorOptions, - getSageIntacctCreditCards, - getSageIntacctNonReimbursableActiveDefaultVendor, - getSageIntacctVendors, - getXeroBankAccounts, -} from '@libs/PolicyUtils'; import Navigation from '@navigation/Navigation'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; @@ -48,16 +40,29 @@ function getExportMenuItem( let data: Account[]; let shouldShowMenuItem = true; let title: string | undefined = ''; + let selectedAccount: string | undefined = ''; + const defaultAccount = nonReimbursableExpensesAccount?.name; + let isDefaultTitle = false; let exportType: ValueOf | undefined; switch (nonReimbursableExpensesExportDestination) { case CONST.QUICKBOOKS_NON_REIMBURSABLE_EXPORT_ACCOUNT_TYPE.CREDIT_CARD: data = creditCards ?? []; - title = companyCard?.nameValuePairs?.quickbooks_desktop_export_account_credit ?? nonReimbursableExpensesAccount?.name; - exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_QUICKBOOKS_DESKTOP_EXPORT_ACCOUNT_CREDIT; + isDefaultTitle = !!( + (defaultAccount && companyCard?.nameValuePairs?.quickbooks_online_export_account === defaultAccount) || + (!companyCard?.nameValuePairs?.quickbooks_online_export_account && defaultAccount) + ); + title = isDefaultTitle ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : companyCard?.nameValuePairs?.quickbooks_online_export_account; + selectedAccount = companyCard?.nameValuePairs?.quickbooks_online_export_account ?? defaultAccount; + exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_QUICKBOOKS_ONLINE_EXPORT_ACCOUNT; break; case CONST.QUICKBOOKS_NON_REIMBURSABLE_EXPORT_ACCOUNT_TYPE.DEBIT_CARD: data = quickbooksOnlineBankAccounts ?? []; - title = companyCard?.nameValuePairs?.quickbooks_online_export_account_debit ?? nonReimbursableExpensesAccount?.name; + isDefaultTitle = !!( + (defaultAccount && companyCard?.nameValuePairs?.quickbooks_online_export_account_debit === defaultAccount) || + (!companyCard?.nameValuePairs?.quickbooks_online_export_account_debit && defaultAccount) + ); + title = isDefaultTitle ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : companyCard?.nameValuePairs?.quickbooks_online_export_account_debit; + selectedAccount = companyCard?.nameValuePairs?.quickbooks_online_export_account_debit ?? defaultAccount; exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_QUICKBOOKS_ONLINE_EXPORT_ACCOUNT_DEBIT; break; default: @@ -71,26 +76,42 @@ function getExportMenuItem( exportType, shouldShowMenuItem, onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_EXPORT.getRoute(policyID)), - data: data.map((card) => ({ - value: card.name, - text: card.name, - keyForList: card.name, - isSelected: card.name === title, - })), + data: data.map((card) => { + const isDefault = card.name === defaultAccount; + return { + value: card.name, + text: isDefault ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : card.name, + keyForList: card.name, + isSelected: card.name === selectedAccount, + }; + }), }; } case CONST.POLICY.CONNECTIONS.NAME.XERO: { const type = translate('workspace.xero.xeroBankAccount'); const description = currentConnectionName && type ? translate('workspace.moreFeatures.companyCards.integrationExport', {integration: currentConnectionName, type}) : undefined; const exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_XERO_EXPORT_BANK_ACCOUNT; - const selectedAccount = (bankAccounts ?? []).find((bank) => bank.id === exportConfiguration?.nonReimbursableAccount); + const defaultAccount = exportConfiguration?.nonReimbursableAccount; + const isDefaultTitle = !!( + (defaultAccount && companyCard?.nameValuePairs?.xero_export_bank_account === defaultAccount) || + (!companyCard?.nameValuePairs?.xero_export_bank_account && defaultAccount) + ); + const selectedAccount = (bankAccounts ?? []).find((bank) => bank.id === (companyCard?.nameValuePairs?.xero_export_bank_account ?? defaultAccount)); return { description, exportType, shouldShowMenuItem: true, - title: companyCard?.nameValuePairs?.xero_export_bank_account ?? selectedAccount?.name ?? bankAccounts?.[0]?.name ?? '', + title: isDefaultTitle ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : selectedAccount?.name, onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_XERO_EXPORT.getRoute(policyID)), - data: getXeroBankAccounts(policy ?? undefined, exportConfiguration?.nonReimbursableAccount), + data: (bankAccounts ?? []).map((card) => { + const isDefault = card.id === defaultAccount; + return { + value: card.id, + text: isDefault ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : card.name, + keyForList: card.id, + isSelected: selectedAccount?.id === card.id, + }; + }), }; } case CONST.POLICY.CONNECTIONS.NAME.NETSUITE: { @@ -102,14 +123,51 @@ function getExportMenuItem( let shouldShowMenuItem = true; const description = currentConnectionName && type ? translate('workspace.moreFeatures.companyCards.integrationExport', {integration: currentConnectionName, type}) : undefined; let data: SelectorType[]; + let defaultAccount: string | undefined = ''; + let isDefaultTitle = false; + switch (config?.nonreimbursableExpensesExportDestination) { case CONST.NETSUITE_EXPORT_DESTINATION.VENDOR_BILL: - data = getNetSuiteVendorOptions(policy ?? undefined, config?.defaultVendor); - title = companyCard?.nameValuePairs?.netsuite_export_vendor ?? data.find((exportVendor) => exportVendor.isSelected)?.text; + defaultAccount = config?.defaultVendor; + isDefaultTitle = !!( + (defaultAccount && companyCard?.nameValuePairs?.netsuite_export_vendor === defaultAccount) || + (!companyCard?.nameValuePairs?.netsuite_export_vendor && defaultAccount) + ); + const vendors = policy?.connections?.netsuite.options.data.vendors; + const selectedVendor = PolicyUtils.findSelectedVendorWithDefaultSelect(vendors, companyCard?.nameValuePairs?.netsuite_export_vendor ?? defaultAccount); + title = isDefaultTitle ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : selectedVendor?.name; + data = (vendors ?? []).map(({id, name}) => { + const isDefault = id === defaultAccount; + return { + value: id, + text: isDefault ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : name, + keyForList: id, + isSelected: selectedVendor?.id === id, + }; + }); exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_NETSUITE_EXPORT_VENDOR; break; case CONST.NETSUITE_EXPORT_DESTINATION.JOURNAL_ENTRY: - data = getNetSuitePayableAccountOptions(policy ?? undefined, config?.payableAcct); + defaultAccount = config?.payableAcct; + isDefaultTitle = !!( + (defaultAccount && companyCard?.nameValuePairs?.netsuite_export_payable_account === defaultAccount) || + (!companyCard?.nameValuePairs?.netsuite_export_payable_account && defaultAccount) + ); + const payableAccounts = policy?.connections?.netsuite.options.data.payableList; + const selectedPayableAccount = PolicyUtils.findSelectedBankAccountWithDefaultSelect( + payableAccounts, + companyCard?.nameValuePairs?.netsuite_export_payable_account ?? defaultAccount, + ); + title = isDefaultTitle ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : selectedPayableAccount?.name; + data = (payableAccounts ?? []).map(({id, name}) => { + const isDefault = id === defaultAccount; + return { + value: id, + text: isDefault ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : name, + keyForList: id, + isSelected: selectedPayableAccount?.id === id, + }; + }); title = companyCard?.nameValuePairs?.netsuite_export_payable_account ?? data.find((exportPayable) => exportPayable.isSelected)?.text; exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_NETSUITE_EXPORT_ACCOUNT; break; @@ -127,18 +185,72 @@ function getExportMenuItem( }; } case CONST.POLICY.CONNECTIONS.NAME.SAGE_INTACCT: { - const isVendor = exportConfig?.nonReimbursable === CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE.VENDOR_BILL; const type = exportConfig?.nonReimbursable ? translate(`workspace.sageIntacct.nonReimbursableExpenses.values.${exportConfig.nonReimbursable}`) : undefined; const description = currentConnectionName && type ? translate('workspace.moreFeatures.companyCards.integrationExport', {integration: currentConnectionName, type}) : undefined; - const activeDefaultVendor = getSageIntacctNonReimbursableActiveDefaultVendor(policy); - const data = isVendor ? getSageIntacctVendors(policy, activeDefaultVendor) : getSageIntacctCreditCards(policy, exportConfig?.nonReimbursableAccount); - const selectedAccount = data.find((account) => account.isSelected)?.text; + let exportType: ValueOf | undefined; + let title: string | undefined = ''; + let isDefaultTitle = false; + + let shouldShowMenuItem = true; + let data: SelectorType[]; + + switch (exportConfig?.nonReimbursable) { + case CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE.VENDOR_BILL: { + const defaultAccount = PolicyUtils.getSageIntacctNonReimbursableActiveDefaultVendor(policy); + isDefaultTitle = !!( + (defaultAccount && companyCard?.nameValuePairs?.netsuite_export_payable_account === defaultAccount) || + (!companyCard?.nameValuePairs?.netsuite_export_payable_account && defaultAccount) + ); + const vendors = policy?.connections?.intacct?.data?.vendors ?? []; + const selectedVendor = PolicyUtils.findSelectedSageVendorWithDefaultSelect(vendors, companyCard?.nameValuePairs?.netsuite_export_payable_account ?? defaultAccount); + title = isDefaultTitle ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : selectedVendor?.name; + + data = (vendors ?? []).map(({id, name}) => { + const isDefault = id === defaultAccount; + return { + value: id, + text: isDefault ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : name, + keyForList: id, + isSelected: selectedVendor?.id === id, + }; + }); + exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_INTACCT_EXPORT_VENDOR; + break; + } + case CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE.CREDIT_CARD_CHARGE: { + const defaultAccount = exportConfig?.nonReimbursableAccount; + + isDefaultTitle = !!( + (defaultAccount && companyCard?.nameValuePairs?.intacct_export_charge_card === defaultAccount) || + (!companyCard?.nameValuePairs?.intacct_export_charge_card && defaultAccount) + ); + const creditCards = policy?.connections?.intacct?.data?.creditCards ?? []; + const selectedCard = PolicyUtils.findSelectedSageVendorWithDefaultSelect(creditCards, companyCard?.nameValuePairs?.intacct_export_charge_card ?? defaultAccount); + title = isDefaultTitle ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : selectedCard?.name; + + data = (creditCards ?? []).map(({id, name}) => { + const isDefault = id === defaultAccount; + return { + value: id, + text: isDefault ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : name, + keyForList: id, + isSelected: selectedCard?.id === id, + }; + }); + exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_INTACCT_EXPORT_CHARGE_CARD; + + break; + } + default: + shouldShowMenuItem = false; + data = []; + } return { description, - shouldShowMenuItem: true, - exportType: isVendor ? CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_INTACCT_EXPORT_VENDOR : CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_INTACCT_EXPORT_CHARGE_CARD, - title: isVendor ? companyCard?.nameValuePairs?.intacct_export_vendor ?? selectedAccount : companyCard?.nameValuePairs?.intacct_export_charge_card ?? selectedAccount, + shouldShowMenuItem, + exportType, + title, onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_EXPORT.getRoute(policyID)), data, }; From af8c107febff4a1e11f64b0a863b329988607cce Mon Sep 17 00:00:00 2001 From: Nicolay Arefyeu Date: Thu, 14 Nov 2024 16:53:03 +0200 Subject: [PATCH 2/9] prettier --- src/libs/PolicyUtils.ts | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 6e876f762516..99e082cb0d9c 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -12,23 +12,24 @@ import type {OnyxInputOrEntry, Policy, PolicyCategories, PolicyEmployeeList, Pol import type {CardFeedData} from '@src/types/onyx/CardFeeds'; import type {ErrorFields, PendingAction, PendingFields} from '@src/types/onyx/OnyxCommon'; import type { - ConnectionLastSync, - ConnectionName, - Connections, - CustomUnit, - InvoiceItem, - NetSuiteAccount, - NetSuiteConnection, - NetSuiteCustomList, - NetSuiteCustomSegment, - NetSuiteTaxAccount, - NetSuiteVendor, - PolicyConnectionSyncProgress, - PolicyFeatureName, - Rate, SageIntacctDataElement, - SageIntacctDataElementWithValue, - Tenant -} from "@src/types/onyx/Policy"; + ConnectionLastSync, + ConnectionName, + Connections, + CustomUnit, + InvoiceItem, + NetSuiteAccount, + NetSuiteConnection, + NetSuiteCustomList, + NetSuiteCustomSegment, + NetSuiteTaxAccount, + NetSuiteVendor, + PolicyConnectionSyncProgress, + PolicyFeatureName, + Rate, + SageIntacctDataElement, + SageIntacctDataElementWithValue, + Tenant, +} from '@src/types/onyx/Policy'; import type PolicyEmployee from '@src/types/onyx/PolicyEmployee'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import {hasSynchronizationErrorMessage} from './actions/connections'; From 84d9d34610fa936f9f3e854bcdac42714b0e5bc6 Mon Sep 17 00:00:00 2001 From: Nicolay Arefyeu Date: Thu, 14 Nov 2024 17:14:30 +0200 Subject: [PATCH 3/9] eslint fixes --- src/pages/workspace/companyCards/utils.tsx | 68 ++++++++++------------ 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/src/pages/workspace/companyCards/utils.tsx b/src/pages/workspace/companyCards/utils.tsx index 0da76866688a..4cc4ce3c544d 100644 --- a/src/pages/workspace/companyCards/utils.tsx +++ b/src/pages/workspace/companyCards/utils.tsx @@ -45,26 +45,26 @@ function getExportMenuItem( let isDefaultTitle = false; let exportType: ValueOf | undefined; switch (nonReimbursableExpensesExportDestination) { - case CONST.QUICKBOOKS_NON_REIMBURSABLE_EXPORT_ACCOUNT_TYPE.CREDIT_CARD: + case CONST.QUICKBOOKS_NON_REIMBURSABLE_EXPORT_ACCOUNT_TYPE.CREDIT_CARD: { data = creditCards ?? []; - isDefaultTitle = !!( - (defaultAccount && companyCard?.nameValuePairs?.quickbooks_online_export_account === defaultAccount) || - (!companyCard?.nameValuePairs?.quickbooks_online_export_account && defaultAccount) - ); + const isDefaultSelected = defaultAccount && companyCard?.nameValuePairs?.quickbooks_online_export_account === defaultAccount; + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + isDefaultTitle = !!(isDefaultSelected || (!companyCard?.nameValuePairs?.quickbooks_online_export_account && defaultAccount)); title = isDefaultTitle ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : companyCard?.nameValuePairs?.quickbooks_online_export_account; selectedAccount = companyCard?.nameValuePairs?.quickbooks_online_export_account ?? defaultAccount; exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_QUICKBOOKS_ONLINE_EXPORT_ACCOUNT; break; - case CONST.QUICKBOOKS_NON_REIMBURSABLE_EXPORT_ACCOUNT_TYPE.DEBIT_CARD: + } + case CONST.QUICKBOOKS_NON_REIMBURSABLE_EXPORT_ACCOUNT_TYPE.DEBIT_CARD: { data = quickbooksOnlineBankAccounts ?? []; - isDefaultTitle = !!( - (defaultAccount && companyCard?.nameValuePairs?.quickbooks_online_export_account_debit === defaultAccount) || - (!companyCard?.nameValuePairs?.quickbooks_online_export_account_debit && defaultAccount) - ); + const isDefaultSelected = defaultAccount && companyCard?.nameValuePairs?.quickbooks_online_export_account_debit === defaultAccount; + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + isDefaultTitle = !!(isDefaultSelected || (!companyCard?.nameValuePairs?.quickbooks_online_export_account_debit && defaultAccount)); title = isDefaultTitle ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : companyCard?.nameValuePairs?.quickbooks_online_export_account_debit; selectedAccount = companyCard?.nameValuePairs?.quickbooks_online_export_account_debit ?? defaultAccount; exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_QUICKBOOKS_ONLINE_EXPORT_ACCOUNT_DEBIT; break; + } default: shouldShowMenuItem = false; data = []; @@ -92,10 +92,9 @@ function getExportMenuItem( const description = currentConnectionName && type ? translate('workspace.moreFeatures.companyCards.integrationExport', {integration: currentConnectionName, type}) : undefined; const exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_XERO_EXPORT_BANK_ACCOUNT; const defaultAccount = exportConfiguration?.nonReimbursableAccount; - const isDefaultTitle = !!( - (defaultAccount && companyCard?.nameValuePairs?.xero_export_bank_account === defaultAccount) || - (!companyCard?.nameValuePairs?.xero_export_bank_account && defaultAccount) - ); + const isDefaultSelected = defaultAccount && companyCard?.nameValuePairs?.xero_export_bank_account === defaultAccount; + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + const isDefaultTitle = !!(isDefaultSelected || (!companyCard?.nameValuePairs?.xero_export_bank_account && defaultAccount)); const selectedAccount = (bankAccounts ?? []).find((bank) => bank.id === (companyCard?.nameValuePairs?.xero_export_bank_account ?? defaultAccount)); return { description, @@ -127,12 +126,11 @@ function getExportMenuItem( let isDefaultTitle = false; switch (config?.nonreimbursableExpensesExportDestination) { - case CONST.NETSUITE_EXPORT_DESTINATION.VENDOR_BILL: + case CONST.NETSUITE_EXPORT_DESTINATION.VENDOR_BILL: { defaultAccount = config?.defaultVendor; - isDefaultTitle = !!( - (defaultAccount && companyCard?.nameValuePairs?.netsuite_export_vendor === defaultAccount) || - (!companyCard?.nameValuePairs?.netsuite_export_vendor && defaultAccount) - ); + const isDefaultSelected = defaultAccount && companyCard?.nameValuePairs?.netsuite_export_vendor === defaultAccount; + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + isDefaultTitle = !!(isDefaultSelected || (!companyCard?.nameValuePairs?.netsuite_export_vendor && defaultAccount)); const vendors = policy?.connections?.netsuite.options.data.vendors; const selectedVendor = PolicyUtils.findSelectedVendorWithDefaultSelect(vendors, companyCard?.nameValuePairs?.netsuite_export_vendor ?? defaultAccount); title = isDefaultTitle ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : selectedVendor?.name; @@ -147,12 +145,12 @@ function getExportMenuItem( }); exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_NETSUITE_EXPORT_VENDOR; break; - case CONST.NETSUITE_EXPORT_DESTINATION.JOURNAL_ENTRY: + } + case CONST.NETSUITE_EXPORT_DESTINATION.JOURNAL_ENTRY: { defaultAccount = config?.payableAcct; - isDefaultTitle = !!( - (defaultAccount && companyCard?.nameValuePairs?.netsuite_export_payable_account === defaultAccount) || - (!companyCard?.nameValuePairs?.netsuite_export_payable_account && defaultAccount) - ); + const isDefaultSelected = defaultAccount && companyCard?.nameValuePairs?.netsuite_export_payable_account === defaultAccount; + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + isDefaultTitle = !!(isDefaultSelected || (!companyCard?.nameValuePairs?.netsuite_export_payable_account && defaultAccount)); const payableAccounts = policy?.connections?.netsuite.options.data.payableList; const selectedPayableAccount = PolicyUtils.findSelectedBankAccountWithDefaultSelect( payableAccounts, @@ -171,6 +169,7 @@ function getExportMenuItem( title = companyCard?.nameValuePairs?.netsuite_export_payable_account ?? data.find((exportPayable) => exportPayable.isSelected)?.text; exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_NETSUITE_EXPORT_ACCOUNT; break; + } default: shouldShowMenuItem = false; data = []; @@ -197,10 +196,9 @@ function getExportMenuItem( switch (exportConfig?.nonReimbursable) { case CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE.VENDOR_BILL: { const defaultAccount = PolicyUtils.getSageIntacctNonReimbursableActiveDefaultVendor(policy); - isDefaultTitle = !!( - (defaultAccount && companyCard?.nameValuePairs?.netsuite_export_payable_account === defaultAccount) || - (!companyCard?.nameValuePairs?.netsuite_export_payable_account && defaultAccount) - ); + const isDefaultSelected = defaultAccount && companyCard?.nameValuePairs?.netsuite_export_payable_account === defaultAccount; + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + isDefaultTitle = !!(isDefaultSelected || (!companyCard?.nameValuePairs?.netsuite_export_payable_account && defaultAccount)); const vendors = policy?.connections?.intacct?.data?.vendors ?? []; const selectedVendor = PolicyUtils.findSelectedSageVendorWithDefaultSelect(vendors, companyCard?.nameValuePairs?.netsuite_export_payable_account ?? defaultAccount); title = isDefaultTitle ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : selectedVendor?.name; @@ -219,16 +217,14 @@ function getExportMenuItem( } case CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE.CREDIT_CARD_CHARGE: { const defaultAccount = exportConfig?.nonReimbursableAccount; - - isDefaultTitle = !!( - (defaultAccount && companyCard?.nameValuePairs?.intacct_export_charge_card === defaultAccount) || - (!companyCard?.nameValuePairs?.intacct_export_charge_card && defaultAccount) - ); - const creditCards = policy?.connections?.intacct?.data?.creditCards ?? []; - const selectedCard = PolicyUtils.findSelectedSageVendorWithDefaultSelect(creditCards, companyCard?.nameValuePairs?.intacct_export_charge_card ?? defaultAccount); + const isDefaultSelected = defaultAccount && companyCard?.nameValuePairs?.intacct_export_charge_card === defaultAccount; + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + isDefaultTitle = !!(isDefaultSelected || (!companyCard?.nameValuePairs?.intacct_export_charge_card && defaultAccount)); + const intacctCreditCards = policy?.connections?.intacct?.data?.creditCards ?? []; + const selectedCard = PolicyUtils.findSelectedSageVendorWithDefaultSelect(intacctCreditCards, companyCard?.nameValuePairs?.intacct_export_charge_card ?? defaultAccount); title = isDefaultTitle ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : selectedCard?.name; - data = (creditCards ?? []).map(({id, name}) => { + data = (intacctCreditCards ?? []).map(({id, name}) => { const isDefault = id === defaultAccount; return { value: id, From ffc6f024c1e285eb307e8e2161ee96120f754537 Mon Sep 17 00:00:00 2001 From: Nicolay Arefyeu Date: Fri, 15 Nov 2024 12:24:44 +0200 Subject: [PATCH 4/9] add translation for default card --- src/CONST.ts | 1 - src/languages/en.ts | 1 + src/languages/es.ts | 1 + src/pages/workspace/companyCards/utils.tsx | 27 +++++++++++----------- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 22b62263b824..4b2b66ab5a2d 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -2811,7 +2811,6 @@ const CONST = { ALLOW: 'personal', }, CARD_LIST_THRESHOLD: 8, - EXPORT_DEFAULT_CARD: 'Default Card', EXPORT_CARD_TYPES: { /** * Name of Card NVP for QBO custom export accounts diff --git a/src/languages/en.ts b/src/languages/en.ts index d13cf61957ea..6f6f56f30839 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -3421,6 +3421,7 @@ const translations = { giveItNameInstruction: 'Give the card a name that sets it apart from the others.', updating: 'Updating...', noAccountsFound: 'No accounts found', + defaultCard: 'Default card', noAccountsFoundDescription: ({connection}: ConnectionParams) => `Please add the account in ${connection} and sync the connection again.`, }, workflows: { diff --git a/src/languages/es.ts b/src/languages/es.ts index d0ca8bc173bd..2617a3555048 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -3465,6 +3465,7 @@ const translations = { giveItNameInstruction: 'Nombra la tarjeta para distingirla de las demás.', updating: 'Actualizando...', noAccountsFound: 'No se han encontrado cuentas', + defaultCard: 'Tarjeta predeterminada', noAccountsFoundDescription: ({connection}: ConnectionParams) => `Añade la cuenta en ${connection} y sincroniza la conexión de nuevo.`, }, workflows: { diff --git a/src/pages/workspace/companyCards/utils.tsx b/src/pages/workspace/companyCards/utils.tsx index 4cc4ce3c544d..e1858610fcdb 100644 --- a/src/pages/workspace/companyCards/utils.tsx +++ b/src/pages/workspace/companyCards/utils.tsx @@ -25,6 +25,7 @@ function getExportMenuItem( companyCard?: Card, ): ExportIntegration | undefined { const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy); + const defaultCard = translate('workspace.moreFeatures.companyCards.defaultCard'); const {nonReimbursableExpensesExportDestination, nonReimbursableExpensesAccount} = policy?.connections?.quickbooksOnline?.config ?? {}; const {export: exportConfig} = policy?.connections?.intacct?.config ?? {}; @@ -50,7 +51,7 @@ function getExportMenuItem( const isDefaultSelected = defaultAccount && companyCard?.nameValuePairs?.quickbooks_online_export_account === defaultAccount; // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing isDefaultTitle = !!(isDefaultSelected || (!companyCard?.nameValuePairs?.quickbooks_online_export_account && defaultAccount)); - title = isDefaultTitle ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : companyCard?.nameValuePairs?.quickbooks_online_export_account; + title = isDefaultTitle ? defaultCard : companyCard?.nameValuePairs?.quickbooks_online_export_account; selectedAccount = companyCard?.nameValuePairs?.quickbooks_online_export_account ?? defaultAccount; exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_QUICKBOOKS_ONLINE_EXPORT_ACCOUNT; break; @@ -60,7 +61,7 @@ function getExportMenuItem( const isDefaultSelected = defaultAccount && companyCard?.nameValuePairs?.quickbooks_online_export_account_debit === defaultAccount; // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing isDefaultTitle = !!(isDefaultSelected || (!companyCard?.nameValuePairs?.quickbooks_online_export_account_debit && defaultAccount)); - title = isDefaultTitle ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : companyCard?.nameValuePairs?.quickbooks_online_export_account_debit; + title = isDefaultTitle ? defaultCard : companyCard?.nameValuePairs?.quickbooks_online_export_account_debit; selectedAccount = companyCard?.nameValuePairs?.quickbooks_online_export_account_debit ?? defaultAccount; exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_QUICKBOOKS_ONLINE_EXPORT_ACCOUNT_DEBIT; break; @@ -80,7 +81,7 @@ function getExportMenuItem( const isDefault = card.name === defaultAccount; return { value: card.name, - text: isDefault ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : card.name, + text: isDefault ? defaultCard : card.name, keyForList: card.name, isSelected: card.name === selectedAccount, }; @@ -100,13 +101,13 @@ function getExportMenuItem( description, exportType, shouldShowMenuItem: true, - title: isDefaultTitle ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : selectedAccount?.name, + title: isDefaultTitle ? defaultCard : selectedAccount?.name, onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_XERO_EXPORT.getRoute(policyID)), data: (bankAccounts ?? []).map((card) => { const isDefault = card.id === defaultAccount; return { value: card.id, - text: isDefault ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : card.name, + text: isDefault ? defaultCard : card.name, keyForList: card.id, isSelected: selectedAccount?.id === card.id, }; @@ -133,12 +134,12 @@ function getExportMenuItem( isDefaultTitle = !!(isDefaultSelected || (!companyCard?.nameValuePairs?.netsuite_export_vendor && defaultAccount)); const vendors = policy?.connections?.netsuite.options.data.vendors; const selectedVendor = PolicyUtils.findSelectedVendorWithDefaultSelect(vendors, companyCard?.nameValuePairs?.netsuite_export_vendor ?? defaultAccount); - title = isDefaultTitle ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : selectedVendor?.name; + title = isDefaultTitle ? defaultCard : selectedVendor?.name; data = (vendors ?? []).map(({id, name}) => { const isDefault = id === defaultAccount; return { value: id, - text: isDefault ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : name, + text: isDefault ? defaultCard : name, keyForList: id, isSelected: selectedVendor?.id === id, }; @@ -156,12 +157,12 @@ function getExportMenuItem( payableAccounts, companyCard?.nameValuePairs?.netsuite_export_payable_account ?? defaultAccount, ); - title = isDefaultTitle ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : selectedPayableAccount?.name; + title = isDefaultTitle ? defaultCard : selectedPayableAccount?.name; data = (payableAccounts ?? []).map(({id, name}) => { const isDefault = id === defaultAccount; return { value: id, - text: isDefault ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : name, + text: isDefault ? defaultCard : name, keyForList: id, isSelected: selectedPayableAccount?.id === id, }; @@ -201,13 +202,13 @@ function getExportMenuItem( isDefaultTitle = !!(isDefaultSelected || (!companyCard?.nameValuePairs?.netsuite_export_payable_account && defaultAccount)); const vendors = policy?.connections?.intacct?.data?.vendors ?? []; const selectedVendor = PolicyUtils.findSelectedSageVendorWithDefaultSelect(vendors, companyCard?.nameValuePairs?.netsuite_export_payable_account ?? defaultAccount); - title = isDefaultTitle ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : selectedVendor?.name; + title = isDefaultTitle ? defaultCard : selectedVendor?.name; data = (vendors ?? []).map(({id, name}) => { const isDefault = id === defaultAccount; return { value: id, - text: isDefault ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : name, + text: isDefault ? defaultCard : name, keyForList: id, isSelected: selectedVendor?.id === id, }; @@ -222,13 +223,13 @@ function getExportMenuItem( isDefaultTitle = !!(isDefaultSelected || (!companyCard?.nameValuePairs?.intacct_export_charge_card && defaultAccount)); const intacctCreditCards = policy?.connections?.intacct?.data?.creditCards ?? []; const selectedCard = PolicyUtils.findSelectedSageVendorWithDefaultSelect(intacctCreditCards, companyCard?.nameValuePairs?.intacct_export_charge_card ?? defaultAccount); - title = isDefaultTitle ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : selectedCard?.name; + title = isDefaultTitle ? defaultCard : selectedCard?.name; data = (intacctCreditCards ?? []).map(({id, name}) => { const isDefault = id === defaultAccount; return { value: id, - text: isDefault ? CONST.COMPANY_CARDS.EXPORT_DEFAULT_CARD : name, + text: isDefault ? defaultCard : name, keyForList: id, isSelected: selectedCard?.id === id, }; From faecce2ce9889c5d735f57e34e97083c67f9ce41 Mon Sep 17 00:00:00 2001 From: Nicolay Arefyeu Date: Wed, 20 Nov 2024 17:33:25 +0200 Subject: [PATCH 5/9] updates for default card --- src/CONST.ts | 1 + ...kspaceCompanyCardAccountSelectCardPage.tsx | 7 +- src/pages/workspace/companyCards/utils.tsx | 109 ++++++++++-------- 3 files changed, 70 insertions(+), 47 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index faa3d35a5e06..5a3dd33d03ad 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -2821,6 +2821,7 @@ const CONST = { ALLOW: 'personal', }, CARD_LIST_THRESHOLD: 8, + DEFAULT_EXPORT_TYPE: 'default', EXPORT_CARD_TYPES: { /** * Name of Card NVP for QBO custom export accounts diff --git a/src/pages/workspace/companyCards/WorkspaceCompanyCardAccountSelectCardPage.tsx b/src/pages/workspace/companyCards/WorkspaceCompanyCardAccountSelectCardPage.tsx index a39a4401cb6e..e367292bfca3 100644 --- a/src/pages/workspace/companyCards/WorkspaceCompanyCardAccountSelectCardPage.tsx +++ b/src/pages/workspace/companyCards/WorkspaceCompanyCardAccountSelectCardPage.tsx @@ -39,6 +39,7 @@ function WorkspaceCompanyCardAccountSelectCardPage({route}: WorkspaceCompanyCard const exportMenuItem = getExportMenuItem(connectedIntegration, policyID, translate, policy, card); const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy); const shouldShowTextInput = (exportMenuItem?.data?.length ?? 0) >= CONST.STANDARD_LIST_ITEM_LIMIT; + const defaultCard = translate('workspace.moreFeatures.companyCards.defaultCard'); const searchedListOptions = useMemo(() => { return exportMenuItem?.data.filter((option) => option.value.toLowerCase().includes(searchText)); @@ -63,11 +64,13 @@ function WorkspaceCompanyCardAccountSelectCardPage({route}: WorkspaceCompanyCard if (!exportMenuItem?.exportType) { return; } - CompanyCards.setCompanyCardExportAccount(policyID, workspaceAccountID, cardID, exportMenuItem.exportType, value, bank); + const isDefaultCardSelected = value === defaultCard; + const exportValue = isDefaultCardSelected ? CONST.COMPANY_CARDS.DEFAULT_EXPORT_TYPE : value; + CompanyCards.setCompanyCardExportAccount(policyID, workspaceAccountID, cardID, exportMenuItem.exportType, exportValue, bank); Navigation.goBack(ROUTES.WORKSPACE_COMPANY_CARD_DETAILS.getRoute(policyID, cardID, bank)); }, - [exportMenuItem?.exportType, workspaceAccountID, cardID, policyID, bank], + [exportMenuItem?.exportType, workspaceAccountID, cardID, policyID, bank, defaultCard], ); return ( diff --git a/src/pages/workspace/companyCards/utils.tsx b/src/pages/workspace/companyCards/utils.tsx index e1858610fcdb..66528b13e089 100644 --- a/src/pages/workspace/companyCards/utils.tsx +++ b/src/pages/workspace/companyCards/utils.tsx @@ -27,6 +27,12 @@ function getExportMenuItem( const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy); const defaultCard = translate('workspace.moreFeatures.companyCards.defaultCard'); + const defaultMenuItem: Account = { + name: defaultCard, + id: defaultCard, + currency: '', + }; + const {nonReimbursableExpensesExportDestination, nonReimbursableExpensesAccount} = policy?.connections?.quickbooksOnline?.config ?? {}; const {export: exportConfig} = policy?.connections?.intacct?.config ?? {}; const {export: exportConfiguration} = policy?.connections?.xero?.config ?? {}; @@ -48,9 +54,11 @@ function getExportMenuItem( switch (nonReimbursableExpensesExportDestination) { case CONST.QUICKBOOKS_NON_REIMBURSABLE_EXPORT_ACCOUNT_TYPE.CREDIT_CARD: { data = creditCards ?? []; - const isDefaultSelected = defaultAccount && companyCard?.nameValuePairs?.quickbooks_online_export_account === defaultAccount; - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - isDefaultTitle = !!(isDefaultSelected || (!companyCard?.nameValuePairs?.quickbooks_online_export_account && defaultAccount)); + isDefaultTitle = !!( + defaultAccount && + (!companyCard?.nameValuePairs?.quickbooks_online_export_account || + companyCard?.nameValuePairs?.quickbooks_online_export_account === CONST.COMPANY_CARDS.DEFAULT_EXPORT_TYPE) + ); title = isDefaultTitle ? defaultCard : companyCard?.nameValuePairs?.quickbooks_online_export_account; selectedAccount = companyCard?.nameValuePairs?.quickbooks_online_export_account ?? defaultAccount; exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_QUICKBOOKS_ONLINE_EXPORT_ACCOUNT; @@ -58,9 +66,11 @@ function getExportMenuItem( } case CONST.QUICKBOOKS_NON_REIMBURSABLE_EXPORT_ACCOUNT_TYPE.DEBIT_CARD: { data = quickbooksOnlineBankAccounts ?? []; - const isDefaultSelected = defaultAccount && companyCard?.nameValuePairs?.quickbooks_online_export_account_debit === defaultAccount; - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - isDefaultTitle = !!(isDefaultSelected || (!companyCard?.nameValuePairs?.quickbooks_online_export_account_debit && defaultAccount)); + isDefaultTitle = !!( + defaultAccount && + (!companyCard?.nameValuePairs?.quickbooks_online_export_account_debit || + companyCard?.nameValuePairs?.quickbooks_online_export_account_debit === CONST.COMPANY_CARDS.DEFAULT_EXPORT_TYPE) + ); title = isDefaultTitle ? defaultCard : companyCard?.nameValuePairs?.quickbooks_online_export_account_debit; selectedAccount = companyCard?.nameValuePairs?.quickbooks_online_export_account_debit ?? defaultAccount; exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_QUICKBOOKS_ONLINE_EXPORT_ACCOUNT_DEBIT; @@ -71,19 +81,20 @@ function getExportMenuItem( data = []; } + const resultData = data.length > 0 ? [...data, defaultMenuItem] : data; + return { description, title, exportType, shouldShowMenuItem, onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_EXPORT.getRoute(policyID)), - data: data.map((card) => { - const isDefault = card.name === defaultAccount; + data: resultData.map((card) => { return { value: card.name, - text: isDefault ? defaultCard : card.name, + text: card.name, keyForList: card.name, - isSelected: card.name === selectedAccount, + isSelected: isDefaultTitle ? card.name === defaultCard : card.name === selectedAccount, }; }), }; @@ -93,23 +104,25 @@ function getExportMenuItem( const description = currentConnectionName && type ? translate('workspace.moreFeatures.companyCards.integrationExport', {integration: currentConnectionName, type}) : undefined; const exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_XERO_EXPORT_BANK_ACCOUNT; const defaultAccount = exportConfiguration?.nonReimbursableAccount; - const isDefaultSelected = defaultAccount && companyCard?.nameValuePairs?.xero_export_bank_account === defaultAccount; - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - const isDefaultTitle = !!(isDefaultSelected || (!companyCard?.nameValuePairs?.xero_export_bank_account && defaultAccount)); + const isDefaultTitle = !!( + defaultAccount && + (!companyCard?.nameValuePairs?.xero_export_bank_account || companyCard?.nameValuePairs?.xero_export_bank_account === CONST.COMPANY_CARDS.DEFAULT_EXPORT_TYPE) + ); const selectedAccount = (bankAccounts ?? []).find((bank) => bank.id === (companyCard?.nameValuePairs?.xero_export_bank_account ?? defaultAccount)); + const resultData = (bankAccounts ?? [])?.length > 0 ? [...(bankAccounts ?? []), defaultMenuItem] : bankAccounts; + return { description, exportType, shouldShowMenuItem: true, title: isDefaultTitle ? defaultCard : selectedAccount?.name, onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_XERO_EXPORT.getRoute(policyID)), - data: (bankAccounts ?? []).map((card) => { - const isDefault = card.id === defaultAccount; + data: (resultData ?? []).map((card) => { return { value: card.id, - text: isDefault ? defaultCard : card.name, + text: card.name, keyForList: card.id, - isSelected: selectedAccount?.id === card.id, + isSelected: isDefaultTitle ? card.name === defaultCard : selectedAccount?.id === card.id, }; }), }; @@ -129,19 +142,20 @@ function getExportMenuItem( switch (config?.nonreimbursableExpensesExportDestination) { case CONST.NETSUITE_EXPORT_DESTINATION.VENDOR_BILL: { defaultAccount = config?.defaultVendor; - const isDefaultSelected = defaultAccount && companyCard?.nameValuePairs?.netsuite_export_vendor === defaultAccount; - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - isDefaultTitle = !!(isDefaultSelected || (!companyCard?.nameValuePairs?.netsuite_export_vendor && defaultAccount)); + isDefaultTitle = !!( + defaultAccount && + (!companyCard?.nameValuePairs?.netsuite_export_vendor || companyCard?.nameValuePairs?.netsuite_export_vendor === CONST.COMPANY_CARDS.DEFAULT_EXPORT_TYPE) + ); const vendors = policy?.connections?.netsuite.options.data.vendors; const selectedVendor = PolicyUtils.findSelectedVendorWithDefaultSelect(vendors, companyCard?.nameValuePairs?.netsuite_export_vendor ?? defaultAccount); title = isDefaultTitle ? defaultCard : selectedVendor?.name; - data = (vendors ?? []).map(({id, name}) => { - const isDefault = id === defaultAccount; + const resultData = (vendors ?? []).length > 0 ? [...(vendors ?? []), defaultMenuItem] : vendors; + data = (resultData ?? []).map(({id, name}) => { return { value: id, - text: isDefault ? defaultCard : name, + text: name, keyForList: id, - isSelected: selectedVendor?.id === id, + isSelected: isDefaultTitle ? name === defaultCard : selectedVendor?.id === id, }; }); exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_NETSUITE_EXPORT_VENDOR; @@ -149,22 +163,24 @@ function getExportMenuItem( } case CONST.NETSUITE_EXPORT_DESTINATION.JOURNAL_ENTRY: { defaultAccount = config?.payableAcct; - const isDefaultSelected = defaultAccount && companyCard?.nameValuePairs?.netsuite_export_payable_account === defaultAccount; - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - isDefaultTitle = !!(isDefaultSelected || (!companyCard?.nameValuePairs?.netsuite_export_payable_account && defaultAccount)); + isDefaultTitle = !!( + defaultAccount && + (!companyCard?.nameValuePairs?.netsuite_export_payable_account || + companyCard?.nameValuePairs?.netsuite_export_payable_account === CONST.COMPANY_CARDS.DEFAULT_EXPORT_TYPE) + ); const payableAccounts = policy?.connections?.netsuite.options.data.payableList; const selectedPayableAccount = PolicyUtils.findSelectedBankAccountWithDefaultSelect( payableAccounts, companyCard?.nameValuePairs?.netsuite_export_payable_account ?? defaultAccount, ); title = isDefaultTitle ? defaultCard : selectedPayableAccount?.name; - data = (payableAccounts ?? []).map(({id, name}) => { - const isDefault = id === defaultAccount; + const resultData = (payableAccounts ?? []).length > 0 ? [...(payableAccounts ?? []), defaultMenuItem] : payableAccounts; + data = (resultData ?? []).map(({id, name}) => { return { value: id, - text: isDefault ? defaultCard : name, + text: name, keyForList: id, - isSelected: selectedPayableAccount?.id === id, + isSelected: isDefaultTitle ? name === defaultCard : selectedPayableAccount?.id === id, }; }); title = companyCard?.nameValuePairs?.netsuite_export_payable_account ?? data.find((exportPayable) => exportPayable.isSelected)?.text; @@ -197,20 +213,22 @@ function getExportMenuItem( switch (exportConfig?.nonReimbursable) { case CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE.VENDOR_BILL: { const defaultAccount = PolicyUtils.getSageIntacctNonReimbursableActiveDefaultVendor(policy); - const isDefaultSelected = defaultAccount && companyCard?.nameValuePairs?.netsuite_export_payable_account === defaultAccount; - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - isDefaultTitle = !!(isDefaultSelected || (!companyCard?.nameValuePairs?.netsuite_export_payable_account && defaultAccount)); + isDefaultTitle = !!( + defaultAccount && + (!companyCard?.nameValuePairs?.netsuite_export_payable_account || + companyCard?.nameValuePairs?.netsuite_export_payable_account === CONST.COMPANY_CARDS.DEFAULT_EXPORT_TYPE) + ); const vendors = policy?.connections?.intacct?.data?.vendors ?? []; const selectedVendor = PolicyUtils.findSelectedSageVendorWithDefaultSelect(vendors, companyCard?.nameValuePairs?.netsuite_export_payable_account ?? defaultAccount); title = isDefaultTitle ? defaultCard : selectedVendor?.name; + const resultData = (vendors ?? []).length > 0 ? [...(vendors ?? []), defaultMenuItem] : vendors; - data = (vendors ?? []).map(({id, name}) => { - const isDefault = id === defaultAccount; + data = (resultData ?? []).map(({id, name}) => { return { value: id, - text: isDefault ? defaultCard : name, + text: name, keyForList: id, - isSelected: selectedVendor?.id === id, + isSelected: isDefaultTitle ? name === defaultCard : selectedVendor?.id === id, }; }); exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_INTACCT_EXPORT_VENDOR; @@ -218,20 +236,21 @@ function getExportMenuItem( } case CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE.CREDIT_CARD_CHARGE: { const defaultAccount = exportConfig?.nonReimbursableAccount; - const isDefaultSelected = defaultAccount && companyCard?.nameValuePairs?.intacct_export_charge_card === defaultAccount; - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - isDefaultTitle = !!(isDefaultSelected || (!companyCard?.nameValuePairs?.intacct_export_charge_card && defaultAccount)); + isDefaultTitle = !!( + defaultAccount && + (!companyCard?.nameValuePairs?.intacct_export_charge_card || companyCard?.nameValuePairs?.intacct_export_charge_card === CONST.COMPANY_CARDS.DEFAULT_EXPORT_TYPE) + ); const intacctCreditCards = policy?.connections?.intacct?.data?.creditCards ?? []; const selectedCard = PolicyUtils.findSelectedSageVendorWithDefaultSelect(intacctCreditCards, companyCard?.nameValuePairs?.intacct_export_charge_card ?? defaultAccount); title = isDefaultTitle ? defaultCard : selectedCard?.name; + const resultData = (intacctCreditCards ?? []).length > 0 ? [...(intacctCreditCards ?? []), defaultMenuItem] : intacctCreditCards; - data = (intacctCreditCards ?? []).map(({id, name}) => { - const isDefault = id === defaultAccount; + data = (resultData ?? []).map(({id, name}) => { return { value: id, - text: isDefault ? defaultCard : name, + text: name, keyForList: id, - isSelected: selectedCard?.id === id, + isSelected: isDefaultTitle ? name === defaultCard : selectedCard?.id === id, }; }); exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_INTACCT_EXPORT_CHARGE_CARD; From 5a1783d15c4d8e48a6ee707d023b52b7161be113 Mon Sep 17 00:00:00 2001 From: narefyev91 Date: Thu, 21 Nov 2024 11:59:46 +0100 Subject: [PATCH 6/9] Update src/pages/workspace/companyCards/utils.tsx Co-authored-by: DylanDylann <141406735+DylanDylann@users.noreply.github.com> --- src/pages/workspace/companyCards/utils.tsx | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/pages/workspace/companyCards/utils.tsx b/src/pages/workspace/companyCards/utils.tsx index 66528b13e089..fccef833b0c4 100644 --- a/src/pages/workspace/companyCards/utils.tsx +++ b/src/pages/workspace/companyCards/utils.tsx @@ -89,14 +89,12 @@ function getExportMenuItem( exportType, shouldShowMenuItem, onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_EXPORT.getRoute(policyID)), - data: resultData.map((card) => { - return { - value: card.name, - text: card.name, - keyForList: card.name, - isSelected: isDefaultTitle ? card.name === defaultCard : card.name === selectedAccount, - }; - }), + data: resultData.map((card) => ({ + value: card.name, + text: card.name, + keyForList: card.name, + isSelected: isDefaultTitle ? card.name === defaultCard : card.name === selectedAccount, + })), }; } case CONST.POLICY.CONNECTIONS.NAME.XERO: { From 4af1801475b82e71918a33ce4d2c0cca540e7d47 Mon Sep 17 00:00:00 2001 From: Nicolay Arefyeu Date: Fri, 22 Nov 2024 13:38:49 -0500 Subject: [PATCH 7/9] Fix items for other integrations --- src/languages/en.ts | 2 +- src/languages/es.ts | 3 +- src/pages/workspace/companyCards/utils.tsx | 32 ++++++++++++---------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 85d0ddb98a11..d97bf11aad97 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -3432,7 +3432,7 @@ const translations = { cardNumber: 'Card number', cardholder: 'Cardholder', cardName: 'Card name', - integrationExport: ({integration, type}: IntegrationExportParams) => `${integration} ${type?.toLowerCase()} export`, + integrationExport: ({integration, type}: IntegrationExportParams) => (integration && type ? `${integration} ${type.toLowerCase()} export` : `${integration} export`), integrationExportTitleFirstPart: ({integration}: IntegrationExportParams) => `Choose the ${integration} account where transactions should be exported. Select a different`, integrationExportTitleLinkPart: 'export option', integrationExportTitleSecondPart: 'to change the available accounts.', diff --git a/src/languages/es.ts b/src/languages/es.ts index b7fdcfe561e4..76f339024f18 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -3475,7 +3475,8 @@ const translations = { cardNumber: 'Número de la tarjeta', cardholder: 'Titular de la tarjeta', cardName: 'Nombre de la tarjeta', - integrationExport: ({integration, type}: IntegrationExportParams) => `Exportación a ${integration} ${type?.toLowerCase()}`, + integrationExport: ({integration, type}: IntegrationExportParams) => + integration && type ? `Exportación a ${integration} ${type.toLowerCase()}` : `Exportación a ${integration}`, integrationExportTitleFirstPart: ({integration}: IntegrationExportParams) => `Seleccione la cuenta ${integration} donde se deben exportar las transacciones. Seleccione una cuenta diferente`, integrationExportTitleLinkPart: 'opción de exportación', diff --git a/src/pages/workspace/companyCards/utils.tsx b/src/pages/workspace/companyCards/utils.tsx index fccef833b0c4..bc961b6b1c90 100644 --- a/src/pages/workspace/companyCards/utils.tsx +++ b/src/pages/workspace/companyCards/utils.tsx @@ -81,7 +81,7 @@ function getExportMenuItem( data = []; } - const resultData = data.length > 0 ? [...data, defaultMenuItem] : data; + const resultData = data.length > 0 ? [defaultMenuItem, ...data] : data; return { description, @@ -99,15 +99,16 @@ function getExportMenuItem( } case CONST.POLICY.CONNECTIONS.NAME.XERO: { const type = translate('workspace.xero.xeroBankAccount'); - const description = currentConnectionName && type ? translate('workspace.moreFeatures.companyCards.integrationExport', {integration: currentConnectionName, type}) : undefined; + const description = currentConnectionName && type ? translate('workspace.moreFeatures.companyCards.integrationExport', {integration: type}) : undefined; const exportType = CONST.COMPANY_CARDS.EXPORT_CARD_TYPES.NVP_XERO_EXPORT_BANK_ACCOUNT; - const defaultAccount = exportConfiguration?.nonReimbursableAccount; + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + const defaultAccount = exportConfiguration?.nonReimbursableAccount || bankAccounts?.[0]?.id; const isDefaultTitle = !!( defaultAccount && (!companyCard?.nameValuePairs?.xero_export_bank_account || companyCard?.nameValuePairs?.xero_export_bank_account === CONST.COMPANY_CARDS.DEFAULT_EXPORT_TYPE) ); const selectedAccount = (bankAccounts ?? []).find((bank) => bank.id === (companyCard?.nameValuePairs?.xero_export_bank_account ?? defaultAccount)); - const resultData = (bankAccounts ?? [])?.length > 0 ? [...(bankAccounts ?? []), defaultMenuItem] : bankAccounts; + const resultData = (bankAccounts ?? [])?.length > 0 ? [defaultMenuItem, ...(bankAccounts ?? [])] : bankAccounts; return { description, @@ -139,15 +140,16 @@ function getExportMenuItem( switch (config?.nonreimbursableExpensesExportDestination) { case CONST.NETSUITE_EXPORT_DESTINATION.VENDOR_BILL: { - defaultAccount = config?.defaultVendor; + const vendors = policy?.connections?.netsuite.options.data.vendors; + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + defaultAccount = config?.defaultVendor || vendors?.[0]?.id; isDefaultTitle = !!( defaultAccount && (!companyCard?.nameValuePairs?.netsuite_export_vendor || companyCard?.nameValuePairs?.netsuite_export_vendor === CONST.COMPANY_CARDS.DEFAULT_EXPORT_TYPE) ); - const vendors = policy?.connections?.netsuite.options.data.vendors; const selectedVendor = PolicyUtils.findSelectedVendorWithDefaultSelect(vendors, companyCard?.nameValuePairs?.netsuite_export_vendor ?? defaultAccount); title = isDefaultTitle ? defaultCard : selectedVendor?.name; - const resultData = (vendors ?? []).length > 0 ? [...(vendors ?? []), defaultMenuItem] : vendors; + const resultData = (vendors ?? []).length > 0 ? [defaultMenuItem, ...(vendors ?? [])] : vendors; data = (resultData ?? []).map(({id, name}) => { return { value: id, @@ -160,19 +162,20 @@ function getExportMenuItem( break; } case CONST.NETSUITE_EXPORT_DESTINATION.JOURNAL_ENTRY: { - defaultAccount = config?.payableAcct; + const payableAccounts = policy?.connections?.netsuite.options.data.payableList; + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + defaultAccount = config?.payableAcct || payableAccounts?.[0]?.id; isDefaultTitle = !!( defaultAccount && (!companyCard?.nameValuePairs?.netsuite_export_payable_account || companyCard?.nameValuePairs?.netsuite_export_payable_account === CONST.COMPANY_CARDS.DEFAULT_EXPORT_TYPE) ); - const payableAccounts = policy?.connections?.netsuite.options.data.payableList; const selectedPayableAccount = PolicyUtils.findSelectedBankAccountWithDefaultSelect( payableAccounts, companyCard?.nameValuePairs?.netsuite_export_payable_account ?? defaultAccount, ); title = isDefaultTitle ? defaultCard : selectedPayableAccount?.name; - const resultData = (payableAccounts ?? []).length > 0 ? [...(payableAccounts ?? []), defaultMenuItem] : payableAccounts; + const resultData = (payableAccounts ?? []).length > 0 ? [defaultMenuItem, ...(payableAccounts ?? [])] : payableAccounts; data = (resultData ?? []).map(({id, name}) => { return { value: id, @@ -219,7 +222,7 @@ function getExportMenuItem( const vendors = policy?.connections?.intacct?.data?.vendors ?? []; const selectedVendor = PolicyUtils.findSelectedSageVendorWithDefaultSelect(vendors, companyCard?.nameValuePairs?.netsuite_export_payable_account ?? defaultAccount); title = isDefaultTitle ? defaultCard : selectedVendor?.name; - const resultData = (vendors ?? []).length > 0 ? [...(vendors ?? []), defaultMenuItem] : vendors; + const resultData = (vendors ?? []).length > 0 ? [defaultMenuItem, ...(vendors ?? [])] : vendors; data = (resultData ?? []).map(({id, name}) => { return { @@ -233,15 +236,16 @@ function getExportMenuItem( break; } case CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE.CREDIT_CARD_CHARGE: { - const defaultAccount = exportConfig?.nonReimbursableAccount; + const intacctCreditCards = policy?.connections?.intacct?.data?.creditCards ?? []; + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + const defaultAccount = exportConfig?.nonReimbursableAccount || intacctCreditCards.at(0)?.id; isDefaultTitle = !!( defaultAccount && (!companyCard?.nameValuePairs?.intacct_export_charge_card || companyCard?.nameValuePairs?.intacct_export_charge_card === CONST.COMPANY_CARDS.DEFAULT_EXPORT_TYPE) ); - const intacctCreditCards = policy?.connections?.intacct?.data?.creditCards ?? []; const selectedCard = PolicyUtils.findSelectedSageVendorWithDefaultSelect(intacctCreditCards, companyCard?.nameValuePairs?.intacct_export_charge_card ?? defaultAccount); title = isDefaultTitle ? defaultCard : selectedCard?.name; - const resultData = (intacctCreditCards ?? []).length > 0 ? [...(intacctCreditCards ?? []), defaultMenuItem] : intacctCreditCards; + const resultData = (intacctCreditCards ?? []).length > 0 ? [defaultMenuItem, ...(intacctCreditCards ?? [])] : intacctCreditCards; data = (resultData ?? []).map(({id, name}) => { return { From 970bbc6296a32b826c18203de04930de04a6cd08 Mon Sep 17 00:00:00 2001 From: Artem Makushov <39777589+waterim@users.noreply.github.com> Date: Mon, 25 Nov 2024 12:40:28 +0100 Subject: [PATCH 8/9] Update src/libs/PolicyUtils.ts to selectedVendorID Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- src/libs/PolicyUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index c11eb2f0397e..4fcd887af8fd 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -712,7 +712,7 @@ function findSelectedVendorWithDefaultSelect(vendors: NetSuiteVendor[] | undefin return selectedVendor ?? vendors?.[0] ?? undefined; } -function findSelectedSageVendorWithDefaultSelect(vendors: SageIntacctDataElementWithValue[] | SageIntacctDataElement[] | undefined, selectedVendorId: string | undefined) { +function findSelectedSageVendorWithDefaultSelect(vendors: SageIntacctDataElementWithValue[] | SageIntacctDataElement[] | undefined, selectedVendorID: string | undefined) { const selectedVendor = (vendors ?? []).find(({id}) => id === selectedVendorId); return selectedVendor ?? vendors?.[0] ?? undefined; } From 33806c3902b90b554d357a244e5b5bae295b41b1 Mon Sep 17 00:00:00 2001 From: Artem Makushov <39777589+waterim@users.noreply.github.com> Date: Mon, 25 Nov 2024 12:40:48 +0100 Subject: [PATCH 9/9] Update src/libs/PolicyUtils.ts to selectedVendorID Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- src/libs/PolicyUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 4fcd887af8fd..9e7ba02167ee 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -713,7 +713,7 @@ function findSelectedVendorWithDefaultSelect(vendors: NetSuiteVendor[] | undefin } function findSelectedSageVendorWithDefaultSelect(vendors: SageIntacctDataElementWithValue[] | SageIntacctDataElement[] | undefined, selectedVendorID: string | undefined) { - const selectedVendor = (vendors ?? []).find(({id}) => id === selectedVendorId); + const selectedVendor = (vendors ?? []).find(({id}) => id === selectedVendorID); return selectedVendor ?? vendors?.[0] ?? undefined; }