Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<button *ngIf="canCreateCorrection() | async" class="dropdown-item"
<button *ngIf="canCreateCorrection$ | async" class="dropdown-item"
[innerHTML]="'context-menu.actions.request-correction.btn' | translate"
(click)="$event.preventDefault();openRequestModal(requestCorrectionModal);">
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -44,6 +44,8 @@ export class RequestCorrectionMenuComponent extends ContextMenuEntryComponent im
* Variable to track subscription and unsubscribe it onDestroy
*/
private sub: Subscription;

canCreateCorrection$: Observable<boolean>;
/**
* Initialize instance variables
*
Expand All @@ -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
*
Expand All @@ -85,26 +94,27 @@ 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();

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

/**
Expand All @@ -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,
Expand Down