diff --git a/src/app/pages/contact/contact-add-form/contact-add-form.html b/src/app/pages/contact/contact-add-form/contact-add-form.html index c752d58..9cf3fbf 100644 --- a/src/app/pages/contact/contact-add-form/contact-add-form.html +++ b/src/app/pages/contact/contact-add-form/contact-add-form.html @@ -1 +1,61 @@ -

contact-add-form works!

+
+ + Nom + + + + + + + Prénom + + + + + + + Email + + + + + + + Téléphone + + + + + + + Adresse + + + + + + + Code postal + + + + + + + Ville + + + + + + + Rôle + + + + + + + + +
\ No newline at end of file diff --git a/src/app/pages/contact/contact-add-form/contact-add-form.ts b/src/app/pages/contact/contact-add-form/contact-add-form.ts index 22c0287..604001f 100644 --- a/src/app/pages/contact/contact-add-form/contact-add-form.ts +++ b/src/app/pages/contact/contact-add-form/contact-add-form.ts @@ -1,11 +1,89 @@ -import { Component } from '@angular/core'; +import {Component, inject, signal} from '@angular/core'; +import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form"; +import {NzInputDirective} from "ng-zorro-antd/input"; +import {FormControl, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms"; +import {NzColDirective} from "ng-zorro-antd/grid"; +import {NzFlexDirective} from "ng-zorro-antd/flex"; +import {ContactsService, CreateContactDto} from "../../../services/api"; +import {NzNotificationService} from "ng-zorro-antd/notification"; +import {firstValueFrom} from "rxjs"; +import {NzButtonComponent} from "ng-zorro-antd/button"; @Component({ selector: 'app-contact-add-form', - imports: [], + imports: [ + NzFormLabelComponent, + NzFormItemComponent, + NzFormControlComponent, + NzInputDirective, + ReactiveFormsModule, + NzColDirective, + NzFormDirective, + NzFlexDirective, + NzButtonComponent + ], templateUrl: './contact-add-form.html', styleUrl: './contact-add-form.css', }) export class ContactAddForm { + private contactsService = inject(ContactsService); + private notificationService = inject(NzNotificationService); + contactForm = new FormGroup({ + lastName: new FormControl(null, [Validators.required]), + firstName: new FormControl(null, [Validators.required]), + phoneNumber: new FormControl(null, [Validators.required]), + email: new FormControl(null, [Validators.required]), + address: new FormControl(null, [Validators.required]), + city: new FormControl(null, [Validators.required]), + role: new FormControl(null, [Validators.required]), + customerId: new FormControl(null), + }) + + contactPost = signal(this.contactForm.value); + contactsLoading = signal(false); + + async submitForm() { + if (this.contactForm.invalid) return; + + console.log(this.contactForm.getRawValue()) + this.contactPost.set(this.contactForm.getRawValue()) + + await this.createContact( + this.contactPost().lastName, + this.contactPost().firstName, + this.contactPost().phoneNumber, + this.contactPost().email, + this.contactPost().address, + this.contactPost().city, + this.contactPost().role, + this.contactPost().customerId + ) + this.contactForm.reset() + } + + async createContact(lastName: string, firstName: string, phoneNumber: string, email: string, address: string, city: string, role: string, customerId: number) { + this.contactsLoading.set(true); + + const contactValue: CreateContactDto = { + lastName: lastName, + firstName: firstName, + phoneNumber: phoneNumber, + email: email, + address: address, + city: city, + role: role, + customerId: customerId + } + + try { + const contact = await firstValueFrom(this.contactsService.createContactEndpoint(contactValue)); + this.contactPost.set(contact); + console.log(contact); + } catch (e) { + this.notificationService.error('Erreur', 'Erreur de communication avec l\'API'); + } + + this.contactsLoading.set(false); + } } diff --git a/src/app/pages/contact/contact-card/contact-card.html b/src/app/pages/contact/contact-card/contact-card.html index 7bb4f76..331e35b 100644 --- a/src/app/pages/contact/contact-card/contact-card.html +++ b/src/app/pages/contact/contact-card/contact-card.html @@ -2,6 +2,11 @@

