diff --git a/dmp-frontend/src/app/ui/dmp/invitation/dialog/dmp-invitation-dialog.component.ts b/dmp-frontend/src/app/ui/dmp/invitation/dialog/dmp-invitation-dialog.component.ts index 5fed32cd6..a6f7ce512 100644 --- a/dmp-frontend/src/app/ui/dmp/invitation/dialog/dmp-invitation-dialog.component.ts +++ b/dmp-frontend/src/app/ui/dmp/invitation/dialog/dmp-invitation-dialog.component.ts @@ -1,26 +1,25 @@ import { COMMA, ENTER } from '@angular/cdk/keycodes'; +import { HttpErrorResponse } from '@angular/common/http'; import { Component, Inject, OnInit } from '@angular/core'; import { UntypedFormGroup } from '@angular/forms'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { ActivatedRoute, Router } from '@angular/router'; import { DmpUserRole } from '@app/core/common/enum/dmp-user-role'; +import { DmpBlueprint } from '@app/core/model/dmp-blueprint/dmp-blueprint'; import { DmpUserPersist } from '@app/core/model/dmp/dmp'; import { DmpService } from '@app/core/services/dmp/dmp.service'; import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service'; -import { UserService } from '@app/core/services/user/user.service'; import { EnumUtils } from '@app/core/services/utilities/enum-utils.service'; import { BaseComponent } from '@common/base/base.component'; -import { FilterService } from '@common/modules/text-filter/filter-service'; +import { FormService } from '@common/forms/form-service'; +import { HttpError, HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service'; import { Guid } from '@common/types/guid'; import { TranslateService } from '@ngx-translate/core'; -import { DmpEditorModel } from '../../dmp-editor-blueprint/dmp-editor.model'; import { takeUntil } from 'rxjs/operators'; -import { DmpBlueprint } from '@app/core/model/dmp-blueprint/dmp-blueprint'; -import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service'; -import { HttpErrorResponse } from '@angular/common/http'; -import { FormService } from '@common/forms/form-service'; +import { DmpEditorModel } from '../../dmp-editor-blueprint/dmp-editor.model'; import { DmpEditorService } from '../../dmp-editor-blueprint/dmp-editor.service'; +import { ResponseErrorCode } from '@app/core/common/enum/respone-error-code'; @Component({ selector: 'app-invitation-dialog-component', @@ -34,7 +33,7 @@ export class DmpInvitationDialogComponent extends BaseComponent implements OnIni editorModel: DmpEditorModel; formGroup: UntypedFormGroup; dmpUserRoleEnum = DmpUserRole; - selectedBlueprint: DmpBlueprint; + selectedBlueprint: DmpBlueprint; inProgressSendButton = false; readonly separatorKeysCodes: number[] = [ENTER, COMMA]; @@ -59,7 +58,6 @@ export class DmpInvitationDialogComponent extends BaseComponent implements OnIni ngOnInit() { this.formGroup = this.editorModel.buildForm(); - this.dmpEditorService.setValidationErrorModel(this.editorModel.validationErrorModel); } send() { @@ -70,7 +68,7 @@ export class DmpInvitationDialogComponent extends BaseComponent implements OnIni this.inProgressSendButton = true; const userFormData = this.formGroup.get("users").value as DmpUserPersist[]; - this.dmpService.inviteUsers(this.dmpId, {users: userFormData}) + this.dmpService.inviteUsers(this.dmpId, { users: userFormData }) .pipe(takeUntil(this._destroyed)) .subscribe( complete => { @@ -93,10 +91,21 @@ export class DmpInvitationDialogComponent extends BaseComponent implements OnIni this.uiNotificationService.snackBarNotification(this.language.instant('DMP-USER-INVITATION-DIALOG.SUCCESS'), SnackBarNotificationLevel.Success); } + // onCallbackError(errorResponse: HttpErrorResponse) { + // this.inProgressSendButton = false; + // let errorOverrides = new Map(); + // errorOverrides.set(-1, this.language.instant('DMP-USER-INVITATION-DIALOG.ERROR')); + // this.httpErrorHandlingService.handleBackedRequestError(errorResponse, errorOverrides, SnackBarNotificationLevel.Error); + // } + onCallbackError(errorResponse: HttpErrorResponse) { this.inProgressSendButton = false; - let errorOverrides = new Map(); - errorOverrides.set(-1, this.language.instant('DMP-USER-INVITATION-DIALOG.ERROR')); - this.httpErrorHandlingService.handleBackedRequestError(errorResponse, errorOverrides, SnackBarNotificationLevel.Error); + this.httpErrorHandlingService.handleBackedRequestError(errorResponse); + + const error: HttpError = this.httpErrorHandlingService.getError(errorResponse); + if (error.statusCode === 400) { + this.editorModel.validationErrorModel.fromJSONObject(errorResponse.error); + this.formService.validateAllFormFields(this.formGroup); + } } }