Fix welcome dialog persistence
The "Don't show again" checkbox on the welcome dialog was not working correctly. This commit ensures that the dialog remains hidden after the user checks the box, even after navigating to other screens.
This commit is contained in:
@@ -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<WelcomeDialogProps> = ({ 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 (
|
||||
<Dialog open={open} onOpenChange={() => handleClose()}>
|
||||
<Dialog open={open} onOpenChange={(isOpen) => {
|
||||
if (!isOpen) handleClose();
|
||||
}}>
|
||||
<DialogContent className="w-[90%] max-w-sm mx-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="text-center text-2xl text-neuro-income mb-2">
|
||||
|
||||
Reference in New Issue
Block a user