diff --git a/src/components/BudgetTabContent.tsx b/src/components/BudgetTabContent.tsx index 04aff15..ce8ae3d 100644 --- a/src/components/BudgetTabContent.tsx +++ b/src/components/BudgetTabContent.tsx @@ -1,4 +1,3 @@ - import React, { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Check, ChevronDown, ChevronUp, Calculator } from 'lucide-react'; @@ -7,20 +6,17 @@ import BudgetProgress from './BudgetProgress'; import CategoryBudgetInputs from './CategoryBudgetInputs'; import { toast } from '@/components/ui/use-toast'; import { EXPENSE_CATEGORIES } from '@/constants/categoryIcons'; - interface BudgetData { targetAmount: number; spentAmount: number; remainingAmount: number; } - interface BudgetTabContentProps { data: BudgetData; formatCurrency: (amount: number) => string; calculatePercentage: (spent: number, target: number) => number; onSaveBudget: (amount: number, categoryBudgets?: Record) => void; } - const BudgetTabContent: React.FC = ({ data, formatCurrency, @@ -30,26 +26,20 @@ const BudgetTabContent: React.FC = ({ const percentage = calculatePercentage(data.spentAmount, data.targetAmount); const [isOpen, setIsOpen] = useState(false); const [budgetInput, setBudgetInput] = useState(data.targetAmount > 0 ? data.targetAmount.toString() : ''); - + // 저장된 카테고리 예산을 불러옵니다 const savedCategoryBudgets = localStorage.getItem('categoryBudgets'); const defaultCategoryAmount = data.targetAmount > 0 ? Math.round(data.targetAmount / EXPENSE_CATEGORIES.length) : 0; - - const initialCategoryBudgets = savedCategoryBudgets - ? JSON.parse(savedCategoryBudgets) - : EXPENSE_CATEGORIES.reduce((acc, category) => { - acc[category] = defaultCategoryAmount; - return acc; - }, {} as Record); - + const initialCategoryBudgets = savedCategoryBudgets ? JSON.parse(savedCategoryBudgets) : EXPENSE_CATEGORIES.reduce((acc, category) => { + acc[category] = defaultCategoryAmount; + return acc; + }, {} as Record); const [categoryBudgets, setCategoryBudgets] = useState>(initialCategoryBudgets); - const handleInputChange = (value: string) => { // Remove all non-numeric characters const numericValue = value.replace(/[^0-9]/g, ''); setBudgetInput(numericValue); }; - const handleCategoryInputChange = (value: string, category: string) => { // Remove all non-numeric characters const numericValue = value.replace(/[^0-9]/g, ''); @@ -58,19 +48,16 @@ const BudgetTabContent: React.FC = ({ [category]: parseInt(numericValue) || 0 })); }; - const handleSave = () => { // Calculate total from all categories const totalAmount = Object.values(categoryBudgets).reduce((sum, value) => sum + value, 0); - + // 카테고리 예산도 함께 전달합니다 onSaveBudget(totalAmount, categoryBudgets); - toast({ title: "예산 설정 완료", - description: "카테고리별 예산이 성공적으로 저장되었습니다.", + description: "카테고리별 예산이 성공적으로 저장되었습니다." }); - setIsOpen(false); }; @@ -78,7 +65,6 @@ const BudgetTabContent: React.FC = ({ const formatWithCommas = (amount: string) => { return amount.replace(/\B(?=(\d{3})+(?!\d))/g, ','); }; - return
@@ -90,7 +76,7 @@ const BudgetTabContent: React.FC = ({
- 카테고리별 예산 설정하기 + 예산 설정하기 {isOpen ? : } @@ -118,5 +104,4 @@ const BudgetTabContent: React.FC = ({
; }; - -export default BudgetTabContent; +export default BudgetTabContent; \ No newline at end of file