Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Internal QA]: Fix default card with export type #52575

Merged
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down Expand Up @@ -3469,6 +3469,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: {
Expand Down
4 changes: 3 additions & 1 deletion src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -3514,6 +3515,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: {
Expand Down
8 changes: 8 additions & 0 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import type {
PolicyConnectionSyncProgress,
PolicyFeatureName,
Rate,
SageIntacctDataElement,
SageIntacctDataElementWithValue,
Tenant,
} from '@src/types/onyx/Policy';
import type PolicyEmployee from '@src/types/onyx/PolicyEmployee';
Expand Down Expand Up @@ -710,6 +712,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;
Expand Down Expand Up @@ -1184,6 +1191,7 @@ export {
findSelectedBankAccountWithDefaultSelect,
findSelectedInvoiceItemWithDefaultSelect,
findSelectedTaxAccountWithDefaultSelect,
findSelectedSageVendorWithDefaultSelect,
getNetSuiteVendorOptions,
canUseTaxNetSuite,
canUseProvincialTaxNetSuite,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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 (
Expand Down
Loading
Loading