Review expense history page

This commit is contained in:
gpt-engineer-app[bot]
2025-03-18 04:12:54 +00:00
parent a0074c2d1d
commit 2b8069a150
5 changed files with 75 additions and 135 deletions

View File

@@ -29,7 +29,7 @@ interface TransactionEditDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
onSave?: (updatedTransaction: Transaction) => void;
onDelete?: (id: string) => void;
onDelete?: (id: string) => Promise<boolean> | boolean;
}
const TransactionEditDialog: React.FC<TransactionEditDialogProps> = ({
@@ -40,6 +40,7 @@ const TransactionEditDialog: React.FC<TransactionEditDialogProps> = ({
onDelete
}) => {
const { updateTransaction, deleteTransaction } = useBudget();
const isMobile = useIsMobile();
const form = useForm<TransactionFormValues>({
@@ -78,48 +79,28 @@ const TransactionEditDialog: React.FC<TransactionEditDialogProps> = ({
});
};
const handleDelete = (): Promise<boolean> => {
return new Promise<boolean>((resolve) => {
try {
// 다이얼로그 닫기를 먼저 수행 (UI 블로킹 방지)
onOpenChange(false);
// 잠시 지연 후 삭제 작업 수행 (안정성 향상)
setTimeout(() => {
try {
// 트랜잭션 ID 임시 저장 (안전성 확보)
const transactionId = transaction.id;
// 부모 컴포넌트의 onDelete 콜백이 있다면 호출
if (onDelete) {
onDelete(transactionId);
}
// 컨텍스트를 통해 트랜잭션 삭제
deleteTransaction(transactionId);
console.log('트랜잭션 삭제 완료:', transactionId);
resolve(true);
} catch (innerError) {
console.error('트랜잭션 삭제 중 내부 오류:', innerError);
toast({
title: "삭제 실패",
description: "지출 항목을 삭제하는데 문제가 발생했습니다.",
variant: "destructive"
});
resolve(false);
}
}, 100);
} catch (outerError) {
console.error('트랜잭션 삭제 처리 중 오류:', outerError);
toast({
title: "시스템 오류",
description: "처리 중 문제가 발생했습니다. 다시 시도해주세요.",
variant: "destructive"
});
resolve(false);
const handleDelete = async (): Promise<boolean> => {
try {
// 다이얼로그 닫기를 먼저 수행 (UI 블로킹 방지)
onOpenChange(false);
// 삭제 처리 - 부모 컴포넌트의 onDelete 콜백이 있다면 호출
if (onDelete) {
return await onDelete(transaction.id);
}
});
// 부모 컴포넌트에서 처리하지 않은 경우 기본 처리
deleteTransaction(transaction.id);
return true;
} catch (error) {
console.error('트랜잭션 삭제 중 오류:', error);
toast({
title: "삭제 실패",
description: "지출 항목을 삭제하는데 문제가 발생했습니다.",
variant: "destructive"
});
return false;
}
};
return (