Fix type errors in BudgetContext

Addresses type errors related to category budgets in BudgetContext and Index page. Specifically, ensures correct type assignment for category budget updates.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-15 10:54:24 +00:00
parent 53096ae26e
commit bbf0f75b66
4 changed files with 35 additions and 65 deletions

View File

@@ -6,6 +6,7 @@ import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/component
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;
@@ -13,17 +14,11 @@ interface BudgetData {
remainingAmount: number;
}
interface CategoryBudget {
식비: number;
생활비: number;
교통비: number;
}
interface BudgetTabContentProps {
data: BudgetData;
formatCurrency: (amount: number) => string;
calculatePercentage: (spent: number, target: number) => number;
onSaveBudget: (amount: number, categoryBudgets?: CategoryBudget) => void;
onSaveBudget: (amount: number, categoryBudgets?: Record<string, number>) => void;
}
const BudgetTabContent: React.FC<BudgetTabContentProps> = ({
@@ -40,13 +35,12 @@ const BudgetTabContent: React.FC<BudgetTabContentProps> = ({
const savedCategoryBudgets = localStorage.getItem('categoryBudgets');
const initialCategoryBudgets = savedCategoryBudgets
? JSON.parse(savedCategoryBudgets)
: {
식비: Math.round(data.targetAmount * 0.4),
생활비: Math.round(data.targetAmount * 0.4),
교통비: Math.round(data.targetAmount * 0.2)
};
: EXPENSE_CATEGORIES.reduce((acc, category) => {
acc[category] = Math.round(data.targetAmount / EXPENSE_CATEGORIES.length);
return acc;
}, {} as Record<string, number>);
const [categoryBudgets, setCategoryBudgets] = useState<CategoryBudget>(initialCategoryBudgets);
const [categoryBudgets, setCategoryBudgets] = useState<Record<string, number>>(initialCategoryBudgets);
const handleInputChange = (value: string) => {
// Remove all non-numeric characters
@@ -54,7 +48,7 @@ const BudgetTabContent: React.FC<BudgetTabContentProps> = ({
setBudgetInput(numericValue);
};
const handleCategoryInputChange = (value: string, category: keyof CategoryBudget) => {
const handleCategoryInputChange = (value: string, category: string) => {
// Remove all non-numeric characters
const numericValue = value.replace(/[^0-9]/g, '');
setCategoryBudgets(prev => ({