diff --git a/src/components/onboarding/WelcomeDialog.tsx b/src/components/onboarding/WelcomeDialog.tsx index 63e677c..f1ef7cc 100644 --- a/src/components/onboarding/WelcomeDialog.tsx +++ b/src/components/onboarding/WelcomeDialog.tsx @@ -1,5 +1,5 @@ -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; import { Dialog, DialogContent, @@ -12,6 +12,7 @@ import { Button } from "@/components/ui/button"; import { Separator } from "@/components/ui/separator"; import { ArrowRight, Wallet, PieChart, LineChart } from "lucide-react"; import { Checkbox } from "@/components/ui/checkbox"; +import { toast } from "sonner"; interface WelcomeDialogProps { open: boolean; @@ -21,16 +22,45 @@ interface WelcomeDialogProps { const WelcomeDialog: React.FC = ({ open, onClose }) => { const [dontShowAgain, setDontShowAgain] = useState(false); - const handleClose = () => { - // 체크박스가 체크되어 있으면 localStorage에 직접 저장 - if (dontShowAgain) { - localStorage.setItem('dontShowWelcome', 'true'); + // 다이얼로그 열릴 때 localStorage 값 확인 + useEffect(() => { + if (open) { + const savedValue = localStorage.getItem('dontShowWelcome'); + console.log('저장된 dontShowWelcome 값:', savedValue); + setDontShowAgain(savedValue === 'true'); } + }, [open]); + + const handleClose = () => { + try { + // 체크박스가 체크되어 있으면 localStorage에 저장 + if (dontShowAgain) { + localStorage.setItem('dontShowWelcome', 'true'); + console.log('dontShowWelcome 값이 true로 저장되었습니다'); + + // 확인을 위한 즉시 재확인 + const savedValue = localStorage.getItem('dontShowWelcome'); + console.log('저장 직후 확인된 값:', savedValue); + + // 토스트 메시지로 사용자에게 알림 + toast.success('환영 메시지가 다시 표시되지 않도록 설정되었습니다'); + } else { + // 체크 해제 시 null이 아닌 'false' 문자열로 명시적 저장 + localStorage.setItem('dontShowWelcome', 'false'); + console.log('dontShowWelcome 값이 false로 저장되었습니다'); + } + } catch (error) { + console.error('localStorage 저장 중 오류 발생:', error); + } + + // 부모 컴포넌트에 상태 전달 onClose(dontShowAgain); }; return ( - handleClose()}> + { + if (!isOpen) handleClose(); + }}> diff --git a/src/pages/Index.tsx b/src/pages/Index.tsx index a1d1171..1aecf52 100644 --- a/src/pages/Index.tsx +++ b/src/pages/Index.tsx @@ -96,10 +96,21 @@ const Index = () => { } // 환영 다이얼로그 표시 여부 결정 (데이터 초기화 후) - const dontShowWelcome = localStorage.getItem('dontShowWelcome') === 'true'; - if (!dontShowWelcome) { - setShowWelcome(true); - } + const checkWelcomeDialogState = () => { + const dontShowWelcome = localStorage.getItem('dontShowWelcome'); + console.log('Index 페이지 로딩 시 dontShowWelcome 값:', dontShowWelcome); + + // 명시적으로 'true' 문자열인 경우에만 숨김 처리 + if (dontShowWelcome === 'true') { + console.log('환영 메시지 표시하지 않음 (저장된 설정)'); + setShowWelcome(false); + } else { + console.log('환영 메시지 표시함'); + setShowWelcome(true); + } + }; + + checkWelcomeDialogState(); // 방문 기록 저장 (초기화 후에 저장) localStorage.setItem('hasVisitedBefore', 'true'); @@ -108,9 +119,18 @@ const Index = () => { // 환영 팝업 닫기 const handleCloseWelcome = (dontShowAgain: boolean) => { setShowWelcome(false); + + // 사용자가 더 이상 보지 않기를 선택한 경우 if (dontShowAgain) { localStorage.setItem('dontShowWelcome', 'true'); - console.log('환영 팝업 더 이상 표시하지 않기 설정됨'); + console.log('환영 팝업 더 이상 표시하지 않기 설정됨:', dontShowAgain); + + // 설정 확인 + const savedValue = localStorage.getItem('dontShowWelcome'); + console.log('설정 후 dontShowWelcome 저장값:', savedValue); + } else { + // 체크하지 않은 경우 명시적으로 false 저장 + localStorage.setItem('dontShowWelcome', 'false'); } };