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
Add registration UI & routing #27
Conversation
Add Routing Add Registration component, actions & reducers
src/PrivateRoute.js
Outdated
<Route {...rest} render={props => ( | ||
localStorage.getItem('token') | ||
? <Component {...props} /> | ||
: <Redirect to='/register'/> |
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.
check if the redirect path is correct once.
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.
Can we make use of register()
in urls.js
instead? @bismitaguha
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.
Also, please add newlines to the end of files which do not have it.
src/PrivateRoute.js
Outdated
<Route {...rest} render={props => ( | ||
localStorage.getItem('token') | ||
? <Component {...props} /> | ||
: <Redirect to='/register'/> |
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.
Can we make use of register()
in urls.js
instead? @bismitaguha
src/actions/info.js
Outdated
import axios from 'axios' | ||
import { | ||
urlInfo | ||
} from '../urls' | ||
import { | ||
GET_USER_INFO, | ||
POST_USER_INFO, | ||
USER_INFO_ERRORS | ||
} from './types' | ||
|
||
export const getInfo = () => async dispatch => { | ||
try { | ||
const config = { | ||
headers: { | ||
Authorization: `Bearer ${localStorage.token}`, | ||
} | ||
} | ||
const res = await axios.get(urlInfo(), config); | ||
dispatch({ | ||
type: GET_USER_INFO, | ||
payload: res.data | ||
}); | ||
} | ||
catch (err) { | ||
dispatch({ | ||
type: USER_INFO_ERRORS, | ||
payload: err.response.data | ||
}) | ||
} | ||
} | ||
|
||
export const postInfo = (data) => async dispatch => { | ||
try { | ||
const config = { | ||
headers: { | ||
'content-type': 'application/json', | ||
Authorization: `Bearer ${localStorage.token}`, | ||
} | ||
} | ||
const res = await axios.post(urlInfo(), data, config); | ||
dispatch({ | ||
type: POST_USER_INFO, | ||
payload: res.data | ||
}); | ||
} | ||
catch (err) { | ||
dispatch({ | ||
type: USER_INFO_ERRORS, | ||
payload: err.response.data | ||
}); | ||
} | ||
}; |
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.
Can we rename this file and its methods to a better name? Like wherever you used info
simply without context, it could be userinfo
?
src/components/Info.js
Outdated
import React, { Component } from 'react' | ||
import { connect } from 'react-redux' | ||
import { getInfo } from '../actions/info' | ||
// import { Form, Grid, Image, Divider, Icon } from 'semantic-ui-react' | ||
import PropTypes from 'prop-types' | ||
// import login from './../styles/Login.css' | ||
|
||
class Info extends Component { | ||
constructor(props) { | ||
super(props) | ||
} | ||
componentDidMount() { | ||
this.props.getInfo() | ||
} | ||
render() { | ||
return( | ||
<div> | ||
hello | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
Info.propTypes = { | ||
userinfo: PropTypes.array.isRequired, | ||
}; | ||
|
||
const mapStateToProps = state => ({ | ||
userinfo: state.info.userinfo, | ||
}) | ||
|
||
export default connect( | ||
mapStateToProps, | ||
{ getInfo, } | ||
)(Info) |
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.
Same as above
src/reducers/info.js
Outdated
import { | ||
GET_USER_INFO, | ||
POST_USER_INFO, | ||
USER_INFO_ERRORS | ||
} from '../actions/types' | ||
|
||
const initialState = { | ||
userinfo: [], | ||
postuserinfo: [], | ||
userinfoerror: null, | ||
} | ||
|
||
const infoReducer = (state = initialState, action) => { | ||
switch(action.type) { | ||
case GET_USER_INFO: | ||
return { | ||
...state, | ||
userinfo: action.payload, | ||
}; | ||
case POST_USER_INFO: | ||
return { | ||
...state, | ||
postuserinfo: action.payload, | ||
userinfo: [...state.userinfo, action.payload], | ||
} | ||
case USER_INFO_ERRORS: | ||
return { | ||
...state, | ||
userinfoerror: action.payload, | ||
} | ||
default: | ||
return state | ||
} | ||
} | ||
|
||
export default infoReducer |
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.
Same as above
The pr was tested locally. Here are the gifs for the same:
|
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.
@bismitaguha could you make the changes that I suggested in my earlier review? Regarding better names for the dashboard (currently called info
/Info
).
@sidvenu Since the dashboard and navbar issues are different I have covered these in that PR so that there won't be any confusion. This info will just be a basic redirect page that confirms login. I hope that will be cool, else we will be mixing PRs???? |
I get your point. In the perspective of this PR, |
I overlooked this in my review earlier, could you add new lines to the end of files you've created in this PR that doesn't have new lines? |
src/components/Register.js
Outdated
username: '', | ||
email: '', | ||
password: '', | ||
password2: '', |
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.
change password2 to confirm_password
src/components/Info.js
Outdated
import React, { Component } from 'react' | ||
import { connect } from 'react-redux' | ||
import { getInfo } from '../actions/info' | ||
// import { Form, Grid, Image, Divider, Icon } from 'semantic-ui-react' |
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.
remove the code commented from this file
@bismitaguha Pls modify the index.html file in public folder appropriately as discussed before. |
@abha224 Removed comments and made the changes. |
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.
LGTM 👍
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.
LGTM 👍
Description
Fixes #7
Type of Change:
Code/Quality Assurance Only
How Has This Been Tested?
Server up and running. Cases of possible form validations covered.
Checklist:
Code/Quality Assurance Only