Agenda refactor

This commit is contained in:
alma 2026-01-14 17:13:59 +01:00
parent 39fd43f995
commit 5d90bc6989

View File

@ -459,13 +459,15 @@ export default async function CalendarPage() {
// Refresh calendars after auto-setup and cleanup
// Exclude "Privée" and "Default" calendars that are not synced
// IMPORTANT: Include all "Privée"/"Default" calendars that have ANY syncConfig (enabled or disabled)
// We'll filter by syncEnabled later
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 active sync config
// Or keep "Privée"/"Default" calendars that have ANY sync config (we'll filter by enabled later)
{
AND: [
{ name: { in: ["Privée", "Default"] } },
@ -505,6 +507,14 @@ export default async function CalendarPage() {
// No default calendar creation - only synced calendars from courrier
// Debug: Log calendars before filtering
console.log(`[AGENDA] Calendars before filtering: ${calendars.length}`);
const infomaniakBeforeFilter = calendars.filter(cal => cal.syncConfig?.provider === 'infomaniak');
console.log(`[AGENDA] Infomaniak calendars before filtering: ${infomaniakBeforeFilter.length}`);
infomaniakBeforeFilter.forEach(cal => {
console.log(`[AGENDA] Before filter - Calendar: ${cal.name}, id: ${cal.id}, syncEnabled: ${cal.syncConfig?.syncEnabled}, hasMailCredential: ${!!cal.syncConfig?.mailCredential}`);
});
// Filter out "Privée" and "Default" calendars that don't have active sync
calendars = calendars.filter(cal => {
const isPrivateOrDefault = cal.name === "Privée" || cal.name === "Default";
@ -529,6 +539,13 @@ export default async function CalendarPage() {
// Log final count of Infomaniak calendars
const infomaniakCalendars = calendars.filter(cal => cal.syncConfig?.provider === 'infomaniak');
console.log(`[AGENDA] Final Infomaniak calendars count: ${infomaniakCalendars.length}`);
// Debug: Log all calendars with syncConfig to see what we have
const calendarsWithSync = calendars.filter(cal => cal.syncConfig);
console.log(`[AGENDA] Total calendars with syncConfig: ${calendarsWithSync.length}`);
calendarsWithSync.forEach(cal => {
console.log(`[AGENDA] Calendar: ${cal.name}, provider: ${cal.syncConfig?.provider}, syncEnabled: ${cal.syncConfig?.syncEnabled}, hasMailCredential: ${!!cal.syncConfig?.mailCredential}`);
});
const now = new Date();
const nextWeek = add(now, { days: 7 });