import { useState } from "react"; import { useNavigate } from "react-router-dom"; import { registerUser } from "../services/authService"; const RegistrationScreen = () => { const [username, setUsername] = useState(""); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const [errorMessage, setErrorMessage] = useState(""); const navigate = useNavigate(); const handleRegister = async () => { if (password !== confirmPassword) { setErrorMessage("Passwörter stimmen nicht überein."); return; } try { const result = await registerUser(email, password, username); if (result) { console.log("Registrierung erfolgreich!"); navigate("/login"); } else { setErrorMessage("Registrierung fehlgeschlagen."); } } catch (error) { console.error("Fehler bei der Registrierung:", error); setErrorMessage("Es gab ein Problem bei der Registrierung."); } }; return (

Registrierung

setUsername(e.target.value)} style={styles.input} /> setEmail(e.target.value)} style={styles.input} /> setPassword(e.target.value)} style={styles.input} /> setConfirmPassword(e.target.value)} style={styles.input} /> {errorMessage &&

{errorMessage}

}

navigate("/login")} style={styles.linkText}> Schon ein Konto? Einloggen

); }; const styles: { [key: string]: React.CSSProperties } = { container: { display: "flex", flexDirection: "column", maxWidth: "400px", margin: "100px auto", padding: "20px", border: "1px solid #ccc", borderRadius: "8px", boxShadow: "0 0 10px rgba(0, 0, 0, 0.1)", }, title: { fontSize: "24px", marginBottom: "20px", textAlign: "center", }, input: { padding: "10px", marginBottom: "10px", borderRadius: "5px", border: "1px solid #ccc", fontSize: "16px", }, button: { padding: "10px", backgroundColor: "#007bff", color: "#fff", border: "none", borderRadius: "5px", cursor: "pointer", fontSize: "16px", }, linkText: { marginTop: "10px", color: "#007bff", textAlign: "center", cursor: "pointer", }, errorText: { color: "red", textAlign: "center", marginBottom: "10px", }, }; export default RegistrationScreen;