Enhance budget input UI

- Improve the '+' icon for budget modification.
- Display the sum of category budgets instead of an input field for the total budget.
- Change the wallet icon in budget input.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-17 12:17:32 +00:00
parent c7300bebb7
commit 236925f787
3 changed files with 54 additions and 24 deletions

View File

@@ -24,7 +24,7 @@ const BudgetCategoriesSection: React.FC<BudgetCategoriesSectionProps> = ({
const actualPercentage = category.total > 0 const actualPercentage = category.total > 0
? Math.round((category.current / category.total) * 100) ? Math.round((category.current / category.total) * 100)
: 0; : 0;
// 프로그레스 바용 퍼센트 (100%로 제한하지 않음) // 프로그레스 바용 퍼센트 - 제한 없이 실제 퍼센트 표시
const displayPercentage = actualPercentage; const displayPercentage = actualPercentage;
// 예산이 얼마 남지 않은 경우 (10% 미만) // 예산이 얼마 남지 않은 경우 (10% 미만)

View File

@@ -1,19 +1,23 @@
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { Plus, Wallet } from 'lucide-react'; import { CirclePlus, Save, Check } from 'lucide-react';
import BudgetInputCard from './BudgetInputCard'; import BudgetInputCard from './BudgetInputCard';
import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';
import CategoryBudgetInputs from './CategoryBudgetInputs'; import CategoryBudgetInputs from './CategoryBudgetInputs';
interface BudgetData { interface BudgetData {
targetAmount: number; targetAmount: number;
spentAmount: number; spentAmount: number;
remainingAmount: number; remainingAmount: number;
} }
interface BudgetTabContentProps { interface BudgetTabContentProps {
data: BudgetData; data: BudgetData;
formatCurrency: (amount: number) => string; formatCurrency: (amount: number) => string;
calculatePercentage: (spent: number, target: number) => number; calculatePercentage: (spent: number, target: number) => number;
onSaveBudget: (amount: number, categoryBudgets?: Record<string, number>) => void; onSaveBudget: (amount: number, categoryBudgets?: Record<string, number>) => void;
} }
const BudgetTabContent: React.FC<BudgetTabContentProps> = ({ const BudgetTabContent: React.FC<BudgetTabContentProps> = ({
data, data,
formatCurrency, formatCurrency,
@@ -22,8 +26,10 @@ const BudgetTabContent: React.FC<BudgetTabContentProps> = ({
}) => { }) => {
const [categoryBudgets, setCategoryBudgets] = useState<Record<string, number>>({}); const [categoryBudgets, setCategoryBudgets] = useState<Record<string, number>>({});
const [showBudgetInput, setShowBudgetInput] = useState(false); const [showBudgetInput, setShowBudgetInput] = useState(false);
const spentAmount = data.spentAmount; const spentAmount = data.spentAmount;
const targetAmount = data.targetAmount; const targetAmount = data.targetAmount;
// 실제 백분율 계산 (초과해도 실제 퍼센트로 표시) // 실제 백분율 계산 (초과해도 실제 퍼센트로 표시)
const actualPercentage = targetAmount > 0 ? Math.round(spentAmount / targetAmount * 100) : 0; const actualPercentage = targetAmount > 0 ? Math.round(spentAmount / targetAmount * 100) : 0;
const percentage = actualPercentage; const percentage = actualPercentage;
@@ -40,6 +46,7 @@ const BudgetTabContent: React.FC<BudgetTabContentProps> = ({
// 남은 예산 또는 초과 예산 텍스트 및 금액 // 남은 예산 또는 초과 예산 텍스트 및 금액
const budgetStatusText = isOverBudget ? '예산 초과: ' : '남은 예산: '; const budgetStatusText = isOverBudget ? '예산 초과: ' : '남은 예산: ';
const budgetAmount = isOverBudget ? formatCurrency(Math.abs(targetAmount - spentAmount)) : formatCurrency(Math.max(0, targetAmount - spentAmount)); const budgetAmount = isOverBudget ? formatCurrency(Math.abs(targetAmount - spentAmount)) : formatCurrency(Math.max(0, targetAmount - spentAmount));
const handleCategoryInputChange = (value: string, category: string) => { const handleCategoryInputChange = (value: string, category: string) => {
const numValue = parseInt(value, 10) || 0; const numValue = parseInt(value, 10) || 0;
setCategoryBudgets(prev => ({ setCategoryBudgets(prev => ({
@@ -47,6 +54,19 @@ const BudgetTabContent: React.FC<BudgetTabContentProps> = ({
[category]: numValue [category]: numValue
})); }));
}; };
// 카테고리별 예산 합계 계산
const calculateTotalBudget = () => {
return Object.values(categoryBudgets).reduce((sum, value) => sum + value, 0);
};
// 카테고리 예산 저장
const handleSaveCategoryBudgets = () => {
const totalBudget = calculateTotalBudget();
onSaveBudget(totalBudget, categoryBudgets);
setShowBudgetInput(false);
};
return <div> return <div>
{targetAmount > 0 ? <> {targetAmount > 0 ? <>
<div className="flex justify-between items-center mb-3"> <div className="flex justify-between items-center mb-3">
@@ -70,14 +90,24 @@ const BudgetTabContent: React.FC<BudgetTabContentProps> = ({
</div> </div>
<div className="mt-6"> <div className="mt-6">
<button onClick={() => setShowBudgetInput(true)} className="text-neuro-income hover:underline flex items-center text-base font-bold"> <button
<Plus size={16} className="mr-1" /> onClick={() => setShowBudgetInput(true)}
className="text-neuro-income hover:underline flex items-center text-base font-bold group"
>
<div className="mr-2 bg-neuro-income text-white rounded-full p-1 transition-transform group-hover:scale-110">
<CirclePlus size={20} className="animate-pulse" />
</div>
<span className="text-lg"> </span>
</button> </button>
</div> </div>
</> : <div className="py-4 text-center"> </> : <div className="py-4 text-center">
<div className="text-gray-400 mb-4"> </div> <div className="text-gray-400 mb-4"> </div>
<Button onClick={() => setShowBudgetInput(true)} variant="default" className="bg-neuro-income hover:bg-neuro-income/90 animate-pulse shadow-lg"> <Button
<Wallet className="mr-2" size={18} /> onClick={() => setShowBudgetInput(true)}
variant="default"
className="bg-neuro-income hover:bg-neuro-income/90 animate-pulse shadow-lg"
>
<CirclePlus className="mr-2" size={20} />
</Button> </Button>
</div>} </div>}
@@ -85,27 +115,27 @@ const BudgetTabContent: React.FC<BudgetTabContentProps> = ({
{showBudgetInput && <div className="mt-4"> {showBudgetInput && <div className="mt-4">
<div className="neuro-card p-4"> <div className="neuro-card p-4">
<div className="mb-4"> <div className="mb-4">
<h3 className="text-base font-medium mb-3"> </h3> <h3 className="text-base font-medium mb-3"> : {formatCurrency(calculateTotalBudget())}</h3>
<div className="flex items-center space-x-2">
<input type="text" className="w-full p-2 rounded neuro-pressed" placeholder="예산 금액 입력" value={targetAmount > 0 ? targetAmount : ''} onChange={e => {
const value = e.target.value.replace(/[^0-9]/g, '');
if (value) {
const amount = parseInt(value, 10);
onSaveBudget(amount, categoryBudgets);
}
}} />
<Button onClick={() => setShowBudgetInput(false)} size="icon" className="bg-neuro-income hover:bg-neuro-income/90 text-white">
<Wallet size={18} />
</Button>
</div>
</div> </div>
<div> <div>
<h3 className="text-base font-medium mb-3"> </h3> <h3 className="text-base font-medium mb-3"> </h3>
<CategoryBudgetInputs categoryBudgets={categoryBudgets} handleCategoryInputChange={handleCategoryInputChange} /> <CategoryBudgetInputs categoryBudgets={categoryBudgets} handleCategoryInputChange={handleCategoryInputChange} />
<div className="mt-4 flex justify-end">
<Button
onClick={handleSaveCategoryBudgets}
size="sm"
className="bg-neuro-income hover:bg-neuro-income/90 text-white"
>
<Check size={18} className="mr-1" />
</Button>
</div>
</div> </div>
</div> </div>
</div>} </div>}
</div>; </div>;
}; };
export default BudgetTabContent;
export default BudgetTabContent;

View File

@@ -35,15 +35,15 @@ const CategoryBudgetInputs: React.FC<CategoryBudgetInputsProps> = ({
}; };
return ( return (
<div className="space-y-2 w-full"> <div className="space-y-3 w-full">
{EXPENSE_CATEGORIES.map(category => ( {EXPENSE_CATEGORIES.map(category => (
<div key={category} className="flex items-center justify-between w-full"> <div key={category} className="flex items-center justify-between w-full p-2 neuro-pressed rounded-lg">
<label className="text-sm text-gray-600">{category}</label> <label className="text-sm font-medium text-gray-700">{category}</label>
<Input <Input
value={formatWithCommas(categoryBudgets[category] || 0)} value={formatWithCommas(categoryBudgets[category] || 0)}
onChange={(e) => handleInput(e, category)} onChange={(e) => handleInput(e, category)}
placeholder="예산 입력" placeholder="예산 입력"
className={`neuro-pressed transition-colors duration-300 ${isMobile ? 'w-[150px]' : 'max-w-[150px]'} text-xs`} className={`neuro-pressed transition-colors duration-300 ${isMobile ? 'w-[150px]' : 'max-w-[150px]'}`}
/> />
</div> </div>
))} ))}