added create fonction, fetch, and delete
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import { Component } from '@angular/core';
|
||||
import {Component, inject, viewChild} from '@angular/core';
|
||||
import {UserTable} from "../../components/user-table/user-table";
|
||||
import {ModalButton} from "../../components/modal-button/modal-button";
|
||||
import {ProfilForm} from "../../components/profil-form/profil-form";
|
||||
import {Search} from "../../components/search/search";
|
||||
import {UsersService} from "../../services/api";
|
||||
import {NzNotificationService} from "ng-zorro-antd/notification";
|
||||
import {firstValueFrom} from "rxjs";
|
||||
|
||||
@Component({
|
||||
selector: 'app-user',
|
||||
@@ -16,5 +19,47 @@ import {Search} from "../../components/search/search";
|
||||
styleUrl: './user.css',
|
||||
})
|
||||
export class User {
|
||||
modal = viewChild.required<ModalButton>('modalButton');
|
||||
createUser = viewChild.required<ProfilForm>('profilForm');
|
||||
usersTable = viewChild.required<UserTable>('userTable');
|
||||
private usersService = inject(UsersService);
|
||||
private notificationService = inject(NzNotificationService)
|
||||
|
||||
async onModalOk() {
|
||||
await this.addUser()
|
||||
this.createUser().profilForm.reset();
|
||||
this.modal().isVisible = false;
|
||||
await this.usersTable().fetchUsers()
|
||||
}
|
||||
|
||||
onModalCancel() {
|
||||
this.modal().isVisible = false;
|
||||
}
|
||||
|
||||
async addUser() {
|
||||
if (this.createUser().profilForm.invalid)
|
||||
{
|
||||
this.notificationService.error(
|
||||
'Erreur',
|
||||
'Erreur d\'écriture dans le formulaire'
|
||||
)
|
||||
}
|
||||
try {
|
||||
const users = this.createUser().profilForm.getRawValue();
|
||||
await firstValueFrom(this.usersService.createUserEndpoint(users))
|
||||
|
||||
console.log(users)
|
||||
|
||||
this.notificationService.success(
|
||||
'Success',
|
||||
'Utilisateur crée'
|
||||
)
|
||||
} catch (e) {
|
||||
this.notificationService.error(
|
||||
'Erreur',
|
||||
'Erreur d\'enregistrement'
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user