From 901f9f769d85aeeb6511810b0f998aa024ec27bf Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Mon, 8 Apr 2024 15:17:53 +0300 Subject: [PATCH] [develop]: Fix an error while inviting a person that it is already a member or manager. Remove message while accepting the member role. --- .../users/role-users/role-users.component.ts | 9 ++- .../role-verification.component.ts | 74 +++++++------------ 2 files changed, 30 insertions(+), 53 deletions(-) diff --git a/dashboard/users/role-users/role-users.component.ts b/dashboard/users/role-users/role-users.component.ts index 788fed32..af6dbaa0 100644 --- a/dashboard/users/role-users/role-users.component.ts +++ b/dashboard/users/role-users/role-users.component.ts @@ -268,9 +268,9 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges { return this.userRegistryService.invite(this.type, this.id, { link: this.link, email: this.emailComposer(this.name, email, this.role) - }, this.role).pipe(map(invitation => new InvitationResponse(email, invitation), catchError(error => { - return of(new InvitationResponse(current, null)); - }))); + }, this.role).pipe(catchError(error => { + return of(null); + }), map(invitation => new InvitationResponse(email, invitation))); }); this.subs.push(forkJoin(invitations).subscribe(responses => { let notifications = responses.map(response => { @@ -292,7 +292,8 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges { return of(null); } } else { - NotificationHandler.rise('An error has occurred while sending the invitation mail to ' + response.email + '.Please try again later', 'danger'); + NotificationHandler.rise('An error has occurred while sending the invitation mail to ' + + response.email + '.Check if the user is already a ' + this.stakeholderUtils.roles[this.role] + ' or try again later', 'danger'); return of(null); } }); diff --git a/role-verification/role-verification.component.ts b/role-verification/role-verification.component.ts index 46dd7899..9563eff9 100644 --- a/role-verification/role-verification.component.ts +++ b/role-verification/role-verification.component.ts @@ -13,6 +13,7 @@ import {Composer} from "../utils/email/composer"; import {ClearCacheService} from "../services/clear-cache.service"; import {BaseComponent} from "../sharedComponents/base/base.component"; import {StakeholderUtils} from "../monitor-admin/utils/indicator-utils"; +import {StringUtils} from "../utils/string-utils.class"; @Component({ selector: 'role-verification', @@ -20,12 +21,9 @@ import {StakeholderUtils} from "../monitor-admin/utils/indicator-utils";
- You have been invited to join {{name}} {{(service === 'monitor' ? 'Monitor' : 'Research Community')}} Dashboard - as a manager. + You have been invited to join {{name}} {{(dashboard)}} Dashboard as a {{stakeholderUtils.roles.manager}}. Fill in the verification code, sent to - your - email, to accept the invitation request. + your email, to accept the invitation request.
@@ -37,14 +35,12 @@ import {StakeholderUtils} from "../monitor-admin/utils/indicator-utils";
-
+ (alertOutput)="verifyMember()" [okDisabled]="(code.invalid || loading)"> +
- You have been invited to join {{name}} Monitor Dashboard as a member. + You have been invited to join {{name}} {{(dashboard)}} as a {{stakeholderUtils.roles.member}}. Fill in the verification code, sent - to - your - email, to accept the invitation request. + to your email, to accept the invitation request.
@@ -55,13 +51,6 @@ import {StakeholderUtils} from "../monitor-admin/utils/indicator-utils";
-
-
- Welcome! You are now a member of the OpenAIRE Monitor Dashboard for the {{name}}! - From now on, you will have access to our restricted content. -
-
@@ -96,6 +85,8 @@ export class RoleVerificationComponent extends BaseComponent implements OnInit, public userInfoLink = null; @Input() public relativeTo: ActivatedRoute = this._route; + @Input() + public dashboard: string = 'Research Community'; public user: User; public verification: any; public code: UntypedFormControl; @@ -106,9 +97,8 @@ export class RoleVerificationComponent extends BaseComponent implements OnInit, @ViewChild('errorModal') errorModal: AlertModal; public error: string = null; public loading: boolean = false; - public isMember: boolean = false; public stakeholderUtils: StakeholderUtils = new StakeholderUtils(); - + constructor(protected _route: ActivatedRoute, protected _router: Router, private fb: UntypedFormBuilder, @@ -119,18 +109,18 @@ export class RoleVerificationComponent extends BaseComponent implements OnInit, private cdr: ChangeDetectorRef) { super(); } - + ngOnInit() { this.reset(); } - + ngAfterViewInit() { this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => { this.user = user; this.paramsSubscription = this._route.queryParams.subscribe(params => { if (params) { this.cdr.detectChanges(); - if(params['verify'] && !this.isMember) { + if(params['verify']) { if (this.user) { this.subscriptions.push(this.userRegistryService.getInvitation(params['verify']).subscribe(verification => { this.verification = verification; @@ -157,51 +147,43 @@ export class RoleVerificationComponent extends BaseComponent implements OnInit, relativeTo: this.relativeTo }); } - } else if(this.isMember) { - this.openMemberModal(); } } else { - this.isMember = false; this.cdr.detectChanges(); } }); })); } - + ngOnDestroy() { super.ngOnDestroy(); if (this.paramsSubscription instanceof Subscription) { this.paramsSubscription.unsubscribe(); } } - + public openManagerModal() { this.error = null; this.managerModal.okButtonLeft = false; this.managerModal.okButtonText = 'Accept'; this.managerModal.stayOpen = true; this.managerModal.cancelButtonText = 'Cancel'; - this.managerModal.alertTitle = this.stakeholderUtils.roles.manager + ' Invitation'; + this.managerModal.alertTitle = StringUtils.capitalize(this.stakeholderUtils.roles.manager) + ' Invitation'; this.managerModal.open(); } - + public openMemberModal() { this.error = null; - if(this.isMember) { - this.memberModal.cancelButton = false; - this.memberModal.okButtonText = 'Close'; - } else { - this.memberModal.cancelButton = true; - this.memberModal.okButtonText = 'Accept'; - } + this.memberModal.cancelButton = true; + this.memberModal.okButtonText = 'Accept'; this.memberModal.okButtonLeft = false; this.memberModal.stayOpen = true; this.memberModal.cancelButtonText = 'Cancel'; - this.memberModal.alertTitle = this.stakeholderUtils.roles.member + ' Invitation'; + this.memberModal.alertTitle = StringUtils.capitalize(this.stakeholderUtils.roles.member) + ' Invitation'; this.cdr.detectChanges(); this.memberModal.open(); } - + public openErrorModal() { this.error = null; this.errorModal.cancelButton = false; @@ -209,7 +191,7 @@ export class RoleVerificationComponent extends BaseComponent implements OnInit, this.errorModal.alertTitle = 'Invalid URL'; this.errorModal.open(); } - + public verifyManager() { this.loading = true; this.subscriptions.push(this.userRegistryService.verify(this.verification.id, this.code.value).subscribe(() => { @@ -252,15 +234,13 @@ export class RoleVerificationComponent extends BaseComponent implements OnInit, this.error = 'The verification code is invalid'; })); } - + public verifyMember() { this.loading = true; - if (!this.isMember) { this.subscriptions.push(this.userRegistryService.verify(this.verification.id, this.code.value, "member").subscribe(() => { this.clearCacheService.clearCache('Members updated'); this.loading = false; this.error = null; - this.isMember = true; this.userManagementService.updateUserInfo(() => { if (this.paramsSubscription instanceof Subscription) { this.paramsSubscription.unsubscribe(); @@ -271,17 +251,13 @@ export class RoleVerificationComponent extends BaseComponent implements OnInit, this.loading = false; this.error = 'The verification code is invalid'; })); - } else { - this.memberModal.cancel(); - } } - + public reset() { this.code = this.fb.control('', [Validators.required, Validators.pattern('^[+0-9]{6}$')]); } - + cancel() { - this.isMember = false; this._router.navigate([]); } }