Added some alerts

This commit is contained in:
Peter KW 2024-03-28 01:35:16 +01:00
parent 19cb8dbd94
commit 752d366cf7

View file

@ -4,7 +4,6 @@ import { api } from "../API/API";
import Logo from "../assets/Logo.svg";
import Button from "./Button";
import InputField from "./InputField";
import { useNavigate } from "react-router-dom";
/**
* Renders a registration form for the admin to add new users in.
@ -15,8 +14,6 @@ export default function Register(): JSX.Element {
const [password, setPassword] = useState<string>();
const [errMessage, setErrMessage] = useState<string>();
const nav = useNavigate();
const handleRegister = async (): Promise<void> => {
const newUser: NewUser = {
username: username ?? "",
@ -24,8 +21,9 @@ export default function Register(): JSX.Element {
};
const response = await api.registerUser(newUser);
if (response.success) {
nav("/"); // Instantly navigate to the login page
alert("User added!");
} else {
alert("User not added");
setErrMessage(response.message ?? "Unknown error");
console.error(errMessage);
}