72 lines
2.3 KiB
TypeScript
72 lines
2.3 KiB
TypeScript
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: `
|
|
<div *ngIf="loading" class="loading-gif"></div>
|
|
<div *ngIf="name && !loading" class="uk-text-center uk-text-large">
|
|
<ng-container *ngIf="state === 'default'">
|
|
<div>
|
|
You have been invited to join <span class="uk-text-bold">{{name}}</span> as Manager;<br>
|
|
Fill in the verification code, sent to your email, to accept the invitation request.
|
|
</div>
|
|
<div class="uk-margin-medium-top">
|
|
<input [formControl]="code" class="uk-input uk-width-small" [class.uk-form-danger]="code.invalid">
|
|
</div>
|
|
<div class="uk-margin-medium-top">
|
|
<button class="uk-button" [class.portal-button]="code.valid" [class.uk-disabled]="code.invalid"
|
|
(click)="verify()">Accept
|
|
</button>
|
|
<button class="uk-button uk-button-danger uk-margin-medium-left" (click)="reject()">Reject</button>
|
|
</div>
|
|
</ng-container>
|
|
<ng-container *ngIf="state === 'verified'">
|
|
<div>
|
|
You are now manager of {{name}}.
|
|
</div>
|
|
</ng-container>
|
|
<ng-container *ngIf="state === 'refused'">
|
|
<div>
|
|
You have been refused to be manager of {{name}}.
|
|
</div>
|
|
</ng-container>
|
|
</div>
|
|
`
|
|
})
|
|
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.verifyManager(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;
|
|
});
|
|
}
|
|
}
|