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 = {
|
2016-05-14 16:56:17 +05:30
|
|
|
onSubmit: PropTypes.func.isRequired,
|
2016-05-22 13:23:40 +05:30
|
|
|
goToProfile: PropTypes.func.isRequired,
|
|
|
|
children: PropTypes.element
|
2016-05-12 10:00:10 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
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';
|
|
|
|
|
|
|
|
export default connect(null, {
|
2016-05-22 13:23:40 +05:30
|
|
|
goToProfile() {
|
|
|
|
return routeActions.push('/');
|
|
|
|
},
|
2016-05-12 10:00:10 +05:30
|
|
|
onSubmit: ({form, sendData}) => (dispatch) =>
|
|
|
|
sendData()
|
|
|
|
.catch((resp) => {
|
2016-05-22 13:23:40 +05:30
|
|
|
const requirePassword = resp.errors && !!resp.errors.password;
|
|
|
|
|
2016-05-12 10:00:10 +05:30
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2016-05-22 13:23:40 +05:30
|
|
|
return Promise.resolve({requirePassword});
|
|
|
|
}
|
2016-05-12 10:00:10 +05:30
|
|
|
})
|
2016-05-22 13:23:40 +05:30
|
|
|
.then((resp) => new Promise((resolve) => {
|
|
|
|
if (resp.requirePassword) {
|
|
|
|
dispatch(createPopup(PasswordRequestForm, (props) => ({
|
|
|
|
form,
|
|
|
|
onSubmit: () => {
|
|
|
|
sendData()
|
|
|
|
.catch((resp) => {
|
|
|
|
if (resp.errors) {
|
|
|
|
form.setErrors(resp.errors);
|
|
|
|
}
|
2016-05-12 10:00:10 +05:30
|
|
|
|
2016-05-22 13:23:40 +05:30
|
|
|
return Promise.reject(resp);
|
|
|
|
})
|
|
|
|
.then(resolve)
|
|
|
|
.then(props.onClose);
|
|
|
|
}
|
|
|
|
})));
|
|
|
|
} else {
|
|
|
|
resolve();
|
|
|
|
}
|
2016-05-12 10:00:10 +05:30
|
|
|
}))
|
|
|
|
})(ProfilePage);
|