import {Component, inject} from '@angular/core'; import { IonButton, IonCard, IonCardContent, IonCardHeader, IonCardTitle, IonContent, IonInput, IonItem, NavController, } from '@ionic/angular/standalone'; import {CommonModule} from "@angular/common"; import {FormBuilder, ReactiveFormsModule, Validators} from "@angular/forms"; import {Router} from "@angular/router"; import {LoginService} from "../../login.service"; @Component({ selector: 'login-form', templateUrl: 'login-form.component.html', styleUrls: ['login-form.component.css'], imports: [IonButton, CommonModule, ReactiveFormsModule, IonItem, IonInput, IonContent,], }) export class LoginFormComponent { private fb = inject(FormBuilder); private loginService = inject(LoginService); private router = inject(Router); private navCtrl = inject(NavController); isLoading = false; goToRegister() { this.router.navigate(['/register']); } loginForm = this.fb.group({ name: ['', [Validators.required]], password: ['', [Validators.required]] }); async submitForm(): Promise { if (this.loginForm.valid) { await this.navCtrl.navigateRoot(['main/messages']); this.isLoading = true; const request = { name: this.loginForm.value.name!, password: this.loginForm.value.password! }; /*this.authService.login(request).subscribe({ next: () => { this.isLoading = false; this.notification.success('Succès', 'Connexion réussie !'); this.router.navigate(['/main/discussions']); }, error: (err) => { this.isLoading = false; // Gestion des erreurs (inchangée) if (err.status === 401) { this.notification.error('Erreur', 'Identifiant ou mot de passe incorrect.'); } else { this.notification.error('Erreur', 'Impossible de contacter le serveur.'); } } }); } else { // Affiche les erreurs de validation visuelles Object.values(this.loginForm.controls).forEach(control => { if (control.invalid) { control.markAsDirty(); control.updateValueAndValidity({ onlySelf: true }); } });*/ } } }