"use client" import { useState } from "react" import { Mail, User, Lock } from "lucide-react" import ErrorToast from "@/components/Error" import { useRouter } from "next/navigation" import useSite from "@/hooks/useSites" import axios from "axios" import useNetworks from "@/hooks/useNetworks" import { Site } from "@/app/types" export default function SetupPage() { const router = useRouter() const [step, setStep] = useState(1) const [email, setEmail] = useState("") const [username, setUsername] = useState("") const [name, setName] = useState("") const [password, setPassword] = useState("") const [passwordConfirm, setPasswordConfirm] = useState("") const [siteName, setSiteName] = useState("") const [networkName, setNetworkName] = useState("") const { addSite } = useSite() const { addNetwork } = useNetworks() const [error, setError] = useState("") const handleNextStep = () => { setStep(step + 1) } const handlePreviousStep = () => { setStep(step - 1) } const handleComplete = async () => { if (password !== passwordConfirm) { setError("Passwords do not match") return } try { // Create user await axios.post("/api/user/create", { email, username, name, password }) // Create site using the hook const siteResult = addSite({ id: 0, name: siteName, description: "", networks: [] }) // Handle validation errors (returned as strings) if (typeof siteResult === "string") { setError(siteResult) return } // If not a string, it's a Promise - await it const site = await siteResult if (!site || !site.id) { setError("Failed to create site") return } // Create network using the hook const networkResult = addNetwork({ id: 0, name: networkName, siteId: site.id, ipv4Subnet: "", ipv6Subnet: "", gateway: "" }) // Handle validation errors if (typeof networkResult === "string") { setError(networkResult) return } // If not a string, it's a Promise - await it const network = await networkResult if (!network) { setError("Failed to create network") return } // Success - navigate to home router.push("/") } catch (error: any) { console.error("Error in setup:", error) setError(typeof error === "string" ? error : error.response?.data?.error || error.message || "An unknown error occurred") } } return (
  • = 1 ? "step step-primary" : "step"}>Create account
  • = 2 ? "step step-primary" : "step"}>Create site & network
  • = 3 ? "step step-primary" : "step"}>Next Steps
{step === 1 && (

Create account

Please create an account to get started.

Email
Enter valid email address
Username
Enter valid username
Full Name
Enter valid full name
Password
Enter valid password
Repeat Password
Enter valid repeat password
)} {step === 2 && (

Create site & network

Please create a site & network to get started. Don't worry, you can always change it later.

Site Name
Enter valid site name
Network Name
Enter valid network name
)} {step === 3 && (

Next Steps

Here are some next steps to get you started

1. Click Complete to finish the setup & create the user

2. Create a site with a network

3. Add your first server to the network

4. Add all your self-hosted applications to the server

5. Setup notifications to be notified about any issues

6. Leave a star on GitHub if you like it

)}
setError("")} />
) }