feat: Implement budget edit functionality

When the "Edit Budget" button is clicked, display a popup similar to the expense input form for budget modification.
This commit is contained in:
gpt-engineer-app[bot]
2025-04-05 05:41:15 +00:00
parent 45df7c368a
commit 62551d58e3
5 changed files with 159 additions and 105 deletions

View File

@@ -16,8 +16,6 @@ interface UseBudgetTabContentProps {
interface UseBudgetTabContentReturn {
categoryBudgets: Record<string, number>;
showBudgetInput: boolean;
toggleBudgetInput: () => void;
handleCategoryInputChange: (value: string, category: string) => void;
handleSaveCategoryBudgets: () => void;
isBudgetSet: boolean;
@@ -38,7 +36,6 @@ export const useBudgetTabContent = ({
onSaveBudget
}: UseBudgetTabContentProps): UseBudgetTabContentReturn => {
const [categoryBudgets, setCategoryBudgets] = useState<Record<string, number>>({});
const [showBudgetInput, setShowBudgetInput] = useState(false);
const spentAmount = data.spentAmount;
const targetAmount = data.targetAmount;
@@ -55,7 +52,7 @@ export const useBudgetTabContent = ({
window.addEventListener('budgetDataUpdated', handleBudgetDataUpdated);
return () => window.removeEventListener('budgetDataUpdated', handleBudgetDataUpdated);
}, [showBudgetInput, targetAmount]);
}, [targetAmount]);
// 예산 설정 여부 확인 - 데이터 targetAmount가 실제로 0보다 큰지 확인
const isBudgetSet = targetAmount > 0;
@@ -112,7 +109,6 @@ export const useBudgetTabContent = ({
if (totalBudget > 0) {
// 명시적으로 월간 예산으로 설정 - 항상 월간 예산만 저장
onSaveBudget(totalBudget, updatedCategoryBudgets);
setShowBudgetInput(false);
// 이벤트 발생 추가 (데이터 저장 후 즉시 UI 업데이트를 위해)
setTimeout(() => {
@@ -126,26 +122,18 @@ export const useBudgetTabContent = ({
// 기존 카테고리 예산 불러오기
useEffect(() => {
if (showBudgetInput) {
// 로컬 스토리지에서 카테고리 예산 불러오기
try {
const storedCategoryBudgets = localStorage.getItem('categoryBudgets');
if (storedCategoryBudgets) {
const parsedBudgets = JSON.parse(storedCategoryBudgets);
console.log('저장된 카테고리 예산 불러옴:', parsedBudgets);
setCategoryBudgets(parsedBudgets);
}
} catch (error) {
console.error('카테고리 예산 불러오기 오류:', error);
// 로컬 스토리지에서 카테고리 예산 불러오기
try {
const storedCategoryBudgets = localStorage.getItem('categoryBudgets');
if (storedCategoryBudgets) {
const parsedBudgets = JSON.parse(storedCategoryBudgets);
console.log('저장된 카테고리 예산 불러옴:', parsedBudgets);
setCategoryBudgets(parsedBudgets);
}
} catch (error) {
console.error('카테고리 예산 불러오기 오류:', error);
}
}, [showBudgetInput]);
// 예산 버튼 클릭 핸들러 - 토글 기능 추가
const toggleBudgetInput = () => {
console.log('예산 입력 폼 토글. 현재 상태:', showBudgetInput, '예산 설정 여부:', isBudgetSet);
setShowBudgetInput(prev => !prev);
};
}, []);
// 예산 여부에 따른 텍스트 결정
const budgetButtonText = isBudgetSet ? "예산 수정하기" : "예산 입력하기";
@@ -155,8 +143,6 @@ export const useBudgetTabContent = ({
return {
categoryBudgets,
showBudgetInput,
toggleBudgetInput,
handleCategoryInputChange,
handleSaveCategoryBudgets,
isBudgetSet,