"use client" import React, { useState } from "react" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card" import { Checkbox } from "@/components/ui/checkbox" import { useAuth } from "@/lib/auth-context" import { type UserRole } from "@/lib/types" import { Mail, Lock, User, UserPlus, AlertCircle, Building2 } from "lucide-react" interface RegisterFormProps { onSwitchToLogin: () => void } export function RegisterForm({ onSwitchToLogin }: RegisterFormProps) { const { register, rooms } = useAuth() const [firstname, setFirstname] = useState("") const [lastname, setLastname] = useState("") const [email, setEmail] = useState("") const [password, setPassword] = useState("") const [role, setRole] = useState("LEHRKRAFT") const [selectedRoomIds, setSelectedRoomIds] = useState([]) const [error, setError] = useState("") const [isLoading, setIsLoading] = useState(false) const handleRoomToggle = (roomId: number) => { setSelectedRoomIds((prev) => (prev.includes(roomId) ? prev.filter((r) => r !== roomId) : [...prev, roomId])) } const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError("") if (role === "RAUMBETREUER" && selectedRoomIds.length === 0) { setError("Bitte wählen Sie mindestens einen Raum aus") return } setIsLoading(true) const success = await register( { firstname, lastname, email, role, roomIds: role === "RAUMBETREUER" ? selectedRoomIds : undefined, password } ) if (!success) { setError("Registrierung fehlgeschlagen") } // API logic redirects or we stay here. If success, we probably want to call onSwitchToLogin if strictly following "register then login" flow, // but AuthContext comments implied auto-login or just handled. // Actually AuthContext returns true if success. if (success) { onSwitchToLogin() } setIsLoading(false) } return ( Konto erstellen Geben Sie Ihre Daten ein
{error && (
{error}
)}
setFirstname(e.target.value)} className="pl-10" required />
setLastname(e.target.value)} className="pl-10" required />
setEmail(e.target.value)} className="pl-10" required />
setPassword(e.target.value)} className="pl-10" required minLength={4} />
{role === "RAUMBETREUER" && (
{rooms.map((room) => (
handleRoomToggle(room.id)} />
))}
{selectedRoomIds.length > 0 && (

{selectedRoomIds.length} Raum/Räume ausgewählt

)}
)}

Bereits registriert?{" "}

) }