Notifications corrections
This commit is contained in:
parent
407fb659f2
commit
37d1089be5
@ -11,7 +11,6 @@ interface TwentyTask {
|
|||||||
markdown?: string;
|
markdown?: string;
|
||||||
};
|
};
|
||||||
dueAt?: string;
|
dueAt?: string;
|
||||||
startAt?: string; // Start date/time for Twenty CRM tasks
|
|
||||||
status?: string; // e.g., "Done", "Todo", etc.
|
status?: string; // e.g., "Done", "Todo", etc.
|
||||||
type?: string;
|
type?: string;
|
||||||
assigneeId?: string;
|
assigneeId?: string;
|
||||||
@ -173,7 +172,6 @@ async function fetchTwentyTasks(userId?: string): Promise<TwentyTask[]> {
|
|||||||
markdown
|
markdown
|
||||||
}
|
}
|
||||||
dueAt
|
dueAt
|
||||||
startAt
|
|
||||||
status
|
status
|
||||||
assigneeId
|
assigneeId
|
||||||
assignee {
|
assignee {
|
||||||
@ -305,7 +303,6 @@ async function fetchTwentyTasks(userId?: string): Promise<TwentyTask[]> {
|
|||||||
title: node.title || 'Untitled Task',
|
title: node.title || 'Untitled Task',
|
||||||
bodyV2: node.bodyV2 || null,
|
bodyV2: node.bodyV2 || null,
|
||||||
dueAt: node.dueAt || null,
|
dueAt: node.dueAt || null,
|
||||||
startAt: node.startAt || null, // Start date for Twenty CRM tasks
|
|
||||||
status: node.status || null,
|
status: node.status || null,
|
||||||
type: node.type || 'Task',
|
type: node.type || 'Task',
|
||||||
assigneeId: node.assigneeId || null,
|
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
|
id: `twenty-${task.id}`, // Prefix to avoid conflicts with Leantime IDs
|
||||||
headline: task.title,
|
headline: task.title,
|
||||||
description: (task as any)._bodyText || null, // Use extracted body text
|
description: (task as any)._bodyText || null, // Use extracted body text
|
||||||
dateToFinish: task.dueAt || null,
|
dateToFinish: task.dueAt || null, // For Twenty CRM, dueAt is used as the notification time
|
||||||
startDate: task.startAt || null, // Start date for Twenty CRM tasks (for notifications)
|
|
||||||
projectName: 'Médiation',
|
projectName: 'Médiation',
|
||||||
projectId: 0,
|
projectId: 0,
|
||||||
status: task.status === 'Done' ? 5 : 1, // 5 = Done, 1 = New (or other status)
|
status: task.status === 'Done' ? 5 : 1, // 5 = Done, 1 = New (or other status)
|
||||||
|
|||||||
@ -252,7 +252,7 @@ export function Duties() {
|
|||||||
|
|
||||||
setTasks(sortedTasks);
|
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 => ({
|
const tasksForNotification = sortedTasks.map(task => ({
|
||||||
id: task.id.toString(),
|
id: task.id.toString(),
|
||||||
headline: task.headline,
|
headline: task.headline,
|
||||||
@ -260,7 +260,6 @@ export function Duties() {
|
|||||||
source: (task as any).source || 'leantime',
|
source: (task as any).source || 'leantime',
|
||||||
projectName: task.projectName,
|
projectName: task.projectName,
|
||||||
url: (task as any).url || null,
|
url: (task as any).url || null,
|
||||||
startDate: (task as any).startDate || null, // For Twenty CRM tasks
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
console.log('[Devoirs Widget] 📋 Dispatching tasks update', {
|
console.log('[Devoirs Widget] 📋 Dispatching tasks update', {
|
||||||
@ -270,7 +269,6 @@ export function Duties() {
|
|||||||
title: t.headline,
|
title: t.headline,
|
||||||
dateToFinish: t.dateToFinish,
|
dateToFinish: t.dateToFinish,
|
||||||
source: t.source,
|
source: t.source,
|
||||||
startDate: t.startDate,
|
|
||||||
})),
|
})),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,6 @@ interface Task {
|
|||||||
source: 'leantime' | 'twenty-crm';
|
source: 'leantime' | 'twenty-crm';
|
||||||
projectName: string;
|
projectName: string;
|
||||||
url?: string;
|
url?: string;
|
||||||
startDate?: string | null; // For Twenty CRM tasks
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,7 +38,6 @@ export function useTaskNotifications() {
|
|||||||
title: t.headline,
|
title: t.headline,
|
||||||
dateToFinish: t.dateToFinish,
|
dateToFinish: t.dateToFinish,
|
||||||
source: t.source,
|
source: t.source,
|
||||||
startDate: t.startDate,
|
|
||||||
})),
|
})),
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -56,7 +54,6 @@ export function useTaskNotifications() {
|
|||||||
source: task.source || 'leantime',
|
source: task.source || 'leantime',
|
||||||
projectName: task.projectName || '',
|
projectName: task.projectName || '',
|
||||||
url: task.url || null,
|
url: task.url || null,
|
||||||
startDate: task.startDate || null,
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
tasksRef.current = formattedTasks;
|
tasksRef.current = formattedTasks;
|
||||||
@ -94,15 +91,11 @@ export function useTaskNotifications() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For Leantime tasks: notification at due date time (dateToFinish)
|
// For both Leantime and Twenty CRM tasks: notification at due date time (dateToFinish)
|
||||||
// For Twenty CRM tasks: notification at start date time (startDate) if available, otherwise due date
|
// Note: Twenty CRM doesn't have a separate start date field, so we use dueAt for notifications
|
||||||
let notificationDate: Date | null = null;
|
let notificationDate: Date | null = null;
|
||||||
|
|
||||||
if (task.source === 'twenty-crm' && task.startDate) {
|
if (task.dateToFinish) {
|
||||||
// Twenty CRM: use start date for notification
|
|
||||||
notificationDate = new Date(task.startDate);
|
|
||||||
} else if (task.dateToFinish) {
|
|
||||||
// Leantime: use due date for notification
|
|
||||||
notificationDate = new Date(task.dateToFinish);
|
notificationDate = new Date(task.dateToFinish);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,8 +108,9 @@ export function useTaskNotifications() {
|
|||||||
const timeUntilNotificationMinutes = Math.round(timeUntilNotification / 1000 / 60);
|
const timeUntilNotificationMinutes = Math.round(timeUntilNotification / 1000 / 60);
|
||||||
const timeUntilNotificationSeconds = Math.round(timeUntilNotification / 1000);
|
const timeUntilNotificationSeconds = Math.round(timeUntilNotification / 1000);
|
||||||
|
|
||||||
// Notification window: within 1 minute of the notification time (30 seconds before to 30 seconds after)
|
// Notification window: within 2 minutes of the notification time (1 minute before to 1 minute after)
|
||||||
const notificationWindow = 30 * 1000; // 30 seconds
|
// This allows catching tasks that are due now or just became due
|
||||||
|
const notificationWindow = 60 * 1000; // 1 minute
|
||||||
const inNotificationWindow =
|
const inNotificationWindow =
|
||||||
timeUntilNotification >= -notificationWindow &&
|
timeUntilNotification >= -notificationWindow &&
|
||||||
timeUntilNotification <= notificationWindow;
|
timeUntilNotification <= notificationWindow;
|
||||||
@ -138,28 +132,22 @@ export function useTaskNotifications() {
|
|||||||
if (dueTasks.length > 0) {
|
if (dueTasks.length > 0) {
|
||||||
// Sort by notification time (earliest first)
|
// Sort by notification time (earliest first)
|
||||||
dueTasks.sort((a, b) => {
|
dueTasks.sort((a, b) => {
|
||||||
const dateA = a.source === 'twenty-crm' && a.startDate
|
const dateA = a.dateToFinish ? new Date(a.dateToFinish).getTime() : Infinity;
|
||||||
? new Date(a.startDate).getTime()
|
const dateB = b.dateToFinish ? new Date(b.dateToFinish).getTime() : Infinity;
|
||||||
: 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;
|
|
||||||
return dateA - dateB;
|
return dateA - dateB;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Show notification for the first task
|
// Show notification for the first task
|
||||||
const task = dueTasks[0];
|
const task = dueTasks[0];
|
||||||
|
|
||||||
const notificationDate = task.source === 'twenty-crm' && task.startDate
|
const notificationDate = task.dateToFinish
|
||||||
? new Date(task.startDate)
|
? new Date(task.dateToFinish)
|
||||||
: task.dateToFinish
|
: new Date();
|
||||||
? new Date(task.dateToFinish)
|
|
||||||
: new Date();
|
|
||||||
|
|
||||||
const timeStr = format(notificationDate, 'HH:mm', { locale: fr });
|
const timeStr = format(notificationDate, 'HH:mm', { locale: fr });
|
||||||
const sourceLabel = task.source === 'twenty-crm' ? 'Médiation' : 'Agilité';
|
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,
|
id: task.id,
|
||||||
title: task.headline,
|
title: task.headline,
|
||||||
source: task.source,
|
source: task.source,
|
||||||
@ -172,7 +160,7 @@ export function useTaskNotifications() {
|
|||||||
source: 'leantime',
|
source: 'leantime',
|
||||||
title: 'Devoirs',
|
title: 'Devoirs',
|
||||||
subtitle: task.source === 'twenty-crm' ? 'Tâche Médiation' : 'Tâche Agilité',
|
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,
|
icon: CheckSquare,
|
||||||
iconColor: 'text-blue-600',
|
iconColor: 'text-blue-600',
|
||||||
iconBgColor: 'bg-blue-100',
|
iconBgColor: 'bg-blue-100',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user