Staff terminé
This commit is contained in:
@@ -1,11 +1,89 @@
|
||||
import { Component } from '@angular/core';
|
||||
import {Component, inject, input, output, signal} from '@angular/core';
|
||||
import {NzCardComponent} from "ng-zorro-antd/card";
|
||||
import {NzColDirective, NzRowDirective} from "ng-zorro-antd/grid";
|
||||
import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
|
||||
import {NzIconDirective} from "ng-zorro-antd/icon";
|
||||
import {NzInputDirective} from "ng-zorro-antd/input";
|
||||
import {FormControl, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms";
|
||||
import {GetStaffDto, StaffsService, UpdateStaffDto} from "../../../services/api";
|
||||
import {NzNotificationService} from "ng-zorro-antd/notification";
|
||||
import {firstValueFrom} from "rxjs";
|
||||
|
||||
@Component({
|
||||
selector: 'app-staff-card',
|
||||
imports: [],
|
||||
imports: [
|
||||
NzCardComponent,
|
||||
NzColDirective,
|
||||
NzFormControlComponent,
|
||||
NzFormDirective,
|
||||
NzFormItemComponent,
|
||||
NzFormLabelComponent,
|
||||
NzIconDirective,
|
||||
NzInputDirective,
|
||||
NzRowDirective,
|
||||
ReactiveFormsModule
|
||||
],
|
||||
templateUrl: './staff-card.html',
|
||||
styleUrl: './staff-card.css',
|
||||
})
|
||||
export class StaffCard {
|
||||
private staffsService = inject(StaffsService);
|
||||
private notificationService = inject(NzNotificationService)
|
||||
|
||||
staffEdit = signal<UpdateStaffDto>(null);
|
||||
staffsLoading = signal<boolean>(false);
|
||||
|
||||
staffForm = new FormGroup({
|
||||
f4T2NumberApproval: new FormControl<string>(null, [Validators.required]),
|
||||
f4T2ExpirationDate: new FormControl<string>(null, [Validators.required]),
|
||||
})
|
||||
|
||||
async submitForm() {
|
||||
this.staffsLoading.set(true);
|
||||
|
||||
const staffValue: UpdateStaffDto = {
|
||||
f4T2NumberApproval: this.staffForm.value.f4T2NumberApproval,
|
||||
f4T2ExpirationDate: this.staffForm.value.f4T2ExpirationDate,
|
||||
}
|
||||
|
||||
try {
|
||||
const staff = await firstValueFrom(this.staffsService.updateStaffRequest(this.staff().id, staffValue));
|
||||
this.staffEdit.set(staff as unknown as UpdateStaffDto);
|
||||
console.log(staff);
|
||||
this.staffForm.reset();
|
||||
this.edit.set(false);
|
||||
this.triggerEdited.emit();
|
||||
} catch (e) {
|
||||
this.notificationService.error('Erreur', '(ou Erreur de communication avec l\'API)');
|
||||
}
|
||||
|
||||
this.staffsLoading.set(false);
|
||||
}
|
||||
|
||||
staff = input<GetStaffDto>(null);
|
||||
edit = signal(false)
|
||||
triggerEdited = output<void>();
|
||||
|
||||
protected Edit() {
|
||||
this.edit.set(true)
|
||||
}
|
||||
|
||||
protected Back() {
|
||||
this.edit.set(false)
|
||||
this.staffForm.reset();
|
||||
}
|
||||
|
||||
async Delete() {
|
||||
this.staffsLoading.set(true);
|
||||
|
||||
try {
|
||||
await firstValueFrom(this.staffsService.deleteStaffEndpoint(this.staff().id));
|
||||
this.staffForm.reset();
|
||||
this.triggerEdited.emit();
|
||||
} catch (e) {
|
||||
this.notificationService.error('Erreur', '(ou Erreur de communication avec l\'API)');
|
||||
}
|
||||
|
||||
this.staffsLoading.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user