Added some alerts
This commit is contained in:
parent
19cb8dbd94
commit
752d366cf7
1 changed files with 2 additions and 4 deletions
|
@ -4,7 +4,6 @@ import { api } from "../API/API";
|
||||||
import Logo from "../assets/Logo.svg";
|
import Logo from "../assets/Logo.svg";
|
||||||
import Button from "./Button";
|
import Button from "./Button";
|
||||||
import InputField from "./InputField";
|
import InputField from "./InputField";
|
||||||
import { useNavigate } from "react-router-dom";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders a registration form for the admin to add new users in.
|
* 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 [password, setPassword] = useState<string>();
|
||||||
const [errMessage, setErrMessage] = useState<string>();
|
const [errMessage, setErrMessage] = useState<string>();
|
||||||
|
|
||||||
const nav = useNavigate();
|
|
||||||
|
|
||||||
const handleRegister = async (): Promise<void> => {
|
const handleRegister = async (): Promise<void> => {
|
||||||
const newUser: NewUser = {
|
const newUser: NewUser = {
|
||||||
username: username ?? "",
|
username: username ?? "",
|
||||||
|
@ -24,8 +21,9 @@ export default function Register(): JSX.Element {
|
||||||
};
|
};
|
||||||
const response = await api.registerUser(newUser);
|
const response = await api.registerUser(newUser);
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
nav("/"); // Instantly navigate to the login page
|
alert("User added!");
|
||||||
} else {
|
} else {
|
||||||
|
alert("User not added");
|
||||||
setErrMessage(response.message ?? "Unknown error");
|
setErrMessage(response.message ?? "Unknown error");
|
||||||
console.error(errMessage);
|
console.error(errMessage);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue