From 8304e3c9e96bd3b3303470cf041a14cbf82df423 Mon Sep 17 00:00:00 2001 From: alma Date: Wed, 14 Jan 2026 14:26:28 +0100 Subject: [PATCH] Agenda Sync refactor --- app/agenda/page.tsx | 24 ++++++++++++++++++++++++ components/calendar/calendar-client.tsx | 23 +++++++++++++++++------ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/app/agenda/page.tsx b/app/agenda/page.tsx index f305223..061fcb4 100644 --- a/app/agenda/page.tsx +++ b/app/agenda/page.tsx @@ -45,9 +45,21 @@ export default async function CalendarPage() { const userId = session.user.username || session.user.email || ''; // Get all calendars for the user with mission relation and sync configuration + // Exclude "Privée" calendars that are not synced (they should only exist if synced from courrier) let calendars = await prisma.calendar.findMany({ where: { userId: session?.user?.id || '', + OR: [ + // Keep calendars that are not "Privée" or "Default" + { name: { notIn: ["Privée", "Default"] } }, + // Or keep "Privée"/"Default" calendars that have sync config + { + AND: [ + { name: { in: ["Privée", "Default"] } }, + { syncConfig: { isNot: null } } + ] + } + ] }, include: { events: { @@ -169,9 +181,21 @@ export default async function CalendarPage() { } // Refresh calendars after auto-setup + // Exclude "Privée" calendars that are not synced calendars = await prisma.calendar.findMany({ where: { userId: session?.user?.id || '', + OR: [ + // Keep calendars that are not "Privée" or "Default" + { name: { notIn: ["Privée", "Default"] } }, + // Or keep "Privée"/"Default" calendars that have sync config + { + AND: [ + { name: { in: ["Privée", "Default"] } }, + { syncConfig: { isNot: null } } + ] + } + ] }, include: { events: { diff --git a/components/calendar/calendar-client.tsx b/components/calendar/calendar-client.tsx index 77793e8..6ed9ef4 100644 --- a/components/calendar/calendar-client.tsx +++ b/components/calendar/calendar-client.tsx @@ -688,9 +688,24 @@ function EventPreview({ event, calendar }: { event: Event; calendar: Calendar }) } export function CalendarClient({ initialCalendars, userId, userProfile }: CalendarClientProps) { + // Filter out "Privée" calendars that are not synced + const filterCalendars = (cals: typeof initialCalendars) => { + return cals.filter(cal => { + // Keep calendars that are synced, groups, missions, or have a different name + const isSynced = cal.syncConfig?.syncEnabled && cal.syncConfig?.mailCredential; + const isGroup = cal.name?.startsWith("Groupe:"); + const isMission = cal.name?.startsWith("Mission:"); + const isPrivateNotSynced = (cal.name === "Privée" || cal.name === "Default") && !isSynced; + + // Exclude "Privée" calendars that are not synced + return !isPrivateNotSynced; + }); + }; + // Sort calendars: synced (courrier) first, then groups, then missions const sortCalendars = (cals: typeof initialCalendars) => { - return [...cals].sort((a, b) => { + const filtered = filterCalendars(cals); + return [...filtered].sort((a, b) => { const aIsSynced = a.syncConfig?.syncEnabled && a.syncConfig?.mailCredential; const bIsSynced = b.syncConfig?.syncEnabled && b.syncConfig?.mailCredential; const aIsGroup = a.name?.startsWith("Groupe:"); @@ -1115,11 +1130,7 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend } // For non-synced calendars, use the calendar name - // Legacy default name handling - if (calendar.name === "Default" || calendar.name === "Privée") { - return "Privée"; - } - + // Don't show "Privée" for non-synced calendars - they should be filtered out return calendar.name; };