2019-01-28 00:42:58 +05:30
|
|
|
// @flow
|
|
|
|
import type { User } from 'components/user';
|
2017-08-23 00:19:50 +05:30
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React, { Component } from 'react';
|
2016-05-01 23:20:55 +05:30
|
|
|
|
2019-01-28 00:42:58 +05:30
|
|
|
import { changePassword } from 'services/api/accounts';
|
2016-05-02 15:08:45 +05:30
|
|
|
import { FormModel } from 'components/ui/form';
|
2016-05-01 23:20:55 +05:30
|
|
|
import ChangePassword from 'components/profile/changePassword/ChangePassword';
|
|
|
|
|
2019-06-30 19:02:50 +05:30
|
|
|
type OwnProps = {|
|
|
|
|
|};
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
...OwnProps,
|
2019-01-28 00:42:58 +05:30
|
|
|
updateUser: (fields: $Shape<User>) => void;
|
|
|
|
}
|
2016-05-01 23:20:55 +05:30
|
|
|
|
2019-01-28 00:42:58 +05:30
|
|
|
class ChangePasswordPage extends Component<Props> {
|
|
|
|
static displayName = 'ChangePasswordPage';
|
2016-05-12 10:00:10 +05:30
|
|
|
|
|
|
|
static contextTypes = {
|
2019-01-28 00:42:58 +05:30
|
|
|
userId: PropTypes.number.isRequired,
|
2016-05-22 13:23:40 +05:30
|
|
|
onSubmit: PropTypes.func.isRequired,
|
2019-01-28 00:42:58 +05:30
|
|
|
goToProfile: PropTypes.func.isRequired,
|
2016-05-01 23:20:55 +05:30
|
|
|
};
|
|
|
|
|
2016-05-02 14:50:50 +05:30
|
|
|
form = new FormModel();
|
|
|
|
|
2016-05-01 23:20:55 +05:30
|
|
|
render() {
|
|
|
|
return (
|
2016-05-02 14:50:50 +05:30
|
|
|
<ChangePassword onSubmit={this.onSubmit} form={this.form} />
|
2016-05-01 23:20:55 +05:30
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-05-02 14:50:50 +05:30
|
|
|
onSubmit = () => {
|
2016-05-12 10:00:10 +05:30
|
|
|
const {form} = this;
|
2017-02-27 11:17:31 +05:30
|
|
|
return this.context.onSubmit({
|
2016-05-12 10:00:10 +05:30
|
|
|
form,
|
2019-01-28 00:42:58 +05:30
|
|
|
sendData: () => changePassword(this.context.userId, form.serialize()),
|
2016-05-12 10:00:10 +05:30
|
|
|
}).then(() => {
|
|
|
|
this.props.updateUser({
|
2016-08-03 00:43:11 +05:30
|
|
|
passwordChangedAt: Date.now() / 1000
|
2016-05-12 10:00:10 +05:30
|
|
|
});
|
2016-05-22 13:23:40 +05:30
|
|
|
this.context.goToProfile();
|
2016-05-12 10:00:10 +05:30
|
|
|
});
|
2016-05-01 23:20:55 +05:30
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
import { connect } from 'react-redux';
|
2016-05-01 23:40:45 +05:30
|
|
|
import { updateUser } from 'components/user/actions';
|
2016-05-01 23:20:55 +05:30
|
|
|
|
2019-06-30 19:02:50 +05:30
|
|
|
export default connect<Props, OwnProps, _, _, _, _>(null, {
|
2019-01-28 00:42:58 +05:30
|
|
|
updateUser,
|
2016-05-01 23:20:55 +05:30
|
|
|
})(ChangePasswordPage);
|