From 566f9aa6d462bd2c967fe5c4a9f9ce1e497f0bcd Mon Sep 17 00:00:00 2001 From: FyloZ Date: Tue, 16 Feb 2021 18:10:02 -0500 Subject: [PATCH] =?UTF-8?q?Le=20AlertHandlerComponent=20va=20maintenant=20?= =?UTF-8?q?chercher=20les=20alertes=20lui-m=C3=AAme=20pour=20ne=20pas=20?= =?UTF-8?q?=C3=AAtre=20limit=C3=A9=20=C3=A0=20voir=20les=20alertes=20dans?= =?UTF-8?q?=20la=20queue=20lorsqu'une=20nouvelle=20alerte=20arrive.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../accounts/pages/login/login.component.ts | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/app/modules/accounts/pages/login/login.component.ts b/src/app/modules/accounts/pages/login/login.component.ts index 9f7b3ba..d3c6736 100644 --- a/src/app/modules/accounts/pages/login/login.component.ts +++ b/src/app/modules/accounts/pages/login/login.component.ts @@ -1,14 +1,20 @@ -import {Component, OnInit} from '@angular/core'; -import {FormBuilder, FormControl, FormGroup, Validators} from "@angular/forms"; -import {AccountService} from "../../services/account.service"; -import {Router} from "@angular/router"; +import {Component, OnInit} from '@angular/core' +import {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms' +import {AccountService} from '../../services/account.service' +import {Router} from '@angular/router' +import {ErrorHandler, ErrorModel, ErrorService} from '../../../shared/service/error.service' @Component({ selector: 'cre-login', templateUrl: './login.component.html', styleUrls: ['./login.component.sass'] }) -export class LoginComponent implements OnInit { +export class LoginComponent extends ErrorHandler implements OnInit { + readonly handledErrorModels: ErrorModel[] = [{ + filter: error => error.status === 401, + messageProducer: () => 'Les identifiants entrés sont invalides.' + }] + form: FormGroup idFormControl: FormControl passwordFormControl: FormControl @@ -18,8 +24,10 @@ export class LoginComponent implements OnInit { constructor( private formBuilder: FormBuilder, private accountService: AccountService, - private router: Router + private router: Router, + errorService: ErrorService ) { + super(errorService) } ngOnInit(): void { @@ -39,8 +47,7 @@ export class LoginComponent implements OnInit { this.accountService.login( this.idFormControl.value, this.passwordFormControl.value, - () => this.router.navigate(["/color"]), - err => this.invalidCredentials = err.status === 401 + () => this.router.navigate(['/color']) ) } }