|
@@ -1,68 +1,89 @@
|
|
|
import React from 'react';
|
|
|
+import { AppRegistry, View, Image } from 'react';
|
|
|
import { connect } from 'react-redux';
|
|
|
-// import { bindActionCreators } from 'redux'
|
|
|
+import { bindActionCreators } from 'redux'
|
|
|
// import {} from './../../../actions'
|
|
|
import axios from 'axios';
|
|
|
+import { userChangeRequest } from '../../../actions/userFields/changeEmail'
|
|
|
+import {passwordChangeRequest} from '../../../actions/userFields/changePassword'
|
|
|
+
|
|
|
+import ChangeLogin from './LoginFild';
|
|
|
+import ChangePassword from './PasswordFields'
|
|
|
|
|
|
// redux-connected container
|
|
|
|
|
|
class profilePage extends React.Component {
|
|
|
|
|
|
state = {
|
|
|
- user: {}
|
|
|
+ files: null,
|
|
|
+ photo: null
|
|
|
}
|
|
|
+ change = e => {
|
|
|
+ const reader = new FileReader();
|
|
|
+
|
|
|
+ const file = e.target.files[0];
|
|
|
+ this.setState({ file });
|
|
|
+
|
|
|
+ reader.onloadend = () => {
|
|
|
+ this.setState({
|
|
|
+ photo: reader.result
|
|
|
+ });
|
|
|
+ };
|
|
|
+ reader.readAsDataURL(file);
|
|
|
+ };
|
|
|
|
|
|
- getUser = () => {
|
|
|
- const randomUserId = Math.ceil(Math.random() * 10);
|
|
|
+ post = () => {
|
|
|
+ const file = new FormData();
|
|
|
|
|
|
- axios.post(`https://quiz.maxcrc.de/api/v1/user`,{
|
|
|
- "login": 'ddd',
|
|
|
- "password":"jhgfhgg"
|
|
|
+ file.append("profilePhoto", this.state.file);
|
|
|
+ };
|
|
|
|
|
|
+ lol = () => {
|
|
|
+ const { user: { data: { id } }, userChangeRequest } = this.props;
|
|
|
+
|
|
|
+ userChangeRequest({
|
|
|
+ id,
|
|
|
+ login: "lol wtf"
|
|
|
})
|
|
|
- .then(({ data }) => this.setState({
|
|
|
- user: data
|
|
|
- }))
|
|
|
- .catch(({ message }) => console.warn(message))
|
|
|
}
|
|
|
|
|
|
- componentDidMount() {
|
|
|
- this.getUser();
|
|
|
- }
|
|
|
|
|
|
render() {
|
|
|
- const { user } = this.state;
|
|
|
+ const { user:{data}, userChangeRequest,passwordChangeRequest } = this.props;
|
|
|
|
|
|
- console.log(user);
|
|
|
+ // console.log('User', user);
|
|
|
+ // console.log('Props', this.props);
|
|
|
+ // console.log('State', this.state);
|
|
|
|
|
|
return (
|
|
|
<div className="page page--bottom-only profile-page">
|
|
|
<section className="container section section--about">
|
|
|
- <h2 className="section__element section__element--header">{user.login}</h2>
|
|
|
- <img className="section__element section__element--image" src={user.avatar} alt="avatar" />
|
|
|
+ {/* <h2 className="section__element section__element--header">{data.login}</h2> */}
|
|
|
+
|
|
|
<div className="sedtion__element section__element--login">
|
|
|
- <h3>Login</h3>
|
|
|
- <p>{user.login}<button className="link link--btn right">Change login</button></p>
|
|
|
+ <h3>Email</h3>
|
|
|
+ {/* <p>{user.login}<button className="link link--btn right" >Change login</button></p> */}
|
|
|
+ <ChangeLogin className="link link--btn right" data={data} actions={{ userChangeRequest }}>{data.login}</ChangeLogin>
|
|
|
</div>
|
|
|
<div className="section__element section__element--">
|
|
|
- <h3>E-mail</h3>
|
|
|
- <p>{user.email}<button className="link link--btn right">Change e-mail</button></p>
|
|
|
+ <h3>Password</h3>
|
|
|
+ <ChangePassword className="link link--btn right" data={data} actions={{ passwordChangeRequest }}>{data.password}</ChangePassword>
|
|
|
</div>
|
|
|
<div className="section__element section__element--">
|
|
|
<h3>Status</h3>
|
|
|
- <p>{user.description}</p>
|
|
|
+ <p>{data.description}</p>
|
|
|
</div>
|
|
|
</section>
|
|
|
<section className="container section section--stats">
|
|
|
<div className="section__element section__element--">
|
|
|
<h3>Member Since</h3>
|
|
|
- <p>{new Date(user.createdAt).toLocaleString()}</p>
|
|
|
+ <p>{new Date(data.createdAt).toLocaleString()}</p>
|
|
|
</div>
|
|
|
<div className="section__element section__element--comments">
|
|
|
<h3>Last comments</h3>
|
|
|
<p className="comments-block">
|
|
|
{
|
|
|
- user.comments && user.comments
|
|
|
+ data.comments && data.comments
|
|
|
.slice(0, 60)
|
|
|
.map(el =>
|
|
|
<p>
|
|
@@ -82,8 +103,9 @@ class profilePage extends React.Component {
|
|
|
const
|
|
|
mapStateToProps = state => ({
|
|
|
user: state.user
|
|
|
- })
|
|
|
-// mapDispatchToProps = dispatch => bindActionCreators({}, dispatch)
|
|
|
+ });
|
|
|
+
|
|
|
+const mapDispatchToProps = dispatch => bindActionCreators({ userChangeRequest, passwordChangeRequest }, dispatch);
|
|
|
|
|
|
-export default connect(mapStateToProps)(profilePage);
|
|
|
+export default connect(mapStateToProps, mapDispatchToProps)(profilePage);
|
|
|
|