From 09894589b472e69c55b74db54f6dcdcc8ea0cd8a Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sat, 22 Mar 2025 06:26:05 +0000 Subject: [PATCH] Fix welcome message and sync - Prevent duplicate welcome messages. - Remove sync notifications. - Ensure automatic sync updates last sync time. --- src/components/AddTransactionButton.tsx | 27 +++++++++- src/components/sync/SyncStatus.tsx | 17 ++++++- src/hooks/sync/syncResultHandler.ts | 65 +++++++++++++++++++------ src/hooks/sync/useManualSync.ts | 17 +++++++ src/hooks/sync/useSyncStatus.ts | 17 ++++++- src/hooks/sync/useSyncToggle.ts | 32 +++++++++++- src/pages/Index.tsx | 9 +++- src/utils/syncUtils.ts | 16 ++++-- 8 files changed, 173 insertions(+), 27 deletions(-) diff --git a/src/components/AddTransactionButton.tsx b/src/components/AddTransactionButton.tsx index b692275..38b7dd3 100644 --- a/src/components/AddTransactionButton.tsx +++ b/src/components/AddTransactionButton.tsx @@ -5,15 +5,17 @@ import { Dialog, DialogContent, DialogHeader, DialogTitle } from './ui/dialog'; import { toast } from '@/hooks/useToast.wrapper'; // 래퍼 사용 import { useBudget } from '@/contexts/BudgetContext'; import { supabase } from '@/lib/supabase'; -import { isSyncEnabled } from '@/utils/syncUtils'; +import { isSyncEnabled, setLastSyncTime, trySyncAllData } from '@/utils/syncUtils'; import ExpenseForm, { ExpenseFormValues } from './expenses/ExpenseForm'; import { Transaction } from '@/components/TransactionCard'; import { normalizeDate } from '@/utils/sync/transaction/dateUtils'; +import useNotifications from '@/hooks/useNotifications'; const AddTransactionButton = () => { const [showExpenseDialog, setShowExpenseDialog] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false); const { addTransaction } = useBudget(); + const { addNotification } = useNotifications(); // Format number with commas const formatWithCommas = (value: string): string => { @@ -68,10 +70,31 @@ const AddTransactionButton = () => { }); if (error) throw error; + + // 지출 추가 후 자동 동기화 실행 + console.log('지출 추가 후 자동 동기화 시작'); + const syncResult = await trySyncAllData(user.id); + + if (syncResult.success) { + // 동기화 성공 시 마지막 동기화 시간 업데이트 + const currentTime = new Date().toISOString(); + console.log('자동 동기화 성공, 시간 업데이트:', currentTime); + setLastSyncTime(currentTime); + + // 동기화 성공 알림 추가 + addNotification( + '동기화 완료', + '방금 추가하신 지출 데이터가 클라우드에 동기화되었습니다.' + ); + } } } catch (error) { console.error('Supabase에 지출 추가 실패:', error); - // 실패해도 로컬에는 저장되어 있으므로 사용자에게 알리지 않음 + // 실패 시 알림 추가 + addNotification( + '동기화 실패', + '지출 데이터 동기화 중 문제가 발생했습니다. 나중에 다시 시도됩니다.' + ); } // 다이얼로그를 닫습니다 diff --git a/src/components/sync/SyncStatus.tsx b/src/components/sync/SyncStatus.tsx index ed0f38c..f2a3142 100644 --- a/src/components/sync/SyncStatus.tsx +++ b/src/components/sync/SyncStatus.tsx @@ -1,8 +1,9 @@ -import React from 'react'; +import React, { useEffect } from 'react'; import { RefreshCw } from "lucide-react"; import { Button } from "@/components/ui/button"; import { useNavigate } from "react-router-dom"; +import useNotifications from '@/hooks/useNotifications'; interface SyncStatusProps { enabled: boolean; @@ -20,6 +21,18 @@ const SyncStatus: React.FC = ({ onManualSync }) => { const navigate = useNavigate(); + const { addNotification } = useNotifications(); + + // 동기화 버튼 클릭 시 알림 추가 + const handleSyncClick = async () => { + if (syncing) return; + + try { + await onManualSync(); + } catch (error) { + console.error('수동 동기화 실패:', error); + } + }; if (!enabled) return null; @@ -29,7 +42,7 @@ const SyncStatus: React.FC = ({
마지막 동기화: {lastSync}