Revert previous changes
Reverting the previous commit due to unresolved issues.
This commit is contained in:
@@ -17,34 +17,37 @@ export const useExtendedBudgetUpdate = (
|
||||
amount: number,
|
||||
newCategoryBudgets?: Record<string, number>
|
||||
) => {
|
||||
console.log(`확장된 예산 목표 업데이트: ${type}, 금액: ${amount}`, newCategoryBudgets);
|
||||
console.log(`확장된 예산 목표 업데이트: ${type}, 금액: ${amount}, 카테고리 예산:`, newCategoryBudgets);
|
||||
|
||||
// 카테고리 예산이 제공된 경우 업데이트
|
||||
if (newCategoryBudgets) {
|
||||
try {
|
||||
// 카테고리명 표준화 처리
|
||||
let updatedCategoryBudgets = { ...newCategoryBudgets };
|
||||
|
||||
// 교통비 값이 있으면 교통으로 통합
|
||||
if (newCategoryBudgets['교통비'] && !newCategoryBudgets['교통']) {
|
||||
newCategoryBudgets['교통'] = newCategoryBudgets['교통비'];
|
||||
delete newCategoryBudgets['교통비'];
|
||||
if (updatedCategoryBudgets['교통비'] && !updatedCategoryBudgets['교통']) {
|
||||
updatedCategoryBudgets['교통'] = updatedCategoryBudgets['교통비'];
|
||||
delete updatedCategoryBudgets['교통비'];
|
||||
}
|
||||
|
||||
// 식비 값이 있으면 음식으로 통합
|
||||
if (newCategoryBudgets['식비'] && !newCategoryBudgets['음식']) {
|
||||
newCategoryBudgets['음식'] = newCategoryBudgets['식비'];
|
||||
delete newCategoryBudgets['식비'];
|
||||
if (updatedCategoryBudgets['식비'] && !updatedCategoryBudgets['음식']) {
|
||||
updatedCategoryBudgets['음식'] = updatedCategoryBudgets['식비'];
|
||||
delete updatedCategoryBudgets['식비'];
|
||||
}
|
||||
|
||||
// 생활비 값이 있으면 쇼핑으로 통합
|
||||
if (newCategoryBudgets['생활비'] && !newCategoryBudgets['쇼핑']) {
|
||||
newCategoryBudgets['쇼핑'] = newCategoryBudgets['생활비'];
|
||||
delete newCategoryBudgets['생활비'];
|
||||
if (updatedCategoryBudgets['생활비'] && !updatedCategoryBudgets['쇼핑']) {
|
||||
updatedCategoryBudgets['쇼핑'] = updatedCategoryBudgets['생활비'];
|
||||
delete updatedCategoryBudgets['생활비'];
|
||||
}
|
||||
|
||||
// 카테고리 예산 저장
|
||||
updateCategoryBudgets(newCategoryBudgets);
|
||||
updateCategoryBudgets(updatedCategoryBudgets);
|
||||
|
||||
// 총액 계산 (0 확인)
|
||||
const totalAmount = Object.values(newCategoryBudgets).reduce((sum, val) => sum + val, 0);
|
||||
const totalAmount = Object.values(updatedCategoryBudgets).reduce((sum, val) => sum + val, 0);
|
||||
console.log('카테고리 총액:', totalAmount);
|
||||
|
||||
if (totalAmount <= 0) {
|
||||
@@ -60,11 +63,19 @@ export const useExtendedBudgetUpdate = (
|
||||
// 월간 예산을 설정하면 자동으로 일간/주간 예산도 계산됨
|
||||
handleBudgetGoalUpdate('monthly', totalAmount);
|
||||
|
||||
// 명시적으로 BudgetData 업데이트 이벤트 발생
|
||||
window.dispatchEvent(new Event('budgetDataUpdated'));
|
||||
|
||||
// 성공 토스트 표시
|
||||
toast({
|
||||
title: "카테고리 예산 설정 완료",
|
||||
description: `월간 총 예산이 ${totalAmount.toLocaleString()}원으로 설정되었습니다.`
|
||||
});
|
||||
|
||||
// 1초 후 페이지 리프레시 (데이터 표시 강제 갱신)
|
||||
setTimeout(() => {
|
||||
window.dispatchEvent(new Event('budgetDataUpdated'));
|
||||
}, 1000);
|
||||
} catch (error) {
|
||||
console.error('카테고리 예산 업데이트 오류:', error);
|
||||
toast({
|
||||
@@ -87,12 +98,20 @@ export const useExtendedBudgetUpdate = (
|
||||
|
||||
handleBudgetGoalUpdate(type, amount);
|
||||
|
||||
// 명시적으로 BudgetData 업데이트 이벤트 발생
|
||||
window.dispatchEvent(new Event('budgetDataUpdated'));
|
||||
|
||||
// 성공 토스트 표시
|
||||
const periodText = type === 'daily' ? '일일' : type === 'weekly' ? '주간' : '월간';
|
||||
toast({
|
||||
title: "예산 설정 완료",
|
||||
description: `${periodText} 예산이 ${amount.toLocaleString()}원으로 설정되었습니다.`
|
||||
});
|
||||
|
||||
// 1초 후 페이지 리프레시 (데이터 표시 강제 갱신)
|
||||
setTimeout(() => {
|
||||
window.dispatchEvent(new Event('budgetDataUpdated'));
|
||||
}, 1000);
|
||||
}
|
||||
}, [categoryBudgets, handleBudgetGoalUpdate, updateCategoryBudgets]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user