Skip to content

Commit

Permalink
hardening
Browse files Browse the repository at this point in the history
  • Loading branch information
dkhalife committed Dec 15, 2024
1 parent 2bf3b70 commit 126c4bd
Showing 1 changed file with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,17 @@ import { Field, Row, Table, TableHeader } from '../table';

import { type NormalizedAccount } from './CreateAccountModal';

const addOnBudgetAccountOption = { id: 'new-on', name: 'Create new account' };
const addOffBudgetAccountOption = {
type LinkAccountOption = {
id: string;
name: string;
};

const addOnBudgetAccountOption: LinkAccountOption = {
id: 'new-on',
name: 'Create new account',
};

const addOffBudgetAccountOption: LinkAccountOption = {
id: 'new-off',
name: 'Create new account (off budget)',
};
Expand Down Expand Up @@ -125,7 +134,7 @@ export function SelectLinkedAccountsModal({

function onSetLinkedAccount(
externalAccount: NormalizedAccount,
localAccountId: string | null,
localAccountId: string | undefined,
) {
setChosenAccounts((accounts: LinkedAccountIds): LinkedAccountIds => {
const updatedAccounts: LinkedAccountIds = { ...accounts };
Expand Down Expand Up @@ -226,11 +235,11 @@ export function SelectLinkedAccountsModal({

type TableRowProps = {
externalAccount: NormalizedAccount;
chosenAccount: string;
unlinkedAccounts: AccountEntity[];
chosenAccount: LinkAccountOption | undefined;
unlinkedAccounts: LinkAccountOption[];
onSetLinkedAccount: (
account: NormalizedAccount,
localAccountId: string | null,
localAccountId: string | undefined,
) => void;
};

Expand All @@ -243,13 +252,16 @@ function TableRow({
const { t } = useTranslation();
const [focusedField, setFocusedField] = useState<string | null>(null);

const availableAccountOptions = [
const availableAccountOptions: LinkAccountOption[] = [
...unlinkedAccounts,
chosenAccount?.id !== addOnBudgetAccountOption.id && chosenAccount,
addOnBudgetAccountOption,
addOffBudgetAccountOption,
].filter(Boolean);

if (chosenAccount && chosenAccount.id !== addOnBudgetAccountOption.id) {
availableAccountOptions.push(chosenAccount);
}

return (
<Row style={{ backgroundColor: theme.tableBackground }}>
<Field width={200}>{externalAccount.name}</Field>
Expand All @@ -267,7 +279,7 @@ function TableRow({
strict
highlightFirst
suggestions={availableAccountOptions}
onSelect={value => {
onSelect={(value: string | undefined) => {
onSetLinkedAccount(externalAccount, value);
}}
inputProps={{
Expand All @@ -283,7 +295,7 @@ function TableRow({
{chosenAccount ? (
<Button
onPress={() => {
onSetLinkedAccount(externalAccount, null);
onSetLinkedAccount(externalAccount, undefined);
}}
style={{ float: 'right' }}
>
Expand Down

0 comments on commit 126c4bd

Please sign in to comment.