From 6d44e43f5da6de17762396eb82a670fa74de6b07 Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Sun, 22 May 2016 21:02:46 +0300 Subject: [PATCH] #100: fetch fresh user data after profile update --- src/pages/profile/ChangeUsernamePage.jsx | 10 ++++------ src/pages/profile/ProfilePage.jsx | 5 ++++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/pages/profile/ChangeUsernamePage.jsx b/src/pages/profile/ChangeUsernamePage.jsx index 4e40c66..103f695 100644 --- a/src/pages/profile/ChangeUsernamePage.jsx +++ b/src/pages/profile/ChangeUsernamePage.jsx @@ -20,13 +20,11 @@ class ChangeUsernamePage extends Component { form = new FormModel(); componentWillMount() { - this.setState({ - actualUsername: this.props.username - }); + this.actualUsername = this.props.username; } componentWillUnmount() { - this.props.updateUsername(this.state.actualUsername); + this.props.updateUsername(this.actualUsername); } render() { @@ -45,7 +43,7 @@ class ChangeUsernamePage extends Component { onSubmit = () => { const {form} = this; - if (this.state.actualUsername === this.props.username) { + if (this.actualUsername === this.props.username) { this.context.goToProfile(); return; } @@ -54,7 +52,7 @@ class ChangeUsernamePage extends Component { form, sendData: () => accounts.changeUsername(form.serialize()) }).then(() => { - this.props.updateUsername(form.value('username')); + this.actualUsername = form.value('username'); this.context.goToProfile(); }); }; diff --git a/src/pages/profile/ProfilePage.jsx b/src/pages/profile/ProfilePage.jsx index ee81507..1ba5a93 100644 --- a/src/pages/profile/ProfilePage.jsx +++ b/src/pages/profile/ProfilePage.jsx @@ -9,6 +9,7 @@ class ProfilePage extends Component { static propTypes = { onSubmit: PropTypes.func.isRequired, + fetchUserData: PropTypes.func.isRequired, goToProfile: PropTypes.func.isRequired, children: PropTypes.element }; @@ -21,7 +22,7 @@ class ProfilePage extends Component { getChildContext() { return { onSubmit: this.props.onSubmit, - goToProfile: this.props.goToProfile + goToProfile: () => this.props.fetchUserData().then(this.props.goToProfile) }; } @@ -40,6 +41,7 @@ class ProfilePage extends Component { import { connect } from 'react-redux'; import { routeActions } from 'react-router-redux'; +import { fetchUserData } from 'components/user/actions'; import { create as createPopup } from 'components/ui/popup/actions'; import PasswordRequestForm from 'components/profile/passwordRequestForm/PasswordRequestForm'; @@ -47,6 +49,7 @@ export default connect(null, { goToProfile() { return routeActions.push('/'); }, + fetchUserData, onSubmit: ({form, sendData}) => (dispatch) => sendData() .catch((resp) => {