diff --git a/src/app/shared/context-menu/request-correction/request-correction-menu.component.html b/src/app/shared/context-menu/request-correction/request-correction-menu.component.html index bdbd281e357..cc309c47152 100644 --- a/src/app/shared/context-menu/request-correction/request-correction-menu.component.html +++ b/src/app/shared/context-menu/request-correction/request-correction-menu.component.html @@ -1,4 +1,4 @@ - diff --git a/src/app/shared/context-menu/request-correction/request-correction-menu.component.ts b/src/app/shared/context-menu/request-correction/request-correction-menu.component.ts index b51e89aaa08..9064af45e8c 100644 --- a/src/app/shared/context-menu/request-correction/request-correction-menu.component.ts +++ b/src/app/shared/context-menu/request-correction/request-correction-menu.component.ts @@ -2,7 +2,7 @@ import { Component, Inject, OnDestroy } from '@angular/core'; import { Router } from '@angular/router'; import { BehaviorSubject, Observable, of as observableOf, Subscription } from 'rxjs'; -import { catchError, take } from 'rxjs/operators'; +import { catchError, take, share, switchMap} from 'rxjs/operators'; import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; import { TranslateService } from '@ngx-translate/core'; @@ -44,6 +44,8 @@ export class RequestCorrectionMenuComponent extends ContextMenuEntryComponent im * Variable to track subscription and unsubscribe it onDestroy */ private sub: Subscription; + + canCreateCorrection$: Observable; /** * Initialize instance variables * @@ -69,6 +71,13 @@ export class RequestCorrectionMenuComponent extends ContextMenuEntryComponent im super(injectedContextMenuObject, injectedContextMenuObjectType, ContextMenuEntryType.RequestCorrection); } + ngOnInit(): void { + this.canCreateCorrection$ = this.notificationService.claimedProfile.pipe( + switchMap(() => this.canCreateCorrection(false)), + share(), + ); + } + /** * Open modal * @@ -85,10 +94,12 @@ export class RequestCorrectionMenuComponent extends ContextMenuEntryComponent im this.processing$.next(true); this.sub = this.submissionService.createSubmissionByItem(this.contextMenuObject.id, 'isCorrectionOfItem').pipe( take(1), - catchError((error: ErrorResponse) => { - this.handleErrorResponse(error.statusCode); - return observableOf({}); - }) + catchError((error: unknown) => { + if (error instanceof ErrorResponse) { + this.handleErrorResponse(error.statusCode); + return observableOf({}); + } + }), ).subscribe((response: SubmissionObject) => { this.processing$.next(false); this.modalRef.close(); @@ -96,15 +107,14 @@ export class RequestCorrectionMenuComponent extends ContextMenuEntryComponent im if (isNotEmpty(response)) { this.notificationService.success( null, - this.translate.instant('submission.workflow.tasks.generic.success') + this.translate.instant('submission.workflow.tasks.generic.success'), ); // redirect to workspaceItem edit page this.router.navigate(['workspaceitems', response.id, 'edit']); + } else { + this.handleErrorResponse(422); } }); - this.notificationService.claimedProfile.subscribe(() => { - this.canCreateCorrection(false); - }); } /** @@ -128,6 +138,12 @@ export class RequestCorrectionMenuComponent extends ContextMenuEntryComponent im this.translate.instant('item.page.context-menu.options.request-correction.error.403') ); break; + case 422: + this.notificationService.warning( + null, + this.translate.instant('context-menu.actions.request-correction.error.422'), + ); + break; default : this.notificationService.error( null,