Agenda refactor
This commit is contained in:
parent
d8846524f0
commit
9d5a8d6d2f
@ -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,
|
||||
}));
|
||||
});
|
||||
|
||||
@ -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
|
||||
}))
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user