member_webapp/@overflow/member/container/reset-password/reset-password.component.ts

59 lines
1.6 KiB
TypeScript
Raw Normal View History

2018-04-06 06:59:49 +00:00
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
2018-05-03 10:33:19 +00:00
import * as ResetPasswordStore from '../../store/reset-password';
import {select, Store} from '@ngrx/store';
import { ResetPasswordSelector } from '../../store';
2018-05-24 06:44:13 +00:00
import {RPCClientError} from '@loafer/ng-rpc';
2018-05-03 10:33:19 +00:00
import {Member} from '@overflow/commons-typescript/model/member/index';
2018-04-06 06:59:49 +00:00
@Component({
selector: 'of-member-reset-password',
templateUrl: './reset-password.component.html',
})
export class ResetPasswordComponent implements OnInit {
2018-05-03 10:33:19 +00:00
resetPassword$ = this.resetPasswordStore.pipe(select(ResetPasswordSelector.select('member')));
2018-04-06 06:59:49 +00:00
resetPassword: FormGroup;
formErrors = {
'email': ''
};
constructor(
2018-05-03 10:33:19 +00:00
private resetPasswordStore: Store<ResetPasswordStore.State>,
2018-04-06 06:59:49 +00:00
private router: Router,
private formBuilder: FormBuilder) { }
ngOnInit() {
this.resetPassword = this.formBuilder.group({
'email': ['', [
Validators.required,
Validators.email
]
]
});
}
sendResetPassword() {
2018-05-03 10:33:19 +00:00
const emailValue = Object.assign({}, this.resetPassword.value);
console.log(emailValue.email);
this.resetPasswordStore.dispatch(new ResetPasswordStore.ResetPassword(emailValue.email));
const resetPasswordSubscription$ = this.resetPassword$.subscribe(
(m: Member) => {
if (m) {
console.log(m);
}
2018-04-06 06:59:49 +00:00
2018-05-03 10:33:19 +00:00
if (resetPasswordSubscription$) {
resetPasswordSubscription$.unsubscribe();
}
},
(error: RPCClientError) => {
console.log(error.response.message);
}
);
2018-04-06 06:59:49 +00:00
}
}