import { useEffect, useState } from "react"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "../ui/dialog"; import { cn } from "@/lib/utils"; import SelectTheme from "@/components/sidebar/settings-tab/select-theme"; import { autoUpdateAtom, enableContributionAtom, } from "@/atoms/user-settings-atom"; import { useAtom } from "jotai"; type OnboardingStep = { title: string; description: string; type: "info" | "settings"; configurationOptions?: { key: string; type: "switch" | "input" | "video" | "component"; label?: string; description?: string; videoSrc?: string; component?: any; }[]; }; const onboardingSteps: OnboardingStep[] = [ { title: "Welcome to Upscayl 🎉", description: "Let's get you started with a few quick steps.", type: "info", }, { title: "Choose Your Preferences 🎨", description: "Configure your initial settings.", type: "settings", configurationOptions: [ { type: "switch", label: "Enable automatic updates", key: "autoUpdate", }, { type: "switch", label: "Help Improve Upscayl", description: "Send anonymous usage data to help improve Upscayl.", key: "improveUpscayl", }, { type: "component", label: "Theme", component: , key: "theme", }, ], }, { title: "How do I use Upscayl? 🚀", type: "info", description: "Watch this short video to learn about the new features.", configurationOptions: [ { key: "video", type: "video", videoSrc: "https://www.youtube-nocookie.com/embed/3M77flVZlVY", }, ], }, { title: "You're All Set! 🎉", description: "You can now start upscaling your images.", type: "info", }, ]; export function OnboardingDialog() { const [currentStep, setCurrentStep] = useState(0); const [settings, setSettings] = useState>({}); const [open, setOpen] = useState(false); const currentStepData = onboardingSteps[currentStep]; const isLastStep = currentStep === onboardingSteps.length - 1; const isFirstStep = currentStep === 0; const [autoUpdate, setAutoUpdate] = useAtom(autoUpdateAtom); const [enableContribution, setEnableContribution] = useAtom( enableContributionAtom, ); useEffect(() => { const storedValue = localStorage.getItem("showOnboarding"); if (storedValue !== null) { setOpen(JSON.parse(storedValue)); } else { setOpen(true); } }, []); const handleNext = () => { if (isLastStep) { setOpen(false); localStorage.setItem("showOnboarding", JSON.stringify(false)); } else { setCurrentStep((prev) => prev + 1); } }; const handleSettingChange = (key: string, value: any) => { setSettings((prev) => ({ ...prev, [key]: value })); }; return ( { setOpen(e); }} > {currentStepData.title} {currentStepData.description} {currentStepData.configurationOptions && ( {currentStepData.configurationOptions.map((option) => ( {option.label && ( {option.label} )} {option.type === "switch" && ( { if (option.key === "autoUpdate") { setAutoUpdate(e.target.checked); } else if (option.key === "improveUpscayl") { setEnableContribution(e.target.checked); } }} /> )} {option.type === "input" && ( handleSettingChange(option.key, e.target.value) } /> )} {option.type === "video" && ( )} {option.type === "component" && option.component} ))} )} {isLastStep ? "Get Started" : "Next"} {!isFirstStep && ( setCurrentStep((prev) => prev - 1)} className="btn btn-primary w-40" > Back )} ); }