Contact n°{{ contact().id }}

Nom : {{ contact().lastName + " " + contact().firstName }}

+

Rôle : {{ contact().role }}

+

Numéro de téléphone : {{ contact().phoneNumber }}

+

Email : {{ contact().email }}

+

Adresse : {{ contact().address + ", " + contact().city }}

+
@@ -15,7 +20,43 @@ Nom - + + + + + Prénom + + + + + + Num. Tél. + + + + + + Email + + + + + + Adresse + + + + + + Ville + + + + + + Rôle + + diff --git a/src/app/pages/opportunities/opportunity-add-form/opportunity-add-form.html b/src/app/pages/opportunities/opportunity-add-form/opportunity-add-form.html index ba1c23c..59f6bf6 100644 --- a/src/app/pages/opportunities/opportunity-add-form/opportunity-add-form.html +++ b/src/app/pages/opportunities/opportunity-add-form/opportunity-add-form.html @@ -20,6 +20,17 @@ + + Contact + + + @for (contact of contacts(); track contact.id) { + + } + + + + diff --git a/src/app/pages/opportunities/opportunity-add-form/opportunity-add-form.ts b/src/app/pages/opportunities/opportunity-add-form/opportunity-add-form.ts index 6b63b21..3056b60 100644 --- a/src/app/pages/opportunities/opportunity-add-form/opportunity-add-form.ts +++ b/src/app/pages/opportunities/opportunity-add-form/opportunity-add-form.ts @@ -4,10 +4,11 @@ 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 {FormControl, FormGroup, ReactiveFormsModule} from "@angular/forms"; -import {CommunicationsService, CreateCommunicationDto} from "../../../services/api"; +import {FormControl, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms"; +import {CommunicationsService, ContactsService, CreateCommunicationDto, GetContactDto} from "../../../services/api"; import {NzNotificationService} from "ng-zorro-antd/notification"; import {firstValueFrom} from "rxjs"; +import {NzOptionComponent, NzSelectComponent} from "ng-zorro-antd/select"; @Component({ selector: 'app-opportunity-add-form', @@ -21,7 +22,9 @@ import {firstValueFrom} from "rxjs"; NzFormLabelComponent, NzInputDirective, NzRowDirective, - ReactiveFormsModule + ReactiveFormsModule, + NzSelectComponent, + NzOptionComponent ], templateUrl: './opportunity-add-form.html', styleUrl: './opportunity-add-form.css', @@ -30,11 +33,14 @@ export class OpportunityAddForm { private communicationsService = inject(CommunicationsService); private notificationService = inject(NzNotificationService) + private contactsService = inject(ContactsService); + communicationForm = new FormGroup({ calling: new FormControl(null), email: new FormControl(null), meeting: new FormControl(null), + contactId: new FormControl(null, [Validators.required]), }, { validators: atLeastOneRequired }) communicationPost = signal(this.communicationForm.value); @@ -46,17 +52,18 @@ export class OpportunityAddForm { console.log(this.communicationForm.getRawValue()) this.communicationPost.set(this.communicationForm.getRawValue()) - await this.createCommunication(this.communicationPost().calling, this.communicationPost().email, this.communicationPost().meeting) + await this.createCommunication(this.communicationPost().calling, this.communicationPost().email, this.communicationPost().meeting, this.communicationPost().contactId) this.communicationForm.reset() } - async createCommunication(calling: string, email: string, meeting: string) { + async createCommunication(calling: string, email: string, meeting: string, contactId: number) { this.communicationsLoading.set(true); const communicationValue: CreateCommunicationDto = { calling: calling, email: email, meeting: meeting, + contactId: contactId } try { @@ -69,8 +76,25 @@ export class OpportunityAddForm { this.communicationsLoading.set(false); } + + contacts = signal([]); + + async ngOnInit() { + await this.fetchContacts(); + } + + async fetchContacts() { + try { + const contacts = await firstValueFrom(this.contactsService.getAllContactEndpoint()); + this.contacts.set(contacts); + } catch (e) { + this.notificationService.error('Erreur', 'Erreur de communication avec l\'API'); + } + } } + + function atLeastOneRequired(group: FormGroup) { const { calling, email, meeting } = group.controls; const valid = [calling, email, meeting].some(c => c.value); diff --git a/src/app/pages/opportunities/opportunity-card/opportunity-card.html b/src/app/pages/opportunities/opportunity-card/opportunity-card.html index c64c11a..e25a26a 100644 --- a/src/app/pages/opportunities/opportunity-card/opportunity-card.html +++ b/src/app/pages/opportunities/opportunity-card/opportunity-card.html @@ -1,14 +1,23 @@ @if (edit() == false) { -

Communication n°{{ communication().id }}

+

Contact n°{{ communication().contactId }}

@if (communication().calling) {

📞 Appel : {{ communication().calling }}

+

Nom du Contact : {{ communication().contactLastName + " " + communication().contactFirstName}}

+

Numéro du Contact : {{ communication().contactPhoneNumber }}

+

Email du Contact : {{ communication().contactEmail }}

} @if (communication().email) {

✉️ Email : {{ communication().email }}

+

Nom du Contact : {{ communication().contactLastName + " " + communication().contactFirstName}}

+

Numéro du Contact : {{ communication().contactPhoneNumber }}

+

Email du Contact : {{ communication().contactEmail }}

} @if (communication().meeting) {

🤝 Réunion : {{ communication().meeting }}

+

Nom du Contact : {{ communication().contactLastName + " " + communication().contactFirstName}}

+

Numéro du Contact : {{ communication().contactPhoneNumber }}

+

Email du Contact : {{ communication().contactEmail }}

}
diff --git a/src/app/pages/staff/staff-card/staff-card.ts b/src/app/pages/staff/staff-card/staff-card.ts index a8f47d1..ef46418 100644 --- a/src/app/pages/staff/staff-card/staff-card.ts +++ b/src/app/pages/staff/staff-card/staff-card.ts @@ -35,7 +35,7 @@ export class StaffCard { staffForm = new FormGroup({ f4T2NumberApproval: new FormControl(null, [Validators.required]), - f4T2ExpirationDate: new FormControl(null, [Validators.required]), + f4T2ExpirationDate: new FormControl(null, [Validators.required]), }) async submitForm() { diff --git a/src/app/services/api/model/create-communication-dto.ts b/src/app/services/api/model/create-communication-dto.ts index 5b44961..27da861 100644 --- a/src/app/services/api/model/create-communication-dto.ts +++ b/src/app/services/api/model/create-communication-dto.ts @@ -13,5 +13,6 @@ export interface CreateCommunicationDto { calling?: string | null; email?: string | null; meeting?: string | null; + contactId?: number; } diff --git a/src/app/services/api/model/get-communication-dto.ts b/src/app/services/api/model/get-communication-dto.ts index bc01d87..bdfd4cc 100644 --- a/src/app/services/api/model/get-communication-dto.ts +++ b/src/app/services/api/model/get-communication-dto.ts @@ -14,5 +14,10 @@ export interface GetCommunicationDto { calling?: string | null; email?: string | null; meeting?: string | null; + contactId?: number; + contactFirstName?: string | null; + contactLastName?: string | null; + contactEmail?: string | null; + contactPhoneNumber?: string | null; } diff --git a/src/app/services/api/model/update-staff-dto.ts b/src/app/services/api/model/update-staff-dto.ts index 66faedf..39f7cb3 100644 --- a/src/app/services/api/model/update-staff-dto.ts +++ b/src/app/services/api/model/update-staff-dto.ts @@ -11,6 +11,6 @@ export interface UpdateStaffDto { f4T2NumberApproval?: string | null; - f4T2ExpirationDate?: string; + f4T2ExpirationDate?: Date | null; }