2016-05-12 10:00:10 +05:30
|
|
|
import React, { Component, PropTypes } from 'react';
|
2016-04-17 15:05:04 +05:30
|
|
|
|
|
|
|
import styles from './profile.scss';
|
|
|
|
|
2016-05-12 10:00:10 +05:30
|
|
|
class ProfilePage extends Component {
|
2016-04-17 15:05:04 +05:30
|
|
|
displayName = 'ProfilePage';
|
|
|
|
|
2016-05-12 10:00:10 +05:30
|
|
|
static propTypes = {
|
|
|
|
onSubmit: PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
static childContextTypes = {
|
2016-05-14 13:24:26 +05:30
|
|
|
onSubmit: PropTypes.func,
|
|
|
|
goToProfile: PropTypes.func
|
2016-05-12 10:00:10 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
getChildContext() {
|
|
|
|
return {
|
2016-05-14 13:24:26 +05:30
|
|
|
onSubmit: this.props.onSubmit,
|
|
|
|
goToProfile: this.props.goToProfile
|
2016-05-12 10:00:10 +05:30
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-04-17 15:05:04 +05:30
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div className={styles.container}>
|
|
|
|
{this.props.children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-05-12 10:00:10 +05:30
|
|
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { routeActions } from 'react-router-redux';
|
|
|
|
import { create as createPopup } from 'components/ui/popup/actions';
|
|
|
|
import PasswordRequestForm from 'components/profile/passwordRequestForm/PasswordRequestForm';
|
|
|
|
|
|
|
|
function goToProfile() {
|
|
|
|
return routeActions.push('/');
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(null, {
|
2016-05-14 13:24:26 +05:30
|
|
|
goToProfile,
|
2016-05-12 10:00:10 +05:30
|
|
|
onSubmit: ({form, sendData}) => (dispatch) =>
|
|
|
|
sendData()
|
|
|
|
.catch((resp) => {
|
|
|
|
// prevalidate user input, because requestPassword popup will block the
|
|
|
|
// entire form from input, so it must be valid
|
|
|
|
if (resp.errors) {
|
|
|
|
Reflect.deleteProperty(resp.errors, 'password');
|
|
|
|
|
|
|
|
if (Object.keys(resp.errors).length) {
|
|
|
|
form.setErrors(resp.errors);
|
|
|
|
return Promise.reject(resp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.resolve();
|
|
|
|
})
|
|
|
|
.then(() => new Promise((resolve) => {
|
|
|
|
dispatch(createPopup(PasswordRequestForm, (props) => ({
|
|
|
|
form,
|
|
|
|
onSubmit: () => {
|
|
|
|
sendData()
|
|
|
|
.catch((resp) => {
|
|
|
|
if (resp.errors) {
|
|
|
|
form.setErrors(resp.errors);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.reject(resp);
|
|
|
|
})
|
|
|
|
.then(resolve)
|
|
|
|
.then(props.onClose)
|
|
|
|
.then(() => dispatch(goToProfile()));
|
|
|
|
}
|
|
|
|
})));
|
|
|
|
}))
|
|
|
|
})(ProfilePage);
|