diff --git a/client/src/components/windows/login/LoginWindow.tsx b/client/src/components/windows/login/LoginWindow.tsx index 134248a..fe9e216 100644 --- a/client/src/components/windows/login/LoginWindow.tsx +++ b/client/src/components/windows/login/LoginWindow.tsx @@ -3,14 +3,23 @@ import { WindowState } from "../Windows"; import { Box, Paper, Typography, TextField, Button } from "@material-ui/core"; import { useHistory, useLocation } from 'react-router'; import { useAuth, Auth } from '../../../lib/useAuth'; +import Alert from '@material-ui/lab/Alert'; + +export enum LoginStatus { + NoneSubmitted = 0, + Unsuccessful, + // Note: no "successful" status because that would lead to a redirect. +} export interface LoginWindowState extends WindowState { email: string, password: string, + status: LoginStatus, } export enum LoginWindowStateActions { SetEmail = "SetEmail", SetPassword = "SetPassword", + SetStatus = "SetStatus", } export function LoginWindowReducer(state: LoginWindowState, action: any) { switch (action.type) { @@ -18,6 +27,8 @@ export function LoginWindowReducer(state: LoginWindowState, action: any) { return { ...state, email: action.value } case LoginWindowStateActions.SetPassword: return { ...state, password: action.value } + case LoginWindowStateActions.SetStatus: + return { ...state, status: action.value } default: throw new Error("Unimplemented LoginWindow state update.") } @@ -27,6 +38,7 @@ export default function LoginWindow(props: {}) { const [state, dispatch] = useReducer(LoginWindowReducer, { email: "", password: "", + status: LoginStatus.NoneSubmitted, }); return @@ -46,6 +58,11 @@ export function LoginWindowControlled(props: { auth.signin(props.state.email, props.state.password) .then(() => { history.replace(from); + }).catch((e: any) => { + props.dispatch({ + type: LoginWindowStateActions.SetStatus, + value: LoginStatus.Unsuccessful, + }) }) } @@ -86,6 +103,10 @@ export function LoginWindowControlled(props: { value: e.target.value })} /> + {props.state.status === LoginStatus.Unsuccessful && + Login failed - Please check your credentials. + + }