mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-21 15:36:50 -05:00
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:
@@ -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 && (
|
||||
|
||||
Reference in New Issue
Block a user