Notifications corrections

This commit is contained in:
alma 2026-01-16 09:54:23 +01:00
parent 407fb659f2
commit 37d1089be5
3 changed files with 15 additions and 33 deletions

View File

@ -11,7 +11,6 @@ interface TwentyTask {
markdown?: string;
};
dueAt?: string;
startAt?: string; // Start date/time for Twenty CRM tasks
status?: string; // e.g., "Done", "Todo", etc.
type?: string;
assigneeId?: string;
@ -173,7 +172,6 @@ async function fetchTwentyTasks(userId?: string): Promise<TwentyTask[]> {
markdown
}
dueAt
startAt
status
assigneeId
assignee {
@ -305,7 +303,6 @@ async function fetchTwentyTasks(userId?: string): Promise<TwentyTask[]> {
title: node.title || 'Untitled Task',
bodyV2: node.bodyV2 || null,
dueAt: node.dueAt || null,
startAt: node.startAt || null, // Start date for Twenty CRM tasks
status: node.status || null,
type: node.type || 'Task',
assigneeId: node.assigneeId || null,
@ -477,8 +474,7 @@ export async function GET(request: NextRequest) {
id: `twenty-${task.id}`, // Prefix to avoid conflicts with Leantime IDs
headline: task.title,
description: (task as any)._bodyText || null, // Use extracted body text
dateToFinish: task.dueAt || null,
startDate: task.startAt || null, // Start date for Twenty CRM tasks (for notifications)
dateToFinish: task.dueAt || null, // For Twenty CRM, dueAt is used as the notification time
projectName: 'Médiation',
projectId: 0,
status: task.status === 'Done' ? 5 : 1, // 5 = Done, 1 = New (or other status)

View File

@ -252,7 +252,7 @@ export function Duties() {
setTasks(sortedTasks);
// Dispatch event for Outlook-style notifications (when tasks are due/starting)
// Dispatch event for Outlook-style notifications (when tasks are due)
const tasksForNotification = sortedTasks.map(task => ({
id: task.id.toString(),
headline: task.headline,
@ -260,7 +260,6 @@ export function Duties() {
source: (task as any).source || 'leantime',
projectName: task.projectName,
url: (task as any).url || null,
startDate: (task as any).startDate || null, // For Twenty CRM tasks
}));
console.log('[Devoirs Widget] 📋 Dispatching tasks update', {
@ -270,7 +269,6 @@ export function Duties() {
title: t.headline,
dateToFinish: t.dateToFinish,
source: t.source,
startDate: t.startDate,
})),
});

View File

@ -11,7 +11,6 @@ interface Task {
source: 'leantime' | 'twenty-crm';
projectName: string;
url?: string;
startDate?: string | null; // For Twenty CRM tasks
}
/**
@ -39,7 +38,6 @@ export function useTaskNotifications() {
title: t.headline,
dateToFinish: t.dateToFinish,
source: t.source,
startDate: t.startDate,
})),
});
@ -56,7 +54,6 @@ export function useTaskNotifications() {
source: task.source || 'leantime',
projectName: task.projectName || '',
url: task.url || null,
startDate: task.startDate || null,
}));
tasksRef.current = formattedTasks;
@ -94,15 +91,11 @@ export function useTaskNotifications() {
return false;
}
// For Leantime tasks: notification at due date time (dateToFinish)
// For Twenty CRM tasks: notification at start date time (startDate) if available, otherwise due date
// For both Leantime and Twenty CRM tasks: notification at due date time (dateToFinish)
// Note: Twenty CRM doesn't have a separate start date field, so we use dueAt for notifications
let notificationDate: Date | null = null;
if (task.source === 'twenty-crm' && task.startDate) {
// Twenty CRM: use start date for notification
notificationDate = new Date(task.startDate);
} else if (task.dateToFinish) {
// Leantime: use due date for notification
if (task.dateToFinish) {
notificationDate = new Date(task.dateToFinish);
}
@ -115,8 +108,9 @@ export function useTaskNotifications() {
const timeUntilNotificationMinutes = Math.round(timeUntilNotification / 1000 / 60);
const timeUntilNotificationSeconds = Math.round(timeUntilNotification / 1000);
// Notification window: within 1 minute of the notification time (30 seconds before to 30 seconds after)
const notificationWindow = 30 * 1000; // 30 seconds
// Notification window: within 2 minutes of the notification time (1 minute before to 1 minute after)
// This allows catching tasks that are due now or just became due
const notificationWindow = 60 * 1000; // 1 minute
const inNotificationWindow =
timeUntilNotification >= -notificationWindow &&
timeUntilNotification <= notificationWindow;
@ -138,28 +132,22 @@ export function useTaskNotifications() {
if (dueTasks.length > 0) {
// Sort by notification time (earliest first)
dueTasks.sort((a, b) => {
const dateA = a.source === 'twenty-crm' && a.startDate
? new Date(a.startDate).getTime()
: a.dateToFinish ? new Date(a.dateToFinish).getTime() : Infinity;
const dateB = b.source === 'twenty-crm' && b.startDate
? new Date(b.startDate).getTime()
: b.dateToFinish ? new Date(b.dateToFinish).getTime() : Infinity;
const dateA = a.dateToFinish ? new Date(a.dateToFinish).getTime() : Infinity;
const dateB = b.dateToFinish ? new Date(b.dateToFinish).getTime() : Infinity;
return dateA - dateB;
});
// Show notification for the first task
const task = dueTasks[0];
const notificationDate = task.source === 'twenty-crm' && task.startDate
? new Date(task.startDate)
: task.dateToFinish
? new Date(task.dateToFinish)
: new Date();
const notificationDate = task.dateToFinish
? new Date(task.dateToFinish)
: new Date();
const timeStr = format(notificationDate, 'HH:mm', { locale: fr });
const sourceLabel = task.source === 'twenty-crm' ? 'Médiation' : 'Agilité';
console.log('[useTaskNotifications] ✅ Task due/starting detected!', {
console.log('[useTaskNotifications] ✅ Task due detected!', {
id: task.id,
title: task.headline,
source: task.source,
@ -172,7 +160,7 @@ export function useTaskNotifications() {
source: 'leantime',
title: 'Devoirs',
subtitle: task.source === 'twenty-crm' ? 'Tâche Médiation' : 'Tâche Agilité',
message: `${task.headline} - ${task.source === 'twenty-crm' ? 'Début' : 'Échéance'} à ${timeStr} (${sourceLabel})`,
message: `${task.headline} - Échéance à ${timeStr} (${sourceLabel})`,
icon: CheckSquare,
iconColor: 'text-blue-600',
iconBgColor: 'bg-blue-100',