"use client"; import { useState } from "react"; import { Alert, Badge, Button, Group, Paper, Stack, Text, ThemeIcon, Title } from "@mantine/core"; import { IconArrowRight, IconDatabaseImport, IconLayoutDashboard, IconSparkles } from "@tabler/icons-react"; import { motion, useReducedMotion } from "motion/react"; import { clientApi } from "@homarr/api/client"; import { revalidatePathActionAsync } from "@homarr/common/client"; import { useScopedI18n } from "@homarr/translation/client"; import type { OnboardingStudioProps } from "./types"; import classes from "./onboarding-studio.module.css"; export const Welcome = ({ environment, sqliteRestore }: OnboardingStudioProps) => { const t = useScopedI18n("init.studio.welcome"); const reduceMotion = useReducedMotion(); const [showRestore, setShowRestore] = useState(false); const [claimPending, setClaimPending] = useState(false); const [claimError, setClaimError] = useState(null); const start = clientApi.onboard.nextStep.useMutation({ async onSuccess() { await revalidatePathActionAsync("/init"); }, }); const claimOnboardingAsync = async () => { setClaimPending(true); setClaimError(null); try { const response = await fetch("/api/onboarding/claim", { method: "POST" }); if (!response.ok) { const body = (await response.json().catch(() => null)) as { error?: string } | null; throw new Error(body?.error ?? t("errorTitle")); } return true; } catch (error) { setClaimError(error instanceof Error ? error.message : t("errorTitle")); return false; } finally { setClaimPending(false); } }; const startOnboardingAsync = async () => { if (await claimOnboardingAsync()) await start.mutateAsync(); }; const toggleRestoreAsync = async () => { if (showRestore) { setShowRestore(false); return; } if (await claimOnboardingAsync()) setShowRestore(true); }; return (
{t("badge")}
{t("eyebrow")} {t("title")} {t("description")} {environment.databaseDriver === "sqlite" && sqliteRestore ? ( ) : null} {showRestore && sqliteRestore ? ( {t("restoreTitle")} {t("restoreDescription")} {sqliteRestore} ) : null} {claimError || start.error ? ( {claimError ?? start.error?.message} ) : null}
{[IconLayoutDashboard, IconSparkles, IconDatabaseImport, IconLayoutDashboard].map((Icon, index) => ( ))}
{t("ready")} {t("panelTitle")} {t("panelDescription")} {t("chipDiscover")} {t("chipConnect")} {t("chipBuild")}
); };