Guest User

Untitled

a guest
May 21st, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. import React,{Component} from 'react'
  2. import PropTypes from 'prop-types'
  3. import {compose} from 'recompose'
  4. import {connect} from 'react-redux'
  5. import {
  6. Divider, Message,Container
  7. } from 'semantic-ui-react';
  8. import { withRouter,} from 'react-router-dom'
  9. import withAuthorization from './hocs/withAuthorization'
  10. import SetUpProfile from './dashboardComponents/SetUpProfile'
  11. import DashboardLayout from './frames/DashboardLayout'
  12. import DashboardTopMenu from './navs/DashboardTopMenu'
  13. import ManageRoleAndPasswordForm from './forms/ManageRoleAndPasswordForm'
  14. import {services} from '../services';
  15.  
  16.  
  17.  
  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)
  25. return onPatch(authUser.id,user).then(
  26. ()=>push(`/${user.role}s/${authUser.id}`)
  27. )
  28.  
  29. }
  30.  
  31. render(){
  32.  
  33. const {authUser,loading,errors,history} = this.props
  34. const errs =(errors)? errors.message.split(","):'';
  35. return (
  36. <DashboardLayout
  37. topMenu={<DashboardTopMenu stProfileIsSet={false} homeURL='/student'/>}
  38. profileIsSet={false}
  39. mainContent=
  40. {// !profileIsSet ?
  41. <SetUpProfile intro={`Welcome ${authUser.firstname}`} subintro="All of us @ Takesavillage are excited to have you:" uploadAction='Add'
  42. instruction="Please tell us more about your intensions:"
  43. >
  44. <Divider section hidden/>
  45. {
  46. errors &&
  47. <Container text textAlign='justified'>
  48.  
  49. <Message
  50. error
  51. header='There are some errors with your submission'
  52. list={errs.map(e=>e)}
  53. />
  54. </Container>
  55. }
  56. <Divider hidden />
  57. <Divider hidden />
  58. <ManageRoleAndPasswordForm
  59. onSubmit={this.onSubmit}
  60. user={authUser}
  61. errors={errors}
  62. loading={loading}
  63. history={history}
  64. />
  65. </SetUpProfile>
  66. // :
  67. // <StudentHomeContent />
  68. }
  69. // sideContent={sideContent}
  70. />
  71. );
  72. }
  73. }
  74.  
  75. UserPageUI.propTypes={
  76. // users:PropTypes.arrayOf(PropTypes.shape({})).isRequired,
  77. authUser:PropTypes.shape({}).isRequired,
  78. loading:PropTypes.bool,
  79. errors:PropTypes.shape({}),
  80. history:PropTypes.shape({
  81. push:PropTypes.func.isRequired
  82. }).isRequired,
  83. onPatch:PropTypes.func.isRequired,
  84. }
  85. UserPageUI.defaultProps={
  86. errors:{},
  87. loading:false
  88. }
  89.  
  90. const mapStateToProps=state=>({
  91. authUser: state.authUserState.authUser,
  92. errors: state.userState.isError ,
  93. loading:state.userState.isLoading
  94. })
  95.  
  96. const mapDispatchToProps = (dispatch) => ({
  97. onPatch:(id,user)=>dispatch(services.users.patch(id,user))
  98. });
  99. const authCondition = (authUser) => !!(authUser);
  100.  
  101. const UserPage=compose( withAuthorization(authCondition,mapDispatchToProps),connect(mapStateToProps))(UserPageUI)
  102.  
  103.  
  104. export default UserPage
Add Comment
Please, Sign In to add comment