Fix issue deleting transactions
Fixes an issue where deleting a transaction on the transaction history screen would cause the application to freeze.
This commit is contained in:
@@ -23,16 +23,9 @@ interface TransactionCardProps {
|
||||
|
||||
const TransactionCard: React.FC<TransactionCardProps> = ({
|
||||
transaction,
|
||||
onUpdate
|
||||
}) => {
|
||||
const [isEditDialogOpen, setIsEditDialogOpen] = useState(false);
|
||||
const { title, amount, date, category, type } = transaction;
|
||||
|
||||
const handleSaveTransaction = (updatedTransaction: Transaction) => {
|
||||
if (onUpdate) {
|
||||
onUpdate(updatedTransaction);
|
||||
}
|
||||
};
|
||||
const { title, amount, date, category } = transaction;
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -54,7 +47,6 @@ const TransactionCard: React.FC<TransactionCardProps> = ({
|
||||
transaction={transaction}
|
||||
open={isEditDialogOpen}
|
||||
onOpenChange={setIsEditDialogOpen}
|
||||
onSave={handleSaveTransaction}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -10,7 +10,8 @@ import {
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogFooter,
|
||||
DialogClose
|
||||
DialogClose,
|
||||
DialogDescription
|
||||
} from '@/components/ui/dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Form } from '@/components/ui/form';
|
||||
@@ -78,20 +79,19 @@ const TransactionEditDialog: React.FC<TransactionEditDialogProps> = ({
|
||||
};
|
||||
|
||||
const handleDelete = () => {
|
||||
// 컨텍스트를 통해 트랜잭션 삭제
|
||||
deleteTransaction(transaction.id);
|
||||
|
||||
// 부모 컴포넌트의 onDelete 콜백이 있다면 호출
|
||||
if (onDelete) {
|
||||
onDelete(transaction.id);
|
||||
}
|
||||
|
||||
// 다이얼로그 닫기를 먼저 수행 (UI 블로킹 방지)
|
||||
onOpenChange(false);
|
||||
|
||||
toast({
|
||||
title: "지출이 삭제되었습니다",
|
||||
description: `${transaction.title} 항목이 삭제되었습니다.`,
|
||||
});
|
||||
// 약간의 지연 후 삭제 작업 수행 (안정성 향상)
|
||||
setTimeout(() => {
|
||||
// 컨텍스트를 통해 트랜잭션 삭제
|
||||
deleteTransaction(transaction.id);
|
||||
|
||||
// 부모 컴포넌트의 onDelete 콜백이 있다면 호출
|
||||
if (onDelete) {
|
||||
onDelete(transaction.id);
|
||||
}
|
||||
}, 100);
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -99,6 +99,9 @@ const TransactionEditDialog: React.FC<TransactionEditDialogProps> = ({
|
||||
<DialogContent className={`sm:max-w-md mx-auto ${isMobile ? 'rounded-xl overflow-hidden' : ''}`}>
|
||||
<DialogHeader>
|
||||
<DialogTitle>지출 수정</DialogTitle>
|
||||
<DialogDescription>
|
||||
지출 내역을 수정하거나 삭제할 수 있습니다.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<Form {...form}>
|
||||
|
||||
Reference in New Issue
Block a user