diff --git a/src/app/components/user-table/user-table.html b/src/app/components/user-table/user-table.html index e15eec3..20c75d7 100644 --- a/src/app/components/user-table/user-table.html +++ b/src/app/components/user-table/user-table.html @@ -48,8 +48,8 @@ diff --git a/src/app/components/user-table/user-table.ts b/src/app/components/user-table/user-table.ts index 68e9dcd..ea88e4c 100644 --- a/src/app/components/user-table/user-table.ts +++ b/src/app/components/user-table/user-table.ts @@ -43,7 +43,6 @@ export class UserTable implements OnInit { try { const users = await firstValueFrom(this.usersService.getAllUsersEndpoint()) - this.users.set(users); } catch (e) { this.notificationService.error( @@ -70,36 +69,37 @@ export class UserTable implements OnInit { await this.fetchUsers(); } - selectedUser: GetUserDto | null = null; + selectedUser: GetUserDto; openEditModal(user: GetUserDto) { this.selectedUser = user; this.modal().showModal(); } - async onModalOk(userId:number) { - await this.edit(userId) - this.updateUser().updateUserForm.reset(); - this.modal().isVisible = false; - await this.fetchUsers() + async onModalOk(userId: number, updateUserComponent: UpdateUser, modal: ModalIcon) { + await this.edit(userId, updateUserComponent); + updateUserComponent.updateUserForm.reset(); + modal.isVisible = false; + await this.fetchUsers(); } - onModalCancel() { - this.modal().isVisible = false; + onModalCancel(modal: ModalIcon) { + modal.isVisible = false; } - async edit(id :number) { - if (this.updateUser().updateUserForm.invalid) - { + async edit(id: number, updateUserComponent: UpdateUser) { + if (updateUserComponent.updateUserForm.invalid) { this.notificationService.error( 'Erreur', 'Erreur d\'écriture dans le formulaire' ) + return; } + try { - const rawDate = this.updateUser().updateUserForm.get('birthDate')?.value; + const rawDate = updateUserComponent.updateUserForm.get('birthDate')?.value; const birthDate = format(rawDate, 'yyyy-MM-dd'); - const users = this.updateUser().updateUserForm.getRawValue(); + const users = updateUserComponent.updateUserForm.getRawValue(); users.birthDate = birthDate; await firstValueFrom(this.usersService.updateUserEndpoint(id, users))