Skip to content

Commit 065c256

Browse files
author
Emile Frey
committed
WIP dding alert display
1 parent d67a177 commit 065c256

File tree

6 files changed

+56
-7
lines changed

6 files changed

+56
-7
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
- [ ] Readme (setup and how to remove remnants of dummy stuff)
55
- [x] Material UI Theme
66
- [ ] Auto Logout with Failed Request
7-
- [ ] Auto Generation of Left Nav based on Routes
7+
- [ ] Auto Generation of Left Nav based on Routes?
88
- [x] Fix NGINX Docker Compose
99
- [ ] Create Axios Interfaces (like in TS)
1010
- [ ] Password Reset Email?
11-
- [ ] Scripting?
11+
- [ ] Scripting for setup?
1212
- [ ] Are we in good shape to deploy?
1313
- [ ] Update and Pin versions (remove anything unused)
14-
- [x] fix django admin not serving css files on admin page
14+
- [x] fix django admin not serving css files on admin page
15+
- [ ] error context
16+
- [ ] show password errors
17+
- [ ] loading icon on login
18+
- [ ] forgot password

frontend/package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"dependencies": {
66
"@material-ui/core": "^4.11.0",
77
"@material-ui/icons": "^4.9.1",
8+
"@material-ui/lab": "^4.0.0-alpha.57",
89
"@testing-library/jest-dom": "^4.2.4",
910
"@testing-library/react": "^9.3.2",
1011
"@testing-library/user-event": "^7.1.2",

frontend/src/App.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ export interface AuthProps {
1111
setAuthenticatedIfRequired: Function
1212
onAuth: Function
1313
token: string
14+
error: {
15+
message: string
16+
response: {
17+
data: {
18+
non_field_errors: string[]
19+
}
20+
}
21+
}
1422
}
1523

1624
export interface AppProps extends AuthProps, PrivateRouteProps { }
@@ -34,15 +42,24 @@ function App(props: AppProps) {
3442

3543
interface MapStateToPropsInterface {
3644
auth: {
37-
token: string
45+
token: string,
46+
error: {
47+
message: string
48+
response: {
49+
data: {
50+
non_field_errors: string[]
51+
}
52+
}
53+
}
3854
}
3955
}
4056

4157
//This means that one or more of the redux states in the store are available as props
4258
const mapStateToProps = (state: MapStateToPropsInterface) => {
4359
return {
4460
isAuthenticated: state.auth.token !== null && typeof state.auth.token !== 'undefined',
45-
token: state.auth.token
61+
token: state.auth.token,
62+
error: state.auth.error
4663
}
4764
}
4865

frontend/src/components/Layout/DropdownMenu.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Popper from '@material-ui/core/Popper';
66
import MenuList from '@material-ui/core/MenuList';
77
import { Children } from '../../interfaces/Children'
88
import { IconButton } from '@material-ui/core';
9+
import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown';
910

1011
interface DropdownMenuProps {
1112
children: Children
@@ -54,6 +55,7 @@ export default function DropdownMenu(props: DropdownMenuProps) {
5455
ref={anchorRef}
5556
>
5657
{props.dropdownButtonIcon}
58+
<ArrowDropDownIcon />
5759
</IconButton>
5860
<Popper open={open} anchorEl={anchorRef.current} role={undefined} transition disablePortal>
5961
{({ TransitionProps, placement }) => (

frontend/src/components/Login/Login.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Dispatch, useState } from 'react';
1+
import React, { Dispatch, useState, useEffect } from 'react';
22
import Avatar from '@material-ui/core/Avatar';
33
import Button from '@material-ui/core/Button';
44
import CssBaseline from '@material-ui/core/CssBaseline';
@@ -14,6 +14,7 @@ import * as actions from '../../auth/authActions';
1414

1515
import { useHistory, useLocation } from "react-router-dom";
1616
import { AppProps } from '../../App';
17+
import MuiAlert from '@material-ui/lab/Alert';
1718

1819

1920
const useStyles = makeStyles((theme) => ({
@@ -47,15 +48,20 @@ function Login(props: AppProps) {
4748
const classes = useStyles();
4849
const [username, setuserName] = useState("");
4950
const [password, setPassword] = useState("");
51+
const [validationErrors, setValidationErrors] = useState<string[]>([])
5052

5153
let history = useHistory();
5254
let location = useLocation<LocationState>();
5355
let { from } = location.state || { from: { pathname: "/" } };
5456

55-
React.useEffect(() => {
57+
useEffect(() => {
5658
if (props.isAuthenticated) { history.replace(from) };
5759
});
5860

61+
useEffect(() => {
62+
setValidationErrors(props.error.response.data.non_field_errors)
63+
}, [props.error])
64+
5965

6066
const handleFormFieldChange = (event: React.ChangeEvent<HTMLInputElement>) => {
6167
switch (event.target.id) {
@@ -71,6 +77,13 @@ function Login(props: AppProps) {
7177
props.onAuth(username, password);
7278
}
7379

80+
const validationErrorMessages = (
81+
validationErrors.map((value, index) => (
82+
<MuiAlert key={index} elevation={6} variant="filled" severity="warning" id="Validation-Message">{value}</MuiAlert>
83+
))
84+
);
85+
86+
7487
return (
7588
<Container component="main" maxWidth="xs">
7689
<CssBaseline />

0 commit comments

Comments
 (0)