Fix budget display issues
The budget was not being displayed correctly in the spending and analytics screens, as well as the weekly and monthly views on the home screen. This commit addresses these issues.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Check, ChevronDown, ChevronUp, Calculator } from 'lucide-react';
|
||||
@@ -6,17 +7,20 @@ 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<string, number>) => void;
|
||||
}
|
||||
|
||||
const BudgetTabContent: React.FC<BudgetTabContentProps> = ({
|
||||
data,
|
||||
formatCurrency,
|
||||
@@ -34,12 +38,15 @@ const BudgetTabContent: React.FC<BudgetTabContentProps> = ({
|
||||
acc[category] = defaultCategoryAmount;
|
||||
return acc;
|
||||
}, {} as Record<string, number>);
|
||||
|
||||
const [categoryBudgets, setCategoryBudgets] = useState<Record<string, number>>(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, '');
|
||||
@@ -48,6 +55,7 @@ const BudgetTabContent: React.FC<BudgetTabContentProps> = ({
|
||||
[category]: parseInt(numericValue) || 0
|
||||
}));
|
||||
};
|
||||
|
||||
const handleSave = () => {
|
||||
// Calculate total from all categories
|
||||
const totalAmount = Object.values(categoryBudgets).reduce((sum, value) => sum + value, 0);
|
||||
@@ -65,8 +73,15 @@ const BudgetTabContent: React.FC<BudgetTabContentProps> = ({
|
||||
const formatWithCommas = (amount: string) => {
|
||||
return amount.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||
};
|
||||
return <div className="space-y-4">
|
||||
<BudgetProgress spentAmount={data.spentAmount} targetAmount={data.targetAmount} percentage={percentage} formatCurrency={formatCurrency} />
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<BudgetProgress
|
||||
spentAmount={data.spentAmount}
|
||||
targetAmount={data.targetAmount}
|
||||
percentage={percentage}
|
||||
formatCurrency={formatCurrency}
|
||||
/>
|
||||
|
||||
<div className="flex justify-between items-center pt-2 border-t border-gray-100">
|
||||
<span className="text-gray-500 text-sm">남은 예산</span>
|
||||
@@ -81,7 +96,10 @@ const BudgetTabContent: React.FC<BudgetTabContentProps> = ({
|
||||
</CollapsibleTrigger>
|
||||
|
||||
<CollapsibleContent className="pt-2 space-y-3">
|
||||
<CategoryBudgetInputs categoryBudgets={categoryBudgets} handleCategoryInputChange={handleCategoryInputChange} />
|
||||
<CategoryBudgetInputs
|
||||
categoryBudgets={categoryBudgets}
|
||||
handleCategoryInputChange={handleCategoryInputChange}
|
||||
/>
|
||||
|
||||
<div className="flex items-center justify-between pt-2 border-t border-gray-100">
|
||||
<div className="flex items-center gap-1">
|
||||
@@ -102,6 +120,8 @@ const BudgetTabContent: React.FC<BudgetTabContentProps> = ({
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
</div>
|
||||
</div>;
|
||||
</div>
|
||||
);
|
||||
};
|
||||
export default BudgetTabContent;
|
||||
|
||||
export default BudgetTabContent;
|
||||
|
||||
Reference in New Issue
Block a user