Files
zellyy-finance/src/contexts/budget/hooks/useExtendedBudgetUpdate.ts
gpt-engineer-app[bot] ef239e6126 Fix budget display and button
- Fix the budget display issue where monthly budgets were showing four amounts instead of one.
- Resolve the functionality of the "Edit Budget" button.
2025-03-22 11:08:04 +00:00

42 lines
1.3 KiB
TypeScript

import { BudgetPeriod } from '../types';
/**
* 예산 목표 업데이트 확장 함수를 제공하는 훅
* 예산 목표 업데이트와 카테고리 예산 업데이트를 통합합니다.
*/
export const useExtendedBudgetUpdate = (
handleBudgetUpdate: (type: BudgetPeriod, amount: number) => void,
setCategoryBudgets: (budgets: Record<string, number>) => void
) => {
// 예산 목표 업데이트 확장 함수
const extendedBudgetUpdate = (
type: BudgetPeriod,
amount: number,
newCategoryBudgets?: Record<string, number>
) => {
console.log('확장 예산 업데이트 시작:', type, amount, newCategoryBudgets);
// 기본 예산 목표 업데이트
handleBudgetUpdate(type, amount);
// 카테고리 예산 업데이트 (제공된 경우)
if (newCategoryBudgets) {
console.log('카테고리 예산 업데이트:', newCategoryBudgets);
setCategoryBudgets(newCategoryBudgets);
// 카테고리 예산 업데이트 이벤트 발생
setTimeout(() => {
window.dispatchEvent(new Event('categoryBudgetsUpdated'));
}, 100);
}
// 모든 업데이트가 완료된 후 전역 예산 데이터 업데이트 이벤트 발생
setTimeout(() => {
window.dispatchEvent(new Event('budgetDataUpdated'));
}, 200);
};
return extendedBudgetUpdate;
};