import React, { useState } from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { motion, AnimatePresence } from "framer-motion"; import { Database, Server, User, ChevronRight, CheckCircle2, ArrowRight, ShieldCheck, Mail, Lock, Check } from "lucide-react"; import { cn } from "@/lib/utils"; const stepVariants = { hidden: { opacity: 0, x: 20 }, visible: { opacity: 1, x: 0, transition: { duration: 0.4, ease: "easeOut" } }, exit: { opacity: 0, x: -20, transition: { duration: 0.2, ease: "easeIn" } } }; export default function SetupWizard() { const [step, setStep] = useState(1); const [loading, setLoading] = useState(false); const [error, setError] = useState(""); const [dbType, setDbType] = useState("sqlite"); const [dbUrl, setDbUrl] = useState(""); const [cacheType, setCacheType] = useState("local"); const [redisUrl, setRedisUrl] = useState(""); const [adminUser, setAdminUser] = useState({ username: "", email: "", password: "", confirmPassword: "" }); const handleNext = () => setStep(step + 1); const handleBack = () => setStep(step - 1); const handleSubmit = async () => { if (adminUser.password !== adminUser.confirmPassword) { setError("Passwords do not match"); return; } if (!adminUser.username || !adminUser.email || !adminUser.password) { setError("Please fill out all admin fields"); return; } setLoading(true); setError(""); try { const res = await fetch("/api/setup", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ database: { driver: dbType, url: dbType === "sqlite" ? "file:./data/opencodehub.db" : dbUrl }, cache: { type: cacheType, url: cacheType === "local" ? "" : redisUrl }, admin: { username: adminUser.username, email: adminUser.email, password: adminUser.password } }) }); const data = await res.json(); if (!res.ok) throw new Error(data.error || "Failed to setup"); window.location.href = "/"; } catch (e: any) { setError(e.message); setLoading(false); } }; const steps = [ { num: 1, title: "Database", icon: Database }, { num: 2, title: "Caching", icon: Server }, { num: 3, title: "Administrator", icon: ShieldCheck } ]; return (
Select the storage backend for OpenCodeHub.
Zero-configuration standalone setup. Ideal for local dev, single VPS, or NAS deployments.
High-performance production database. Required for multi-node setups and large teams.
Configure caching to accelerate repository indexing and API requests.
Fast on-device caching. Recommended for single-instance deployments.
Distributed caching. Essential for High Availability and horizontal scaling.
Set up the initial master account for platform administration.