90 lines
2.9 KiB
TypeScript
90 lines
2.9 KiB
TypeScript
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 {NzNotificationService} from "ng-zorro-antd/notification";
|
|
import {firstValueFrom} from "rxjs";
|
|
import {GetStaffDto, StaffsService, UpdateStaffDto} from "../../../services/api";
|
|
|
|
@Component({
|
|
selector: 'app-staff-card',
|
|
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<Date>(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.updateStaffEndpoint(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);
|
|
}
|
|
}
|