Investigate default value for number inputs
The prompt asks to investigate the current default value (0) for number input fields and consider alternative approaches based on other applications.
This commit is contained in:
@@ -21,9 +21,9 @@ const BudgetInputCard: React.FC<BudgetGoalProps> = ({
|
||||
}) => {
|
||||
const [selectedTab, setSelectedTab] = useState<'daily' | 'weekly' | 'monthly'>('daily');
|
||||
const [budgetInputs, setBudgetInputs] = useState({
|
||||
daily: initialBudgets.daily.toString(),
|
||||
weekly: initialBudgets.weekly.toString(),
|
||||
monthly: initialBudgets.monthly.toString()
|
||||
daily: initialBudgets.daily > 0 ? initialBudgets.daily.toString() : '',
|
||||
weekly: initialBudgets.weekly > 0 ? initialBudgets.weekly.toString() : '',
|
||||
monthly: initialBudgets.monthly > 0 ? initialBudgets.monthly.toString() : ''
|
||||
});
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
|
||||
@@ -36,9 +36,9 @@ const BudgetInputCard: React.FC<BudgetGoalProps> = ({
|
||||
|
||||
useEffect(() => {
|
||||
setBudgetInputs({
|
||||
daily: initialBudgets.daily.toString(),
|
||||
weekly: initialBudgets.weekly.toString(),
|
||||
monthly: initialBudgets.monthly.toString()
|
||||
daily: initialBudgets.daily > 0 ? initialBudgets.daily.toString() : '',
|
||||
weekly: initialBudgets.weekly > 0 ? initialBudgets.weekly.toString() : '',
|
||||
monthly: initialBudgets.monthly > 0 ? initialBudgets.monthly.toString() : ''
|
||||
});
|
||||
}, [initialBudgets]);
|
||||
|
||||
@@ -58,6 +58,18 @@ const BudgetInputCard: React.FC<BudgetGoalProps> = ({
|
||||
setIsOpen(false);
|
||||
};
|
||||
|
||||
// 비어있으면 빈 문자열을, 그렇지 않으면 포맷팅된 문자열을 반환
|
||||
const getDisplayValue = (type: 'daily' | 'weekly' | 'monthly') => {
|
||||
return budgetInputs[type] === '' ? '' : formatWithCommas(budgetInputs[type]);
|
||||
};
|
||||
|
||||
// 금액을 표시할 때 0원이면 '설정되지 않음'으로 표시
|
||||
const getGoalDisplayText = (type: 'daily' | 'weekly' | 'monthly') => {
|
||||
const amount = parseInt(budgetInputs[type].replace(/,/g, ''), 10) || 0;
|
||||
if (amount === 0) return '설정되지 않음';
|
||||
return formatWithCommas(budgetInputs[type]) + '원';
|
||||
};
|
||||
|
||||
return (
|
||||
<Collapsible
|
||||
open={isOpen}
|
||||
@@ -84,7 +96,7 @@ const BudgetInputCard: React.FC<BudgetGoalProps> = ({
|
||||
<TabsContent value="daily" className="space-y-4 mt-0">
|
||||
<div className="flex items-center space-x-2">
|
||||
<Input
|
||||
value={formatWithCommas(budgetInputs.daily)}
|
||||
value={getDisplayValue('daily')}
|
||||
onChange={e => handleInputChange(e.target.value, 'daily')}
|
||||
placeholder="목표 금액 입력"
|
||||
className="neuro-pressed"
|
||||
@@ -93,13 +105,15 @@ const BudgetInputCard: React.FC<BudgetGoalProps> = ({
|
||||
<Check size={18} />
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-xs text-gray-500">현재 일일 목표: {formatWithCommas(budgetInputs.daily)}원</p>
|
||||
<p className="text-xs text-gray-500">
|
||||
현재 일일 목표: {getGoalDisplayText('daily')}
|
||||
</p>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="weekly" className="space-y-4 mt-0">
|
||||
<div className="flex items-center space-x-2">
|
||||
<Input
|
||||
value={formatWithCommas(budgetInputs.weekly)}
|
||||
value={getDisplayValue('weekly')}
|
||||
onChange={e => handleInputChange(e.target.value, 'weekly')}
|
||||
placeholder="목표 금액 입력"
|
||||
className="neuro-pressed"
|
||||
@@ -108,13 +122,15 @@ const BudgetInputCard: React.FC<BudgetGoalProps> = ({
|
||||
<Check size={18} />
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-xs text-gray-500">현재 주간 목표: {formatWithCommas(budgetInputs.weekly)}원</p>
|
||||
<p className="text-xs text-gray-500">
|
||||
현재 주간 목표: {getGoalDisplayText('weekly')}
|
||||
</p>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="monthly" className="space-y-4 mt-0">
|
||||
<div className="flex items-center space-x-2">
|
||||
<Input
|
||||
value={formatWithCommas(budgetInputs.monthly)}
|
||||
value={getDisplayValue('monthly')}
|
||||
onChange={e => handleInputChange(e.target.value, 'monthly')}
|
||||
placeholder="목표 금액 입력"
|
||||
className="neuro-pressed"
|
||||
@@ -123,7 +139,9 @@ const BudgetInputCard: React.FC<BudgetGoalProps> = ({
|
||||
<Check size={18} />
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-xs text-gray-500">현재 월간 목표: {formatWithCommas(budgetInputs.monthly)}원</p>
|
||||
<p className="text-xs text-gray-500">
|
||||
현재 월간 목표: {getGoalDisplayText('monthly')}
|
||||
</p>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</CollapsibleContent>
|
||||
|
||||
@@ -29,14 +29,16 @@ const BudgetTabContent: React.FC<BudgetTabContentProps> = ({
|
||||
}) => {
|
||||
const percentage = calculatePercentage(data.spentAmount, data.targetAmount);
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [budgetInput, setBudgetInput] = useState(data.targetAmount.toString());
|
||||
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] = Math.round(data.targetAmount / EXPENSE_CATEGORIES.length);
|
||||
acc[category] = defaultCategoryAmount;
|
||||
return acc;
|
||||
}, {} as Record<string, number>);
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ const CategoryBudgetInputs: React.FC<CategoryBudgetInputsProps> = ({
|
||||
}) => {
|
||||
// Format number with commas for display
|
||||
const formatWithCommas = (value: number): string => {
|
||||
if (value === 0) return '';
|
||||
return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||
};
|
||||
|
||||
@@ -31,7 +32,8 @@ const CategoryBudgetInputs: React.FC<CategoryBudgetInputsProps> = ({
|
||||
<label className="text-sm text-gray-600">{category}</label>
|
||||
<Input
|
||||
value={formatWithCommas(categoryBudgets[category] || 0)}
|
||||
onChange={(e) => handleInput(e, category)}
|
||||
onChange={(e) => handleInput(e, category)}
|
||||
placeholder="예산 입력"
|
||||
className="neuro-pressed max-w-[150px]"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -59,7 +59,7 @@ const ExpenseForm: React.FC<ExpenseFormProps> = ({ onSubmit, onCancel }) => {
|
||||
<FormItem>
|
||||
<FormLabel>금액</FormLabel>
|
||||
<Input
|
||||
placeholder="0"
|
||||
placeholder="금액을 입력하세요"
|
||||
value={field.value}
|
||||
onChange={handleAmountChange}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user