Fix transaction deletion issue

Addresses the issue where deleting a transaction in the transaction history would cause the application to freeze.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-18 03:51:17 +00:00
parent 7f30d08466
commit 27b4e3274e
4 changed files with 126 additions and 99 deletions

View File

@@ -1,7 +1,7 @@
import React from 'react';
import React, { useState } from 'react';
import { Button } from '@/components/ui/button';
import { Trash2 } from 'lucide-react';
import { Trash2, Loader2 } from 'lucide-react';
import {
AlertDialog,
AlertDialogAction,
@@ -19,15 +19,30 @@ interface TransactionDeleteAlertProps {
}
const TransactionDeleteAlert: React.FC<TransactionDeleteAlertProps> = ({ onDelete }) => {
const [isOpen, setIsOpen] = useState(false);
const [isDeleting, setIsDeleting] = useState(false);
const handleDelete = async () => {
try {
setIsDeleting(true);
await onDelete();
setIsOpen(false);
} catch (error) {
console.error('삭제 작업 처리 중 오류:', error);
} finally {
setIsDeleting(false);
}
};
return (
<AlertDialog>
<AlertDialog open={isOpen} onOpenChange={setIsOpen}>
<AlertDialogTrigger asChild>
<Button
type="button"
variant="outline"
className="border-red-200 text-red-500 hover:bg-red-50"
>
<Trash2 size={16} />
<Trash2 size={16} className="mr-1" />
</Button>
</AlertDialogTrigger>
@@ -39,13 +54,24 @@ const TransactionDeleteAlert: React.FC<TransactionDeleteAlertProps> = ({ onDelet
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel></AlertDialogCancel>
<AlertDialogAction
<AlertDialogCancel disabled={isDeleting}></AlertDialogCancel>
<Button
className="bg-red-500 hover:bg-red-600"
onClick={onDelete}
onClick={handleDelete}
disabled={isDeleting}
>
</AlertDialogAction>
{isDeleting ? (
<>
<Loader2 size={16} className="mr-1 animate-spin" />
...
</>
) : (
<>
<Trash2 size={16} className="mr-1" />
</>
)}
</Button>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>