added edit fonction

This commit is contained in:
2025-11-27 17:15:35 +01:00
parent 8d95127a46
commit 40b1c2620a
8 changed files with 77 additions and 15 deletions

View File

@@ -65,4 +65,46 @@ export class UserTable implements OnInit {
await this.fetchUsers();
}
async edit(id: number, updateUserComponent: ProfilForm) {
if (updateUserComponent.profilForm.invalid) {
this.notificationService.error(
'Erreur',
'Erreur d\'écriture dans le formulaire'
)
return;
}
try {
const users = updateUserComponent.profilForm.getRawValue();
await firstValueFrom(this.usersService.updateUserEndpoint(id, users))
this.notificationService.success(
'Success',
'Utilisateur modifié'
)
} catch (e) {
this.notificationService.error(
'Erreur',
'Erreur lors de la modification'
)
}
}
selectedUser: GetUserDto | null = null;
openEditModal(user: GetUserDto) {
this.selectedUser = { ...user };
this.modal().showModal();
}
async onModalOk(userId: number, updateUserComponent: ProfilForm, modal: ModalNav) {
if (!this.selectedUser) return;
await this.edit(userId, updateUserComponent);
updateUserComponent.profilForm.reset();
modal.isVisible = false;
await this.fetchUsers();
}
onModalCancel(modal: ModalNav) {
modal.isVisible = false;
}
}