added edit fonction
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user