From c2c6604ca526329f77a0f6216df9ccdd82bac88a Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Sat, 14 May 2016 10:54:26 +0300 Subject: [PATCH] #65: Return to profile, if username was not changed. --- src/pages/profile/ChangeUsernamePage.jsx | 8 +++++++- src/pages/profile/ProfilePage.jsx | 7 +++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/pages/profile/ChangeUsernamePage.jsx b/src/pages/profile/ChangeUsernamePage.jsx index 751a54b..d062db9 100644 --- a/src/pages/profile/ChangeUsernamePage.jsx +++ b/src/pages/profile/ChangeUsernamePage.jsx @@ -13,7 +13,8 @@ class ChangeUsernamePage extends Component { }; static contextTypes = { - onSubmit: PropTypes.func.isRequired + onSubmit: PropTypes.func.isRequired, + goToProfile: PropTypes.func.isRequired }; form = new FormModel(); @@ -44,6 +45,11 @@ class ChangeUsernamePage extends Component { onSubmit = () => { const {form} = this; + if (this.state.actualUsername === this.props.username) { + this.context.goToProfile(); + return; + } + this.context.onSubmit({ form, sendData: () => accounts.changeUsername(form.serialize()) diff --git a/src/pages/profile/ProfilePage.jsx b/src/pages/profile/ProfilePage.jsx index e905f2f..0550570 100644 --- a/src/pages/profile/ProfilePage.jsx +++ b/src/pages/profile/ProfilePage.jsx @@ -10,12 +10,14 @@ class ProfilePage extends Component { }; static childContextTypes = { - onSubmit: PropTypes.func + onSubmit: PropTypes.func, + goToProfile: PropTypes.func }; getChildContext() { return { - onSubmit: this.props.onSubmit + onSubmit: this.props.onSubmit, + goToProfile: this.props.goToProfile }; } @@ -38,6 +40,7 @@ function goToProfile() { } export default connect(null, { + goToProfile, onSubmit: ({form, sendData}) => (dispatch) => sendData() .catch((resp) => {