2019-12-07 16:58:52 +05:30
|
|
|
import React from 'react';
|
2020-07-22 15:31:12 +05:30
|
|
|
|
|
|
|
import { connect } from 'app/functions';
|
2019-12-08 00:32:00 +05:30
|
|
|
import { changePassword } from 'app/services/api/accounts';
|
|
|
|
import { FormModel } from 'app/components/ui/form';
|
|
|
|
import ChangePassword from 'app/components/profile/changePassword/ChangePassword';
|
|
|
|
import { User } from 'app/components/user';
|
|
|
|
import { updateUser } from 'app/components/user/actions';
|
2019-12-12 12:56:23 +05:30
|
|
|
import Context from 'app/components/profile/Context';
|
2016-05-01 23:20:55 +05:30
|
|
|
|
2019-12-12 12:56:23 +05:30
|
|
|
interface Props {
|
2020-05-24 04:38:24 +05:30
|
|
|
updateUser: (fields: Partial<User>) => void;
|
2019-12-12 12:56:23 +05:30
|
|
|
}
|
2016-05-01 23:20:55 +05:30
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
class ChangePasswordPage extends React.Component<Props> {
|
2020-05-24 04:38:24 +05:30
|
|
|
static contextType = Context;
|
|
|
|
/* TODO: use declare */ context: React.ContextType<typeof Context>;
|
2019-11-27 14:33:32 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
form = new FormModel();
|
2019-11-27 14:33:32 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
render() {
|
|
|
|
return <ChangePassword onSubmit={this.onSubmit} form={this.form} />;
|
|
|
|
}
|
2019-11-27 14:33:32 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
onSubmit = () => {
|
|
|
|
const { form } = this;
|
2019-11-27 14:33:32 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
return this.context
|
|
|
|
.onSubmit({
|
|
|
|
form,
|
|
|
|
sendData: () => changePassword(this.context.userId, form.serialize()),
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
this.props.updateUser({
|
|
|
|
passwordChangedAt: Date.now() / 1000,
|
|
|
|
});
|
|
|
|
this.context.goToProfile();
|
|
|
|
});
|
|
|
|
};
|
2016-05-01 23:20:55 +05:30
|
|
|
}
|
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
export default connect(null, {
|
2020-05-24 04:38:24 +05:30
|
|
|
updateUser,
|
2016-05-01 23:20:55 +05:30
|
|
|
})(ChangePasswordPage);
|