'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, MapPin, Receipt, Palette, Send } 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, testSmtpConfig } from '@/lib/actions/setup' import { ColorThemePicker } from '@/components/admin/ColorThemePicker' export function SetupWizard() { const router = useRouter() const [step, setStep] = useState(1) const [loading, setLoading] = useState(false) const [errorMsg, setErrorMsg] = useState('') const [testSmtpLoading, setTestSmtpLoading] = useState(false) const [testSmtpResult, setTestSmtpResult] = useState<{ success: boolean; message: string } | null>(null) // Step 2: Admin Account const [adminForm, setAdminForm] = useState({ email: '', password: '', confirmPassword: '', firstName: '', lastName: '', }) // Step 3: Firmendaten & Rechnungsadresse const [brandingForm, setBrandingForm] = useState({ companyName: '', street: '', zip: '', city: '', billingStreet: '', billingZip: '', billingCity: '', sameBillingAddress: true, colorScheme: 'modern_blue', primaryColor: '#2563eb', accentColor: '#38bdf8', }) // Step 5: SMTP Config const [smtpForm, setSmtpForm] = useState({ host: '', port: '587', secure: false, user: '', pass: '', }) // Validations const isAdminFormValid = adminForm.email.includes('@') && adminForm.password.length >= 6 && adminForm.password === adminForm.confirmPassword && adminForm.firstName.trim().length > 0 && adminForm.lastName.trim().length > 0 const isCompanyFormValid = brandingForm.companyName.trim().length > 0 && brandingForm.street.trim().length > 0 && brandingForm.zip.trim().length > 0 && brandingForm.city.trim().length > 0 && (brandingForm.sameBillingAddress || (brandingForm.billingStreet.trim().length > 0 && brandingForm.billingZip.trim().length > 0 && brandingForm.billingCity.trim().length > 0)) const handleTestSmtp = async () => { setTestSmtpLoading(true) setTestSmtpResult(null) const res = await testSmtpConfig( { host: smtpForm.host, port: Number(smtpForm.port), secure: smtpForm.secure, user: smtpForm.user, pass: smtpForm.pass, }, adminForm.email ) setTestSmtpResult(res) setTestSmtpLoading(false) } const handleFinishSetup = async () => { if (!isAdminFormValid || !isCompanyFormValid) return setLoading(true) setErrorMsg('') try { const res = await completeSetup( { email: adminForm.email, password: adminForm.password, companyName: brandingForm.companyName, firstName: adminForm.firstName, lastName: adminForm.lastName, }, { street: brandingForm.street, zip: brandingForm.zip, city: brandingForm.city, billingStreet: brandingForm.billingStreet, billingZip: brandingForm.billingZip, billingCity: brandingForm.billingCity, sameBillingAddress: brandingForm.sameBillingAddress, colorScheme: brandingForm.colorScheme, primaryColor: brandingForm.primaryColor, accentColor: brandingForm.accentColor, }, { 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 } // Setup erfolgreich – Weiterleitung zur Login-Seite router.push('/auth/login?setup=success') router.refresh() } catch (e: any) { setErrorMsg(e.message || 'Ein unerwarteter Fehler ist aufgetreten.') setLoading(false) } } return (
Richten Sie Ihren persönlichen Lizenz- und Anfrage-Shop ein. Wir konfigurieren Administrator-Zugang, Firmendaten, Rechnungsadresse und Ihr persönliches Farbschema.
Erstellen Sie das erste Administrator-Konto für vollen Systemzugriff.
Tragen Sie Ihren Firmennamen, die Anschrift und die Rechnungsadresse ein.
Wählen Sie aus 9 vorgegebenen Farbpaletten oder erstellen Sie eine eigene Farbkombination mit Live-Vorschau.
Tragen Sie Ihre Mailserver-Daten ein oder überspringen Sie diesen Schritt. Sie können die Einstellungen jederzeit im Admin-Bereich anpassen.