Role verification: Fix a bug after success verification, error modal is appeared.
This commit is contained in:
parent
cdffb018b6
commit
6295bd8c44
|
@ -4,7 +4,7 @@ import {ActivatedRoute, Router} from "@angular/router";
|
|||
import {UserManagementService} from "../services/user-management.service";
|
||||
import {UserRegistryService} from "../services/user-registry.service";
|
||||
import {LoginErrorCodes} from "../login/utils/guardHelper.class";
|
||||
import {Subscriber} from "rxjs";
|
||||
import {Subscriber, Subscription} from "rxjs";
|
||||
import {UntypedFormBuilder, UntypedFormControl, Validators} from "@angular/forms";
|
||||
import {AlertModal} from "../utils/modal/alert";
|
||||
import {properties} from "../../../environments/environment";
|
||||
|
@ -80,7 +80,8 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn
|
|||
public user: User;
|
||||
public verification: any;
|
||||
public code: UntypedFormControl;
|
||||
private subs: any[] = [];
|
||||
private subscriptions: any[] = [];
|
||||
private paramsSubscription: Subscription;
|
||||
@ViewChild('managerModal') managerModal: AlertModal;
|
||||
@ViewChild('memberModal') memberModal: AlertModal;
|
||||
@ViewChild('errorModal') errorModal: AlertModal;
|
||||
|
@ -101,12 +102,15 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn
|
|||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
this.subs.push(this.route.queryParams.subscribe(params => {
|
||||
if (params && params['verify']) {
|
||||
this.subs.push(this.userManagementService.getUserInfo().subscribe(user => {
|
||||
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
|
||||
this.user = user;
|
||||
if (this.user) {
|
||||
this.subs.push(this.userRegistryService.getInvitation(params['verify']).subscribe(verification => {
|
||||
if(this.paramsSubscription instanceof Subscription) {
|
||||
this.paramsSubscription.unsubscribe();
|
||||
}
|
||||
this.paramsSubscription = this.route.queryParams.subscribe(params => {
|
||||
if (params && params['verify']) {
|
||||
this.subscriptions.push(this.userRegistryService.getInvitation(params['verify']).subscribe(verification => {
|
||||
this.verification = verification;
|
||||
if (this.user.email === this.verification.email.toLowerCase() && this.id === this.verification.entity && this.type === this.verification.type) {
|
||||
if (this.verification.verificationType === 'manager') {
|
||||
|
@ -122,6 +126,8 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn
|
|||
}, error => {
|
||||
this.openErrorModal();
|
||||
}));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.router.navigate(['/user-info'], {
|
||||
queryParams: {
|
||||
|
@ -132,13 +138,14 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn
|
|||
}
|
||||
}));
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.subs.forEach(value => {
|
||||
if (value instanceof Subscriber) {
|
||||
value.unsubscribe();
|
||||
if(this.paramsSubscription instanceof Subscription) {
|
||||
this.paramsSubscription.unsubscribe();
|
||||
}
|
||||
this.subscriptions.forEach(subscription => {
|
||||
if (subscription instanceof Subscriber) {
|
||||
subscription.unsubscribe();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -174,7 +181,7 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn
|
|||
|
||||
public verifyManager() {
|
||||
this.loading = true;
|
||||
this.subs.push(this.userRegistryService.verify(this.verification.id, this.code.value).subscribe(() => {
|
||||
this.subscriptions.push(this.userRegistryService.verify(this.verification.id, this.code.value).subscribe(() => {
|
||||
this.managerModal.cancel();
|
||||
this.error = null;
|
||||
this.userManagementService.updateUserInfo(() => {
|
||||
|
@ -182,9 +189,9 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn
|
|||
this.loading = false;
|
||||
this.router.navigate(['/admin/' + this.verification.entity]);
|
||||
} else {
|
||||
this.subs.push(this.emailService.notifyManagers(this.id, 'manager',
|
||||
this.subscriptions.push(this.emailService.notifyManagers(this.id, 'manager',
|
||||
Composer.composeEmailToInformOldManagersForTheNewOnes(this.name, this.id)).subscribe(() => {
|
||||
this.subs.push(this.emailService.notifyNewManager(Composer.composeEmailForNewManager(this.id, this.name)).subscribe(
|
||||
this.subscriptions.push(this.emailService.notifyNewManager(Composer.composeEmailForNewManager(this.id, this.name)).subscribe(
|
||||
() => {
|
||||
this.loading = false;
|
||||
window.location.href = properties.adminPortalURL + '/' + this.verification.entity;
|
||||
|
@ -211,7 +218,7 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn
|
|||
public verifyMember() {
|
||||
this.loading = true;
|
||||
if (!this.isMember) {
|
||||
this.subs.push(this.userRegistryService.verify(this.verification.id, this.code.value, "member").subscribe(() => {
|
||||
this.subscriptions.push(this.userRegistryService.verify(this.verification.id, this.code.value, "member").subscribe(() => {
|
||||
this.loading = false;
|
||||
this.error = null;
|
||||
this.userManagementService.updateUserInfo(() => {
|
||||
|
|
Loading…
Reference in New Issue