updated create-form of loan and book

This commit is contained in:
2025-11-23 13:41:55 +01:00
parent 6b1f3ece94
commit af1dec318f
8 changed files with 147 additions and 15 deletions

View File

@@ -1,8 +1,8 @@
<app-modal type="primary" [name]="'Ajouter un livre'">
<app-create-book></app-create-book>
<app-modal #modal type="primary" [name]="'Ajouter un livre'" (ok)="onModalOk()" (cancel)="onModalCancel()">
<app-create-book #createBook></app-create-book>
</app-modal>
<section class="mt-5">
<app-book-table></app-book-table>
<app-book-table #bookTable></app-book-table>
</section>

View File

@@ -1,7 +1,10 @@
import {Component, inject, OnInit, signal} from '@angular/core';
import {Component, inject, viewChild} from '@angular/core';
import {BookTable} from "../../components/book-table/book-table";
import {Modal} from "../../components/modal/modal";
import {CreateBook} from "../../components/create-book/create-book";
import {BooksService} from "../../services/api";
import {NzNotificationService} from "ng-zorro-antd/notification";
import {firstValueFrom} from "rxjs";
@Component({
selector: 'app-book',
@@ -14,4 +17,45 @@ import {CreateBook} from "../../components/create-book/create-book";
styleUrls: ['./book.css'],
})
export class Book{
modal = viewChild.required<Modal>('modal');
createBook = viewChild.required<CreateBook>('createBook');
booksTable = viewChild.required<BookTable>('bookTable');
private booksService = inject(BooksService);
private notificationService = inject(NzNotificationService)
async onModalOk() {
await this.addBook()
this.createBook().createBookForm.reset();
this.modal().isVisible = false;
await this.booksTable().fetchBooks()
}
onModalCancel() {
this.modal().isVisible = false;
}
async addBook() {
if (this.createBook().createBookForm.invalid)
{
this.notificationService.error(
'Erreur',
'Erreur d\'écriture dans le formulaire'
)
}
try {
const books = this.createBook().createBookForm.getRawValue();
await firstValueFrom(this.booksService.createBookEndpoint(books))
this.notificationService.success(
'Success',
'Enregistrement réussi'
)
} catch (e) {
this.notificationService.error(
'Erreur',
'Erreur d\'enregistrement'
)
}
}
}