accounts-frontend/src/pages/profile/ChangePasswordPage.js

55 lines
1.4 KiB
JavaScript
Raw Normal View History

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