Fix transaction deletion issue
Addresses the issue where the transaction history page becomes unresponsive after deleting a transaction.
This commit is contained in:
@@ -3,6 +3,7 @@ import { MutableRefObject } from 'react';
|
||||
import { Transaction } from '@/components/TransactionCard';
|
||||
import { saveTransactionsToStorage } from '../../storageUtils';
|
||||
import { deleteTransactionFromSupabase } from '../../supabaseUtils';
|
||||
import { toast } from '@/hooks/useToast.wrapper';
|
||||
|
||||
/**
|
||||
* 스토리지 및 Supabase 삭제 처리
|
||||
@@ -27,29 +28,41 @@ export const handleDeleteStorage = (
|
||||
// Supabase 업데이트
|
||||
if (user) {
|
||||
deleteTransactionFromSupabase(user, id)
|
||||
.then(() => {
|
||||
if (!isCanceled) {
|
||||
console.log('Supabase 트랜잭션 삭제 성공');
|
||||
// 성공 로그만 추가, UI 업데이트는 이미 수행됨
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Supabase 삭제 오류:', error);
|
||||
handleDeleteError(error, isCanceled, id, transactionToDelete, pendingDeletionRef);
|
||||
// 오류 시에도 UI에는 영향이 없도록 함 (이미 로컬에서는 제거됨)
|
||||
})
|
||||
.finally(() => {
|
||||
// 삭제 완료 후 토스트 표시
|
||||
if (!isCanceled) {
|
||||
// 작업 완료 후 보류 중인 삭제 목록에서 제거
|
||||
pendingDeletionRef.current?.delete(id);
|
||||
toast({
|
||||
title: "삭제 완료",
|
||||
description: "지출 항목이 삭제되었습니다.",
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 사용자 정보 없을 경우 목록에서 제거
|
||||
pendingDeletionRef.current?.delete(id);
|
||||
}
|
||||
|
||||
// 삭제 완료 이벤트 발생
|
||||
setTimeout(() => {
|
||||
try {
|
||||
window.dispatchEvent(new Event('transactionDeleted'));
|
||||
} catch (e) {
|
||||
console.error('이벤트 발생 오류:', e);
|
||||
}
|
||||
}, 100);
|
||||
|
||||
} catch (storageError) {
|
||||
console.error('스토리지 작업 중 오류:', storageError);
|
||||
pendingDeletionRef.current?.delete(id);
|
||||
|
||||
// 삭제 실패 알림
|
||||
toast({
|
||||
title: "삭제 중 오류",
|
||||
description: "지출 항목 삭제 중 문제가 발생했습니다.",
|
||||
variant: "destructive",
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user