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:
@@ -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; // 타입 변경됨: boolean 또는 Promise<boolean> 반환
|
||||
}
|
||||
|
||||
const TransactionCard: React.FC<TransactionCardProps> = ({
|
||||
transaction,
|
||||
onDelete, // onDelete prop 추가
|
||||
onDelete,
|
||||
}) => {
|
||||
const [isEditDialogOpen, setIsEditDialogOpen] = useState(false);
|
||||
const { title, amount, date, category } = transaction;
|
||||
|
||||
// 삭제 핸들러 - 인자로 받은 onDelete가 없거나 타입이 맞지 않을 때 기본 함수 제공
|
||||
const handleDelete = async (id: string): Promise<boolean> => {
|
||||
try {
|
||||
if (onDelete) {
|
||||
return await onDelete(id);
|
||||
}
|
||||
console.log('삭제 핸들러가 제공되지 않았습니다');
|
||||
return false;
|
||||
} catch (error) {
|
||||
console.error('트랜잭션 삭제 처리 중 오류:', error);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
@@ -49,7 +63,7 @@ const TransactionCard: React.FC<TransactionCardProps> = ({
|
||||
transaction={transaction}
|
||||
open={isEditDialogOpen}
|
||||
onOpenChange={setIsEditDialogOpen}
|
||||
onDelete={onDelete} // onDelete prop 전달
|
||||
onDelete={handleDelete} // 래핑된 핸들러 사용
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user