diff --git a/src/app/components/create-user/create-user.html b/src/app/components/create-user/create-user.html
index c85e91d..bd2c67f 100644
--- a/src/app/components/create-user/create-user.html
+++ b/src/app/components/create-user/create-user.html
@@ -1,4 +1,4 @@
-
\ No newline at end of file
diff --git a/src/app/components/create-user/create-user.ts b/src/app/components/create-user/create-user.ts
index 6775c22..de0e25a 100644
--- a/src/app/components/create-user/create-user.ts
+++ b/src/app/components/create-user/create-user.ts
@@ -3,6 +3,7 @@ import {FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators} fr
import {NzColDirective, NzRowDirective} from "ng-zorro-antd/grid";
import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
import {NzInputDirective} from "ng-zorro-antd/input";
+import {NzDatePickerComponent} from "ng-zorro-antd/date-picker";
@Component({
selector: 'app-create-user',
@@ -15,7 +16,8 @@ import {NzInputDirective} from "ng-zorro-antd/input";
NzFormLabelComponent,
NzInputDirective,
NzRowDirective,
- ReactiveFormsModule
+ ReactiveFormsModule,
+ NzDatePickerComponent
],
templateUrl: './create-user.html',
styleUrl: './create-user.css',
@@ -25,17 +27,6 @@ export class CreateUser {
name: new FormControl(null, [Validators.required]),
firstName: new FormControl(null, [Validators.required]),
email: new FormControl(null, [Validators.required]),
- birthDate: new FormControl(null, [Validators.required]),
+ birthDate: new FormControl(null),
})
-
- submitForm() {
- // Pour annuler si le formulaire est invalide
- if (this.createUserForm.invalid) return;
-
- // Pour obtenir la valeur du formulaire
- console.log(this.createUserForm.getRawValue())
-
- // Pour vider le formulaire
- this.createUserForm.reset()
- }
}
diff --git a/src/app/components/modal/modal.ts b/src/app/components/modal/modal.ts
index 8d7a042..4e2f924 100644
--- a/src/app/components/modal/modal.ts
+++ b/src/app/components/modal/modal.ts
@@ -1,4 +1,4 @@
-import {Component, input} from '@angular/core';
+import {Component, input, output} from '@angular/core';
import { NzButtonModule } from 'ng-zorro-antd/button';
import { NzModalModule } from 'ng-zorro-antd/modal';
@@ -14,6 +14,9 @@ export class Modal {
isVisible = false;
isOkLoading = false;
+ ok = output();
+ cancel = output();
+
showModal(): void {
this.isVisible = true;
}
@@ -21,12 +24,13 @@ export class Modal {
handleOk(): void {
this.isOkLoading = true;
setTimeout(() => {
- this.isVisible = false;
+ this.ok.emit();
this.isOkLoading = false;
- }, 1000); // 1 secondes
+ }, 1000);
}
handleCancel(): void {
+ this.cancel.emit();
this.isVisible = false;
}
}
diff --git a/src/app/components/user-table/user-table.html b/src/app/components/user-table/user-table.html
index ce3715f..2b630fb 100644
--- a/src/app/components/user-table/user-table.html
+++ b/src/app/components/user-table/user-table.html
@@ -9,7 +9,7 @@
Email |
Anniversaire |
Emprunt |
- Action |
+ Action |
@@ -43,20 +43,15 @@
-
|
diff --git a/src/app/pages/user/user.html b/src/app/pages/user/user.html
index 57631da..9a6d0ed 100644
--- a/src/app/pages/user/user.html
+++ b/src/app/pages/user/user.html
@@ -1,7 +1,13 @@
-
-
+
+
+
\ No newline at end of file
diff --git a/src/app/pages/user/user.ts b/src/app/pages/user/user.ts
index 035f50b..2b2a90a 100644
--- a/src/app/pages/user/user.ts
+++ b/src/app/pages/user/user.ts
@@ -1,7 +1,11 @@
-import { Component } from '@angular/core';
+import {Component, inject, OnInit, viewChild} from '@angular/core';
import {Modal} from "../../components/modal/modal";
import {CreateUser} from "../../components/create-user/create-user";
import {UserTable} from "../../components/user-table/user-table";
+import {CreateUserDto, UsersService} from "../../services/api";
+import {NzNotificationService} from "ng-zorro-antd/notification";
+import {firstValueFrom} from "rxjs";
+import { format } from 'date-fns';
@Component({
selector: 'app-user',
@@ -13,6 +17,47 @@ import {UserTable} from "../../components/user-table/user-table";
templateUrl: './user.html',
styleUrl: './user.css',
})
-export class User {
+export class User implements OnInit {
+ modal = viewChild.required('modal');
+ createUser = viewChild.required('createUser');
+ usersTable = viewChild.required('userTable');
+ private usersService = inject(UsersService);
+ private notificationService = inject(NzNotificationService)
+
+ async ngOnInit() {
+ await this.addUser();
+ }
+
+ async onModalOk() {
+ await this.addUser()
+ this.createUser().createUserForm.reset();
+ this.modal().isVisible = false;
+ await this.usersTable().fetchUsers()
+ }
+
+ onModalCancel() {
+ this.modal().isVisible = false;
+ }
+
+ async addUser() {
+ if (this.createUser().createUserForm.invalid)
+ {
+ return
+ }
+ try {
+ const rawDate = this.createUser().createUserForm.get('birthDate')?.value;
+ const birthDate = format(rawDate, 'yyyy-MM-dd');
+
+ const users = this.createUser().createUserForm.getRawValue();
+ users.birthDate = birthDate;
+
+ await firstValueFrom(this.usersService.createUserEndpoint(users))
+ } catch (e) {
+ this.notificationService.error(
+ 'Erreur',
+ 'Erreur d\'enregistrement'
+ )
+ }
+ }
}