import {Component, Input, OnInit} from "@angular/core";
import {FormBuilder, FormControl, Validators} from "@angular/forms";
import {UserRegistryService} from "../services/user-registry.service";
@Component({
selector: 'verification',
template: `
You have been invited to join {{name}} as Manager;
Fill in the verification code, sent to your email, to accept the invitation request.
You are now manager of {{name}}.
You have been refused to be manager of {{name}}.
`
})
export class VerificationComponent implements OnInit {
@Input()
public name: string;
@Input()
public invitation;
public code: FormControl;
public loading = false;
public state: 'default' | 'verified' | 'refused' | 'error' = 'default';
constructor(private fb: FormBuilder,
private userRegistryService: UserRegistryService) {
}
ngOnInit() {
this.code = this.fb.control('', [Validators.required, Validators.pattern('^[+0-9]{6}$')]);
}
verify() {
this.loading = true;
this.userRegistryService.verify(this.invitation.id, this.code.value).subscribe(() => {
this.state = 'verified';
this.loading = false;
});
}
reject() {
this.loading = true;
this.userRegistryService.deleteVerification(this.invitation.id).subscribe(() => {
this.state = 'refused';
this.loading = false;
});
}
}