Last active
May 16, 2018 10:36
-
-
Save jermsam/501667a8a2cd479242777b13c8a72861 to your computer and use it in GitHub Desktop.
My this.props.history tends to get lost before it reaches my authenticated component
This file contains 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
TypeError: Cannot read property 'push' of undefined | |
UserPageUI._this.onSubmit | |
E:/code/auth/cash/tav/tav-c/src/pages/UserPage.js:21 | |
18 | | |
19 | class UserPageUI extends Component { | |
20 | | |
> 21 | onSubmit= (user) => { | |
22 | const {onPatch, history:{push},authUser } = this.props; | |
23 | // const {onPatch, authUser} = this.props; | |
24 | console.log ('babababababa: ',user) | |
View compiled | |
▶ 26 stack frames were collapsed. |
This file contains 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
import React,{Component} from 'react' | |
import PropTypes from 'prop-types' | |
import {compose} from 'recompose' | |
import {connect} from 'react-redux' | |
import { | |
Divider, Message,Container | |
} from 'semantic-ui-react'; | |
import { withRouter,} from 'react-router-dom' | |
import withAuthorization from './hocs/withAuthorization' | |
import SetUpProfile from './dashboardComponents/SetUpProfile' | |
import DashboardLayout from './frames/DashboardLayout' | |
import DashboardTopMenu from './navs/DashboardTopMenu' | |
import ManageRoleAndPasswordForm from './forms/ManageRoleAndPasswordForm' | |
import {services} from '../services'; | |
class UserPageUI extends Component { | |
onSubmit= (user) => { | |
const {onPatch, history:{push},authUser } = this.props; | |
// const {onPatch, authUser} = this.props; | |
console.log ('babababababa: ',user) | |
return onPatch(authUser.id,user).then( | |
()=>push(`/${user.role}s/${authUser.id}`) | |
) | |
} | |
render(){ | |
const {authUser,loading,errors,history} = this.props | |
const errs =(errors)? errors.message.split(","):''; | |
return ( | |
<DashboardLayout | |
topMenu={<DashboardTopMenu stProfileIsSet={false} homeURL='/student'/>} | |
profileIsSet={false} | |
mainContent= | |
{// !profileIsSet ? | |
<SetUpProfile intro={`Welcome ${authUser.firstname}`} subintro="All of us @ Takesavillage are excited to have you:" uploadAction='Add' | |
instruction="Please tell us more about your intensions:" | |
> | |
<Divider section hidden/> | |
{ | |
errors && | |
<Container text textAlign='justified'> | |
<Message | |
error | |
header='There are some errors with your submission' | |
list={errs.map(e=>e)} | |
/> | |
</Container> | |
} | |
<Divider hidden /> | |
<Divider hidden /> | |
<ManageRoleAndPasswordForm | |
onSubmit={this.onSubmit} | |
user={authUser} | |
errors={errors} | |
loading={loading} | |
history={history} | |
/> | |
</SetUpProfile> | |
// : | |
// <StudentHomeContent /> | |
} | |
// sideContent={sideContent} | |
/> | |
); | |
} | |
} | |
UserPageUI.propTypes={ | |
// users:PropTypes.arrayOf(PropTypes.shape({})).isRequired, | |
authUser:PropTypes.shape({}).isRequired, | |
loading:PropTypes.bool, | |
errors:PropTypes.shape({}), | |
history:PropTypes.shape({ | |
push:PropTypes.func.isRequired | |
}).isRequired, | |
onPatch:PropTypes.func.isRequired, | |
} | |
UserPageUI.defaultProps={ | |
errors:{}, | |
loading:false | |
} | |
const mapStateToProps=state=>({ | |
authUser: state.authUserState.authUser, | |
errors: state.userState.isError , | |
loading:state.userState.isLoading | |
}) | |
const mapDispatchToProps = (dispatch) => ({ | |
onPatch:(id,user)=>dispatch(services.users.patch(id,user)) | |
}); | |
const authCondition = (authUser) => !!(authUser); | |
const UserPage=compose( withAuthorization(authCondition,mapDispatchToProps),connect(mapStateToProps))(UserPageUI) | |
export default UserPage | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment