added create fonction, fetch, and delete
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
<div class="flex mt-2">
|
||||
<app-modal-button type="primary" name="Ajouter un utilisateur">
|
||||
<app-profil-form></app-profil-form>
|
||||
<app-modal-button #modalButton
|
||||
type="primary"
|
||||
name="Ajouter un utilisateur"
|
||||
(ok)="onModalOk()"
|
||||
(cancel)="onModalCancel()">
|
||||
|
||||
<app-profil-form #profilForm></app-profil-form>
|
||||
</app-modal-button>
|
||||
|
||||
<div class="ml-95 w-150">
|
||||
@@ -9,5 +14,5 @@
|
||||
</div>
|
||||
|
||||
<div class="mt-1">
|
||||
<app-user-table></app-user-table>
|
||||
<app-user-table #userTable></app-user-table>
|
||||
</div>
|
||||
|
||||
@@ -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