Skip to content

Commit e450396

Browse files
committed
Add "New User" tab on login page; Login page prettify
1 parent 04e7b4a commit e450396

File tree

3 files changed

+301
-133
lines changed

3 files changed

+301
-133
lines changed

src/pages/login/LoginContainer.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,50 @@
1-
import { compose, withState, withHandlers, lifecycle } from 'recompose';
2-
import { withRouter } from 'react-router-dom';
3-
import { connect } from 'react-redux';
1+
import { compose, withState, withHandlers, lifecycle } from "recompose";
2+
import { withRouter } from "react-router-dom";
3+
import { connect } from "react-redux";
44

5-
import LoginView from './LoginView';
6-
import { loginUser, resetError } from './LoginState';
5+
import LoginView from "./LoginView";
6+
import { loginUser, resetError } from "./LoginState";
77

88
export default compose(
99
connect(
1010
state => ({
1111
isLoading: state.login.isLoading,
1212
isAuthenticated: state.login.isAuthenticated,
13-
error: state.login.error,
13+
error: state.login.error
1414
}),
15-
{ loginUser, resetError },
15+
{ loginUser, resetError }
1616
),
1717
withRouter,
18-
withState('activeTabId', 'setActiveTabId', 0),
19-
withState('loginValue', 'setLoginValue', ''),
20-
withState('passwordValue', 'setPasswordValue', ''),
18+
withState("activeTabId", "setActiveTabId", 0),
19+
withState("nameValue", "setNameValue", ""),
20+
withState("loginValue", "setLoginValue", ""),
21+
withState("passwordValue", "setPasswordValue", ""),
2122
withHandlers({
2223
handleTabChange: props => (e, id) => {
2324
props.setActiveTabId(id);
2425
},
25-
handleInput: props => (e, input = 'login') => {
26+
handleInput: props => (e, input = "login") => {
2627
if (props.error) {
2728
props.resetError();
2829
}
2930

30-
if (input === 'login') {
31+
if (input === "login") {
3132
props.setLoginValue(e.target.value);
32-
} else {
33+
} else if (input === "password") {
3334
props.setPasswordValue(e.target.value);
35+
} else if (input === "name") {
36+
props.setNameValue(e.target.value);
3437
}
3538
},
3639
handleLoginButtonClick: props => () => {
3740
props.loginUser(props.loginValue, props.passwordValue);
38-
},
41+
}
3942
}),
4043
lifecycle({
4144
componentWillReceiveProps(nextProps) {
4245
if (!this.props.error && nextProps.error) {
43-
this.props.setPasswordValue('');
46+
this.props.setPasswordValue("");
4447
}
4548
}
4649
})
47-
)(LoginView);
50+
)(LoginView);

src/pages/login/LoginState.js

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
export const initialState = {
22
isLoading: false,
33
isAuthenticated: false,
4-
error: null,
4+
error: null
55
};
66

7-
export const START_LOGIN = 'Login/START_LOGIN';
8-
export const LOGIN_SUCCESS = 'Login/LOGIN_SUCCESS';
9-
export const LOGIN_FAILURE = 'Login/LOGIN_FAILURE';
10-
export const RESET_ERROR = 'Login/RESET_ERROR';
11-
export const LOGIN_USER = 'Login/LOGIN_USER';
12-
export const SIGN_OUT_SUCCESS = 'Login/SIGN_OUT_SUCCESS';
7+
export const START_LOGIN = "Login/START_LOGIN";
8+
export const LOGIN_SUCCESS = "Login/LOGIN_SUCCESS";
9+
export const LOGIN_FAILURE = "Login/LOGIN_FAILURE";
10+
export const RESET_ERROR = "Login/RESET_ERROR";
11+
export const LOGIN_USER = "Login/LOGIN_USER";
12+
export const SIGN_OUT_SUCCESS = "Login/SIGN_OUT_SUCCESS";
1313

1414
export const startLogin = () => ({
15-
type: START_LOGIN,
15+
type: START_LOGIN
1616
});
1717

1818
export const loginSuccess = () => ({
19-
type: LOGIN_SUCCESS,
19+
type: LOGIN_SUCCESS
2020
});
2121

2222
export const loginFailure = () => ({
23-
type: LOGIN_FAILURE,
23+
type: LOGIN_FAILURE
2424
});
2525

2626
export const resetError = () => ({
27-
type: RESET_ERROR,
28-
})
27+
type: RESET_ERROR
28+
});
2929

3030
export const loginUser = (login, password) => dispatch => {
3131
dispatch(startLogin());
3232

3333
if (!!login && !!password) {
3434
setTimeout(() => {
35-
localStorage.setItem('id_token', '1');
35+
localStorage.setItem("id_token", "1");
3636
dispatch(loginSuccess());
3737
}, 2000);
3838
} else {
@@ -41,11 +41,11 @@ export const loginUser = (login, password) => dispatch => {
4141
};
4242

4343
export const signOutSuccess = () => ({
44-
type: SIGN_OUT_SUCCESS,
44+
type: SIGN_OUT_SUCCESS
4545
});
4646

4747
export const signOut = () => dispatch => {
48-
localStorage.removeItem('id_token');
48+
localStorage.removeItem("id_token");
4949
dispatch(signOutSuccess());
5050
};
5151

@@ -54,32 +54,31 @@ export default function LoginReducer(state = initialState, { type, payload }) {
5454
case START_LOGIN:
5555
return {
5656
...state,
57-
isLoading: true,
57+
isLoading: true
5858
};
5959
case LOGIN_SUCCESS:
6060
return {
6161
...state,
6262
isLoading: false,
6363
isAuthenticated: true,
64-
error: null,
64+
error: null
6565
};
6666
case LOGIN_FAILURE:
6767
return {
6868
...state,
6969
isLoading: false,
70-
error: true,
70+
error: true
7171
};
7272
case RESET_ERROR:
7373
return {
74-
error: false,
74+
error: false
7575
};
7676
case SIGN_OUT_SUCCESS:
77-
debugger;
7877
return {
7978
...state,
80-
isAuthenticated: false,
79+
isAuthenticated: false
8180
};
8281
default:
8382
return state;
8483
}
85-
}
84+
}

0 commit comments

Comments
 (0)