import React from 'react'; import { FormField, FormItem, FormLabel, FormControl, FormMessage } from '@/components/ui/form'; import { Input } from '@/components/ui/input'; import { UseFormReturn } from 'react-hook-form'; import { z } from 'zod'; import { categoryIcons, EXPENSE_CATEGORIES } from '@/constants/categoryIcons'; // Form schema for validation - 카테고리를 3개로 제한 export const transactionFormSchema = z.object({ title: z.string().min(1, '제목을 입력해주세요'), amount: z.string().min(1, '금액을 입력해주세요'), category: z.enum(['식비', '생활비', '교통비']), }); export type TransactionFormValues = z.infer; // Function to format number with commas export const formatWithCommas = (value: string) => { const numericValue = value.replace(/[^0-9]/g, ''); return numericValue.replace(/\B(?=(\d{3})+(?!\d))/g, ','); }; interface TransactionFormFieldsProps { form: UseFormReturn; } const TransactionFormFields: React.FC = ({ form }) => { const handleAmountChange = (e: React.ChangeEvent) => { const formattedValue = formatWithCommas(e.target.value); form.setValue('amount', formattedValue); }; return ( <> ( 제목 )} /> ( 금액 )} /> ( 카테고리
{EXPENSE_CATEGORIES.map((category) => (
form.setValue('category', category as any)} >
{categoryIcons[category]}
{category}
))}
)} /> ); }; export default TransactionFormFields;