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

@@ -1,7 +1,8 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { PlusIcon } from 'lucide-react'; import { PlusIcon } from 'lucide-react';
import { Dialog, DialogContent, DialogHeader, DialogTitle } from './ui/dialog'; import { Dialog, DialogContent, DialogHeader, DialogTitle } from './ui/dialog';
import { toast } from '@/components/ui/use-toast'; import { toast } from '@/hooks/use-toast';
import { useBudget } from '@/contexts/BudgetContext'; import { useBudget } from '@/contexts/BudgetContext';
import { supabase } from '@/lib/supabase'; import { supabase } from '@/lib/supabase';
import { isSyncEnabled } from '@/utils/syncUtils'; import { isSyncEnabled } from '@/utils/syncUtils';
@@ -76,6 +77,7 @@ const AddTransactionButton = () => {
// 브라우저 이벤트 발생시켜 다른 페이지에서도 업데이트되도록 함 // 브라우저 이벤트 발생시켜 다른 페이지에서도 업데이트되도록 함
window.dispatchEvent(new Event('budgetDataUpdated')); window.dispatchEvent(new Event('budgetDataUpdated'));
window.dispatchEvent(new Event('transactionAdded')); window.dispatchEvent(new Event('transactionAdded'));
window.dispatchEvent(new Event('transactionUpdated'));
} catch (error) { } catch (error) {
console.error('지출 추가 중 오류 발생:', error); console.error('지출 추가 중 오류 발생:', error);
toast({ toast({

View File

@@ -45,7 +45,7 @@ const MonthlyComparisonChart: React.FC<MonthlyComparisonChartProps> = ({
// 데이터 여부 확인 로직 개선 - 데이터가 비어있거나 모든 값이 0인 경우도 고려 // 데이터 여부 확인 로직 개선 - 데이터가 비어있거나 모든 값이 0인 경우도 고려
const hasValidData = monthlyData && const hasValidData = monthlyData &&
monthlyData.length > 0 && monthlyData.length > 0 &&
monthlyData.some(item => item.budget > 0 || item.expense > 0); monthlyData.some(item => (item.budget > 0 || item.expense > 0));
return ( return (
<div className="neuro-card h-72 w-full"> <div className="neuro-card h-72 w-full">

View File

@@ -76,9 +76,24 @@ const addToRemoveQueue = (toastId: string) => {
export const reducer = (state: State, action: Action): State => { export const reducer = (state: State, action: Action): State => {
switch (action.type) { switch (action.type) {
case "ADD_TOAST": case "ADD_TOAST":
// 동일한 내용의 토스트가 있으면 추가하지 않음
if (state.toasts.some(t =>
t.title === action.toast.title &&
t.description === action.toast.description &&
t.open === true
)) {
return state;
}
// 이전 토스트 모두 닫기
const updatedToasts = state.toasts.map(t => ({
...t,
open: false
}));
return { return {
...state, ...state,
toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT), toasts: [action.toast, ...updatedToasts].slice(0, TOAST_LIMIT),
} }
case "UPDATE_TOAST": case "UPDATE_TOAST":

View File

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