Skip to content

Commit

Permalink
Display error (#123)
Browse files Browse the repository at this point in the history
* add error alert when trying to login

* Add Sidebar errors
  • Loading branch information
chennisden authored Jun 13, 2024
1 parent 972e6cd commit ca37a88
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
24 changes: 21 additions & 3 deletions frontend/src/components/nav/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useAlertQueue } from "hooks/alerts";
import { api } from "hooks/api";
import { useAuthentication } from "hooks/auth";
import { FormEvent, useEffect, useState } from "react";
Expand All @@ -10,6 +11,8 @@ interface Props {
}

const Sidebar = ({ show, onHide }: Props) => {
const { addAlert } = useAlertQueue();

const [needToCall, setNeedToCall] = useState<boolean>(true);
const [email, setEmail] = useState<string>("");
const [verified, setVerified] = useState<boolean>(false);
Expand All @@ -27,7 +30,14 @@ const Sidebar = ({ show, onHide }: Props) => {
try {
await auth_api.send_verify_email();
} catch (error) {
console.error(error);
if (error instanceof Error) {
addAlert(error.message, "error");
} else {
addAlert(
"Unexpected error when trying to send verification email",
"error",
);
}
}
};

Expand All @@ -37,7 +47,11 @@ const Sidebar = ({ show, onHide }: Props) => {
await auth_api.send_change_email(newEmail);
setChangeEmailSuccess(true);
} catch (error) {
console.error(error);
if (error instanceof Error) {
addAlert(error.message, "error");
} else {
addAlert("Unexpected error when trying to change email", "error");
}
}
};

Expand All @@ -47,7 +61,11 @@ const Sidebar = ({ show, onHide }: Props) => {
await auth_api.change_password(oldPassword, newPassword);
setChangePasswordSuccess(true);
} catch (error) {
console.error(error);
if (error instanceof Error) {
addAlert(error.message, "error");
} else {
addAlert("Unexpected error when trying to change password", "error");
}
}
};

Expand Down
9 changes: 8 additions & 1 deletion frontend/src/pages/Login.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useAlertQueue } from "hooks/alerts";
import { api } from "hooks/api";
import { setLocalStorageAuth, useAuthentication } from "hooks/auth";
import { FormEvent, useState } from "react";
Expand All @@ -8,6 +9,8 @@ const Login = () => {
const auth = useAuthentication();
const auth_api = new api(auth.api);

const { addAlert } = useAlertQueue();

const navigate = useNavigate();

const [password, setPassword] = useState<string>("");
Expand All @@ -20,7 +23,11 @@ const Login = () => {
setLocalStorageAuth(email);
navigate("/");
} catch (err) {
console.error(err);
if (err instanceof Error) {
addAlert(err.message, "error");
} else {
addAlert("Unexpected error when trying to log in", "error");
}
}
};

Expand Down

0 comments on commit ca37a88

Please sign in to comment.