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 {UserManagementService} from "../services/user-management.service";
|
||||||
import {UserRegistryService} from "../services/user-registry.service";
|
import {UserRegistryService} from "../services/user-registry.service";
|
||||||
import {LoginErrorCodes} from "../login/utils/guardHelper.class";
|
import {LoginErrorCodes} from "../login/utils/guardHelper.class";
|
||||||
import {Subscriber} from "rxjs";
|
import {Subscriber, Subscription} from "rxjs";
|
||||||
import {UntypedFormBuilder, UntypedFormControl, Validators} from "@angular/forms";
|
import {UntypedFormBuilder, UntypedFormControl, Validators} from "@angular/forms";
|
||||||
import {AlertModal} from "../utils/modal/alert";
|
import {AlertModal} from "../utils/modal/alert";
|
||||||
import {properties} from "../../../environments/environment";
|
import {properties} from "../../../environments/environment";
|
||||||
|
@ -80,7 +80,8 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn
|
||||||
public user: User;
|
public user: User;
|
||||||
public verification: any;
|
public verification: any;
|
||||||
public code: UntypedFormControl;
|
public code: UntypedFormControl;
|
||||||
private subs: any[] = [];
|
private subscriptions: any[] = [];
|
||||||
|
private paramsSubscription: Subscription;
|
||||||
@ViewChild('managerModal') managerModal: AlertModal;
|
@ViewChild('managerModal') managerModal: AlertModal;
|
||||||
@ViewChild('memberModal') memberModal: AlertModal;
|
@ViewChild('memberModal') memberModal: AlertModal;
|
||||||
@ViewChild('errorModal') errorModal: AlertModal;
|
@ViewChild('errorModal') errorModal: AlertModal;
|
||||||
|
@ -101,12 +102,15 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewInit() {
|
ngAfterViewInit() {
|
||||||
this.subs.push(this.route.queryParams.subscribe(params => {
|
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
|
||||||
if (params && params['verify']) {
|
this.user = user;
|
||||||
this.subs.push(this.userManagementService.getUserInfo().subscribe(user => {
|
if (this.user) {
|
||||||
this.user = user;
|
if(this.paramsSubscription instanceof Subscription) {
|
||||||
if (this.user) {
|
this.paramsSubscription.unsubscribe();
|
||||||
this.subs.push(this.userRegistryService.getInvitation(params['verify']).subscribe(verification => {
|
}
|
||||||
|
this.paramsSubscription = this.route.queryParams.subscribe(params => {
|
||||||
|
if (params && params['verify']) {
|
||||||
|
this.subscriptions.push(this.userRegistryService.getInvitation(params['verify']).subscribe(verification => {
|
||||||
this.verification = verification;
|
this.verification = verification;
|
||||||
if (this.user.email === this.verification.email.toLowerCase() && this.id === this.verification.entity && this.type === this.verification.type) {
|
if (this.user.email === this.verification.email.toLowerCase() && this.id === this.verification.entity && this.type === this.verification.type) {
|
||||||
if (this.verification.verificationType === 'manager') {
|
if (this.verification.verificationType === 'manager') {
|
||||||
|
@ -122,23 +126,26 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn
|
||||||
}, error => {
|
}, error => {
|
||||||
this.openErrorModal();
|
this.openErrorModal();
|
||||||
}));
|
}));
|
||||||
} else {
|
|
||||||
this.router.navigate(['/user-info'], {
|
|
||||||
queryParams: {
|
|
||||||
'errorCode': LoginErrorCodes.NOT_LOGIN,
|
|
||||||
'redirectUrl': this.router.url
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
|
} else {
|
||||||
|
this.router.navigate(['/user-info'], {
|
||||||
|
queryParams: {
|
||||||
|
'errorCode': LoginErrorCodes.NOT_LOGIN,
|
||||||
|
'redirectUrl': this.router.url
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
this.subs.forEach(value => {
|
if(this.paramsSubscription instanceof Subscription) {
|
||||||
if (value instanceof Subscriber) {
|
this.paramsSubscription.unsubscribe();
|
||||||
value.unsubscribe();
|
}
|
||||||
|
this.subscriptions.forEach(subscription => {
|
||||||
|
if (subscription instanceof Subscriber) {
|
||||||
|
subscription.unsubscribe();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -174,7 +181,7 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn
|
||||||
|
|
||||||
public verifyManager() {
|
public verifyManager() {
|
||||||
this.loading = true;
|
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.managerModal.cancel();
|
||||||
this.error = null;
|
this.error = null;
|
||||||
this.userManagementService.updateUserInfo(() => {
|
this.userManagementService.updateUserInfo(() => {
|
||||||
|
@ -182,9 +189,9 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
this.router.navigate(['/admin/' + this.verification.entity]);
|
this.router.navigate(['/admin/' + this.verification.entity]);
|
||||||
} else {
|
} 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(() => {
|
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;
|
this.loading = false;
|
||||||
window.location.href = properties.adminPortalURL + '/' + this.verification.entity;
|
window.location.href = properties.adminPortalURL + '/' + this.verification.entity;
|
||||||
|
@ -211,7 +218,7 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn
|
||||||
public verifyMember() {
|
public verifyMember() {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
if (!this.isMember) {
|
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.loading = false;
|
||||||
this.error = null;
|
this.error = null;
|
||||||
this.userManagementService.updateUserInfo(() => {
|
this.userManagementService.updateUserInfo(() => {
|
||||||
|
|
Loading…
Reference in New Issue