disable login btn on click

This commit is contained in:
Chneemann 2024-05-29 20:17:45 +02:00
parent 803e1feea2
commit 2cab8b84a8
3 changed files with 13 additions and 0 deletions

View file

@ -21,6 +21,7 @@
required required
[ngClass]="{ aktivInput: emailField.valid && emailField.touched }" [ngClass]="{ aktivInput: emailField.valid && emailField.touched }"
pattern="[^@]+@[^.]+\..+" pattern="[^@]+@[^.]+\..+"
disabled="{{ loginService.isBtnDisabled }}"
/> />
@if (!emailField.valid && emailField.touched) { @if (!emailField.valid && emailField.touched) {
<p class="error">{{ "login.errorText" | translate }}</p> <p class="error">{{ "login.errorText" | translate }}</p>
@ -44,6 +45,7 @@
}" }"
cols="30" cols="30"
rows="10" rows="10"
disabled="{{ loginService.isBtnDisabled }}"
/> />
<img <img
class="passwordEye" class="passwordEye"
@ -86,6 +88,7 @@
<button <button
type="button" type="button"
class="guestButton" class="guestButton"
[disabled]="loginService.isBtnDisabled"
(click)="loginService.guestLogin()" (click)="loginService.guestLogin()"
> >
{{ "login.BtnRight" | translate }} {{ "login.BtnRight" | translate }}

View file

@ -126,6 +126,9 @@ button {
color: #fff; color: #fff;
border: 1px solid #ffff; border: 1px solid #ffff;
} }
&:disabled {
@include buttonGrey;
}
} }
.mobileRegisterContainer { .mobileRegisterContainer {
display: none; display: none;

View file

@ -42,6 +42,7 @@ export class loginService {
isFirstLoad: boolean = true; isFirstLoad: boolean = true;
passwordFieldType: string = 'password'; passwordFieldType: string = 'password';
passwordIcon: string = './assets/img/login/close-eye.svg'; passwordIcon: string = './assets/img/login/close-eye.svg';
isBtnDisabled: boolean = false;
private hasAnimationPlayed = false; private hasAnimationPlayed = false;
private introCompleteStatus = false; private introCompleteStatus = false;
private secretKey: string = CryptoJSSecretKey.secretKey; 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. * Authenticates a user using their email and password, fetches the user document, and handles errors.
*/ */
login() { login() {
this.isBtnDisabled = true;
const auth = getAuth(); const auth = getAuth();
signInWithEmailAndPassword(auth, this.email, this.password) signInWithEmailAndPassword(auth, this.email, this.password)
.then((userCredential) => { .then((userCredential) => {
@ -86,10 +88,12 @@ export class loginService {
.catch((error) => { .catch((error) => {
console.error('Error when retrieving the user document:', error); console.error('Error when retrieving the user document:', error);
}); });
this.isBtnDisabled = false;
}) })
.catch((error) => { .catch((error) => {
const errorCode = error.code; const errorCode = error.code;
this.switchCase(errorCode); 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. * Performs a guest login using predetermined credentials and updates the user's online status.
*/ */
guestLogin() { guestLogin() {
this.isBtnDisabled = true;
const auth = getAuth(); const auth = getAuth();
const email = 'guest@guestaccount.com'; const email = 'guest@guestaccount.com';
const password = 'guest@guestaccount.com'; const password = 'guest@guestaccount.com';
@ -149,12 +154,14 @@ export class loginService {
this.getUserIdInLocalStorage(userId); this.getUserIdInLocalStorage(userId);
this.email = ''; this.email = '';
this.password = ''; this.password = '';
this.isBtnDisabled = false;
}) })
.catch((error) => { .catch((error) => {
console.error(error); console.error(error);
this.translate.get('login.errorText6').subscribe((res: string) => { this.translate.get('login.errorText6').subscribe((res: string) => {
this.errorMessage = res; this.errorMessage = res;
}); });
this.isBtnDisabled = false;
}); });
} }