Agenda Sync refactor
This commit is contained in:
parent
b728e3e3f4
commit
8304e3c9e9
@ -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: {
|
||||
|
||||
@ -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;
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user