Providers Pt1
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
<p>create-providers-modal works!</p>
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
import {Component, output} from '@angular/core';
|
||||||
|
import {NzMessageService} from "ng-zorro-antd/message";
|
||||||
|
import {NzButtonComponent} from "ng-zorro-antd/button";
|
||||||
|
import {NzModalComponent} from "ng-zorro-antd/modal";
|
||||||
|
import {ProvidersAddForm} from "../providers-add-form/providers-add-form";
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-create-providers-modal',
|
||||||
|
imports: [NzButtonComponent, NzModalComponent, ProvidersAddForm],
|
||||||
|
template: `
|
||||||
|
<button nz-button nzType="primary" (click)="showModal()">
|
||||||
|
<span style="font-weight: bold">+</span>
|
||||||
|
</button>
|
||||||
|
<nz-modal
|
||||||
|
[(nzVisible)]="isVisible"
|
||||||
|
[nzTitle]="modalTitle"
|
||||||
|
[nzContent]="modalContent"
|
||||||
|
[nzFooter]="modalFooter"
|
||||||
|
(nzOnCancel)="handleCancel()">
|
||||||
|
<ng-template #modalTitle style="text-align: center">Création de clients</ng-template>
|
||||||
|
|
||||||
|
<ng-template #modalContent>
|
||||||
|
<app-providers-add-form/>
|
||||||
|
</ng-template>
|
||||||
|
|
||||||
|
<ng-template #modalFooter>
|
||||||
|
<button nz-button nzType="default" (click)="handleCancel()">Annuler</button>
|
||||||
|
<button nz-button nzType="primary" (click)="handleOk()" [nzLoading]="isConfirmLoading">Confirmer</button>
|
||||||
|
</ng-template>
|
||||||
|
</nz-modal>
|
||||||
|
`,
|
||||||
|
styleUrl: './create-providers-modal.css',
|
||||||
|
})
|
||||||
|
export class CreateProvidersModal {
|
||||||
|
constructor(private message: NzMessageService) {}
|
||||||
|
isVisible = false;
|
||||||
|
isConfirmLoading = false;
|
||||||
|
|
||||||
|
showModal(): void {
|
||||||
|
this.isVisible = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
handleOk(): void {
|
||||||
|
this.isConfirmLoading = true;
|
||||||
|
this.message.success('Prestataire créé !');
|
||||||
|
setTimeout(() => {
|
||||||
|
this.isVisible = false;
|
||||||
|
this.isConfirmLoading = false;
|
||||||
|
}, 300);
|
||||||
|
this.triggerCreated.emit();
|
||||||
|
}
|
||||||
|
|
||||||
|
handleCancel(): void {
|
||||||
|
this.isVisible = false;
|
||||||
|
this.message.info('Création annulée');
|
||||||
|
}
|
||||||
|
|
||||||
|
triggerCreated = output<void>()
|
||||||
|
}
|
||||||
@@ -1,51 +1,23 @@
|
|||||||
<form nz-form nzLayout="horizontal" [formGroup]="providerForm">
|
<form nz-form nzLayout="horizontal" [formGroup]="providerForm">
|
||||||
<nz-form-item>
|
<nz-form-item>
|
||||||
<nz-form-label nzSpan="5" nzRequired> Nom </nz-form-label>
|
<nz-form-label nzSpan="5" nzRequired>Note</nz-form-label>
|
||||||
<nz-form-control nzSpan="22" nzErrorTip="Ce champ est requis !">
|
|
||||||
<input nz-input placeholder="Nom" formControlName="lastName">
|
|
||||||
</nz-form-control>
|
|
||||||
</nz-form-item>
|
|
||||||
|
|
||||||
<nz-form-item>
|
|
||||||
<nz-form-label nzSpan="5" nzRequired>Prénom</nz-form-label>
|
|
||||||
<nz-form-control nzErrorTip="Ce champ est requis">
|
<nz-form-control nzErrorTip="Ce champ est requis">
|
||||||
<input nz-input placeholder="Prénom" formControlName="firstName">
|
<input nz-input placeholder="Note" formControlName="note">
|
||||||
</nz-form-control>
|
</nz-form-control>
|
||||||
</nz-form-item>
|
</nz-form-item>
|
||||||
|
|
||||||
<nz-form-item>
|
<nz-form-item>
|
||||||
<nz-form-label nzSpan="5" nzRequired>Téléphone</nz-form-label>
|
<nz-form-label nzSpan="5" nzRequired> Type </nz-form-label>
|
||||||
<nz-form-control nzErrorTip="Ce champ est requis !">
|
|
||||||
<input nz-input placeholder="Numéro de téléphone" formControlName="phoneNumber">
|
|
||||||
</nz-form-control>
|
|
||||||
</nz-form-item>
|
|
||||||
|
|
||||||
<nz-form-item>
|
|
||||||
<nz-form-label nzSpan="5" nzRequired>Email</nz-form-label>
|
|
||||||
<nz-form-control nzErrorTip="Ce champ est requis !">
|
|
||||||
<input nz-input placeholder="Email" formControlName="email">
|
|
||||||
</nz-form-control>
|
|
||||||
</nz-form-item>
|
|
||||||
|
|
||||||
<nz-form-item>
|
|
||||||
<nz-form-label nzSpan="5" nzRequired>Adresse</nz-form-label>
|
|
||||||
<nz-form-control nzErrorTip="Ce champ est requis !">
|
|
||||||
<input nz-input placeholder="Adresse" formControlName="address">
|
|
||||||
</nz-form-control>
|
|
||||||
</nz-form-item>
|
|
||||||
|
|
||||||
<nz-form-item>
|
|
||||||
<nz-form-label nzSpan="5" nzRequired>Rôle</nz-form-label>
|
|
||||||
<nz-form-control nzErrorTip="Ce champ est requis">
|
<nz-form-control nzErrorTip="Ce champ est requis">
|
||||||
<input nz-input placeholder="Rôle" formControlName="role">
|
<nz-select placeholder="Type de client" formControlName="providerTypeId">
|
||||||
</nz-form-control>
|
@for (providertype of providerTypes(); track providertype.id) {
|
||||||
</nz-form-item>
|
<nz-option nzValue="{{providertype.id}}" nzLabel="{{ providertype.label }}"></nz-option>
|
||||||
|
}
|
||||||
<nz-form-item>
|
</nz-select>
|
||||||
<nz-form-label nzSpan="5" nzRequired>Prix</nz-form-label>
|
|
||||||
<nz-form-control nzErrorTip="Ce champ est requis">
|
|
||||||
<input nz-input placeholder="Prix" formControlName="price">
|
|
||||||
</nz-form-control>
|
</nz-form-control>
|
||||||
</nz-form-item>
|
</nz-form-item>
|
||||||
|
|
||||||
|
<nz-flex nzJustify="end">
|
||||||
|
<button nz-button nzType="primary" (click)="submitForm()">Valider</button>
|
||||||
|
</nz-flex>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -1,34 +1,105 @@
|
|||||||
import { Component } from '@angular/core';
|
import {Component, inject, signal} from '@angular/core';
|
||||||
import {FormControl, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms";
|
import {FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators} from "@angular/forms";
|
||||||
import {NzFormModule} from "ng-zorro-antd/form";
|
|
||||||
import {NzInputDirective} from "ng-zorro-antd/input";
|
|
||||||
import {NzFlexDirective} from "ng-zorro-antd/flex";
|
|
||||||
import {NzButtonComponent} from "ng-zorro-antd/button";
|
import {NzButtonComponent} from "ng-zorro-antd/button";
|
||||||
|
import {NzColDirective, NzRowDirective} from "ng-zorro-antd/grid";
|
||||||
|
import {NzFlexDirective} from "ng-zorro-antd/flex";
|
||||||
|
import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
|
||||||
|
import {NzInputDirective} from "ng-zorro-antd/input";
|
||||||
|
import {NzOptionComponent, NzSelectComponent} from "ng-zorro-antd/select";
|
||||||
|
import {
|
||||||
|
CreateCustomerDto,
|
||||||
|
CustomersService,
|
||||||
|
CustomertypesService,
|
||||||
|
GetCustomerTypeDto,
|
||||||
|
ProvidersService, ProvidertypesService
|
||||||
|
} from "../../../services/api";
|
||||||
|
import {NzNotificationService} from "ng-zorro-antd/notification";
|
||||||
|
import {firstValueFrom} from "rxjs";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-providers-add-form',
|
selector: 'app-providers-add-form',
|
||||||
imports: [ReactiveFormsModule, NzFormModule, NzInputDirective,],
|
imports: [
|
||||||
|
FormsModule,
|
||||||
|
NzButtonComponent,
|
||||||
|
NzColDirective,
|
||||||
|
NzFlexDirective,
|
||||||
|
NzFormControlComponent,
|
||||||
|
NzFormDirective,
|
||||||
|
NzFormItemComponent,
|
||||||
|
NzFormLabelComponent,
|
||||||
|
NzInputDirective,
|
||||||
|
NzOptionComponent,
|
||||||
|
NzRowDirective,
|
||||||
|
NzSelectComponent,
|
||||||
|
ReactiveFormsModule
|
||||||
|
],
|
||||||
templateUrl: './providers-add-form.html',
|
templateUrl: './providers-add-form.html',
|
||||||
styleUrl: './providers-add-form.css',
|
styleUrl: './providers-add-form.css',
|
||||||
})
|
})
|
||||||
export class ProvidersAddForm {
|
export class ProvidersAddForm {
|
||||||
|
private providersService = inject(ProvidersService);
|
||||||
|
private providertypesService = inject(ProvidertypesService);
|
||||||
|
private notificationService = inject(NzNotificationService)
|
||||||
|
|
||||||
|
|
||||||
providerForm = new FormGroup({
|
providerForm = new FormGroup({
|
||||||
lastName: new FormControl<string>(null, [Validators.required]),
|
Price: new FormControl<string>(null, [Validators.required]),
|
||||||
firstName: new FormControl<string>(null, [Validators.required]),
|
providerTypeId: new FormControl<number>(null, [Validators.required]),
|
||||||
phoneNumber: new FormControl<string>(null, [Validators.required]),
|
|
||||||
email: new FormControl<string>(null, [Validators.required]),
|
|
||||||
address: new FormControl<string>(null, [Validators.required]),
|
|
||||||
role: new FormControl<string>(null, [Validators.required]),
|
|
||||||
price: new FormControl<string>(null, [Validators.required]),
|
|
||||||
})
|
})
|
||||||
submitForm() {
|
|
||||||
|
providerPost = signal<CreateCustomerDto>(this.providerForm.value);
|
||||||
|
providersLoading = signal<boolean>(false);
|
||||||
|
|
||||||
|
async submitForm() {
|
||||||
// Pour annuler si le formulaire est invalide
|
// Pour annuler si le formulaire est invalide
|
||||||
if (this.providerForm.invalid) return;
|
if (this.providerForm.invalid) return;
|
||||||
|
|
||||||
// Pour obtenir la valeur du formulaire
|
// Pour obtenir la valeur du formulaire
|
||||||
console.log(this.providerForm.getRawValue())
|
console.log(this.providerForm.getRawValue())
|
||||||
|
this.providerPost.set(this.providerForm.getRawValue())
|
||||||
|
|
||||||
|
await this.createCustomers(this.providerPost().note, this.providerPost().customerTypeId)
|
||||||
// Pour vider le formulaire
|
// Pour vider le formulaire
|
||||||
this.providerForm.reset()
|
this.providerForm.reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async createCustomers(note: string, customerTypeId: number) {
|
||||||
|
this.providersLoading.set(true);
|
||||||
|
|
||||||
|
const providerValue = {
|
||||||
|
note: note,
|
||||||
|
customerTypeId: customerTypeId
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const provider = await firstValueFrom(this.providersService.createProviderEndpoint(providerValue));
|
||||||
|
this.providerPost.set(provider);
|
||||||
|
console.log(provider);
|
||||||
|
} 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
customerTypes = signal<GetCustomerTypeDto[]>([])
|
||||||
|
|
||||||
|
async ngOnInit() {
|
||||||
|
await this.fetchCustomerTypes()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fetchCustomerTypes() {
|
||||||
|
this.customersLoading.set(true);
|
||||||
|
try {
|
||||||
|
const customerType = await firstValueFrom(this.customertypesService.getAllCustomerTypeEndpoint())
|
||||||
|
this.customerTypes.set(customerType)
|
||||||
|
} catch (e) {
|
||||||
|
this.notificationService.error('Erreur', 'Erreur de communication avec l\'API');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.customersLoading.set(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
.ant-modal-content {
|
|
||||||
background: #272727;
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
<p>providers-card-form works!</p>
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
import { Component } from '@angular/core';
|
|
||||||
import {NzModalComponent, NzModalModule} from "ng-zorro-antd/modal";
|
|
||||||
import {NzButtonComponent, NzButtonModule} from "ng-zorro-antd/button";
|
|
||||||
import {NzMessageService} from "ng-zorro-antd/message";
|
|
||||||
import {ProvidersAddForm} from "../providers-add-form/providers-add-form";
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
selector: 'app-providers-card-form',
|
|
||||||
imports: [NzButtonModule, NzModalModule, ProvidersAddForm],
|
|
||||||
template: `
|
|
||||||
<button nz-button nzType="primary" (click)="showModal()">
|
|
||||||
<span style="font-weight: bold">+</span>
|
|
||||||
</button>
|
|
||||||
<nz-modal
|
|
||||||
[(nzVisible)]="isVisible"
|
|
||||||
[nzTitle]="modalTitle"
|
|
||||||
[nzContent]="modalContent"
|
|
||||||
[nzFooter]="modalFooter"
|
|
||||||
(nzOnCancel)="handleCancel()"
|
|
||||||
>
|
|
||||||
<ng-template #modalTitle>Création de prestataires</ng-template>
|
|
||||||
|
|
||||||
<ng-template #modalContent>
|
|
||||||
<app-providers-add-form/>
|
|
||||||
</ng-template>
|
|
||||||
|
|
||||||
<ng-template #modalFooter>
|
|
||||||
<button nz-button nzType="default" (click)="handleCancel()">Annuler</button>
|
|
||||||
<button nz-button nzType="primary" (click)="handleOk()" [nzLoading]="isConfirmLoading">Confirmer</button>
|
|
||||||
</ng-template>
|
|
||||||
</nz-modal>
|
|
||||||
`,
|
|
||||||
styleUrl: './providers-card-form.css',
|
|
||||||
})
|
|
||||||
export class ProvidersCardForm {
|
|
||||||
constructor(private message: NzMessageService) {}
|
|
||||||
isVisible = false;
|
|
||||||
isConfirmLoading = false;
|
|
||||||
|
|
||||||
showModal(): void {
|
|
||||||
this.isVisible = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
handleOk(): void {
|
|
||||||
this.isConfirmLoading = true;
|
|
||||||
this.message.success('Prestataire créé !');
|
|
||||||
setTimeout(() => {
|
|
||||||
this.isVisible = false;
|
|
||||||
this.isConfirmLoading = false;
|
|
||||||
}, 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
handleCancel(): void {
|
|
||||||
this.isVisible = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<p>providers-card works!</p>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-providers-card',
|
||||||
|
imports: [],
|
||||||
|
templateUrl: './providers-card.html',
|
||||||
|
styleUrl: './providers-card.css',
|
||||||
|
})
|
||||||
|
export class ProvidersCard {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1 +0,0 @@
|
|||||||
<p>providers-get-all works!</p>
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
import {Component, inject, signal} from '@angular/core';
|
|
||||||
import {NzNotificationService} from "ng-zorro-antd/notification";
|
|
||||||
import {Router} from "@angular/router";
|
|
||||||
import {firstValueFrom} from "rxjs";
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
selector: 'app-providers-get-all',
|
|
||||||
imports: [],
|
|
||||||
templateUrl: './providers-get-all.html',
|
|
||||||
styleUrl: './providers-get-all.css',
|
|
||||||
})
|
|
||||||
export class ProvidersGetAll {
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,11 @@
|
|||||||
<app-providers-card-form/>
|
<app-create-providers-modal (triggerCreated)="fetchProviders()" />
|
||||||
|
|
||||||
<app-providers-get-all/>
|
<div class="card">
|
||||||
|
<div nz-row [nzGutter]="10" style="gap: 30px">
|
||||||
|
@for (provider of providers(); track provider.id)
|
||||||
|
{
|
||||||
|
<!-- Passage de la donnée du parent vers l'enfant + signal à émettre -->
|
||||||
|
<app-providers-card [provider]="provider" (triggerEdited)="fetchProviders()" />
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -1,16 +1,40 @@
|
|||||||
import { Component } from '@angular/core';
|
import {Component, inject, signal} from '@angular/core';
|
||||||
import {ProvidersCardForm} from "./providers-card-form/providers-card-form";
|
import {NzRowDirective} from "ng-zorro-antd/grid";
|
||||||
import {ProvidersGetAll} from "./providers-get-all/providers-get-all";
|
import {GetProviderDto, ProvidersService} from "../../services/api";
|
||||||
|
import {NzNotificationService} from "ng-zorro-antd/notification";
|
||||||
|
import {Router} from "@angular/router";
|
||||||
|
import {firstValueFrom} from "rxjs";
|
||||||
|
import {ProvidersCard} from "./providers-card/providers-card";
|
||||||
|
import {CreateProvidersModal} from "./create-providers-modal/create-providers-modal";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-providers',
|
selector: 'app-providers',
|
||||||
imports: [
|
imports: [NzRowDirective, ProvidersCard, CreateProvidersModal],
|
||||||
ProvidersCardForm,
|
|
||||||
ProvidersGetAll
|
|
||||||
],
|
|
||||||
templateUrl: './providers.html',
|
templateUrl: './providers.html',
|
||||||
styleUrl: './providers.css',
|
styleUrl: './providers.css',
|
||||||
})
|
})
|
||||||
export class Providers {
|
export class Providers {
|
||||||
|
private providersService = inject(ProvidersService);
|
||||||
|
private notificationService = inject(NzNotificationService)
|
||||||
|
|
||||||
|
router = inject(Router);
|
||||||
|
|
||||||
|
providers = signal<GetProviderDto[]>([]);
|
||||||
|
providersLoading = signal<boolean>(false);
|
||||||
|
|
||||||
|
async ngOnInit() {
|
||||||
|
await this.fetchProviders();
|
||||||
|
}
|
||||||
|
|
||||||
|
async fetchProviders() {
|
||||||
|
this.providersLoading.set(true);
|
||||||
|
try {
|
||||||
|
const providers = await firstValueFrom(this.providersService.getAllProvidersEndpoint())
|
||||||
|
this.providers.set(providers)
|
||||||
|
} catch (e) {
|
||||||
|
this.notificationService.error('Erreur', 'Erreur de communication avec l\'API');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.providersLoading.set(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user