import { useEffect, useMemo, 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"; import useTranslation from "../hooks/use-translation"; 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; }[]; }; export function OnboardingDialog() { const t = useTranslation(); const [currentStep, setCurrentStep] = useState(0); const [settings, setSettings] = useState>({}); const [open, setOpen] = useState(false); const onboardingSteps: OnboardingStep[] = useMemo( () => [ { title: t("ONBOARDING_DIALOG.STEP_1.TITLE"), description: t("ONBOARDING_DIALOG.STEP_1.DESCRIPTION"), type: "info", }, { title: t("ONBOARDING_DIALOG.STEP_2.TITLE"), description: t("ONBOARDING_DIALOG.STEP_2.DESCRIPTION"), type: "settings", configurationOptions: [ { type: "switch", label: t("SETTINGS.AUTO_UPDATE.TITLE"), key: "autoUpdate", }, { type: "switch", label: t("SETTINGS.ENABLE_CONTRIBUTION.TITLE"), description: t("SETTINGS.ENABLE_CONTRIBUTION.DESCRIPTION"), key: "improveUpscayl", }, { type: "component", label: t("SETTINGS.THEME.TITLE"), component: , key: "theme", }, ], }, { type: "info", title: t("ONBOARDING_DIALOG.STEP_3.TITLE"), description: t("ONBOARDING_DIALOG.STEP_3.DESCRIPTION"), configurationOptions: [ { key: "video", type: "video", videoSrc: "https://www.youtube-nocookie.com/embed/3M77flVZlVY?autoplay=1", }, ], }, { title: t("ONBOARDING_DIALOG.STEP_4.TITLE"), description: t("ONBOARDING_DIALOG.STEP_4.DESCRIPTION"), type: "info", }, ], [], ); 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.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" && (