connect api to stock page for get, patch and delete

This commit is contained in:
2025-11-29 23:14:04 +01:00
parent a76b184dc1
commit 0189fb0440
8 changed files with 255 additions and 78 deletions
@@ -1,12 +1,12 @@
<form nz-form nzLayout="horizontal" [formGroup]="stockForm" (ngSubmit)="submitForm()">
<form nz-form nzLayout="horizontal" [formGroup]="stockForm">
<nz-form-item nz-flex>
<nz-form-label nzSpan="15" nzRequired>
Quantité minimale du produit
</nz-form-label>
<nz-form-control nzSpan="4" nzErrorTip="Ce champ est requis">
<input nz-input placeholder="12345" formControlName="minQuantity">
<nz-form-control nzSpan="4" nzErrorTip="Requis">
<input nz-input type="number" placeholder="12345" formControlName="minimalQuantity">
</nz-form-control>
</nz-form-item>
</form>
+14 -11
View File
@@ -1,9 +1,10 @@
import { Component } from '@angular/core';
import {Component, effect, input} from '@angular/core';
import {FormControl, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms";
import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
import {NzInputDirective} from "ng-zorro-antd/input";
import {NzColDirective} from "ng-zorro-antd/grid";
import {NzFlexDirective} from "ng-zorro-antd/flex";
import {GetProductDto} from "../../services/api";
@Component({
selector: 'app-stock-form',
@@ -22,17 +23,19 @@ import {NzFlexDirective} from "ng-zorro-antd/flex";
})
export class StockForm {
stockForm = new FormGroup({
minQuantity: new FormControl<number>(null, [Validators.required])
id: new FormControl<number>(null),
minimalQuantity: new FormControl<number>(null, [Validators.required])
})
submitForm() {
// Pour annuler si le formulaire est invalide
if (this.stockForm.invalid) return;
// Pour obtenir la valeur du formulaire
console.log(this.stockForm.getRawValue())
// Pour vider le formulaire
this.stockForm.reset()
product= input<GetProductDto>();
constructor() {
effect(() => {
if (this.product()) {
this.stockForm.patchValue({
id: this.product().id,
minimalQuantity: this.product().minimalQuantity,
});
}
});
}
}