Skip to content

Commit 6cb6f1b

Browse files
Added progress spinner to signIn and signUp page
1 parent c90b7dd commit 6cb6f1b

File tree

7 files changed

+85
-29
lines changed

7 files changed

+85
-29
lines changed

client/src/components/routes/navbar/navBar.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import log from "loglevel";
2525
import Hidden from "@material-ui/core/Hidden";
2626
import BagButton from "./bagButton";
2727
import {tabsDataReducer} from "../../../reducers/screens/commonScreenReducer";
28-
import Spinner from "../../ui/spinner";
2928
import {HTTPError} from "../../ui/error/httpError";
3029
import {BadRequest} from "../../ui/error/badRequest";
3130
import SearchBar from "./searchBar";
@@ -100,7 +99,7 @@ const NavBar = props => {
10099

101100
if (tabsAPIData.isLoading) {
102101
log.info("[NavBar]: loading")
103-
return <Spinner/>
102+
return null
104103
} else {
105104
if (tabsAPIData.hasOwnProperty("data")) {
106105
if (Object.entries(tabsAPIData.data).length !== TABS_API_OBJECT_LEN) {
@@ -156,8 +155,8 @@ const NavBar = props => {
156155
open={isMenuOpen}
157156
onClose={handleMenuClose}
158157
>
159-
<Link to={!tokenId ? "/login" : "/"}>
160-
<MenuItem onClick={handleLoginStatus}>{!tokenId ? 'Login' : 'Logout'}</MenuItem>
158+
<Link to={!tokenId ? "/signin" : "/"}>
159+
<MenuItem onClick={handleLoginStatus}>{!tokenId ? 'SignIn' : 'SignOut'}</MenuItem>
161160
</Link>
162161
<MenuItem onClick={handleMenuClose}>My account</MenuItem>
163162
</Menu>

client/src/components/routes/signin/signIn.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,38 @@
1-
import React from "react";
1+
import React, {useEffect, useState} from "react";
22
import SignInForm from "./signInForm"
33
import {Grid, Typography} from "@material-ui/core";
44
import log from "loglevel";
55
import {StyledWebButton} from "../../../styles/semanticUI/customStyles";
66
import {Divider, Icon} from "semantic-ui-react";
77
import {Link} from "react-router-dom";
8+
import { Dimmer, Loader } from 'semantic-ui-react'
9+
import {useSelector} from "react-redux";
810

911
const SignIn = () => {
12+
const [isLoading, setIsLoading] = useState(false);
13+
const {timestamp} = useSelector(state => state.signInReducer)
14+
15+
const setIsLoadingState = () => {
16+
setIsLoading(true);
17+
}
18+
19+
useEffect(() => {
20+
log.info(`[SignIn]: Component did mount...`)
21+
setIsLoading(false)
22+
23+
}, [timestamp])
1024

1125
log.info(`[SignIn]: Rendering SignIn Component`)
1226

1327
return (
1428
<Grid container justify="center" style={{paddingTop: "2rem"}}>
15-
<Grid item container xs={3} direction="column">
29+
<Grid item container xs={10} sm={5} lg={3} direction="column">
1630

1731
<Grid item style={{alignSelf: "center", paddingBottom: "1rem"}}>
1832
<h1 style={{fontSize: "2.5rem"}}>Sign In</h1>
1933
</Grid>
2034

21-
<SignInForm/>
35+
<SignInForm loadingHandler={setIsLoadingState}/>
2236

2337
<Grid container justify="center">
2438
<Grid item style={{width: "100%", padding: "1rem 0"}}>
@@ -27,7 +41,7 @@ const SignIn = () => {
2741
</Grid>
2842

2943
<Grid container justify="center">
30-
<Grid item xs={5}>
44+
<Grid item xs={7} sm={5}>
3145
<StyledWebButton color='google plus'>
3246
<Icon name='google plus'/> Google
3347
</StyledWebButton>
@@ -41,6 +55,10 @@ const SignIn = () => {
4155
</Typography>
4256
</Grid>
4357

58+
{isLoading ? <Dimmer active inverted>
59+
<Loader inverted>Loading</Loader>
60+
</Dimmer> : null}
61+
4462
</Grid>
4563
</Grid>
4664
)

client/src/components/routes/signin/signInForm.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@ import {renderReduxTextField} from "../../ui/reduxTextField";
1010

1111
class SignInForm extends Component {
1212

13+
constructor(props) {
14+
super(props);
15+
this.state = {
16+
isLoading: false
17+
}
18+
}
19+
1320
handleSubmit = event => {
1421
event.preventDefault();
22+
this.props.loadingHandler(true)
1523
this.props.signIn(this.props.signInFormStore.values)
1624
}
1725

@@ -43,7 +51,7 @@ class SignInForm extends Component {
4351
)
4452
}
4553

46-
log.info(`[SignUpForm] Rendering SignUpForm Component...`)
54+
log.info(`[SignInForm] Rendering SignInForm Component...`)
4755

4856
return (
4957
<Grid container>
@@ -56,7 +64,7 @@ class SignInForm extends Component {
5664
{renderErrorMsg(this.props.signInReducer.errorMsg)}
5765

5866
<Grid container justify="center" style={{paddingTop: "2rem"}}>
59-
<Grid item sm={5}>
67+
<Grid item xs={7} sm={5}>
6068
<Button variant="contained"
6169
size="large"
6270
style={{

client/src/components/routes/signup/signUp.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
1-
import React from "react";
1+
import React, {useEffect, useState} from "react";
22
import SignUpForm from "./signUpForm"
33
import {Grid} from "@material-ui/core";
44
import log from "loglevel";
5+
import {useSelector} from "react-redux";
6+
import {Dimmer, Loader} from "semantic-ui-react";
57

68
const SignUp = () => {
9+
const [isLoading, setIsLoading] = useState(false);
10+
const {timestamp} = useSelector(state => state.signUpReducer)
11+
12+
const setIsLoadingState = () => {
13+
setIsLoading(true);
14+
}
15+
16+
useEffect(() => {
17+
log.info(`[SignIn]: Component did mount...`)
18+
setIsLoading(false)
19+
20+
}, [timestamp])
721

822
log.info(`[SignUp]: Rendering SignUp Component`)
923

1024
return (
1125
<Grid container justify="center" style={{paddingTop: "2rem"}}>
12-
<Grid item container xs={4} direction="column">
26+
<Grid item container xs={10} sm={6} lg={4} direction="column">
1327
<Grid item style={{alignSelf: "center"}}>
1428
<h1 style={{fontSize: "2.5rem"}}>Sign Up</h1>
1529
</Grid>
16-
<SignUpForm/>
30+
<SignUpForm loadingHandler={setIsLoadingState}/>
1731
</Grid>
32+
33+
{isLoading ? <Dimmer active inverted>
34+
<Loader inverted>Loading</Loader>
35+
</Dimmer> : null}
1836
</Grid>
1937
)
2038
}

client/src/components/routes/signup/signUpForm.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class SignUpForm extends Component {
2828
this.setState({errorMsg: "Please read the terms and conditions. Checkbox is uncheck."})
2929
return
3030
}
31+
32+
this.props.loadingHandler(true)
3133
this.props.signUp(this.props.signUpFormStore.values)
3234
}
3335

@@ -116,17 +118,19 @@ class SignUpForm extends Component {
116118
{renderErrorMsg(this.state.errorMsg)}
117119
{renderErrorMsg(this.props.signUpReducer.errorMsg)}
118120

119-
<Grid item container justify="center" style={{padding: "1rem 0"}}>
120-
<Button variant="contained"
121-
size="large"
122-
style={{
123-
width: "35%", backgroundColor: "teal",
124-
color: "white", fontSize: "1rem", fontWeight: "bold"
125-
}}
126-
disabled={submitting || pristine}
127-
type="submit">
128-
Sign Up
129-
</Button>
121+
<Grid container justify="center" style={{padding: "1rem 0"}}>
122+
<Grid item xs={10} sm={6}>
123+
<Button variant="contained"
124+
size="large"
125+
style={{
126+
width: "100%", backgroundColor: "teal",
127+
color: "white", fontSize: "1rem", fontWeight: "bold"
128+
}}
129+
disabled={submitting || pristine}
130+
type="submit">
131+
Sign Up
132+
</Button>
133+
</Grid>
130134
</Grid>
131135

132136
</form>

client/src/reducers/screens/commonScreenReducer.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ import {
3030
import _ from "lodash";
3131

3232

33-
export const signInReducer = (state = {isSignedIn: null}, action) => {
33+
export const signInReducer = (state = {isSignedIn: null, timestamp: null}, action) => {
34+
35+
// timestamp is used to update the state so that
36+
// we can stop loading progress component
3437
switch (action.type) {
3538
case HANDLE_SIGN_IN:
36-
return {...state, isSignedIn: true, tokenId: action.payload};
39+
return {...state, isSignedIn: true, tokenId: action.payload, timestamp: Date.now()};
3740
case HANDLE_SIGN_IN_ERROR:
38-
return {...state, isSignedIn: false, errorMsg: action.payload};
41+
return {...state, isSignedIn: false, errorMsg: action.payload, timestamp: Date.now()};
3942
case HANDLE_SIGN_OUT:
4043
return _.omit(state, 'tokenId', 'errorMsg');
4144
default:
@@ -44,10 +47,12 @@ export const signInReducer = (state = {isSignedIn: null}, action) => {
4447
};
4548

4649
export const signUpReducer = (state
47-
= {errorMsg: null}, action) => {
50+
= {errorMsg: null, timestamp: null}, action) => {
51+
// timestamp is used to update the state so that
52+
// we can stop loading progress component
4853
switch (action.type) {
4954
case HANDLE_SIGN_UP_ERROR:
50-
return {...state, errorMsg: action.payload};
55+
return {...state, errorMsg: action.payload, timestamp: Date.now()};
5156
case HANDLE_SIGN_UP_RESET:
5257
return {account_status: null, errorMsg: null}
5358
default:

client/src/styles/index.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ body ::-webkit-scrollbar {
1212

1313
#customDropdown {
1414
font-weight: bold;
15+
}
16+
17+
input {
18+
font-size: 1.2rem !important;
1519
}

0 commit comments

Comments
 (0)