Fix budget display issues
Addresses issues where budget data wasn't displaying correctly after input and ensures correct automatic calculation of daily/weekly budgets from monthly input.
This commit is contained in:
@@ -34,7 +34,7 @@ const BudgetTabContent: React.FC<BudgetTabContentProps> = ({
|
||||
const percentage = actualPercentage;
|
||||
|
||||
// 예산이 설정되었는지 여부 확인 (정확히 0이면 미설정으로 간주)
|
||||
const isBudgetSet = targetAmount !== 0;
|
||||
const isBudgetSet = targetAmount > 0;
|
||||
|
||||
// 예산 초과 여부 계산
|
||||
const isOverBudget = spentAmount > targetAmount && targetAmount > 0;
|
||||
|
||||
@@ -92,6 +92,7 @@ export const calculateUpdatedBudgetData = (
|
||||
|
||||
console.log(`최종 예산 계산: 월간=${monthlyAmount}원, 주간=${weeklyAmount}원, 일일=${dailyAmount}원`);
|
||||
|
||||
// 새로운 BudgetData를 생성하되, 기존의 spentAmount는 유지합니다
|
||||
return {
|
||||
daily: {
|
||||
targetAmount: dailyAmount,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { BudgetData, BudgetPeriod } from '../types';
|
||||
import {
|
||||
@@ -98,7 +99,7 @@ export const useBudgetDataState = (transactions: Transaction[]) => {
|
||||
newCategoryBudgets?: Record<string, number>
|
||||
) => {
|
||||
try {
|
||||
console.log(`예산 목표 업데이트: ${type}, 금액: ${amount}`);
|
||||
console.log(`예산 목표 업데이트 시작: ${type}, 금액: ${amount}`);
|
||||
|
||||
// 금액이 유효한지 확인
|
||||
if (isNaN(amount) || amount <= 0) {
|
||||
@@ -113,7 +114,7 @@ export const useBudgetDataState = (transactions: Transaction[]) => {
|
||||
|
||||
// 예산 데이터 업데이트 - 일간, 주간, 월간 예산이 모두 자동으로 계산됨
|
||||
const updatedBudgetData = calculateUpdatedBudgetData(budgetData, type, amount);
|
||||
console.log('새 예산 데이터:', updatedBudgetData);
|
||||
console.log('새 예산 데이터 계산됨:', updatedBudgetData);
|
||||
|
||||
// 상태 및 스토리지 둘 다 업데이트
|
||||
setBudgetData(updatedBudgetData);
|
||||
@@ -122,10 +123,16 @@ export const useBudgetDataState = (transactions: Transaction[]) => {
|
||||
// 저장 시간 업데이트
|
||||
localStorage.setItem('lastBudgetSaveTime', new Date().toISOString());
|
||||
|
||||
// 이벤트 발생시켜 다른 컴포넌트에 알림
|
||||
window.dispatchEvent(new Event('budgetDataUpdated'));
|
||||
|
||||
console.log('예산 목표 업데이트 완료:', updatedBudgetData);
|
||||
|
||||
// 성공 메시지 표시
|
||||
const periodText = type === 'daily' ? '일일' : type === 'weekly' ? '주간' : '월간';
|
||||
toast({
|
||||
title: "예산 설정 완료",
|
||||
description: `${type === 'daily' ? '일일' : type === 'weekly' ? '주간' : '월간'} 예산이 ${amount.toLocaleString()}원으로 설정되었습니다.`,
|
||||
description: `${periodText} 예산이 ${amount.toLocaleString()}원으로 설정되었습니다.`,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('예산 목표 업데이트 중 오류:', error);
|
||||
|
||||
@@ -86,6 +86,13 @@ export const useExtendedBudgetUpdate = (
|
||||
}
|
||||
|
||||
handleBudgetGoalUpdate(type, amount);
|
||||
|
||||
// 성공 토스트 표시
|
||||
const periodText = type === 'daily' ? '일일' : type === 'weekly' ? '주간' : '월간';
|
||||
toast({
|
||||
title: "예산 설정 완료",
|
||||
description: `${periodText} 예산이 ${amount.toLocaleString()}원으로 설정되었습니다.`
|
||||
});
|
||||
}
|
||||
}, [categoryBudgets, handleBudgetGoalUpdate, updateCategoryBudgets]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user