Fix transaction delete type mismatch
The `onDelete` prop in `TransactionCard` and `RecentTransactionsSection` components was expecting a function that returns a boolean or a Promise resolving to a boolean, but was receiving a function that returns void. This commit updates the type definition and implementation to ensure the `onDelete` function returns the expected type.
This commit is contained in:
@@ -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<RecentTransactionsSectionProps> = ({
|
||||
transactions,
|
||||
onUpdateTransaction
|
||||
@@ -20,10 +23,12 @@ const RecentTransactionsSection: React.FC<RecentTransactionsSectionProps> = ({
|
||||
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<RecentTransactionsSectionProps> = ({
|
||||
// 직접 컨텍스트를 통해 업데이트
|
||||
updateTransaction(updatedTransaction);
|
||||
};
|
||||
const handleDeleteTransaction = (id: string) => {
|
||||
// 직접 컨텍스트를 통해 삭제
|
||||
deleteTransaction(id);
|
||||
|
||||
// 타입 불일치 해결: boolean 또는 Promise<boolean> 반환하도록 수정
|
||||
const handleDeleteTransaction = async (id: string): Promise<boolean> => {
|
||||
try {
|
||||
// 직접 컨텍스트를 통해 삭제
|
||||
deleteTransaction(id);
|
||||
return true; // 삭제 성공 시 true 반환
|
||||
} catch (error) {
|
||||
console.error('트랜잭션 삭제 중 오류:', error);
|
||||
return false; // 삭제 실패 시 false 반환
|
||||
}
|
||||
};
|
||||
|
||||
const formatCurrency = (amount: number) => {
|
||||
return amount.toLocaleString('ko-KR') + '원';
|
||||
};
|
||||
|
||||
return <div className="mt-6 mb-[50px]">
|
||||
<div className="flex justify-between items-center mb-3">
|
||||
<h2 className="text-lg font-semibold">최근 지출</h2>
|
||||
@@ -66,4 +81,5 @@ const RecentTransactionsSection: React.FC<RecentTransactionsSectionProps> = ({
|
||||
{selectedTransaction && <TransactionEditDialog transaction={selectedTransaction} open={isDialogOpen} onOpenChange={setIsDialogOpen} onSave={handleUpdateTransaction} onDelete={handleDeleteTransaction} />}
|
||||
</div>;
|
||||
};
|
||||
export default RecentTransactionsSection;
|
||||
|
||||
export default RecentTransactionsSection;
|
||||
|
||||
Reference in New Issue
Block a user