From ed19051fc063d97a34b7ee4601bc5fd68aac3baa Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Tue, 21 Mar 2023 14:02:59 +0200 Subject: [PATCH] 1. Fix a bug with get stakeholder promise. 2. Fix a bug with infinity loop in user-info page. 3. Fix a bug with verify member error modal open on success. --- .../users/role-users/role-users.component.ts | 4 +- login/user.component.ts | 4 +- monitor/services/stakeholder.service.ts | 5 +- .../role-verification.component.ts | 76 +++++++++++-------- 4 files changed, 53 insertions(+), 36 deletions(-) diff --git a/dashboard/users/role-users/role-users.component.ts b/dashboard/users/role-users/role-users.component.ts index 2acc7edc..222f8530 100644 --- a/dashboard/users/role-users/role-users.component.ts +++ b/dashboard/users/role-users/role-users.component.ts @@ -1,4 +1,4 @@ -import {Component, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output, SimpleChanges, ViewChild} from '@angular/core'; +import {Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewChild} from '@angular/core'; import {UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, Validators} from '@angular/forms'; import {AlertModal} from "../../../utils/modal/alert"; import {UserRegistryService} from "../../../services/user-registry.service"; @@ -278,7 +278,7 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges { } public isMe(userId: string) { - return userId.includes(this.user.id) && !this.isCurator; + return userId && userId.includes(this.user.id) && !this.isCurator; } public get isManager(): boolean { diff --git a/login/user.component.ts b/login/user.component.ts index 1fcdc867..15922fe7 100644 --- a/login/user.component.ts +++ b/login/user.component.ts @@ -43,8 +43,8 @@ export class UserComponent { this.loginUrl = this.properties.loginUrl; if (typeof document !== 'undefined') { this.server = false; - this.userManagementsService.updateUserInfo(() => { - this.user = this.userManagementsService.user; + this.userManagementsService.getUserInfo().subscribe( user => { + this.user = user; this.loggedIn = !!this.user; this.errorMessage = ""; this.loading = true; diff --git a/monitor/services/stakeholder.service.ts b/monitor/services/stakeholder.service.ts index 272cbb39..c71f7f8e 100644 --- a/monitor/services/stakeholder.service.ts +++ b/monitor/services/stakeholder.service.ts @@ -58,7 +58,10 @@ export class StakeholderService { } async getStakeholderAsync() { - await this.promise; + if(this.promise) { + await this.promise; + this.promise = null; + } this.clearSubscriptions(); return this.stakeholderSubject.getValue(); } diff --git a/role-verification/role-verification.component.ts b/role-verification/role-verification.component.ts index 253fa91c..9030d636 100644 --- a/role-verification/role-verification.component.ts +++ b/role-verification/role-verification.component.ts @@ -1,4 +1,4 @@ -import {AfterViewInit, Component, Input, OnDestroy, OnInit, ViewChild} from "@angular/core"; +import {AfterViewInit, ChangeDetectorRef, Component, Input, OnDestroy, OnInit, ViewChild} from "@angular/core"; import {User} from "../login/utils/helper.class"; import {ActivatedRoute, Router} from "@angular/router"; import {UserManagementService} from "../services/user-management.service"; @@ -35,7 +35,7 @@ import {ClearCacheService} from "../services/clear-cache.service"; + (alertOutput)="verifyMember()" [okDisabled]="(code.invalid || loading) && !isMember">
You have been invited to join {{name}} Monitor Dashboard as a member. @@ -108,7 +108,8 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn private emailService: EmailService, private userManagementService: UserManagementService, private userRegistryService: UserRegistryService, - private clearCacheService: ClearCacheService) { + private clearCacheService: ClearCacheService, + private cdr: ChangeDetectorRef) { } ngOnInit() { @@ -122,33 +123,42 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn this.paramsSubscription.unsubscribe(); } this.paramsSubscription = this.route.queryParams.subscribe(params => { - if (params && params['verify']) { - if (this.user) { - 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') { - this.openManagerModal(); - } else if (this.verification.verificationType === 'member' && this.service === "monitor") { - this.openMemberModal(); + if (params) { + this.isMember = !!params['isMember']; + this.cdr.detectChanges(); + if(params['verify'] && !this.isMember) { + if (this.user) { + 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') { + this.openManagerModal(); + } else if (this.verification.verificationType === 'member' && this.service === "monitor") { + this.openMemberModal(); + } else { + this.openErrorModal(); + } } else { this.openErrorModal(); } - } else { + }, error => { this.openErrorModal(); - } - }, error => { - this.openErrorModal(); - })); - } else { - this.router.navigate(['user-info'], { - queryParams: { - 'errorCode': LoginErrorCodes.NOT_LOGIN, - 'redirectUrl': this.router.url - }, - relativeTo: this.route - }); + })); + } else { + this.router.navigate(['user-info'], { + queryParams: { + 'errorCode': LoginErrorCodes.NOT_LOGIN, + 'redirectUrl': this.router.url + }, + relativeTo: this.route + }); + } + } else if(this.isMember) { + this.openMemberModal(); } + } else { + this.isMember = false; + this.cdr.detectChanges(); } }); })); @@ -177,12 +187,18 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn public openMemberModal() { this.error = null; - this.isMember = false; + if(this.isMember) { + this.memberModal.cancelButton = false; + this.memberModal.okButtonText = 'Close'; + } else { + this.memberModal.cancelButton = true; + this.memberModal.okButtonText = 'Accept'; + } this.memberModal.okButtonLeft = false; - this.memberModal.okButtonText = 'Accept'; this.memberModal.stayOpen = true; this.memberModal.cancelButtonText = 'Cancel'; this.memberModal.alertTitle = 'Member Invitation'; + this.cdr.detectChanges(); this.memberModal.open(); } @@ -239,9 +255,7 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn this.loading = false; this.error = null; this.userManagementService.updateUserInfo(() => { - this.memberModal.cancelButton = false; - this.memberModal.okButtonText = 'Close'; - this.isMember = true; + this.router.navigate([], {queryParams: {'verify': null, 'isMember': true}}); }); }, error => { this.loading = false; @@ -257,6 +271,6 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn } cancel() { - this.router.navigate([this.router.url.split('?')[0]]); + this.router.navigate([], {queryParams: {'verify': null, 'isMember': null}}); } }