From 3de29f94e17a06abe30bd92e1b398bc3630c12c8 Mon Sep 17 00:00:00 2001 From: alma Date: Wed, 14 Jan 2026 14:02:54 +0100 Subject: [PATCH] Agenda Sync refactor --- app/agenda/page.tsx | 13 ++++- components/calendar/calendar-client.tsx | 76 +++++++++++++++++++++---- 2 files changed, 78 insertions(+), 11 deletions(-) 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 = () => (
@@ -847,7 +879,14 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend className="w-3 h-3 rounded-full" style={{ backgroundColor: calendar.color }} /> - {calendar.name === "Default" ? "Privée" : calendar.name} + + {getCalendarDisplayName(calendar as CalendarWithMission)} + {calendar.syncConfig?.syncEnabled && ( + + Sync + + )} +
{visibleCalendarIds.includes(calendar.id) ? ( @@ -951,14 +990,23 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
{/* Display selected calendar name */} {(() => { - const selectedCal = calendars.find(cal => visibleCalendarIds.includes(cal.id) && visibleCalendarIds.length === 1); - const displayName = selectedCal - ? (selectedCal.name === "Default" ? "Privée" : selectedCal.name) + const selectedCal = calendars.find( + cal => visibleCalendarIds.includes(cal.id) && visibleCalendarIds.length === 1 + ) as CalendarWithMission | undefined; + const displayName = selectedCal + ? getCalendarDisplayName(selectedCal) : "Tous les calendriers"; return ( -

- {displayName} -

+
+

+ {displayName} +

+ {selectedCal?.syncConfig?.syncEnabled && ( + + Synchronisé + + )} +
); })()} {(() => { @@ -1275,7 +1323,10 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
- {calendars.map((cal) => ( + {calendars.map((cal) => { + const calWithMission = cal as CalendarWithMission; + const label = getCalendarDisplayName(calWithMission); + return ( - ))} + );})}