'use client' import { useState } from 'react' import { useRouter } from 'next/navigation' import { motion, AnimatePresence } from 'framer-motion' import { Sparkles, ShieldCheck, Mail, ArrowRight, Loader2, Check, Lock, Building, User } from 'lucide-react' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { createClient } from '@/lib/supabase/client' import { completeSetup } from '@/lib/actions/setup' export function SetupWizard() { const router = useRouter() const [step, setStep] = useState(1) const [loading, setLoading] = useState(false) const [errorMsg, setErrorMsg] = useState('') // Step 2 Form: Admin account const [adminForm, setAdminForm] = useState({ email: '', password: '', confirmPassword: '', companyName: '', firstName: '', lastName: '', }) // Step 3 Form: SMTP Config const [smtpForm, setSmtpForm] = useState({ host: '', port: '587', secure: false, user: '', pass: '', }) // Validation checks for Admin form const isAdminFormValid = adminForm.email.includes('@') && adminForm.password.length >= 6 && adminForm.password === adminForm.confirmPassword && adminForm.companyName.trim().length > 0 && adminForm.firstName.trim().length > 0 && adminForm.lastName.trim().length > 0 // Validation checks for SMTP form const isSmtpFormValid = smtpForm.host.trim().length > 0 && !isNaN(Number(smtpForm.port)) && smtpForm.user.trim().length > 0 const handleFinishSetup = async () => { if (!isAdminFormValid || !isSmtpFormValid) return setLoading(true) setErrorMsg('') try { // 1. Submit details via server action const res = await completeSetup( { email: adminForm.email, password: adminForm.password, companyName: adminForm.companyName, firstName: adminForm.firstName, lastName: adminForm.lastName, }, { host: smtpForm.host, port: Number(smtpForm.port), secure: smtpForm.secure, user: smtpForm.user, pass: smtpForm.pass, } ) if (!res.success) { setErrorMsg(res.error || 'Fehler beim Setup.') setLoading(false) return } // 2. Automatischer Login für flüssiges Erlebnis const supabase = createClient() const { error: loginError } = await supabase.auth.signInWithPassword({ email: adminForm.email, password: adminForm.password, }) if (loginError) { console.error('Auto login failed:', loginError) // Redirect anyway since setup is done } // 3. Weiterleitung router.push('/') router.refresh() } catch (e: any) { setErrorMsg(e.message || 'Ein unerwarteter Fehler ist aufgetreten.') setLoading(false) } } return (
{/* Dynamic Background Glow */}
{/* Step Indicator Header */}
CASPOS Initialisierung
{[1, 2, 3].map((s) => (
))}
{step === 1 && (

Willkommen bei CASPOS!

Richten Sie Ihren persönlichen Lizenz- und Angebots-Shop in wenigen Schritten ein. Wir konfigurieren Ihr Administrator-Konto und die Mailverbindung.

Komplett self-hosted & sicher
Automatische Schema-Updates auf dem neuesten Stand
SMTP Mailversand für direkte Angebotsbestätigungen
)} {step === 2 && (

Admin-Konto anlegen

Erstellen Sie den ersten Administrator-Benutzer. Dieser erhält vollen Zugriff auf das System.

setAdminForm({ ...adminForm, firstName: e.target.value })} placeholder="Vorname" className="pl-9 bg-white/5 border-white/10 text-white placeholder:text-slate-600" />
setAdminForm({ ...adminForm, lastName: e.target.value })} placeholder="Nachname" className="pl-9 bg-white/5 border-white/10 text-white placeholder:text-slate-600" />
setAdminForm({ ...adminForm, companyName: e.target.value })} placeholder="Name Ihrer Firma" className="pl-9 bg-white/5 border-white/10 text-white placeholder:text-slate-600" />
setAdminForm({ ...adminForm, email: e.target.value })} placeholder="admin@firma.de" className="pl-9 bg-white/5 border-white/10 text-white placeholder:text-slate-600" />
setAdminForm({ ...adminForm, password: e.target.value })} placeholder="••••••" className="pl-9 bg-white/5 border-white/10 text-white placeholder:text-slate-600" />
setAdminForm({ ...adminForm, confirmPassword: e.target.value })} placeholder="••••••" className="pl-9 bg-white/5 border-white/10 text-white placeholder:text-slate-600" />
)} {step === 3 && (

SMTP-Mailserver konfigurieren

Tragen Sie Ihre Mailserver-Daten ein, um automatisierte E-Mails an Partner und Kunden senden zu können.

{errorMsg && (
{errorMsg}
)}
setSmtpForm({ ...smtpForm, host: e.target.value })} placeholder="smtp.domain.de" className="bg-white/5 border-white/10 text-white placeholder:text-slate-600" />
setSmtpForm({ ...smtpForm, port: e.target.value })} placeholder="587" className="bg-white/5 border-white/10 text-white" />
setSmtpForm({ ...smtpForm, user: e.target.value })} placeholder="mail@domain.de" className="bg-white/5 border-white/10 text-white placeholder:text-slate-600" />
setSmtpForm({ ...smtpForm, pass: e.target.value })} placeholder="••••••••••••" className="bg-white/5 border-white/10 text-white placeholder:text-slate-600" />
setSmtpForm({ ...smtpForm, secure: e.target.checked })} className="w-4 h-4 rounded border-slate-700 bg-white/5 text-blue-500 focus:ring-0 focus:ring-offset-0" />
)}
) }