2020-08-14 11:54:12 +02:00
|
|
|
import {Component, Input, OnInit} from "@angular/core";
|
|
|
|
import {FormBuilder, FormControl, Validators} from "@angular/forms";
|
|
|
|
import {UserRegistryService} from "../services/user-registry.service";
|
2020-08-12 17:16:09 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'verification',
|
2020-08-14 11:54:12 +02:00
|
|
|
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>
|
|
|
|
`
|
2020-08-12 17:16:09 +02:00
|
|
|
})
|
2020-08-14 11:54:12 +02:00
|
|
|
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;
|
2020-11-03 19:25:03 +01:00
|
|
|
this.userRegistryService.verify(this.invitation.id, this.code.value).subscribe(() => {
|
2020-08-14 11:54:12 +02:00
|
|
|
this.state = 'verified';
|
|
|
|
this.loading = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
reject() {
|
|
|
|
this.loading = true;
|
|
|
|
this.userRegistryService.deleteVerification(this.invitation.id).subscribe(() => {
|
|
|
|
this.state = 'refused';
|
|
|
|
this.loading = false;
|
|
|
|
});
|
|
|
|
}
|
2020-08-12 17:16:09 +02:00
|
|
|
}
|