Refactor code
This commit is contained in:
@@ -9,7 +9,6 @@ import {DelivererForm} from "../deliverer-form/deliverer-form";
|
||||
import {DeliverersService, GetDelivererDto, GetSupplierDto} from "../../services/api";
|
||||
import {NzNotificationService} from "ng-zorro-antd/notification";
|
||||
import {firstValueFrom} from "rxjs";
|
||||
import {SupplierForm} from "../supplier-form/supplier-form";
|
||||
|
||||
@Component({
|
||||
selector: 'app-deliverer-table',
|
||||
@@ -29,9 +28,10 @@ import {SupplierForm} from "../supplier-form/supplier-form";
|
||||
export class DelivererTable implements OnInit {
|
||||
private deliverersService = inject(DeliverersService);
|
||||
private notificationService = inject(NzNotificationService)
|
||||
|
||||
deliverers = signal<GetDelivererDto[]>([]);
|
||||
deliverersLoading = signal<boolean>(false);
|
||||
updateDeliverer = viewChild.required<DelivererForm>('delivererForm');
|
||||
|
||||
modal = viewChild.required<ModalNav>('modalNav');
|
||||
|
||||
async ngOnInit() {
|
||||
@@ -44,11 +44,8 @@ export class DelivererTable implements OnInit {
|
||||
try {
|
||||
const deliverers = await firstValueFrom(this.deliverersService.getAllDelivererEndpoint())
|
||||
this.deliverers.set(deliverers);
|
||||
} catch (e) {
|
||||
this.notificationService.error(
|
||||
'Erreur',
|
||||
'Erreur de communication avec l\'API'
|
||||
)
|
||||
} catch {
|
||||
this.notificationService.error('Erreur', 'Erreur lors du chargement des transporteurs');
|
||||
}
|
||||
this.deliverersLoading.set(false)
|
||||
}
|
||||
@@ -56,11 +53,8 @@ export class DelivererTable implements OnInit {
|
||||
async delete(deliverer: number) {
|
||||
try {
|
||||
await firstValueFrom(this.deliverersService.deleteDelivererEndpoint(deliverer))
|
||||
this.notificationService.success(
|
||||
'Success',
|
||||
'Suppression effectuée'
|
||||
)
|
||||
} catch (e) {
|
||||
this.notificationService.success('Success', 'Suppression effectuée');
|
||||
} catch {
|
||||
this.notificationService.error(
|
||||
'Erreur',
|
||||
'Impossible de supprimer la ligne'
|
||||
@@ -71,10 +65,7 @@ export class DelivererTable implements OnInit {
|
||||
|
||||
async edit(id: number, updateDelivererComponent: DelivererForm) {
|
||||
if (updateDelivererComponent.delivererForm.invalid) {
|
||||
this.notificationService.error(
|
||||
'Erreur',
|
||||
'Erreur d\'écriture dans le formulaire'
|
||||
)
|
||||
this.notificationService.error('Erreur', 'Formulaire invalide');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -83,7 +74,7 @@ export class DelivererTable implements OnInit {
|
||||
await firstValueFrom(this.deliverersService.updateDelivererEndpoint(id, deliverers))
|
||||
|
||||
this.notificationService.success('Success', 'Transporteur modifié')
|
||||
} catch (e) {
|
||||
} catch {
|
||||
this.notificationService.error('Erreur', 'Erreur lors de la modification')
|
||||
}
|
||||
}
|
||||
@@ -100,7 +91,7 @@ export class DelivererTable implements OnInit {
|
||||
|
||||
await this.edit(supplierId, updateDelivererComponent);
|
||||
updateDelivererComponent.delivererForm.reset();
|
||||
modal.isVisible = false;
|
||||
this.onModalCancel(modal);
|
||||
await this.fetchDeliverers();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user