[develop]: Fix an error while inviting a person that it is already a member or manager. Remove message while accepting the member role.

This commit is contained in:
Konstantinos Triantafyllou 2024-04-08 15:17:53 +03:00
parent e6d03d324f
commit 901f9f769d
2 changed files with 30 additions and 53 deletions

View File

@ -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);
}
});

View File

@ -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";
<modal-alert #managerModal [overflowBody]="false" (alertOutput)="verifyManager()" (cancelOutput)="cancel()"
[okDisabled]="code.invalid || loading">
<div>
You have been invited to join <span
class="uk-text-bold">{{name}}</span> {{(service === 'monitor' ? 'Monitor' : 'Research Community')}} Dashboard
as a manager.
You have been invited to join <span class="uk-text-bold">{{name}}</span> {{(dashboard)}} Dashboard as a {{stakeholderUtils.roles.manager}}.
<span class="uk-text-primary">Fill</span> in the <span class="uk-text-primary">verification code</span>, sent to
your
email, to accept the invitation request.
your email, to accept the invitation request.
</div>
<div *ngIf="!loading" class="uk-margin-medium-top uk-flex uk-flex-center">
<div input [formInput]="code" class="uk-width-medium" placeholder="Verification code">
@ -37,14 +35,12 @@ import {StakeholderUtils} from "../monitor-admin/utils/indicator-utils";
</div>
</modal-alert>
<modal-alert #memberModal [overflowBody]="false" (cancelOutput)="cancel()"
(alertOutput)="verifyMember()" [okDisabled]="(code.invalid || loading) && !isMember">
<div *ngIf="!isMember">
(alertOutput)="verifyMember()" [okDisabled]="(code.invalid || loading)">
<div>
<div>
You have been invited to join <span class="uk-text-bold">{{name}}</span> Monitor Dashboard as a member.
You have been invited to join <span class="uk-text-bold">{{name}}</span> {{(dashboard)}} as a {{stakeholderUtils.roles.member}}.
<span class="uk-text-primary">Fill</span> in the <span class="uk-text-primary">verification code</span>, sent
to
your
email, to accept the invitation request.
to your email, to accept the invitation request.
</div>
<div *ngIf="!loading" class="uk-margin-medium-top uk-flex uk-flex-wrap uk-flex-center">
<div input [formInput]="code" class="uk-width-medium" placeholder="Verification code">
@ -55,13 +51,6 @@ import {StakeholderUtils} from "../monitor-admin/utils/indicator-utils";
<loading></loading>
</div>
</div>
<div *ngIf="isMember">
<div>
Welcome! You are now a member of the OpenAIRE Monitor Dashboard for the <span
class="uk-text-bold">{{name}}</span>!
From now on, you will have access to our restricted content.
</div>
</div>
</modal-alert>
<modal-alert #errorModal (alertOutput)="cancel()" [overflowBody]="false">
<div>
@ -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([]);
}
}