Fix budget calculation and display

Ensure daily and weekly budgets are calculated correctly based on the monthly budget, and that the monthly budget is consistent across the app.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-22 12:02:41 +00:00
parent cbee1f4fb9
commit 0bc53208b5
3 changed files with 45 additions and 13 deletions

View File

@@ -2,8 +2,7 @@
import { useCallback } from 'react';
import { toast } from '@/hooks/useToast.wrapper';
import {
loadTransactionsFromStorage,
loadBudgetFromStorage
loadTransactionsFromStorage
} from './storageUtils';
/**
@@ -25,11 +24,28 @@ export const useTransactionsLoader = (
const localTransactions = loadTransactionsFromStorage();
setTransactions(localTransactions);
// 예산 가져오기 (월간 예산만 설정)
const budgetAmount = loadBudgetFromStorage();
setTotalBudget(budgetAmount);
console.log('로드된 예산 금액:', budgetAmount);
// 예산 데이터에서 직접 월간 예산 값을 가져옴
try {
const budgetDataStr = localStorage.getItem('budgetData');
if (budgetDataStr) {
const budgetData = JSON.parse(budgetDataStr);
// 월간 예산 값만 사용
if (budgetData && budgetData.monthly && typeof budgetData.monthly.targetAmount === 'number') {
const monthlyBudget = budgetData.monthly.targetAmount;
setTotalBudget(monthlyBudget);
console.log('월간 예산 설정:', monthlyBudget);
} else {
console.log('유효한 월간 예산 데이터가 없습니다. 기본값 0 사용');
setTotalBudget(0);
}
} else {
console.log('예산 데이터가 없습니다. 기본값 0 사용');
setTotalBudget(0);
}
} catch (budgetErr) {
console.error('예산 데이터 파싱 오류:', budgetErr);
setTotalBudget(0);
}
} catch (err) {
console.error('트랜잭션 로드 중 오류:', err);
setError('데이터를 불러오는 중 문제가 발생했습니다.');