From 9d5a8d6d2fcad0bc8b47944397373cec4531a3cd Mon Sep 17 00:00:00 2001 From: alma Date: Thu, 15 Jan 2026 18:25:09 +0100 Subject: [PATCH] Agenda refactor --- components/calendar-widget.tsx | 13 ++++++++++++- components/calendar.tsx | 13 ++++++++++++- components/calendar/calendar-client.tsx | 2 +- components/calendar/calendar-widget.tsx | 16 ++++++++++++++-- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/components/calendar-widget.tsx b/components/calendar-widget.tsx index 66fd357..c8f3f0c 100644 --- a/components/calendar-widget.tsx +++ b/components/calendar-widget.tsx @@ -54,6 +54,17 @@ export function CalendarWidget() { // @ts-ignore const nextWeek = addDays(now, 7); + // Helper function to get display name for calendar + const getCalendarDisplayName = (calendar: any) => { + // If calendar is synced to an external account, use the account name + if (calendar.syncConfig?.syncEnabled && calendar.syncConfig?.mailCredential) { + return calendar.syncConfig.mailCredential.display_name || + calendar.syncConfig.mailCredential.email; + } + // For non-synced calendars, use the calendar name + return calendar.name; + }; + // Récupérer les événements pour chaque calendrier const allEventsPromises = calendars.map(async (calendar: any) => { const eventsRes = await fetch( @@ -74,7 +85,7 @@ export function CalendarWidget() { // Ajouter les informations du calendrier à chaque événement return events.map((event: any) => ({ ...event, - calendarName: calendar.name, + calendarName: getCalendarDisplayName(calendar), calendarColor: calendar.color, })); }); diff --git a/components/calendar.tsx b/components/calendar.tsx index 7fa2d5a..350b45e 100644 --- a/components/calendar.tsx +++ b/components/calendar.tsx @@ -37,6 +37,17 @@ export function Calendar() { const now = new Date(); now.setHours(0, 0, 0, 0); + // Helper function to get display name for calendar + const getCalendarDisplayName = (calendar: any) => { + // If calendar is synced to an external account, use the account name + if (calendar.syncConfig?.syncEnabled && calendar.syncConfig?.mailCredential) { + return calendar.syncConfig.mailCredential.display_name || + calendar.syncConfig.mailCredential.email; + } + // For non-synced calendars, use the calendar name + return calendar.name; + }; + // Extract and process events from all calendars const allEvents = calendarsData.flatMap((calendar: any) => (calendar.events || []).map((event: any) => ({ @@ -45,7 +56,7 @@ export function Calendar() { start: event.start, end: event.end, allDay: event.isAllDay, - calendar: calendar.name, + calendar: getCalendarDisplayName(calendar), calendarColor: calendar.color, externalEventId: event.externalEventId || null, // Add externalEventId for deduplication })) diff --git a/components/calendar/calendar-client.tsx b/components/calendar/calendar-client.tsx index c677b08..790f3f8 100644 --- a/components/calendar/calendar-client.tsx +++ b/components/calendar/calendar-client.tsx @@ -1603,7 +1603,7 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend borderColor: cal.color, textColor: '#ffffff', extendedProps: { - calendarName: cal.name, + calendarName: getCalendarDisplayName(cal as CalendarWithMission), location: event.location, description: cleanDescription(event.description), calendarId: event.calendarId, diff --git a/components/calendar/calendar-widget.tsx b/components/calendar/calendar-widget.tsx index 465b2b7..deec4cc 100644 --- a/components/calendar/calendar-widget.tsx +++ b/components/calendar/calendar-widget.tsx @@ -67,9 +67,21 @@ export function CalendarWidget() { const now = new Date(); now.setHours(0, 0, 0, 0); + // Helper function to get display name for calendar + const getCalendarDisplayName = (calendar: any) => { + // If calendar is synced to an external account, use the account name + if (calendar.syncConfig?.syncEnabled && calendar.syncConfig?.mailCredential) { + return calendar.syncConfig.mailCredential.display_name || + calendar.syncConfig.mailCredential.email; + } + // For non-synced calendars, use the calendar name + return calendar.name; + }; + // Extract all events and add calendar info const allEvents = calendarsData.flatMap((calendar) => { - console.log("Calendar Widget - Processing calendar:", calendar.name, "Events:", calendar.events?.length || 0); + const displayName = getCalendarDisplayName(calendar); + console.log("Calendar Widget - Processing calendar:", displayName, "Events:", calendar.events?.length || 0); return (calendar.events || []).map((event: { id: string; title: string; start: string | Date; end: string | Date; isAllDay: boolean; calendarId: string }) => { const startDate = new Date(event.start); const endDate = new Date(event.end); @@ -81,7 +93,7 @@ export function CalendarWidget() { isAllDay: event.isAllDay, calendarId: event.calendarId, calendarColor: calendar.color, - calendarName: calendar.name + calendarName: displayName }; }); });