-
Notifications
You must be signed in to change notification settings - Fork 0
[WIP] generate LoginPage container and LoginForm component #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aze3ma
wants to merge
2
commits into
dev
Choose a base branch
from
FE-3_migrate-login-page
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* Asynchronously loads the component for LoginPage | ||
*/ | ||
import loadable from 'loadable-components'; | ||
|
||
export default loadable(() => import('./index')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* | ||
* LoginPage actions | ||
* | ||
*/ | ||
|
||
import { AUTHENTICATION } from './constants'; | ||
|
||
export function login(credentials) { | ||
console.log({ credentials }); | ||
return { | ||
type: AUTHENTICATION.LOGIN_REQUEST, | ||
}; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* | ||
* LoginPage constants | ||
* | ||
*/ | ||
|
||
export const AUTHENTICATION = { | ||
LOGIN_REQUEST: 'USER_LOGIN_REQUEST', | ||
LOGIN_SUCCESS: 'USER_LOGIN_SUCCESS', | ||
LOGIN_FAILURE: 'USER_LOGIN_FAILURE', | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
|
||
import { login } from './actions'; | ||
|
||
/* eslint-disable react/prefer-stateless-function */ | ||
class LoginPage extends React.PureComponent { | ||
static propTypes = { | ||
login: PropTypes.func.isRequired, | ||
}; | ||
|
||
state = { | ||
username: '', | ||
password: '', | ||
}; | ||
|
||
handleSubmit = event => { | ||
event.preventDefault(); | ||
this.props.login(this.state); | ||
}; | ||
|
||
handleChange = event => { | ||
this.setState({ [event.target.name]: event.target.value }); | ||
}; | ||
|
||
render() { | ||
const { username, password } = this.state; | ||
|
||
return ( | ||
<form className="login-form" onSubmit={this.handleSubmit}> | ||
<div className="login-form__field"> | ||
<label htmlFor="username">Username</label> | ||
<input | ||
type="text" | ||
id="username" | ||
name="username" | ||
placeholder="Username" | ||
value={username} | ||
onChange={this.handleChange} | ||
required | ||
/> | ||
</div> | ||
<div className="login-form__field"> | ||
<label htmlFor="password">Password</label> | ||
<input | ||
type="password" | ||
id="password" | ||
name="password" | ||
placeholder="Password" | ||
value={password} | ||
onChange={this.handleChange} | ||
required | ||
/> | ||
</div> | ||
<button type="submit">Login</button> | ||
</form> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = state => ({ | ||
username: state.username, | ||
password: state.password, | ||
}); | ||
|
||
export default connect( | ||
mapStateToProps, | ||
{ login }, | ||
)(LoginPage); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* | ||
* LoginPage reducer | ||
* | ||
*/ | ||
|
||
import { fromJS } from 'immutable'; | ||
|
||
import { AUTHENTICATION } from './constants'; | ||
import { retrieveFromLocalStorage } from '../../utils/localStorage'; | ||
|
||
export const initialState = fromJS({ | ||
isAuthenticated: !!retrieveFromLocalStorage('xSessionToken'), | ||
}); | ||
|
||
function loginPageReducer(state = initialState, action) { | ||
switch (action.type) { | ||
case AUTHENTICATION.LOGIN_REQUEST: | ||
return state.set('isAuthenticated', false); | ||
default: | ||
return state; | ||
} | ||
} | ||
|
||
export default loginPageReducer; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { browserHistory } from 'react-router-dom'; | ||
import { Provider } from 'react-redux'; | ||
|
||
import LoginPage from 'containers/LoginPage'; | ||
|
||
import configureStore from '../../../configureStore'; | ||
|
||
describe('<LoginPage />', () => { | ||
let mountedLoginPage; | ||
|
||
let store; | ||
|
||
beforeAll(() => { | ||
store = configureStore({}, browserHistory); | ||
}); | ||
|
||
beforeEach(() => { | ||
mountedLoginPage = mount( | ||
<Provider store={store}> | ||
<LoginPage /> | ||
</Provider>, | ||
); | ||
}); | ||
|
||
it('should render without crashing', () => { | ||
mount( | ||
<Provider store={store}> | ||
<LoginPage /> | ||
</Provider>, | ||
); | ||
}); | ||
|
||
it('should renders its children ', () => { | ||
const children = mountedLoginPage.find('form.login-form'); | ||
expect(children.length).toBe(1); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export function storeInLocalStorage({ label, value }) { | ||
localStorage.setItem(label, value); | ||
} | ||
|
||
export function retrieveFromLocalStorage(item) { | ||
return localStorage.getItem(item); | ||
} | ||
|
||
export function removeFromLocalStorage(item) { | ||
return localStorage.removeItem(item); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to remove all
console.log
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course I will that's why I labeled my PR [WIP] (work in progress).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahaa, sorry didn't notice that.