refactor: rename LoadingDialogComponent to LoginLoaderComponent and adjust functionality

This commit is contained in:
Chneemann 2025-04-05 14:14:30 +02:00
parent 82f0687b77
commit b02ebe78ba
9 changed files with 42 additions and 57 deletions

View file

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { LoadingDialogComponent } from './loading-dialog.component';
describe('LoadingDialogComponent', () => {
let component: LoadingDialogComponent;
let fixture: ComponentFixture<LoadingDialogComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [LoadingDialogComponent]
})
.compileComponents();
fixture = TestBed.createComponent(LoadingDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View file

@ -1,4 +1,5 @@
@if (isButtonDisabled()) { <!-- Show loading indicator and text only if the button is deactivated -->
@if (isLoginButtonDisabled()) {
<div class="loading-dialog"> <div class="loading-dialog">
<div id="loading" class="loader"></div> <div id="loading" class="loader"></div>
<div id="loadingText" class="loading-text"> <div id="loadingText" class="loading-text">

View file

@ -0,0 +1,22 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { LoginLoaderComponent } from './login-loader.component';
describe('LoginLoaderComponent', () => {
let component: LoginLoaderComponent;
let fixture: ComponentFixture<LoginLoaderComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [LoginLoaderComponent],
}).compileComponents();
fixture = TestBed.createComponent(LoginLoaderComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View file

@ -3,16 +3,20 @@ import { TranslateModule } from '@ngx-translate/core';
import { ButtonStateService } from '../../../services/button-state.service'; import { ButtonStateService } from '../../../services/button-state.service';
@Component({ @Component({
selector: 'app-loading-dialog', selector: 'app-login-loader',
standalone: true, standalone: true,
imports: [TranslateModule], imports: [TranslateModule],
templateUrl: './loading-dialog.component.html', templateUrl: './login-loader.component.html',
styleUrl: './loading-dialog.component.scss', styleUrl: './login-loader.component.scss',
}) })
export class LoadingDialogComponent { export class LoginLoaderComponent {
constructor(private buttonStateService: ButtonStateService) {} constructor(private buttonStateService: ButtonStateService) {}
isButtonDisabled() { /**
* Checks if the button is disabled (i.e., loading is in progress)
* @returns whether the button is disabled
*/
isLoginButtonDisabled(): boolean {
return this.buttonStateService.isButtonDisabled; return this.buttonStateService.isButtonDisabled;
} }
} }

View file

@ -98,17 +98,6 @@
}}</a> }}</a>
</div> </div>
</div> </div>
<!--
<div class="google-button">
<app-form-btn
[class]="'btn-google'"
[type]="'button'"
[value]="'login.google' | translate"
[disabled]="sharedService.isBtnDisabled"
(click)="googleLogin()"
></app-form-btn>
</div>
-->
<div class="form-buttons"> <div class="form-buttons">
<app-form-btn <app-form-btn
[class]="'btn-login'" [class]="'btn-login'"
@ -135,4 +124,4 @@
</form> </form>
<app-footer></app-footer> <app-footer></app-footer>
</section> </section>
<app-loading-dialog></app-loading-dialog> <app-login-loader></app-login-loader>

View file

@ -7,7 +7,7 @@ import { LoginService } from '../../services/login.service';
import { FooterComponent } from './footer/footer.component'; import { FooterComponent } from './footer/footer.component';
import { HeaderComponent } from './header/header.component'; import { HeaderComponent } from './header/header.component';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { LoadingDialogComponent } from './loading-dialog/loading-dialog.component'; import { LoginLoaderComponent } from './login-loader/login-loader.component';
import { OverlayService } from '../../services/overlay.service'; import { OverlayService } from '../../services/overlay.service';
import { AuthService } from '../../services/auth.service'; import { AuthService } from '../../services/auth.service';
import { TokenService } from '../../services/token.service'; import { TokenService } from '../../services/token.service';
@ -23,7 +23,7 @@ import { ButtonStateService } from '../../services/button-state.service';
FooterComponent, FooterComponent,
HeaderComponent, HeaderComponent,
TranslateModule, TranslateModule,
LoadingDialogComponent, LoginLoaderComponent,
RouterLink, RouterLink,
], ],
templateUrl: './login.component.html', templateUrl: './login.component.html',
@ -74,33 +74,25 @@ export class LoginComponent {
} }
async onSubmit(ngForm: NgForm) { async onSubmit(ngForm: NgForm) {
this.buttonStateService.enableButton(); this.buttonStateService.disableButton();
if (ngForm.submitted && ngForm.form.valid) { if (ngForm.submitted && ngForm.form.valid) {
try { try {
await this.authService.login(this.loginData, this.checkboxRememberMe); await this.authService.login(this.loginData, this.checkboxRememberMe);
this.router.navigate(['/summary']); this.router.navigate(['/summary']);
this.buttonStateService.disableButton(); this.buttonStateService.enableButton();
} catch (error) { } catch (error) {
this.buttonStateService.disableButton(); this.buttonStateService.enableButton();
} }
} }
} }
guestLogin() { guestLogin() {
this.buttonStateService.enableButton();
this.loginData.email = 'guest@guestaccount.com'; this.loginData.email = 'guest@guestaccount.com';
this.loginData.password = 'guest@guestaccount.com'; this.loginData.password = 'guest@guestaccount.com';
this.isPasswordIconVisible = !this.isPasswordIconVisible; this.isPasswordIconVisible = !this.isPasswordIconVisible;
this.onSubmit({ submitted: true, form: { valid: true } } as NgForm); this.onSubmit({ submitted: true, form: { valid: true } } as NgForm);
} }
/*
googleLogin() {
this.sharedService.isBtnDisabled = true;
this.loginService.googleLogin();
}
*/
checkIfUserEmailIsValid(emailValue: string) { checkIfUserEmailIsValid(emailValue: string) {
const emailRegex = /^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,}$/; const emailRegex = /^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,}$/;
if (emailRegex.test(emailValue)) { if (emailRegex.test(emailValue)) {

View file

@ -196,4 +196,4 @@
</form> </form>
<app-footer></app-footer> <app-footer></app-footer>
</section> </section>
<app-loading-dialog></app-loading-dialog> <app-login-loader></app-login-loader>

View file

@ -8,8 +8,8 @@ import { LoginService } from '../../../services/login.service';
import { BtnBackComponent } from '../../../shared/components/buttons/btn-back/btn-back.component'; import { BtnBackComponent } from '../../../shared/components/buttons/btn-back/btn-back.component';
import { RouterModule } from '@angular/router'; import { RouterModule } from '@angular/router';
import { TranslateModule, TranslateService } from '@ngx-translate/core'; import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { LoadingDialogComponent } from '../loading-dialog/loading-dialog.component';
import { ButtonStateService } from '../../../services/button-state.service'; import { ButtonStateService } from '../../../services/button-state.service';
import { LoginLoaderComponent } from '../login-loader/login-loader.component';
@Component({ @Component({
selector: 'app-register', selector: 'app-register',
@ -23,7 +23,7 @@ import { ButtonStateService } from '../../../services/button-state.service';
CommonModule, CommonModule,
RouterModule, RouterModule,
TranslateModule, TranslateModule,
LoadingDialogComponent, LoginLoaderComponent,
], ],
templateUrl: './register.component.html', templateUrl: './register.component.html',
styleUrl: './register.component.scss', styleUrl: './register.component.scss',