added suppr and edit modal for supplier price
This commit is contained in:
@@ -45,7 +45,7 @@
|
||||
<div class="flex items-center justify-center space-x-2">
|
||||
<nz-icon nzType="edit" nzTheme="outline"
|
||||
class="cursor-pointer text-gray-600 hover:text-gray-900"
|
||||
(click)="openEditProductModal(product)"></nz-icon>
|
||||
(click)="openEditProductModal(product, supplier.id)"></nz-icon>
|
||||
<nz-divider nzType="vertical"></nz-divider>
|
||||
<nz-icon nzType="delete" nzTheme="outline" class="cursor-pointer text-red-600 hover:text-red-800"
|
||||
(click)="deleteProduct(product.productId, product.supplierId)"></nz-icon>
|
||||
@@ -81,7 +81,7 @@
|
||||
|
||||
<div class="hidden">
|
||||
<app-modal-nav #productModal nameIcon="edit" [name]="'Modifier les prix des fournisseurs'"
|
||||
(ok)="onModalProductOk(selectedProduct?.id, selectedSupplier?.id, priceForm, productModal)"
|
||||
(ok)="onModalProductOk(selectedProduct?.productId, selectedProductSupplierId, priceForm, productModal)"
|
||||
(cancel)="onModalCancel(productModal)">
|
||||
<app-price-form #priceForm [price]="selectedProduct"></app-price-form>
|
||||
</app-modal-nav>
|
||||
|
||||
@@ -36,6 +36,7 @@ export class SupplierTable implements OnInit {
|
||||
productModal = viewChild.required<ModalNav>('productModal');
|
||||
selectedSupplier: GetSupplierDto | null = null;
|
||||
selectedProduct: GetPriceDto | null = null;
|
||||
selectedProductSupplierId: number | null = null;
|
||||
|
||||
async ngOnInit() {
|
||||
await this.fetchSuppliers();
|
||||
@@ -82,8 +83,9 @@ export class SupplierTable implements OnInit {
|
||||
this.supplierModal().showModal();
|
||||
}
|
||||
|
||||
openEditProductModal(product: GetPriceDto) {
|
||||
openEditProductModal(product: GetPriceDto, supplierId: number) {
|
||||
this.selectedProduct = { ...product };
|
||||
this.selectedProductSupplierId = supplierId;
|
||||
this.productModal().showModal();
|
||||
}
|
||||
|
||||
@@ -98,11 +100,14 @@ export class SupplierTable implements OnInit {
|
||||
|
||||
async onModalProductOk(
|
||||
productId: number | undefined,
|
||||
supplierId: number | undefined,
|
||||
supplierId: number | null | undefined,
|
||||
updateProductComponent: PriceForm,
|
||||
modal: ModalNav
|
||||
) {
|
||||
if (!productId || !supplierId || !this.selectedProduct) return;
|
||||
if (productId == null || supplierId == null || !this.selectedProduct) {
|
||||
this.notificationService.error('Erreur', 'Identifiants produit/fournisseur manquants');
|
||||
return;
|
||||
}
|
||||
|
||||
await this.editPrice(productId, supplierId, updateProductComponent);
|
||||
updateProductComponent.priceForm.reset();
|
||||
@@ -119,7 +124,6 @@ export class SupplierTable implements OnInit {
|
||||
this.notificationService.error('Erreur', 'Erreur d\'écriture dans le formulaire');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const formValue = updateProductComponent.priceForm.getRawValue();
|
||||
const body = {
|
||||
@@ -127,9 +131,6 @@ export class SupplierTable implements OnInit {
|
||||
supplierId,
|
||||
sellingPrice: Number(formValue.price),
|
||||
};
|
||||
|
||||
console.log('PATCH body =>', body);
|
||||
|
||||
await firstValueFrom(this.pricesService.patchPriceEndpoint(productId, supplierId, body));
|
||||
this.notificationService.success('Success', 'Prix modifié');
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user