Refactor payment method selection
Refactored the payment method selection to use a button-style interface with icons and smaller font size.
This commit is contained in:
@@ -4,12 +4,11 @@ import { useForm } from 'react-hook-form';
|
|||||||
import { Form, FormField, FormItem, FormLabel } from '@/components/ui/form';
|
import { Form, FormField, FormItem, FormLabel } from '@/components/ui/form';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Loader2 } from 'lucide-react';
|
import { Loader2, CreditCard, Banknote } from 'lucide-react';
|
||||||
import ExpenseCategorySelector from './ExpenseCategorySelector';
|
import ExpenseCategorySelector from './ExpenseCategorySelector';
|
||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
import { getPersonalizedTitleSuggestions } from '@/utils/userTitlePreferences';
|
import { getPersonalizedTitleSuggestions } from '@/utils/userTitlePreferences';
|
||||||
import { Separator } from '@/components/ui/separator';
|
import { Separator } from '@/components/ui/separator';
|
||||||
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group';
|
|
||||||
|
|
||||||
export interface ExpenseFormValues {
|
export interface ExpenseFormValues {
|
||||||
title: string;
|
title: string;
|
||||||
@@ -36,6 +35,7 @@ const ExpenseForm: React.FC<ExpenseFormProps> = ({ onSubmit, onCancel, isSubmitt
|
|||||||
|
|
||||||
// 현재 선택된 카테고리 가져오기
|
// 현재 선택된 카테고리 가져오기
|
||||||
const selectedCategory = form.watch('category');
|
const selectedCategory = form.watch('category');
|
||||||
|
const selectedPaymentMethod = form.watch('paymentMethod');
|
||||||
|
|
||||||
// 선택된 카테고리에 대한 개인화된 제목 제안 목록 상태
|
// 선택된 카테고리에 대한 개인화된 제목 제안 목록 상태
|
||||||
const [titleSuggestions, setTitleSuggestions] = useState<string[]>([]);
|
const [titleSuggestions, setTitleSuggestions] = useState<string[]>([]);
|
||||||
@@ -137,29 +137,37 @@ const ExpenseForm: React.FC<ExpenseFormProps> = ({ onSubmit, onCancel, isSubmitt
|
|||||||
{/* 구분선 추가 */}
|
{/* 구분선 추가 */}
|
||||||
<Separator className="my-2" />
|
<Separator className="my-2" />
|
||||||
|
|
||||||
{/* 지출 방법 필드 추가 */}
|
{/* 지출 방법 필드 수정 - 버튼 형식으로 변경 */}
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="paymentMethod"
|
name="paymentMethod"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>지출 방법</FormLabel>
|
<FormLabel>지출 방법</FormLabel>
|
||||||
<RadioGroup
|
<div className="grid grid-cols-2 gap-3">
|
||||||
onValueChange={field.onChange}
|
<div
|
||||||
defaultValue={field.value}
|
className={`flex items-center justify-center gap-2 p-2 rounded-md cursor-pointer border transition-colors ${
|
||||||
className="flex gap-4"
|
field.value === '신용카드'
|
||||||
value={field.value}
|
? 'border-neuro-income bg-neuro-income/10'
|
||||||
disabled={isSubmitting}
|
: 'border-gray-200 hover:bg-gray-50'
|
||||||
|
} ${isSubmitting ? 'opacity-50 cursor-not-allowed' : ''}`}
|
||||||
|
onClick={() => !isSubmitting && form.setValue('paymentMethod', '신용카드')}
|
||||||
>
|
>
|
||||||
<div className="flex items-center space-x-2">
|
<CreditCard size={16} className="text-neuro-income" />
|
||||||
<RadioGroupItem value="신용카드" id="credit-card" />
|
<span className="text-sm">신용카드</span>
|
||||||
<label htmlFor="credit-card" className="cursor-pointer">신용카드</label>
|
</div>
|
||||||
|
<div
|
||||||
|
className={`flex items-center justify-center gap-2 p-2 rounded-md cursor-pointer border transition-colors ${
|
||||||
|
field.value === '현금'
|
||||||
|
? 'border-neuro-income bg-neuro-income/10'
|
||||||
|
: 'border-gray-200 hover:bg-gray-50'
|
||||||
|
} ${isSubmitting ? 'opacity-50 cursor-not-allowed' : ''}`}
|
||||||
|
onClick={() => !isSubmitting && form.setValue('paymentMethod', '현금')}
|
||||||
|
>
|
||||||
|
<Banknote size={16} className="text-neuro-income" />
|
||||||
|
<span className="text-sm">현금</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center space-x-2">
|
|
||||||
<RadioGroupItem value="현금" id="cash" />
|
|
||||||
<label htmlFor="cash" className="cursor-pointer">현금</label>
|
|
||||||
</div>
|
</div>
|
||||||
</RadioGroup>
|
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { categoryIcons, EXPENSE_CATEGORIES } from '@/constants/categoryIcons';
|
|||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
import { getPersonalizedTitleSuggestions } from '@/utils/userTitlePreferences';
|
import { getPersonalizedTitleSuggestions } from '@/utils/userTitlePreferences';
|
||||||
import { Separator } from '@/components/ui/separator';
|
import { Separator } from '@/components/ui/separator';
|
||||||
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group';
|
import { CreditCard, Banknote } from 'lucide-react';
|
||||||
|
|
||||||
// Form schema for validation - 카테고리를 4개로 확장 및 지출 방법 추가
|
// Form schema for validation - 카테고리를 4개로 확장 및 지출 방법 추가
|
||||||
export const transactionFormSchema = z.object({
|
export const transactionFormSchema = z.object({
|
||||||
@@ -39,6 +39,9 @@ const TransactionFormFields: React.FC<TransactionFormFieldsProps> = ({ form }) =
|
|||||||
// 현재 선택된 카테고리 가져오기
|
// 현재 선택된 카테고리 가져오기
|
||||||
const selectedCategory = form.watch('category');
|
const selectedCategory = form.watch('category');
|
||||||
|
|
||||||
|
// 현재 선택된 지불 방법 가져오기
|
||||||
|
const selectedPaymentMethod = form.watch('paymentMethod');
|
||||||
|
|
||||||
// 선택된 카테고리에 대한 개인화된 제목 제안 목록 상태
|
// 선택된 카테고리에 대한 개인화된 제목 제안 목록 상태
|
||||||
const [titleSuggestions, setTitleSuggestions] = useState<string[]>([]);
|
const [titleSuggestions, setTitleSuggestions] = useState<string[]>([]);
|
||||||
|
|
||||||
@@ -142,7 +145,7 @@ const TransactionFormFields: React.FC<TransactionFormFieldsProps> = ({ form }) =
|
|||||||
{/* 구분선 추가 */}
|
{/* 구분선 추가 */}
|
||||||
<Separator className="my-4" />
|
<Separator className="my-4" />
|
||||||
|
|
||||||
{/* 지출 방법 필드 추가 */}
|
{/* 지출 방법 필드 수정 - 버튼 형식으로 변경 */}
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="paymentMethod"
|
name="paymentMethod"
|
||||||
@@ -150,21 +153,30 @@ const TransactionFormFields: React.FC<TransactionFormFieldsProps> = ({ form }) =
|
|||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>지출 방법</FormLabel>
|
<FormLabel>지출 방법</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<RadioGroup
|
<div className="grid grid-cols-2 gap-3">
|
||||||
onValueChange={field.onChange}
|
<div
|
||||||
defaultValue={field.value}
|
className={`flex items-center justify-center gap-2 p-2 rounded-md cursor-pointer border transition-colors ${
|
||||||
className="flex gap-4"
|
field.value === '신용카드'
|
||||||
value={field.value}
|
? 'border-neuro-income bg-neuro-income/10'
|
||||||
|
: 'border-gray-200 hover:bg-gray-50'
|
||||||
|
}`}
|
||||||
|
onClick={() => form.setValue('paymentMethod', '신용카드')}
|
||||||
>
|
>
|
||||||
<div className="flex items-center space-x-2">
|
<CreditCard size={16} className="text-neuro-income" />
|
||||||
<RadioGroupItem value="신용카드" id="credit-card" />
|
<span className="text-sm">신용카드</span>
|
||||||
<label htmlFor="credit-card" className="cursor-pointer">신용카드</label>
|
</div>
|
||||||
|
<div
|
||||||
|
className={`flex items-center justify-center gap-2 p-2 rounded-md cursor-pointer border transition-colors ${
|
||||||
|
field.value === '현금'
|
||||||
|
? 'border-neuro-income bg-neuro-income/10'
|
||||||
|
: 'border-gray-200 hover:bg-gray-50'
|
||||||
|
}`}
|
||||||
|
onClick={() => form.setValue('paymentMethod', '현금')}
|
||||||
|
>
|
||||||
|
<Banknote size={16} className="text-neuro-income" />
|
||||||
|
<span className="text-sm">현금</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center space-x-2">
|
|
||||||
<RadioGroupItem value="현금" id="cash" />
|
|
||||||
<label htmlFor="cash" className="cursor-pointer">현금</label>
|
|
||||||
</div>
|
</div>
|
||||||
</RadioGroup>
|
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|||||||
Reference in New Issue
Block a user