feat: update dashboard components and analytics for 7-day summaries

- Modified `ManagerWeeklySummary`, `MetricsTab`, and `ProductivityAnalytics` to reflect a focus on the last 7 days instead of the current week.
- Enhanced `ManagerSummaryService` and `MetricsService` to calculate metrics over a sliding 7-day window, improving data relevance.
- Added a new utility function `formatDistanceToNow` for better date formatting in French.
- Updated comments and documentation to clarify changes in timeframes.
This commit is contained in:
Julien Froidefond
2025-09-23 21:22:59 +02:00
parent 336b5c1006
commit fd3827214f
14 changed files with 738 additions and 32 deletions

View File

@@ -1,5 +1,4 @@
import { prisma } from '@/services/core/database';
import { startOfWeek, endOfWeek } from 'date-fns';
import { getToday } from '@/lib/date-utils';
type TaskType = {
@@ -83,11 +82,13 @@ export interface ManagerSummary {
export class ManagerSummaryService {
/**
* Génère un résumé orienté manager pour la semaine
* Génère un résumé orienté manager pour les 7 derniers jours
*/
static async getManagerSummary(date: Date = getToday()): Promise<ManagerSummary> {
const weekStart = startOfWeek(date, { weekStartsOn: 1 }); // Lundi
const weekEnd = endOfWeek(date, { weekStartsOn: 1 }); // Dimanche
// Fenêtre glissante de 7 jours au lieu de semaine calendaire
const weekEnd = new Date(date);
const weekStart = new Date(date);
weekStart.setDate(weekStart.getDate() - 6); // 7 jours en arrière (incluant aujourd'hui)
// Récupérer les données de base
const [tasks, checkboxes] = await Promise.all([
@@ -537,22 +538,22 @@ export class ManagerSummaryService {
accomplishments: KeyAccomplishment[],
challenges: UpcomingChallenge[]
) {
// Points forts de la semaine
// Points forts des 7 derniers jours
const topAccomplishments = accomplishments.slice(0, 3);
const weekHighlight = topAccomplishments.length > 0
? `Cette semaine, j'ai principalement progressé sur ${topAccomplishments.map(a => a.title).join(', ')}.`
: 'Semaine focalisée sur l\'exécution des tâches quotidiennes.';
? `Ces 7 derniers jours, j'ai principalement progressé sur ${topAccomplishments.map(a => a.title).join(', ')}.`
: 'Période focalisée sur l\'exécution des tâches quotidiennes.';
// Défis rencontrés
const highImpactItems = accomplishments.filter(a => a.impact === 'high');
const mainChallenges = highImpactItems.length > 0
? `Les principaux enjeux traités ont été liés aux ${[...new Set(highImpactItems.flatMap(a => a.tags))].join(', ')}.`
: 'Pas de blockers majeurs rencontrés cette semaine.';
: 'Pas de blockers majeurs rencontrés sur cette période.';
// Focus semaine prochaine
// Focus 7 prochains jours
const topChallenges = challenges.slice(0, 3);
const nextWeekFocus = topChallenges.length > 0
? `La semaine prochaine sera concentrée sur ${topChallenges.map(c => c.title).join(', ')}.`
? `Les 7 prochains jours seront concentrés sur ${topChallenges.map(c => c.title).join(', ')}.`
: 'Continuation du travail en cours selon les priorités établies.';
return {