added edit fonction
This commit is contained in:
@@ -18,9 +18,7 @@
|
||||
<td>{{user.fonction}}</td>
|
||||
<td>
|
||||
<div style="justify-content: center; display: flex">
|
||||
<app-modal-nav nameIcon="edit" name="Modification de l'utilisateur" class="cursor-pointer">
|
||||
<app-profil-form></app-profil-form>
|
||||
</app-modal-nav>
|
||||
<nz-icon nzType="edit" nzTheme="outline" class="cursor-pointer" (click)="openEditModal(user)"></nz-icon>
|
||||
<nz-divider nzType="vertical"></nz-divider>
|
||||
<div>
|
||||
<nz-icon nzType="delete" nzTheme="outline" (click)="delete(user.id)" class="cursor-pointer text-red-700"/>
|
||||
@@ -31,3 +29,9 @@
|
||||
}
|
||||
</tbody>
|
||||
</nz-table>
|
||||
|
||||
<div class="hidden">
|
||||
<app-modal-nav #modalNav nameIcon="edit" [name]="'Modifier'" (ok)="onModalOk(selectedUser.id, updateUser, modalNav)" (cancel)="onModalCancel(modalNav)">
|
||||
<app-profil-form #updateUser [user]="selectedUser"></app-profil-form>
|
||||
</app-modal-nav>
|
||||
</div>
|
||||
|
||||
@@ -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