Agenda refactor
This commit is contained in:
parent
5a4e746bf4
commit
ac4617a874
@ -232,60 +232,61 @@ export default async function CalendarPage() {
|
||||
data: { syncEnabled: true }
|
||||
});
|
||||
} else {
|
||||
// Try to discover calendars to verify if credentials are now valid
|
||||
// But if discovery fails and we have an existing URL, re-enable sync anyway
|
||||
// The existing URL might still work even if discovery fails
|
||||
try {
|
||||
const { discoverInfomaniakCalendars } = await import('@/lib/services/caldav-sync');
|
||||
const externalCalendars = await discoverInfomaniakCalendars(
|
||||
account.email,
|
||||
account.password!
|
||||
);
|
||||
|
||||
if (externalCalendars.length > 0) {
|
||||
// Credentials are now valid, re-enable sync with discovered calendar
|
||||
await prisma.calendarSync.update({
|
||||
where: { id: existingSync.id },
|
||||
data: {
|
||||
syncEnabled: true,
|
||||
lastSyncError: null,
|
||||
externalCalendarId: externalCalendars[0].id,
|
||||
externalCalendarUrl: externalCalendars[0].url
|
||||
}
|
||||
});
|
||||
} else if (existingSync.externalCalendarUrl) {
|
||||
// Discovery succeeded but no calendars found, but we have an existing URL
|
||||
// Re-enable sync with existing URL - it might still work
|
||||
await prisma.calendarSync.update({
|
||||
where: { id: existingSync.id },
|
||||
data: {
|
||||
syncEnabled: true,
|
||||
lastSyncError: 'Aucun calendrier trouvé lors de la découverte, utilisation de l\'URL existante'
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
// Discovery failed, but if we have an existing URL, re-enable sync anyway
|
||||
// The existing URL might still work even if discovery fails (e.g., due to network issues)
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
||||
|
||||
if (existingSync.externalCalendarUrl) {
|
||||
// We have an existing URL, re-enable sync - it worked before, might still work
|
||||
await prisma.calendarSync.update({
|
||||
where: { id: existingSync.id },
|
||||
data: {
|
||||
syncEnabled: true,
|
||||
lastSyncError: `Découverte CalDAV échouée (${errorMessage}), mais réactivation du sync avec l'URL existante`
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// No existing URL, keep sync disabled
|
||||
await prisma.calendarSync.update({
|
||||
where: { id: existingSync.id },
|
||||
data: {
|
||||
lastSyncError: `Identifiants invalides ou expirés (${errorMessage}). Veuillez vérifier vos identifiants Infomaniak dans la page courrier.`
|
||||
}
|
||||
});
|
||||
// Try to discover calendars to verify if credentials are now valid
|
||||
// But if discovery fails and we have an existing URL, re-enable sync anyway
|
||||
// The existing URL might still work even if discovery fails
|
||||
try {
|
||||
const { discoverInfomaniakCalendars } = await import('@/lib/services/caldav-sync');
|
||||
const externalCalendars = await discoverInfomaniakCalendars(
|
||||
account.email,
|
||||
account.password!
|
||||
);
|
||||
|
||||
if (externalCalendars.length > 0) {
|
||||
// Credentials are now valid, re-enable sync with discovered calendar
|
||||
await prisma.calendarSync.update({
|
||||
where: { id: existingSync.id },
|
||||
data: {
|
||||
syncEnabled: true,
|
||||
lastSyncError: null,
|
||||
externalCalendarId: externalCalendars[0].id,
|
||||
externalCalendarUrl: externalCalendars[0].url
|
||||
}
|
||||
});
|
||||
} else if (existingSync.externalCalendarUrl) {
|
||||
// Discovery succeeded but no calendars found, but we have an existing URL
|
||||
// Re-enable sync with existing URL - it might still work
|
||||
await prisma.calendarSync.update({
|
||||
where: { id: existingSync.id },
|
||||
data: {
|
||||
syncEnabled: true,
|
||||
lastSyncError: 'Aucun calendrier trouvé lors de la découverte, utilisation de l\'URL existante'
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
// Discovery failed, but if we have an existing URL, re-enable sync anyway
|
||||
// The existing URL might still work even if discovery fails (e.g., due to network issues)
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
||||
|
||||
if (existingSync.externalCalendarUrl) {
|
||||
// We have an existing URL, re-enable sync - it worked before, might still work
|
||||
await prisma.calendarSync.update({
|
||||
where: { id: existingSync.id },
|
||||
data: {
|
||||
syncEnabled: true,
|
||||
lastSyncError: `Découverte CalDAV échouée (${errorMessage}), mais réactivation du sync avec l'URL existante`
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// No existing URL, keep sync disabled
|
||||
await prisma.calendarSync.update({
|
||||
where: { id: existingSync.id },
|
||||
data: {
|
||||
lastSyncError: `Identifiants invalides ou expirés (${errorMessage}). Veuillez vérifier vos identifiants Infomaniak dans la page courrier.`
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user