Skip to content

Commit 5fb2663

Browse files
author
Emile Frey
committed
adds loading to login and password update
1 parent 855f99e commit 5fb2663

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
- [ ] Are we in good shape to deploy?
1313
- [ ] Update and Pin versions (remove anything unused)
1414
- [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
15+
- [x] error context
16+
- [x] show password errors
17+
- [x] loading icon on login
18+
- [ ] forgot password functionality

frontend/src/components/Login/Login.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import * as actions from '../../auth/authActions';
1515
import { useHistory, useLocation } from "react-router-dom";
1616
import { AppProps } from '../../App';
1717
import validationErrorMessages from '../../helpers/validationErrorMessages'
18+
import { LinearProgress } from '@material-ui/core';
1819

1920
const useStyles = makeStyles((theme) => ({
2021
paper: {
@@ -48,6 +49,7 @@ function Login(props: AppProps) {
4849
const [username, setuserName] = useState("");
4950
const [password, setPassword] = useState("");
5051
const [validationErrors, setValidationErrors] = useState<string[]>([])
52+
const [isLoading, setIsLoading] = useState(false)
5153

5254
let history = useHistory();
5355
let location = useLocation<LocationState>();
@@ -59,6 +61,7 @@ function Login(props: AppProps) {
5961

6062
useEffect(() => {
6163
setValidationErrors(props.error ? props.error.response.data.non_field_errors : [])
64+
setIsLoading(false)
6265
}, [props.error])
6366

6467
const handleFormFieldChange = (event: React.ChangeEvent<HTMLInputElement>) => {
@@ -73,6 +76,7 @@ function Login(props: AppProps) {
7376
const handleSubmit = (e: React.ChangeEvent<HTMLFormElement>) => {
7477
e.preventDefault();
7578
props.onAuth(username, password);
79+
setIsLoading(true)
7680
}
7781

7882
return (
@@ -111,6 +115,7 @@ function Login(props: AppProps) {
111115
onChange={handleFormFieldChange}
112116
/>
113117
{validationErrorMessages(validationErrors)}
118+
{isLoading && <LinearProgress color="secondary" />}
114119
<Button
115120
type="submit"
116121
fullWidth

frontend/src/components/Login/PasswordUpdate.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import axios, { AxiosRequestConfig } from 'axios';
33
import * as settings from '../../settings';
44

55
import { makeStyles } from '@material-ui/core/styles';
6-
import { Avatar, Button, Container, CssBaseline, TextField, Typography } from '@material-ui/core';
6+
import { Avatar, Button, Container, CssBaseline, LinearProgress, TextField, Typography } from '@material-ui/core';
77
import VpnKeyIcon from '@material-ui/icons/VpnKey';
88
import { AuthProps } from '../../App';
99
import { PasswordUpdateError } from '../../interfaces/axios/AxiosError';
@@ -39,6 +39,7 @@ function PasswordUpdate(props: AuthProps) {
3939
const [new_password2, setNewPassword2] = useState("");
4040
const [success, setSuccess] = useState(false);
4141
const [validationErrors, setValidationErrors] = useState<string[]>([])
42+
const [isLoading, setIsLoading] = useState(false)
4243

4344
const handleFormFieldChange = (event: React.ChangeEvent<HTMLInputElement>) => {
4445
setSuccess(false);
@@ -52,6 +53,7 @@ function PasswordUpdate(props: AuthProps) {
5253

5354
const handleSubmit = (e: React.ChangeEvent<HTMLFormElement>) => {
5455
e.preventDefault();
56+
setIsLoading(true)
5557
if (new_password1 !== new_password2) {
5658
setValidationErrors(["Passwords don't match!"])
5759
} else if (new_password1 === "") {
@@ -72,6 +74,7 @@ function PasswordUpdate(props: AuthProps) {
7274
(error: PasswordUpdateError) => {
7375
console.log(error.response.data.new_password2)
7476
setValidationErrors(error.response.data.new_password2)
77+
setIsLoading(false)
7578
})
7679
}
7780
}
@@ -88,7 +91,7 @@ function PasswordUpdate(props: AuthProps) {
8891
<>
8992
<Typography component="h1" variant="h5">
9093
Update Password
91-
</Typography>
94+
</Typography>
9295
<form className={classes.form} noValidate onSubmit={handleSubmit}>
9396
<TextField
9497
variant="outlined"
@@ -117,6 +120,7 @@ function PasswordUpdate(props: AuthProps) {
117120
helperText={new_password1 !== new_password2 ? "Passwords don't match" : null}
118121
/>
119122
{validationErrorMessages(validationErrors)}
123+
{isLoading && <LinearProgress color="secondary" />}
120124
<Button
121125
type="submit"
122126
fullWidth
@@ -133,7 +137,7 @@ function PasswordUpdate(props: AuthProps) {
133137
variant="contained"
134138
color="primary"
135139
href="/"> Return Home
136-
</Button>
140+
</Button>
137141
}
138142
</div >
139143
</Container >

0 commit comments

Comments
 (0)