Fix type error in TransactionEditDialog
Fixes a type error in TransactionEditDialog.tsx where the category type was incorrectly assigned.
This commit is contained in:
@@ -23,6 +23,7 @@ import TransactionFormFields, {
|
|||||||
} from './transaction/TransactionFormFields';
|
} from './transaction/TransactionFormFields';
|
||||||
import TransactionDeleteAlert from './transaction/TransactionDeleteAlert';
|
import TransactionDeleteAlert from './transaction/TransactionDeleteAlert';
|
||||||
import { useIsMobile } from '@/hooks/use-mobile';
|
import { useIsMobile } from '@/hooks/use-mobile';
|
||||||
|
import { EXPENSE_CATEGORIES } from '@/constants/categoryIcons';
|
||||||
|
|
||||||
interface TransactionEditDialogProps {
|
interface TransactionEditDialogProps {
|
||||||
transaction: Transaction;
|
transaction: Transaction;
|
||||||
@@ -49,13 +50,22 @@ const TransactionEditDialog: React.FC<TransactionEditDialogProps> = ({
|
|||||||
// 작업 중첩 방지를 위한 참조
|
// 작업 중첩 방지를 위한 참조
|
||||||
const isProcessingRef = useRef(false);
|
const isProcessingRef = useRef(false);
|
||||||
|
|
||||||
|
// 카테고리 매핑 함수 - 이전 카테고리명을 새 카테고리명으로 변환
|
||||||
|
const mapCategoryToNew = (oldCategory: string): "음식" | "쇼핑" | "교통비" => {
|
||||||
|
if (oldCategory === '식비') return '음식';
|
||||||
|
if (oldCategory === '생활비') return '쇼핑';
|
||||||
|
if (EXPENSE_CATEGORIES.includes(oldCategory as any)) return oldCategory as "음식" | "쇼핑" | "교통비";
|
||||||
|
// 기본값은 '쇼핑'으로 설정
|
||||||
|
return '쇼핑';
|
||||||
|
};
|
||||||
|
|
||||||
// 폼 설정
|
// 폼 설정
|
||||||
const form = useForm<TransactionFormValues>({
|
const form = useForm<TransactionFormValues>({
|
||||||
resolver: zodResolver(transactionFormSchema),
|
resolver: zodResolver(transactionFormSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
title: transaction.title,
|
title: transaction.title,
|
||||||
amount: formatWithCommas(transaction.amount.toString()),
|
amount: formatWithCommas(transaction.amount.toString()),
|
||||||
category: transaction.category as '식비' | '생활비' | '교통비',
|
category: mapCategoryToNew(transaction.category),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -65,7 +75,7 @@ const TransactionEditDialog: React.FC<TransactionEditDialogProps> = ({
|
|||||||
form.reset({
|
form.reset({
|
||||||
title: transaction.title,
|
title: transaction.title,
|
||||||
amount: formatWithCommas(transaction.amount.toString()),
|
amount: formatWithCommas(transaction.amount.toString()),
|
||||||
category: transaction.category as '식비' | '생활비' | '교통비',
|
category: mapCategoryToNew(transaction.category),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [open, transaction, form]);
|
}, [open, transaction, form]);
|
||||||
|
|||||||
Reference in New Issue
Block a user