Fixed bug where closing account did not properly validate transfer or category (#4769)

Co-authored-by: Alec Bakholdin <abakho@icims.com>
This commit is contained in:
Alec Bakholdin
2025-04-08 09:52:54 -04:00
committed by GitHub
parent aba97e8b74
commit 4e0ab44e2f
2 changed files with 24 additions and 14 deletions

View File

@@ -91,24 +91,27 @@ export function CloseAccountModal({
const onSubmit = (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();
const transferError = balance !== 0 && transferAccountId === '';
const transferError = balance !== 0 && !transferAccountId;
setTransferError(transferError);
const categoryError =
needsCategory(account, transferAccountId, accounts) && categoryId === '';
needsCategory(account, transferAccountId, accounts) && !categoryId;
setCategoryError(categoryError);
if (!transferError && !categoryError) {
setLoading(true);
dispatch(
closeAccount({
id: account.id,
transferAccountId: transferAccountId || null,
categoryId: categoryId || null,
}),
);
if (transferError || categoryError) {
return false;
}
setLoading(true);
dispatch(
closeAccount({
id: account.id,
transferAccountId: transferAccountId || null,
categoryId: categoryId || null,
}),
);
return true;
};
return (
@@ -150,8 +153,9 @@ export function CloseAccountModal({
</Paragraph>
<Form
onSubmit={e => {
onSubmit(e);
close();
if (onSubmit(e)) {
close();
}
}}
>
{balance !== 0 && (