55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
import {Component, inject, signal} from '@angular/core';
|
|
import {CreateOpportunityModal} from "./create-opportunity-modal/create-opportunity-modal";
|
|
import {NzNotificationService} from "ng-zorro-antd/notification";
|
|
import {Router} from "@angular/router";
|
|
import {firstValueFrom} from "rxjs";
|
|
import {NzCardComponent} from "ng-zorro-antd/card";
|
|
import {NzDividerComponent} from "ng-zorro-antd/divider";
|
|
import {NzColDirective, NzRowDirective} from "ng-zorro-antd/grid";
|
|
import {OpportunityCard} from "./opportunity-card/opportunity-card";
|
|
import {CommunicationsService, GetCommunicationDto} from "../../services/api";
|
|
|
|
@Component({
|
|
selector: 'app-opportunities',
|
|
imports: [CreateOpportunityModal, NzCardComponent, NzDividerComponent, NzRowDirective, NzColDirective, OpportunityCard],
|
|
templateUrl: './opportunities.html',
|
|
styleUrl: './opportunities.css',
|
|
})
|
|
export class Opportunities {
|
|
private communicationsService = inject(CommunicationsService);
|
|
private notificationService = inject(NzNotificationService)
|
|
|
|
router = inject(Router);
|
|
|
|
communications = signal<GetCommunicationDto[]>([]);
|
|
communicationsLoading = signal<boolean>(false);
|
|
|
|
async ngOnInit() {
|
|
await this.fetchCommunications();
|
|
}
|
|
|
|
get totalCalls() {
|
|
return this.communications().filter(c => c.calling).length;
|
|
}
|
|
|
|
get totalEmails() {
|
|
return this.communications().filter(c => c.email).length;
|
|
}
|
|
|
|
get totalMeetings() {
|
|
return this.communications().filter(c => c.meeting).length;
|
|
}
|
|
|
|
async fetchCommunications() {
|
|
this.communicationsLoading.set(true);
|
|
try {
|
|
const communications = await firstValueFrom(this.communicationsService.getAllCommunicationsEndpoint())
|
|
this.communications.set(communications)
|
|
} catch (e) {
|
|
this.notificationService.error('Erreur', 'Erreur de communication avec l\'API');
|
|
}
|
|
|
|
this.communicationsLoading.set(false);
|
|
}
|
|
}
|