Fix toast and data reset issues

- Resolved issue where budget creation toast appeared before expense creation toast.
- Fixed data reset causing a redirect to the login screen.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-16 09:13:08 +00:00
parent 468bb79c9e
commit 7ab79d125e
6 changed files with 213 additions and 240 deletions

View File

@@ -2,7 +2,7 @@
import React, { useState } from 'react';
import { PlusIcon } from 'lucide-react';
import { Dialog, DialogContent, DialogHeader, DialogTitle } from './ui/dialog';
import { toast } from '@/hooks/use-toast';
import { toast } from '@/hooks/useToast.wrapper';
import { useBudget } from '@/contexts/BudgetContext';
import { supabase } from '@/lib/supabase';
import { isSyncEnabled } from '@/utils/syncUtils';
@@ -11,6 +11,7 @@ import { Transaction } from '@/components/TransactionCard';
const AddTransactionButton = () => {
const [showExpenseDialog, setShowExpenseDialog] = useState(false);
const [isSubmitting, setIsSubmitting] = useState(false);
const { addTransaction } = useBudget();
// Format number with commas
@@ -21,7 +22,12 @@ const AddTransactionButton = () => {
};
const onSubmit = async (data: ExpenseFormValues) => {
// 중복 제출 방지
if (isSubmitting) return;
try {
setIsSubmitting(true);
// Remove commas before processing the amount
const numericAmount = data.amount.replace(/,/g, '');
@@ -68,11 +74,14 @@ const AddTransactionButton = () => {
// 다이얼로그를 닫습니다
setShowExpenseDialog(false);
// 사용자에게 알림을 표시합니다
toast({
title: "지출이 추가되었습니다",
description: `${data.title} 항목이 ${formatWithCommas(numericAmount)}원으로 등록되었습니다.`,
});
// 사용자에게 알림을 표시합니다 (지연 추가하여 다른 토스트와 충돌 방지)
setTimeout(() => {
toast({
title: "지출이 추가되었습니다",
description: `${data.title} 항목이 ${formatWithCommas(numericAmount)}원으로 등록되었습니다.`,
duration: 3000
});
}, 100);
// 브라우저 이벤트 발생시켜 다른 페이지에서도 업데이트되도록 함
window.dispatchEvent(new Event('budgetDataUpdated'));
@@ -84,7 +93,10 @@ const AddTransactionButton = () => {
title: "지출 추가 실패",
description: "지출을 추가하는 도중 오류가 발생했습니다.",
variant: "destructive",
duration: 4000
});
} finally {
setIsSubmitting(false);
}
};
@@ -95,19 +107,23 @@ const AddTransactionButton = () => {
className="p-4 rounded-full transition-all duration-300 bg-neuro-income shadow-neuro-flat hover:shadow-neuro-convex text-white animate-pulse-subtle"
onClick={() => setShowExpenseDialog(true)}
aria-label="지출 추가"
disabled={isSubmitting}
>
<PlusIcon size={24} />
</button>
</div>
<Dialog open={showExpenseDialog} onOpenChange={setShowExpenseDialog}>
<Dialog open={showExpenseDialog} onOpenChange={(open) => {
if (!isSubmitting) setShowExpenseDialog(open);
}}>
<DialogContent className="w-[90%] max-w-sm mx-auto">
<DialogHeader>
<DialogTitle> </DialogTitle>
</DialogHeader>
<ExpenseForm
onSubmit={onSubmit}
onCancel={() => setShowExpenseDialog(false)}
onCancel={() => !isSubmitting && setShowExpenseDialog(false)}
isSubmitting={isSubmitting}
/>
</DialogContent>
</Dialog>