Skip to content

Commit

Permalink
Fix: Create budget and remaining budget not working (#53)
Browse files Browse the repository at this point in the history
* Fix: Create budget and remaining budget not working
  • Loading branch information
drishit96 authored Dec 21, 2023
1 parent 13b9aae commit 2cd09a7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
15 changes: 10 additions & 5 deletions app/components/TargetSetter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,20 @@ export default function TargetSetter({
}, [categoryBudgets]);

useEffect(() => {
if (previousBudgetFetcher.type === "done") {
if (previousBudgetFetcher.data && previousBudgetFetcher.data.length > 0) {
setCategoryBudgets([...categoryBudgets, ...previousBudgetFetcher.data]);
setMaxKey(previousBudgetFetcher.data.length);
if (previousBudgetFetcher.data != null) {
const budgetData = previousBudgetFetcher.data as {
index: number;
category: string;
budget: string;
}[];
if (budgetData.length > 0) {
setCategoryBudgets([...categoryBudgets, ...budgetData]);
setMaxKey(budgetData.length);
} else {
context.setSnackBarMsg("No budget found for previous month");
}
}
}, [previousBudgetFetcher.type]);
}, [previousBudgetFetcher.data]);

return (
<>
Expand Down
20 changes: 9 additions & 11 deletions app/routes/transaction/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,16 @@ export default function Create() {
}, [selectedCategories]);

useEffect(() => {
if (categoryRemainingBudgetFetcher.type === "done") {
if (categoryRemainingBudgetFetcher.data) {
categoryRemainingBudgetMap.current = {
...categoryRemainingBudgetMap.current,
...(categoryRemainingBudgetFetcher.data as {
[key: string]: number | null;
}),
};
calculateRemainingBudget(amount);
}
if (categoryRemainingBudgetFetcher.data) {
categoryRemainingBudgetMap.current = {
...categoryRemainingBudgetMap.current,
...(categoryRemainingBudgetFetcher.data as {
[key: string]: number | null;
}),
};
calculateRemainingBudget(amount);
}
}, [amount, calculateRemainingBudget, categoryRemainingBudgetFetcher]);
}, [amount, calculateRemainingBudget, categoryRemainingBudgetFetcher.data]);

useEffect(() => {
calculateRemainingBudget(amount);
Expand Down
20 changes: 9 additions & 11 deletions app/routes/transaction/edit/$transactionId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,18 +281,16 @@ export default function EditTransaction() {
}, [selectedCategories]);

useEffect(() => {
if (categoryRemainingBudgetFetcher.type === "done") {
if (categoryRemainingBudgetFetcher.data) {
categoryRemainingBudgetMap.current = {
...categoryRemainingBudgetMap.current,
...(categoryRemainingBudgetFetcher.data as {
[key: string]: number | null;
}),
};
calculateRemainingBudget(amount);
}
if (categoryRemainingBudgetFetcher.data) {
categoryRemainingBudgetMap.current = {
...categoryRemainingBudgetMap.current,
...(categoryRemainingBudgetFetcher.data as {
[key: string]: number | null;
}),
};
calculateRemainingBudget(amount);
}
}, [amount, calculateRemainingBudget, categoryRemainingBudgetFetcher]);
}, [amount, calculateRemainingBudget, categoryRemainingBudgetFetcher.data]);

useEffect(() => {
calculateRemainingBudget(amount);
Expand Down

0 comments on commit 2cd09a7

Please sign in to comment.