|
@@ -1,88 +1,117 @@
|
|
|
import React from 'react';
|
|
|
import { connect } from 'react-redux';
|
|
|
import { bindActionCreators } from 'redux'
|
|
|
- import ChangeLoginForm from './ChangeLoginForm/index';
|
|
|
+import ChangeLoginForm from './ChangeLoginForm/index';
|
|
|
+import ChangeEmailForm from './ChangeEmailForm/index';
|
|
|
+import ChangePasswordForm from './changePassword/index'
|
|
|
+import {changeLoginRequest} from '../../../actions/user/changelogin';
|
|
|
+import {changeEmailRequest} from '../../../actions/user/changeEmail';
|
|
|
+import {changePasswordRequest } from '../../../actions/user/changePassword'
|
|
|
|
|
|
-const user = {
|
|
|
- "data": {
|
|
|
- "_id": "5c48461c40ca670017ba5974",
|
|
|
- "name": "Debil",
|
|
|
- "email": "superus@lol.com",
|
|
|
- "password": "$2a$10$qoxrQ2Sp3BDTLa9Xdc0ZPuLVHamipMQRWxeWxw1RwthICnbPoFLvC",
|
|
|
- "profilePhoto": "",
|
|
|
- "role": 0
|
|
|
- },
|
|
|
- "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVjNDg0NjFjNDBjYTY3MDAxN2JhNTk3NCIsInJvbGUiOjAsImlhdCI6MTU0ODI1NTczMiwiZXhwIjoxNTQ4MzQyMTMyfQ.RAIiCLjBJ2u1VEQWy1oUgPjHj0dZRG27l0J3c8FDss0"
|
|
|
-}
|
|
|
|
|
|
class ProfilePage extends React.Component {
|
|
|
+
|
|
|
state={
|
|
|
- clicked:false
|
|
|
+ clicked:false,
|
|
|
+ klick: false,
|
|
|
+ click: false
|
|
|
}
|
|
|
|
|
|
handleClick = () => {
|
|
|
this.setState((prevState) => ({ clicked: !prevState.clicked }));
|
|
|
}
|
|
|
+ handleClicks = () => {
|
|
|
+ this.setState((prevState) => ({ klick: !prevState.klick }));
|
|
|
+ }
|
|
|
+ handleClicked = () => {
|
|
|
+ this.setState((prevState) => ({ click: !prevState.click }));
|
|
|
+ }
|
|
|
|
|
|
render() {
|
|
|
- const { users, userChangeRequest, passwordChangeRequest } = this.props;
|
|
|
- const { data } = user;
|
|
|
- const {clicked} =this.state;
|
|
|
+ const { signIn:{data, token}, changeLoginRequest, chageLoginReducer, changeEmailRequest, changeEmailReducer, changePasswordRequest} = this.props;
|
|
|
+ console.log(changeEmailReducer)
|
|
|
+ const {clicked, klick, click} =this.state;
|
|
|
+ const {handleClick, handleClicks, handleClicked} = this;
|
|
|
|
|
|
return (
|
|
|
<div className="page page--bottom-only profile-page">
|
|
|
- <section className="border bg-autumn-foliage m-5 rounded d-flex">
|
|
|
+ <div className="border bg-autumn-foliage m-5 rounded d-flex">
|
|
|
+ <div>
|
|
|
+ {/* <h5 className="p-2 font-po-bold flex-fill bd-highlight align-self-end">{data.name}</h5> */}
|
|
|
+ {/* <div className="d-flex" >
|
|
|
+ <p className="p-2 flex-fill font-po-bold bd-highlight align-self-end">Email</p><p className="p-2 flex-fill font-po-bold bd-highlight align-self-end">{data.email}</p>
|
|
|
+ </div> */}
|
|
|
+ {/* <div className="d-flex" >
|
|
|
+ <p className="p-2 flex-fill font-po-bold bd-highlight align-self-end">Role</p><p className="p-2 flex-fill font-po-bold bd-highlight align-self-end">{data.role}</p>
|
|
|
+ </div> */}
|
|
|
+
|
|
|
<div>
|
|
|
<img className="m-4 " src=" https://cdn.iconscout.com/icon/free/png-256/avatar-373-456325.png" ></img>
|
|
|
</div>
|
|
|
+ </div>
|
|
|
<div className="border-left bg-autumn-foliage m-5 rounded w-75 ">
|
|
|
{!clicked
|
|
|
?
|
|
|
<div className ="d-flex mb-3" >
|
|
|
<h3 className = " p-2 flex-fill bd-highlight">Name</h3>
|
|
|
- <h5 className="p-2 font-po-bold flex-fill bd-highlight align-self-end">{data.name}</h5>
|
|
|
- <button type="button" onClick ={this.handleClick} className=" flex-fill bg-shadow btn btn-outline-light col-3">Change</button>
|
|
|
+ <h5 className="p-2 font-po-bold flex-fill bd-highlight align-self-end">{
|
|
|
+ chageLoginReducer.data == null
|
|
|
+ ?
|
|
|
+ data.name
|
|
|
+ :
|
|
|
+ chageLoginReducer.data
|
|
|
+
|
|
|
+ }</h5>
|
|
|
+ <button type="button" onClick ={handleClick} className=" flex-fill bg-shadow btn btn-outline-primary col-3">Change</button>
|
|
|
</div>
|
|
|
:
|
|
|
<div>
|
|
|
<h3 className = " p-2 flex-fill bd-highlight">Name</h3>
|
|
|
<h5 className="p-2 font-po-bold flex-fill bd-highlight align-self-end">{data.name}</h5>
|
|
|
- <ChangeLoginForm> </ChangeLoginForm>
|
|
|
+ <ChangeLoginForm data ={data} token={token} actions ={{changeLoginRequest}} handlers={{ handleClick}}> </ChangeLoginForm>
|
|
|
</div>
|
|
|
}
|
|
|
+ {!klick
|
|
|
+ ?
|
|
|
+ <div className ="d-flex mb-3" >
|
|
|
+ <h3 className = "p-2 flex-fill bd-highlight">Email</h3>
|
|
|
+ <h5 className="p-2 flex-fill font-po-bold bd-highlight align-self-end">
|
|
|
+ {
|
|
|
+ changeEmailReducer.data ===null
|
|
|
+ ?
|
|
|
+ data.email
|
|
|
+ :
|
|
|
+ changeEmailReducer.data
|
|
|
+ }
|
|
|
+ </h5>
|
|
|
+ <button type="button" name ="name" onClick ={handleClicks} className=" flex-fill bg-shadow btn btn-outline-primary col-3">Change</button>
|
|
|
+ </div>
|
|
|
+ :
|
|
|
<div className ="d-flex mb-3" >
|
|
|
<h3 className = "p-2 flex-fill bd-highlight">Email</h3>
|
|
|
<h5 className="p-2 flex-fill font-po-bold bd-highlight align-self-end">{data.email}</h5>
|
|
|
- <button type="button" className=" flex-fill bg-shadow btn btn-outline-light col-3">Change</button>
|
|
|
+ <ChangeEmailForm data ={data} token={token} actions ={{changeEmailRequest}} handlers={{ handleClicks}}></ChangeEmailForm>
|
|
|
</div>
|
|
|
+ }
|
|
|
+ {
|
|
|
+ !click
|
|
|
+ ?
|
|
|
<div className ="d-flex mb-3" >
|
|
|
<h3 className = "p-2 flex-fill bd-highlight">Password</h3>
|
|
|
- <button type="button" className=" flex-fill bg-shadow btn btn-outline-light col-3">Change</button>
|
|
|
+ <button type="button" onClick ={handleClicked} className=" flex-fill bg-shadow btn btn-outline-primary col-3">Change</button>
|
|
|
+ </div>
|
|
|
+ :
|
|
|
+ <div className ="d-flex mb-3" >
|
|
|
+ <h3 className = "p-2 flex-fill bd-highlight">Password</h3>
|
|
|
+ <ChangePasswordForm data ={data} token={token} actions ={{changePasswordRequest}} handlers={{ handleClicked}}></ChangePasswordForm>
|
|
|
</div>
|
|
|
-
|
|
|
- </div>
|
|
|
- </section>
|
|
|
- <section className="container section section--stats">
|
|
|
- <div className="section__element section__element--">
|
|
|
- <h3>Member Since</h3>
|
|
|
- <p>{new Date(data.createdAt).toLocaleString()}</p>
|
|
|
- </div>
|
|
|
- <div className="section__element section__element--comments border-right-0">
|
|
|
- <h3>Last comments</h3>
|
|
|
- <p className="comments-block">
|
|
|
- {
|
|
|
- data.comments && data.comments
|
|
|
- .slice(0, 60)
|
|
|
- .map(el =>
|
|
|
- <p>
|
|
|
- <h4>{new Date(el.createdAt).toLocaleString()}</h4>
|
|
|
- {el.text}
|
|
|
- </p>)
|
|
|
}
|
|
|
- </p>
|
|
|
+
|
|
|
</div>
|
|
|
- </section>
|
|
|
- </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ </div>
|
|
|
+
|
|
|
)
|
|
|
}
|
|
|
|
|
@@ -90,10 +119,11 @@ class ProfilePage extends React.Component {
|
|
|
|
|
|
const
|
|
|
mapStateToProps = state => ({
|
|
|
- user: state.user,
|
|
|
- users: state.users
|
|
|
+ signIn: state.signIn,
|
|
|
+ chageLoginReducer: state.chageLoginReducer,
|
|
|
+ changeEmailReducer:state.changeEmailReducer
|
|
|
});
|
|
|
|
|
|
-const mapDispatchToProps = dispatch => bindActionCreators({}, dispatch);
|
|
|
+const mapDispatchToProps = dispatch => bindActionCreators({changeLoginRequest, changeEmailRequest, changePasswordRequest}, dispatch);
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(ProfilePage);
|