Finished form to edit user infos
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import {Component, inject, input, OnInit} from '@angular/core';
|
||||
import {Component, inject, input, OnInit, output} 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 {GetUserDetailsDto, GetUserStatsDto, UsersService} from "../../services/api";
|
||||
import {firstValueFrom} from "rxjs";
|
||||
|
||||
@Component({
|
||||
@@ -27,6 +27,7 @@ export class ProfilFormComponent implements OnInit {
|
||||
})
|
||||
|
||||
user = input.required<GetUserDetailsDto>();
|
||||
userEdited = output<GetUserDetailsDto>();
|
||||
|
||||
ngOnInit() {
|
||||
this.profileForm.patchValue({
|
||||
@@ -64,12 +65,28 @@ export class ProfilFormComponent implements OnInit {
|
||||
await loading2.present();
|
||||
|
||||
try {
|
||||
await firstValueFrom(this.usersServices.updateUserEndpoint(this.profileForm.getRawValue()));
|
||||
const form = this.profileForm.getRawValue();
|
||||
|
||||
await firstValueFrom(this.usersServices.updateUserEndpoint(form));
|
||||
const userEdited = {
|
||||
id: this.user().id,
|
||||
firstName: form.firstName,
|
||||
name: form.name,
|
||||
username: form.username,
|
||||
email: form.email,
|
||||
designationName: this.user().designationName,
|
||||
creationDate: this.user().creationDate,
|
||||
getUserStatsDto: this.user().getUserStatsDto
|
||||
}
|
||||
|
||||
this.userEdited.emit(userEdited);
|
||||
|
||||
const toast = await this.toastCtrl.create({
|
||||
message: 'Modification réussie',
|
||||
duration: 2000,
|
||||
color: 'success'
|
||||
});
|
||||
|
||||
await loading2.dismiss();
|
||||
await toast.present();
|
||||
} catch {
|
||||
@@ -78,6 +95,7 @@ export class ProfilFormComponent implements OnInit {
|
||||
duration: 2000,
|
||||
color: 'danger'
|
||||
});
|
||||
await loading2.dismiss();
|
||||
await toast.present();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user