Fix analytics graph and toast

- Corrected analytics graph to only display budget data when budget is entered.
- Fixed issue where expense toast notifications were appearing twice.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-16 08:56:39 +00:00
parent e392557b9c
commit da9120ba61
4 changed files with 29 additions and 31 deletions

View File

@@ -88,7 +88,7 @@ const Analytics = () => {
category.title === '교통비' ? '#2E7D32' : '#4CAF50'
}));
// 월별 데이터 생성
// 월별 데이터 생성 - 샘플 데이터 제거하고 현재 달만 실제 데이터 사용
useEffect(() => {
console.log('Analytics 페이지: 월별 데이터 생성', { totalBudget, totalExpense });
@@ -96,34 +96,15 @@ const Analytics = () => {
const today = new Date();
const currentMonth = today.getMonth();
// 최근 6개월 데이터 배열 생성
const last6Months = [];
for (let i = 5; i >= 0; i--) {
const monthIndex = (currentMonth - i + 12) % 12; // 순환적으로 이전 월 계산
const month = MONTHS_KR[monthIndex]; // 월 이름 가져오기
// 현재 달은 실제 데이터 사용, 다른 달은 샘플 데이터
if (i === 0) {
last6Months.push({
name: month.split(' ')[0], // '8월' 형식으로 변환
budget: totalBudget,
expense: totalExpense
});
} else {
// 샘플 데이터 (랜덤 값 대신 이전 달의 데이터 추정)
const sampleBudget = i === 1 ? Math.round(totalBudget * 0.9) : Math.round(totalBudget * 0.8);
const sampleExpense = i === 1 ? Math.round(totalExpense * 0.8) : Math.round(totalExpense * 0.7);
last6Months.push({
name: month.split(' ')[0],
budget: sampleBudget > 0 ? sampleBudget : 0,
expense: sampleExpense > 0 ? sampleExpense : 0
});
}
}
// 현재 달만 실제 데이터 사용하는 배열 생성
const monthlyDataArray = [{
name: MONTHS_KR[currentMonth].split(' ')[0], // '8월' 형식으로 변환
budget: totalBudget,
expense: totalExpense
}];
setMonthlyData(last6Months);
console.log('Analytics 페이지: 월별 데이터 생성 완료', last6Months);
setMonthlyData(monthlyDataArray);
console.log('Analytics 페이지: 월별 데이터 생성 완료', monthlyDataArray);
}, [totalBudget, totalExpense, refreshTrigger]);
// 이전/다음 기간 이동 처리