diff --git a/app/agenda/page.tsx b/app/agenda/page.tsx index 37ce451..e8793fb 100644 --- a/app/agenda/page.tsx +++ b/app/agenda/page.tsx @@ -44,7 +44,7 @@ export default async function CalendarPage() { const userId = session.user.username || session.user.email || ''; - // Get all calendars for the user with mission relation + // Get all calendars for the user with mission relation and sync configuration let calendars = await prisma.calendar.findMany({ where: { userId: session?.user?.id || '', @@ -59,6 +59,17 @@ export default async function CalendarPage() { include: { missionUsers: true } + }, + syncConfig: { + include: { + mailCredential: { + select: { + id: true, + email: true, + display_name: true, + } + } + } } } }); diff --git a/components/calendar/calendar-client.tsx b/components/calendar/calendar-client.tsx index 5faa345..e4180c1 100644 --- a/components/calendar/calendar-client.tsx +++ b/components/calendar/calendar-client.tsx @@ -72,6 +72,21 @@ interface CalendarWithMission extends Calendar { role: string; }>; } | null; + syncConfig?: { + id: string; + provider: string; + externalCalendarId: string | null; + externalCalendarUrl: string | null; + syncEnabled: boolean; + lastSyncAt: Date | null; + syncFrequency: number; + lastSyncError: string | null; + mailCredential?: { + id: string; + email: string; + display_name: string | null; + } | null; + } | null; } interface CalendarClientProps { @@ -827,6 +842,23 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend } }; + const getCalendarDisplayName = (calendar: CalendarWithMission) => { + // If calendar is synced to an external account, show the account label + if (calendar.syncConfig && calendar.syncConfig.mailCredential) { + const accountLabel = + calendar.syncConfig.mailCredential.display_name || + calendar.syncConfig.mailCredential.email; + return accountLabel || (calendar.name === "Default" ? "Privée" : calendar.name); + } + + // Legacy default name + if (calendar.name === "Default") { + return "Privée"; + } + + return calendar.name; + }; + // Update CalendarSelector to handle visibility - displayed as a left column const CalendarSelector = () => (