index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import React from 'react';
  2. import { AppRegistry, View, Image } from 'react';
  3. import { connect } from 'react-redux';
  4. import { bindActionCreators } from 'redux'
  5. // import {} from './../../../actions'
  6. import axios from 'axios';
  7. import { userChangeRequest } from '../../../actions/userFields/changeEmail'
  8. import {passwordChangeRequest} from '../../../actions/userFields/changePassword'
  9. import ChangeLogin from './LoginFild';
  10. import ChangePassword from './PasswordFields'
  11. // redux-connected container
  12. class profilePage extends React.Component {
  13. state = {
  14. files: null,
  15. photo: null
  16. }
  17. change = e => {
  18. const reader = new FileReader();
  19. const file = e.target.files[0];
  20. this.setState({ file });
  21. reader.onloadend = () => {
  22. this.setState({
  23. photo: reader.result
  24. });
  25. };
  26. reader.readAsDataURL(file);
  27. };
  28. post = () => {
  29. const file = new FormData();
  30. file.append("profilePhoto", this.state.file);
  31. };
  32. lol = () => {
  33. const { user: { data: { id } }, userChangeRequest } = this.props;
  34. userChangeRequest({
  35. id,
  36. login: "lol wtf"
  37. })
  38. }
  39. render() {
  40. const { user:{data}, userChangeRequest,passwordChangeRequest } = this.props;
  41. // console.log('User', user);
  42. // console.log('Props', this.props);
  43. // console.log('State', this.state);
  44. return (
  45. <div className="page page--bottom-only profile-page">
  46. <section className="container section section--about">
  47. {/* <h2 className="section__element section__element--header">{data.login}</h2> */}
  48. <div className="sedtion__element section__element--login">
  49. <h3>Email</h3>
  50. {/* <p>{user.login}<button className="link link--btn right" >Change login</button></p> */}
  51. <ChangeLogin className="link link--btn right" data={data} actions={{ userChangeRequest }}>{data.login}</ChangeLogin>
  52. </div>
  53. <div className="section__element section__element--">
  54. <h3>Password</h3>
  55. <ChangePassword className="link link--btn right" data={data} actions={{ passwordChangeRequest }}>{data.password}</ChangePassword>
  56. </div>
  57. <div className="section__element section__element--">
  58. <h3>Status</h3>
  59. <p>{data.description}</p>
  60. </div>
  61. </section>
  62. <section className="container section section--stats">
  63. <div className="section__element section__element--">
  64. <h3>Member Since</h3>
  65. <p>{new Date(data.createdAt).toLocaleString()}</p>
  66. </div>
  67. <div className="section__element section__element--comments">
  68. <h3>Last comments</h3>
  69. <p className="comments-block">
  70. {
  71. data.comments && data.comments
  72. .slice(0, 60)
  73. .map(el =>
  74. <p>
  75. <h4>{new Date(el.createdAt).toLocaleString()}</h4>
  76. {el.text}
  77. </p>)
  78. }
  79. </p>
  80. </div>
  81. </section>
  82. </div>
  83. )
  84. }
  85. }
  86. const
  87. mapStateToProps = state => ({
  88. user: state.user
  89. });
  90. const mapDispatchToProps = dispatch => bindActionCreators({ userChangeRequest, passwordChangeRequest }, dispatch);
  91. export default connect(mapStateToProps, mapDispatchToProps)(profilePage);