import React from 'react'; import { useForm } from 'react-hook-form'; import { Form, FormField, FormItem, FormLabel } from '@/components/ui/form'; import { Input } from '@/components/ui/input'; import { Button } from '@/components/ui/button'; import { Loader2 } from 'lucide-react'; import ExpenseCategorySelector from './ExpenseCategorySelector'; export interface ExpenseFormValues { title: string; amount: string; category: string; } interface ExpenseFormProps { onSubmit: (data: ExpenseFormValues) => void; onCancel: () => void; isSubmitting?: boolean; } const ExpenseForm: React.FC = ({ onSubmit, onCancel, isSubmitting = false }) => { const form = useForm({ defaultValues: { title: '', amount: '', category: '식비', } }); // Format number with commas const formatWithCommas = (value: string): string => { // Remove commas first to avoid duplicates when typing const numericValue = value.replace(/[^0-9]/g, ''); return numericValue.replace(/\B(?=(\d{3})+(?!\d))/g, ','); }; const handleAmountChange = (e: React.ChangeEvent) => { const formattedValue = formatWithCommas(e.target.value); form.setValue('amount', formattedValue); }; return (
( 제목 )} /> ( 금액 )} /> ( 카테고리 field.onChange(value)} /> )} />
); }; export default ExpenseForm;