2019-12-07 13:28:52 +02:00
|
|
|
import React from 'react';
|
2020-07-22 13:01:12 +03:00
|
|
|
|
|
|
|
import { connect } from 'app/functions';
|
2019-12-07 21:02:00 +02:00
|
|
|
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 09:26:23 +02:00
|
|
|
import Context from 'app/components/profile/Context';
|
2016-05-01 20:50:55 +03:00
|
|
|
|
2019-12-12 09:26:23 +02:00
|
|
|
interface Props {
|
2020-05-24 02:08:24 +03:00
|
|
|
updateUser: (fields: Partial<User>) => void;
|
2019-12-12 09:26:23 +02:00
|
|
|
}
|
2016-05-01 20:50:55 +03:00
|
|
|
|
2019-12-07 13:28:52 +02:00
|
|
|
class ChangePasswordPage extends React.Component<Props> {
|
2020-05-24 02:08:24 +03:00
|
|
|
static contextType = Context;
|
2020-10-11 19:33:55 +03:00
|
|
|
declare context: React.ContextType<typeof Context>;
|
2019-11-27 11:03:32 +02:00
|
|
|
|
2020-05-24 02:08:24 +03:00
|
|
|
form = new FormModel();
|
2019-11-27 11:03:32 +02:00
|
|
|
|
2020-05-24 02:08:24 +03:00
|
|
|
render() {
|
|
|
|
return <ChangePassword onSubmit={this.onSubmit} form={this.form} />;
|
|
|
|
}
|
2019-11-27 11:03:32 +02:00
|
|
|
|
2020-05-24 02:08:24 +03:00
|
|
|
onSubmit = () => {
|
|
|
|
const { form } = this;
|
2019-11-27 11:03:32 +02:00
|
|
|
|
2020-05-24 02:08:24 +03:00
|
|
|
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 20:50:55 +03:00
|
|
|
}
|
|
|
|
|
2019-12-07 13:28:52 +02:00
|
|
|
export default connect(null, {
|
2020-05-24 02:08:24 +03:00
|
|
|
updateUser,
|
2016-05-01 20:50:55 +03:00
|
|
|
})(ChangePasswordPage);
|