Skip to content

Commit

Permalink
Merge pull request #52575 from callstack-internal/fix-default-card-wi…
Browse files Browse the repository at this point in the history
…th-export-type

[Internal QA]: Fix default card with export type
  • Loading branch information
mountiny authored Nov 25, 2024
2 parents 787d804 + 33806c3 commit 8c4661d
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 35 deletions.
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2850,6 +2850,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 @@ -3489,7 +3489,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 @@ -3526,6 +3526,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 @@ -3531,7 +3531,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 @@ -3570,6 +3571,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 @@ -711,6 +713,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 @@ -1185,6 +1192,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

0 comments on commit 8c4661d

Please sign in to comment.