Skip to content

Commit

Permalink
type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dkhalife committed Dec 15, 2024
1 parent 1c51a5c commit 2bf3b70
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -31,7 +33,7 @@ const addOffBudgetAccountOption = {

type SelectLinkedAccountsModalProps = {
requisitionId: string;
externalAccounts: AccountEntity[];
externalAccounts: NormalizedAccount[];
syncSource: AccountSyncSource;
};

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -181,14 +186,13 @@ export function SelectLinkedAccountsModal({
<TableRow
externalAccount={item}
chosenAccount={

Check failure on line 188 in packages/desktop-client/src/components/modals/SelectLinkedAccountsModal.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Type '{ id: string; name: string; }' is not assignable to type 'string'.
chosenAccounts[item.account_id] ===
addOnBudgetAccountOption.id
chosenAccounts[item.id] === addOnBudgetAccountOption.id
? addOnBudgetAccountOption
: chosenAccounts[item.account_id] ===
: chosenAccounts[item.id] ===
addOffBudgetAccountOption.id
? addOffBudgetAccountOption
: localAccounts.find(
acc => chosenAccounts[item.account_id] === acc.id,
acc => chosenAccounts[item.id] === acc.id,
)
}
unlinkedAccounts={unlinkedAccounts}
Expand Down Expand Up @@ -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({
Expand All @@ -234,7 +241,7 @@ function TableRow({
onSetLinkedAccount,
}: TableRowProps) {
const { t } = useTranslation();
const [focusedField, setFocusedField] = useState(null);
const [focusedField, setFocusedField] = useState<string | null>(null);

const availableAccountOptions = [
...unlinkedAccounts,
Expand Down

0 comments on commit 2bf3b70

Please sign in to comment.