Providers & Contact fini
This commit is contained in:
@@ -1,11 +1,96 @@
|
||||
import { Component } from '@angular/core';
|
||||
import {Component, inject, input, output, signal} from '@angular/core';
|
||||
import {FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators} from "@angular/forms";
|
||||
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 {
|
||||
CustomersService,
|
||||
GetCustomerDto, GetProviderDto,
|
||||
ServiceprovidersService,
|
||||
UpdateCustomerDto,
|
||||
UpdateProviderDto
|
||||
} from "../../../services/api";
|
||||
import {NzNotificationService} from "ng-zorro-antd/notification";
|
||||
import {firstValueFrom} from "rxjs";
|
||||
|
||||
@Component({
|
||||
selector: 'app-providers-card',
|
||||
imports: [],
|
||||
imports: [FormsModule, NzCardComponent, NzColDirective, NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent, NzIconDirective, NzInputDirective, NzRowDirective, ReactiveFormsModule],
|
||||
templateUrl: './providers-card.html',
|
||||
styleUrl: './providers-card.css',
|
||||
})
|
||||
export class ProvidersCard {
|
||||
private providersService = inject(ServiceprovidersService);
|
||||
private notificationService = inject(NzNotificationService)
|
||||
|
||||
providerEdit = signal<UpdateProviderDto>(null);
|
||||
providersLoading = signal<boolean>(false);
|
||||
|
||||
providerForm = new FormGroup({
|
||||
id: new FormControl(null, [Validators.required]),
|
||||
price: new FormControl<number>(null, [Validators.required]),
|
||||
})
|
||||
|
||||
async submitForm() {
|
||||
this.providersLoading.set(true);
|
||||
|
||||
const providerValue = {
|
||||
price: this.providerForm.value.price,
|
||||
}
|
||||
|
||||
try {
|
||||
const provider = await firstValueFrom(this.providersService.updateProviderEndpoint(this.provider().id,providerValue));
|
||||
this.providerEdit.set(provider);
|
||||
console.log(provider);
|
||||
this.providerForm.reset();
|
||||
this.edit.set(false);
|
||||
|
||||
this.triggerEdited.emit();
|
||||
|
||||
} catch (e)
|
||||
{
|
||||
this.notificationService.error('Erreur', ' (ou Erreur de communication avec l\'API)');
|
||||
}
|
||||
|
||||
this.providersLoading.set(false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
provider = input<GetProviderDto>(null);
|
||||
|
||||
edit = signal(false)
|
||||
|
||||
triggerEdited = output<void>();
|
||||
|
||||
protected Edit() {
|
||||
this.edit.set(true)
|
||||
}
|
||||
|
||||
protected Back() {
|
||||
this.edit.set(false)
|
||||
this.providerForm.reset();
|
||||
}
|
||||
|
||||
async Delete() {
|
||||
this.providersLoading.set(true);
|
||||
|
||||
try {
|
||||
const provider = await firstValueFrom(this.providersService.deleteProviderEndpoint(this.provider().id));
|
||||
this.providerEdit.set(provider);
|
||||
|
||||
this.providerForm.reset();
|
||||
this.triggerEdited.emit();
|
||||
|
||||
} catch (e)
|
||||
{
|
||||
this.notificationService.error('Erreur de recherche', "L\'auteur n\'existe pas !");
|
||||
|
||||
this.notificationService.error('Erreur', ' (ou Erreur de communication avec l\'API)');
|
||||
}
|
||||
|
||||
this.providersLoading.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user