diff --git a/src/components/RecentTransactionsSection.tsx b/src/components/RecentTransactionsSection.tsx index b9bd6b8..f5c3093 100644 --- a/src/components/RecentTransactionsSection.tsx +++ b/src/components/RecentTransactionsSection.tsx @@ -1,3 +1,4 @@ + import React, { useState } from 'react'; import { Transaction } from './TransactionCard'; import TransactionEditDialog from './TransactionEditDialog'; @@ -6,10 +7,12 @@ import { useBudget } from '@/contexts/BudgetContext'; import { Link } from 'react-router-dom'; import { categoryIcons } from '@/constants/categoryIcons'; import TransactionIcon from './transaction/TransactionIcon'; + interface RecentTransactionsSectionProps { transactions: Transaction[]; onUpdateTransaction?: (transaction: Transaction) => void; } + const RecentTransactionsSection: React.FC = ({ transactions, onUpdateTransaction @@ -20,10 +23,12 @@ const RecentTransactionsSection: React.FC = ({ updateTransaction, deleteTransaction } = useBudget(); + const handleTransactionClick = (transaction: Transaction) => { setSelectedTransaction(transaction); setIsDialogOpen(true); }; + const handleUpdateTransaction = (updatedTransaction: Transaction) => { if (onUpdateTransaction) { onUpdateTransaction(updatedTransaction); @@ -31,13 +36,23 @@ const RecentTransactionsSection: React.FC = ({ // 직접 컨텍스트를 통해 업데이트 updateTransaction(updatedTransaction); }; - const handleDeleteTransaction = (id: string) => { - // 직접 컨텍스트를 통해 삭제 - deleteTransaction(id); + + // 타입 불일치 해결: boolean 또는 Promise 반환하도록 수정 + const handleDeleteTransaction = async (id: string): Promise => { + try { + // 직접 컨텍스트를 통해 삭제 + deleteTransaction(id); + return true; // 삭제 성공 시 true 반환 + } catch (error) { + console.error('트랜잭션 삭제 중 오류:', error); + return false; // 삭제 실패 시 false 반환 + } }; + const formatCurrency = (amount: number) => { return amount.toLocaleString('ko-KR') + '원'; }; + return

최근 지출

@@ -66,4 +81,5 @@ const RecentTransactionsSection: React.FC = ({ {selectedTransaction && }
; }; -export default RecentTransactionsSection; \ No newline at end of file + +export default RecentTransactionsSection; diff --git a/src/components/TransactionCard.tsx b/src/components/TransactionCard.tsx index 81d8337..968fda5 100644 --- a/src/components/TransactionCard.tsx +++ b/src/components/TransactionCard.tsx @@ -19,16 +19,30 @@ export type Transaction = { interface TransactionCardProps { transaction: Transaction; onUpdate?: (updatedTransaction: Transaction) => void; - onDelete?: (id: string) => void; // onDelete 속성 추가 + onDelete?: (id: string) => Promise | boolean; // 타입 변경됨: boolean 또는 Promise 반환 } const TransactionCard: React.FC = ({ transaction, - onDelete, // onDelete prop 추가 + onDelete, }) => { const [isEditDialogOpen, setIsEditDialogOpen] = useState(false); const { title, amount, date, category } = transaction; + // 삭제 핸들러 - 인자로 받은 onDelete가 없거나 타입이 맞지 않을 때 기본 함수 제공 + const handleDelete = async (id: string): Promise => { + try { + if (onDelete) { + return await onDelete(id); + } + console.log('삭제 핸들러가 제공되지 않았습니다'); + return false; + } catch (error) { + console.error('트랜잭션 삭제 처리 중 오류:', error); + return false; + } + }; + return ( <>
= ({ transaction={transaction} open={isEditDialogOpen} onOpenChange={setIsEditDialogOpen} - onDelete={onDelete} // onDelete prop 전달 + onDelete={handleDelete} // 래핑된 핸들러 사용 /> );