From 92b85377c22bdfb87e1814d0a53dc042a1358bcd Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Wed, 15 Apr 2026 20:58:04 +0100 Subject: [PATCH] Implemented form to update profile and fixed labels in sign on form --- src/app/components/modal/modal.component.html | 2 +- .../profil-form/profil-form.component.html | 25 ++++++ .../profil-form/profil-form.component.scss | 0 .../profil-form/profil-form.component.ts | 84 +++++++++++++++++++ .../sign-on-form/sign-on-form.component.html | 20 ++--- src/app/pages/home/home.component.html | 2 +- src/app/pages/home/home.component.ts | 4 +- 7 files changed, 124 insertions(+), 13 deletions(-) create mode 100644 src/app/components/profil-form/profil-form.component.html create mode 100644 src/app/components/profil-form/profil-form.component.scss create mode 100644 src/app/components/profil-form/profil-form.component.ts diff --git a/src/app/components/modal/modal.component.html b/src/app/components/modal/modal.component.html index ee932a3..0e0bb2b 100644 --- a/src/app/components/modal/modal.component.html +++ b/src/app/components/modal/modal.component.html @@ -1,3 +1,3 @@ -
+
\ No newline at end of file diff --git a/src/app/components/profil-form/profil-form.component.html b/src/app/components/profil-form/profil-form.component.html new file mode 100644 index 0000000..196eac0 --- /dev/null +++ b/src/app/components/profil-form/profil-form.component.html @@ -0,0 +1,25 @@ +
+
+ + Prénom * + + + + + Nom * + + + + + Pseudo * + + + + + Adresse email * + + + + Modifier +
+
\ No newline at end of file diff --git a/src/app/components/profil-form/profil-form.component.scss b/src/app/components/profil-form/profil-form.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/components/profil-form/profil-form.component.ts b/src/app/components/profil-form/profil-form.component.ts new file mode 100644 index 0000000..17b4f26 --- /dev/null +++ b/src/app/components/profil-form/profil-form.component.ts @@ -0,0 +1,84 @@ +import {Component, inject, input, OnInit} from '@angular/core'; +import {FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators} from "@angular/forms"; +import {IonicModule, LoadingController, ToastController} from "@ionic/angular"; +import {GetUserDetailsDto, GetUserDto, UsersService} from "../../services/api"; +import {firstValueFrom} from "rxjs"; + +@Component({ + selector: 'app-profil-form', + templateUrl: './profil-form.component.html', + styleUrls: ['./profil-form.component.scss'], + imports: [ + FormsModule, + IonicModule, + ReactiveFormsModule + ] +}) +export class ProfilFormComponent implements OnInit { + private toastCtrl = inject(ToastController); + private loadCtrl = inject(LoadingController); + private usersServices = inject(UsersService); + + profileForm: FormGroup = new FormGroup({ + firstName: new FormControl(null, [Validators.required]), + name: new FormControl(null, [Validators.required]), + username: new FormControl(null, [Validators.required]), + email: new FormControl(null, [Validators.required]) + }) + + user = input.required(); + + ngOnInit() { + this.profileForm.patchValue({ + firstName: this.user().firstName, + name: this.user().name, + username: this.user().username, + email: this.user().email, + }) + } + + async updateUser() { + const loading = await this.loadCtrl.create({ + message: 'Vérification...', + spinner: 'lines-sharp-small' + }); + await loading.present(); + + if (this.profileForm.invalid) { + const toast = await this.toastCtrl.create({ + message: 'Tout les champs sont requis', + duration: 2000, + color: 'danger' + }); + await loading.dismiss(); + await toast.present(); + + return; + } + await loading.dismiss(); + + const loading2 = await this.loadCtrl.create({ + message: 'Modification...', + spinner: 'lines-sharp-small' + }); + await loading2.present(); + + try { + await firstValueFrom(this.usersServices.updateUserEndpoint(this.profileForm.getRawValue())); + const toast = await this.toastCtrl.create({ + message: 'Modification réussie', + duration: 2000, + color: 'success' + }); + await loading2.dismiss(); + await toast.present(); + } catch { + const toast = await this.toastCtrl.create({ + message: 'Modification impossible', + duration: 2000, + color: 'danger' + }); + await toast.present(); + } + } +} \ No newline at end of file diff --git a/src/app/components/sign-on-form/sign-on-form.component.html b/src/app/components/sign-on-form/sign-on-form.component.html index 9390987..7c12895 100644 --- a/src/app/components/sign-on-form/sign-on-form.component.html +++ b/src/app/components/sign-on-form/sign-on-form.component.html @@ -1,27 +1,27 @@
- Prénom - + Prénom * + - Nom - + Nom * + - Pseudo - + Pseudo * + - Adresse email - + Adresse email * + - Mot de passe - + Mot de passe * + diff --git a/src/app/pages/home/home.component.html b/src/app/pages/home/home.component.html index a4f6601..47c2c58 100644 --- a/src/app/pages/home/home.component.html +++ b/src/app/pages/home/home.component.html @@ -88,7 +88,7 @@ @case ('profile') {
-

Formulaire profil

+
} diff --git a/src/app/pages/home/home.component.ts b/src/app/pages/home/home.component.ts index 22430b7..1762a81 100644 --- a/src/app/pages/home/home.component.ts +++ b/src/app/pages/home/home.component.ts @@ -21,6 +21,7 @@ import { } from "../../components/challenges-accomplished/challenges-accomplished.component"; import {UserAchievementsComponent} from "../../components/user-achievements/user-achievements.component"; import {ModalComponent} from "../../components/modal/modal.component"; +import {ProfilFormComponent} from "../../components/profil-form/profil-form.component"; addIcons({ 'profile': personOutline, @@ -42,7 +43,8 @@ type View = 'menu' | 'profile' | 'password' | 'designation' | 'gallery'; GenericUserInfoComponent, ChallengesAccomplishedComponent, UserAchievementsComponent, - ModalComponent + ModalComponent, + ProfilFormComponent ] }) export class HomeComponent implements OnInit {