diff --git a/packages/desktop-client/src/components/modals/CreateAccountModal.tsx b/packages/desktop-client/src/components/modals/CreateAccountModal.tsx index 6ba131bf6dd..6e785b41b7a 100644 --- a/packages/desktop-client/src/components/modals/CreateAccountModal.tsx +++ b/packages/desktop-client/src/components/modals/CreateAccountModal.tsx @@ -22,6 +22,15 @@ import { Popover } from '../common/Popover'; import { Text } from '../common/Text'; import { View } from '../common/View'; +export type NormalizedAccount = { + id: string; + name: string; + institution: string; + orgDomain: string; + orgId: string; + balance: number; +}; + type CreateAccountProps = { upgradingAccountId?: string; }; @@ -70,20 +79,11 @@ export function CreateAccountModal({ upgradingAccountId }: CreateAccountProps) { throw new Error(results.reason); } - const newAccounts = []; - - type NormalizedAccount = { - account_id: string; - name: string; - institution: string; - orgDomain: string; - orgId: string; - balance: number; - }; + const newAccounts: NormalizedAccount[] = []; for (const oldAccount of results.accounts) { const newAccount: NormalizedAccount = { - account_id: oldAccount.id, + id: oldAccount.id, name: oldAccount.name, institution: oldAccount.org.name, orgDomain: oldAccount.org.domain, diff --git a/packages/desktop-client/src/components/modals/SelectLinkedAccountsModal.tsx b/packages/desktop-client/src/components/modals/SelectLinkedAccountsModal.tsx index 53d3b1c3446..7e4dc8820c1 100644 --- a/packages/desktop-client/src/components/modals/SelectLinkedAccountsModal.tsx +++ b/packages/desktop-client/src/components/modals/SelectLinkedAccountsModal.tsx @@ -23,6 +23,8 @@ import { View } from '../common/View'; import { PrivacyFilter } from '../PrivacyFilter'; import { Field, Row, Table, TableHeader } from '../table'; +import { type NormalizedAccount } from './CreateAccountModal'; + const addOnBudgetAccountOption = { id: 'new-on', name: 'Create new account' }; const addOffBudgetAccountOption = { id: 'new-off', @@ -31,7 +33,7 @@ const addOffBudgetAccountOption = { type SelectLinkedAccountsModalProps = { requisitionId: string; - externalAccounts: AccountEntity[]; + externalAccounts: NormalizedAccount[]; syncSource: AccountSyncSource; }; @@ -76,7 +78,7 @@ export function SelectLinkedAccountsModal({ Object.entries(chosenAccounts).forEach( ([chosenExternalAccountId, chosenLocalAccountId]) => { const externalAccount = externalAccounts.find( - account => account.account_id === chosenExternalAccountId, + account => account.id === chosenExternalAccountId, ); const offBudget = chosenLocalAccountId === addOffBudgetAccountOption.id; @@ -121,14 +123,17 @@ export function SelectLinkedAccountsModal({ account => !Object.values(chosenAccounts).includes(account.id), ); - function onSetLinkedAccount(externalAccount: AccountEntity, localAccountId: string) { + function onSetLinkedAccount( + externalAccount: NormalizedAccount, + localAccountId: string | null, + ) { setChosenAccounts((accounts: LinkedAccountIds): LinkedAccountIds => { const updatedAccounts: LinkedAccountIds = { ...accounts }; if (localAccountId) { - updatedAccounts[externalAccount.account_id] = localAccountId; + updatedAccounts[externalAccount.id] = localAccountId; } else { - delete updatedAccounts[externalAccount.account_id]; + delete updatedAccounts[externalAccount.id]; } return updatedAccounts; @@ -181,14 +186,13 @@ export function SelectLinkedAccountsModal({ chosenAccounts[item.account_id] === acc.id, + acc => chosenAccounts[item.id] === acc.id, ) } unlinkedAccounts={unlinkedAccounts} @@ -221,10 +225,13 @@ export function SelectLinkedAccountsModal({ } type TableRowProps = { - externalAccount: AccountEntity; - chosenAccount: any; + externalAccount: NormalizedAccount; + chosenAccount: string; unlinkedAccounts: AccountEntity[]; - onSetLinkedAccount: (account: AccountEntity, localAccountId: string) => void; + onSetLinkedAccount: ( + account: NormalizedAccount, + localAccountId: string | null, + ) => void; }; function TableRow({ @@ -234,7 +241,7 @@ function TableRow({ onSetLinkedAccount, }: TableRowProps) { const { t } = useTranslation(); - const [focusedField, setFocusedField] = useState(null); + const [focusedField, setFocusedField] = useState(null); const availableAccountOptions = [ ...unlinkedAccounts,