updated create-form of loan and book
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import {Component} from '@angular/core';
|
||||
import {Component, inject, viewChild} from '@angular/core';
|
||||
import {CreateAuthor} from "../../components/create-author/create-author";
|
||||
import {Modal} from "../../components/modal/modal";
|
||||
import {AuthorTable} from "../../components/author-table/author-table";
|
||||
import {AuthorsService} from "../../services/api";
|
||||
import {NzNotificationService} from "ng-zorro-antd/notification";
|
||||
import {firstValueFrom} from "rxjs";
|
||||
|
||||
@Component({
|
||||
selector: 'app-author',
|
||||
@@ -14,5 +17,45 @@ import {AuthorTable} from "../../components/author-table/author-table";
|
||||
styleUrl: './author.css',
|
||||
})
|
||||
export class Author{
|
||||
modal = viewChild.required<Modal>('modal');
|
||||
createAuthor = viewChild.required<CreateAuthor>('createAuthor');
|
||||
authorTable = viewChild.required<AuthorTable>('authorTable');
|
||||
private authorsService = inject(AuthorsService);
|
||||
private notificationService = inject(NzNotificationService)
|
||||
|
||||
async onModalOk() {
|
||||
await this.addAuthor()
|
||||
this.createAuthor().createAuthorForm.reset();
|
||||
this.modal().isVisible = false;
|
||||
await this.authorTable().fetchAuthors()
|
||||
}
|
||||
|
||||
onModalCancel() {
|
||||
this.modal().isVisible = false;
|
||||
}
|
||||
|
||||
async addAuthor() {
|
||||
if (this.createAuthor().createAuthorForm.invalid)
|
||||
{
|
||||
this.notificationService.error(
|
||||
'Erreur',
|
||||
'Erreur d\'écriture dans le formulaire'
|
||||
)
|
||||
}
|
||||
try {
|
||||
const authors = this.createAuthor().createAuthorForm.getRawValue();
|
||||
|
||||
await firstValueFrom(this.authorsService.createAuthorEndpoint(authors))
|
||||
|
||||
this.notificationService.success(
|
||||
'Success',
|
||||
'Utilisateur crée'
|
||||
)
|
||||
} catch (e) {
|
||||
this.notificationService.error(
|
||||
'Erreur',
|
||||
'Erreur d\'enregistrement'
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user