import { useState } from "react"; import { NewUser } from "../Types/goTypes"; import { api } from "../API/API"; import Logo from "../assets/Logo.svg"; import Button from "./Button"; import InputField from "./InputField"; /** * Renders a registration form for the admin to add new users in. * @returns The JSX element representing the registration form. */ export default function Register(): JSX.Element { const [username, setUsername] = useState(); const [password, setPassword] = useState(); const [errMessage, setErrMessage] = useState(); const handleRegister = async (): Promise => { if (username === "" || password === "") { alert("Must provide username and password"); return; } const newUser: NewUser = { username: username?.replace(/ /g, "") ?? "", password: password ?? "", }; const response = await api.registerUser(newUser); if (response.success) { alert(`${newUser.username} added!`); setPassword(""); setUsername(""); } else { alert("User not added, name could be taken"); setErrMessage(response.message ?? "Unknown error"); console.error(errMessage); } }; return (
{ e.preventDefault(); void handleRegister(); }} > TTIME Logo

Register New User

{ setUsername(e.target.value); }} placeholder={"Username"} /> { setPassword(e.target.value); }} placeholder={"Password"} />

); }