From 2cab8b84a829a814c2c2eec76e9c100385149ae5 Mon Sep 17 00:00:00 2001 From: Chneemann Date: Wed, 29 May 2024 20:17:45 +0200 Subject: [PATCH] disable login btn on click --- src/app/components/main-login/login/login.component.html | 3 +++ src/app/components/main-login/login/login.component.scss | 3 +++ src/app/service/login.service.ts | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/src/app/components/main-login/login/login.component.html b/src/app/components/main-login/login/login.component.html index 5b542fc..0bea5a5 100644 --- a/src/app/components/main-login/login/login.component.html +++ b/src/app/components/main-login/login/login.component.html @@ -21,6 +21,7 @@ required [ngClass]="{ aktivInput: emailField.valid && emailField.touched }" pattern="[^@]+@[^.]+\..+" + disabled="{{ loginService.isBtnDisabled }}" /> @if (!emailField.valid && emailField.touched) {

{{ "login.errorText" | translate }}

@@ -44,6 +45,7 @@ }" cols="30" rows="10" + disabled="{{ loginService.isBtnDisabled }}" /> {{ "login.BtnRight" | translate }} diff --git a/src/app/components/main-login/login/login.component.scss b/src/app/components/main-login/login/login.component.scss index dc78665..5c38543 100644 --- a/src/app/components/main-login/login/login.component.scss +++ b/src/app/components/main-login/login/login.component.scss @@ -126,6 +126,9 @@ button { color: #fff; border: 1px solid #ffff; } + &:disabled { + @include buttonGrey; + } } .mobileRegisterContainer { display: none; diff --git a/src/app/service/login.service.ts b/src/app/service/login.service.ts index f1dc59c..727008f 100644 --- a/src/app/service/login.service.ts +++ b/src/app/service/login.service.ts @@ -42,6 +42,7 @@ export class loginService { isFirstLoad: boolean = true; passwordFieldType: string = 'password'; passwordIcon: string = './assets/img/login/close-eye.svg'; + isBtnDisabled: boolean = false; private hasAnimationPlayed = false; private introCompleteStatus = false; private secretKey: string = CryptoJSSecretKey.secretKey; @@ -72,6 +73,7 @@ export class loginService { * Authenticates a user using their email and password, fetches the user document, and handles errors. */ login() { + this.isBtnDisabled = true; const auth = getAuth(); signInWithEmailAndPassword(auth, this.email, this.password) .then((userCredential) => { @@ -86,10 +88,12 @@ export class loginService { .catch((error) => { console.error('Error when retrieving the user document:', error); }); + this.isBtnDisabled = false; }) .catch((error) => { const errorCode = error.code; this.switchCase(errorCode); + this.isBtnDisabled = false; }); } @@ -137,6 +141,7 @@ export class loginService { * Performs a guest login using predetermined credentials and updates the user's online status. */ guestLogin() { + this.isBtnDisabled = true; const auth = getAuth(); const email = 'guest@guestaccount.com'; const password = 'guest@guestaccount.com'; @@ -149,12 +154,14 @@ export class loginService { this.getUserIdInLocalStorage(userId); this.email = ''; this.password = ''; + this.isBtnDisabled = false; }) .catch((error) => { console.error(error); this.translate.get('login.errorText6').subscribe((res: string) => { this.errorMessage = res; }); + this.isBtnDisabled = false; }); }