Skip to content

Commit

Permalink
Merge pull request #52819 from ZhenjaHorbach/qbd-export-accounts-defa…
Browse files Browse the repository at this point in the history
…ult-account

Fix bug with default accounts for QBD
  • Loading branch information
lakchote authored Nov 22, 2024
2 parents 5f483dc + a106765 commit 056e8ee
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ function QuickbooksDesktopCompanyCardExpenseAccountPage({policy}: WithPolicyConn
const nonReimbursable = qbdConfig?.export?.nonReimbursable;
const nonReimbursableAccount = qbdConfig?.export?.nonReimbursableAccount;

const accountName = useMemo(
() => getQBDReimbursableAccounts(policy?.connections?.quickbooksDesktop, nonReimbursable).find(({id}) => nonReimbursableAccount === id)?.name,
[policy?.connections?.quickbooksDesktop, nonReimbursable, nonReimbursableAccount],
);
const accountName = useMemo(() => {
const qbdReimbursableAccounts = getQBDReimbursableAccounts(policy?.connections?.quickbooksDesktop, nonReimbursable);
// We use the logical OR (||) here instead of ?? because `nonReimbursableAccount` can be an empty string
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
return qbdReimbursableAccounts.find(({id}) => nonReimbursableAccount === id)?.name || qbdReimbursableAccounts.at(0)?.name || translate('workspace.qbd.notConfigured');
}, [policy?.connections?.quickbooksDesktop, nonReimbursable, translate, nonReimbursableAccount]);

const sections = [
{
Expand All @@ -42,7 +44,7 @@ function QuickbooksDesktopCompanyCardExpenseAccountPage({policy}: WithPolicyConn
keyForList: translate('workspace.accounting.exportAs'),
},
{
title: accountName ?? translate('workspace.qbd.notConfigured'),
title: accountName,
description: ConnectionUtils.getQBDNonReimbursableExportAccountType(nonReimbursable),
onPress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_COMPANY_CARD_EXPENSE_ACCOUNT_SELECT.getRoute(policyID)),
subscribedSettings: [CONST.QUICKBOOKS_DESKTOP_CONFIG.NON_REIMBURSABLE_ACCOUNT],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ function QuickbooksDesktopCompanyCardExpenseAccountSelectPage({policy}: WithPoli
value: card,
text: card.name,
keyForList: card.name,
isSelected: card.id === nonReimbursableAccount,
// We use the logical OR (||) here instead of ?? because `nonReimbursableAccount` can be an empty string
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
isSelected: card.id === (nonReimbursableAccount || accounts.at(0)?.id),
}));
}, [policy?.connections?.quickbooksDesktop, nonReimbursable, nonReimbursableAccount]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ function QuickbooksDesktopNonReimbursableDefaultVendorSelectPage({policy}: WithP
value: vendor.id,
text: vendor.name,
keyForList: vendor.name,
isSelected: vendor.id === nonReimbursableBillDefaultVendor,
// We use the logical OR (||) here instead of ?? because `nonReimbursableBillDefaultVendor` can be an empty string
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
isSelected: vendor.id === (nonReimbursableBillDefaultVendor || vendors.at(0)?.id),
})) ?? [];
return data.length ? [{data}] : [];
}, [nonReimbursableBillDefaultVendor, vendors]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ function QuickbooksDesktopOutOfPocketExpenseAccountSelectPage({policy}: WithPoli
value: account,
text: account.name,
keyForList: account.name,
isSelected: account.id === qbdConfig?.export?.reimbursableAccount,
// We use the logical OR (||) here instead of ?? because `reimbursableAccount` can be an empty string
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
isSelected: account.id === (qbdConfig?.export?.reimbursableAccount || accounts.at(0)?.id),
}));
}, [policy?.connections?.quickbooksDesktop, qbdConfig?.export?.reimbursableAccount]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ function QuickbooksDesktopOutOfPocketExpenseConfigurationPage({policy}: WithPoli
brickRoadIndicator: PolicyUtils.areSettingsInErrorFields(accountOrExportDestination, qbdConfig?.errorFields) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
},
{
title: accountsList.find(({id}) => qbdConfig?.export.reimbursableAccount === id)?.name ?? translate('workspace.qbd.notConfigured'),
// We use the logical OR (||) here instead of ?? because `reimbursableAccount` can be an empty string
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
title: accountsList.find(({id}) => qbdConfig?.export.reimbursableAccount === id)?.name || accountsList.at(0)?.name || translate('workspace.qbd.notConfigured'),
description: accountDescription,
onPress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_EXPORT_OUT_OF_POCKET_EXPENSES_ACCOUNT_SELECT.getRoute(policyID)),
subscribedSettings: account,
Expand Down

0 comments on commit 056e8ee

Please sign in to comment.