Implement personalized data handling
Implement personalized data handling based on the number of recent expense records.
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
|
||||
import React from 'react';
|
||||
import React, { useEffect, useState } 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';
|
||||
import { CATEGORY_TITLE_SUGGESTIONS } from '@/constants/categoryIcons';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { getPersonalizedTitleSuggestions } from '@/utils/userTitlePreferences';
|
||||
|
||||
export interface ExpenseFormValues {
|
||||
title: string;
|
||||
@@ -33,8 +33,16 @@ const ExpenseForm: React.FC<ExpenseFormProps> = ({ onSubmit, onCancel, isSubmitt
|
||||
// 현재 선택된 카테고리 가져오기
|
||||
const selectedCategory = form.watch('category');
|
||||
|
||||
// 선택된 카테고리에 대한 제목 제안 목록 가져오기
|
||||
const titleSuggestions = selectedCategory ? CATEGORY_TITLE_SUGGESTIONS[selectedCategory] : [];
|
||||
// 선택된 카테고리에 대한 개인화된 제목 제안 목록 상태
|
||||
const [titleSuggestions, setTitleSuggestions] = useState<string[]>([]);
|
||||
|
||||
// 카테고리가 변경될 때마다 개인화된 제목 목록 업데이트
|
||||
useEffect(() => {
|
||||
if (selectedCategory) {
|
||||
const suggestions = getPersonalizedTitleSuggestions(selectedCategory);
|
||||
setTitleSuggestions(suggestions);
|
||||
}
|
||||
}, [selectedCategory]);
|
||||
|
||||
// 제안된 제목 클릭 시 제목 필드에 설정
|
||||
const handleTitleSuggestionClick = (suggestion: string) => {
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import React, { useState, useEffect } 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, CATEGORY_TITLE_SUGGESTIONS } from '@/constants/categoryIcons';
|
||||
import { categoryIcons, EXPENSE_CATEGORIES } from '@/constants/categoryIcons';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { getPersonalizedTitleSuggestions } from '@/utils/userTitlePreferences';
|
||||
|
||||
// Form schema for validation - 카테고리를 4개로 확장
|
||||
export const transactionFormSchema = z.object({
|
||||
@@ -35,8 +36,16 @@ const TransactionFormFields: React.FC<TransactionFormFieldsProps> = ({ form }) =
|
||||
// 현재 선택된 카테고리 가져오기
|
||||
const selectedCategory = form.watch('category');
|
||||
|
||||
// 선택된 카테고리에 대한 제목 제안 목록 가져오기
|
||||
const titleSuggestions = selectedCategory ? CATEGORY_TITLE_SUGGESTIONS[selectedCategory] : [];
|
||||
// 선택된 카테고리에 대한 개인화된 제목 제안 목록 상태
|
||||
const [titleSuggestions, setTitleSuggestions] = useState<string[]>([]);
|
||||
|
||||
// 카테고리가 변경될 때마다 개인화된 제목 목록 업데이트
|
||||
useEffect(() => {
|
||||
if (selectedCategory) {
|
||||
const suggestions = getPersonalizedTitleSuggestions(selectedCategory);
|
||||
setTitleSuggestions(suggestions);
|
||||
}
|
||||
}, [selectedCategory]);
|
||||
|
||||
// 제안된 제목 클릭 시 제목 필드에 설정
|
||||
const handleTitleSuggestionClick = (suggestion: string) => {
|
||||
|
||||
Reference in New Issue
Block a user