Implement category selection in expense form

The category field in the expense input form is now implemented as a selection between three options.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-15 03:02:56 +00:00
parent 77a966c87c
commit 1ce5e3927c

View File

@@ -8,6 +8,7 @@ import { Form, FormField, FormItem, FormLabel, FormControl } from './ui/form';
import { Input } from './ui/input'; import { Input } from './ui/input';
import { Button } from './ui/button'; import { Button } from './ui/button';
import { useForm } from 'react-hook-form'; import { useForm } from 'react-hook-form';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from './ui/select';
interface ExpenseFormValues { interface ExpenseFormValues {
title: string; title: string;
@@ -15,6 +16,8 @@ interface ExpenseFormValues {
category: string; category: string;
} }
const EXPENSE_CATEGORIES = ['식비', '교통비', '생활비'];
const AddTransactionButton = () => { const AddTransactionButton = () => {
const [showExpenseDialog, setShowExpenseDialog] = useState(false); const [showExpenseDialog, setShowExpenseDialog] = useState(false);
const navigate = useNavigate(); const navigate = useNavigate();
@@ -89,12 +92,23 @@ const AddTransactionButton = () => {
render={({ field }) => ( render={({ field }) => (
<FormItem> <FormItem>
<FormLabel></FormLabel> <FormLabel></FormLabel>
<FormControl> <Select
<Input onValueChange={field.onChange}
placeholder="카테고리" defaultValue={field.value}
{...field} >
/> <FormControl>
</FormControl> <SelectTrigger>
<SelectValue placeholder="카테고리 선택" />
</SelectTrigger>
</FormControl>
<SelectContent>
{EXPENSE_CATEGORIES.map((category) => (
<SelectItem key={category} value={category}>
{category}
</SelectItem>
))}
</SelectContent>
</Select>
</FormItem> </FormItem>
)} )}
/> />