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 || '';
|
const userId = session.user.username || session.user.email || '';
|
||||||
|
|
||||||
// Get all calendars for the user with mission relation and sync configuration
|
// 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({
|
let calendars = await prisma.calendar.findMany({
|
||||||
where: {
|
where: {
|
||||||
userId: session?.user?.id || '',
|
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: {
|
include: {
|
||||||
events: {
|
events: {
|
||||||
@ -169,9 +181,21 @@ export default async function CalendarPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Refresh calendars after auto-setup
|
// Refresh calendars after auto-setup
|
||||||
|
// Exclude "Privée" calendars that are not synced
|
||||||
calendars = await prisma.calendar.findMany({
|
calendars = await prisma.calendar.findMany({
|
||||||
where: {
|
where: {
|
||||||
userId: session?.user?.id || '',
|
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: {
|
include: {
|
||||||
events: {
|
events: {
|
||||||
|
|||||||
@ -688,9 +688,24 @@ function EventPreview({ event, calendar }: { event: Event; calendar: Calendar })
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function CalendarClient({ initialCalendars, userId, userProfile }: CalendarClientProps) {
|
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
|
// Sort calendars: synced (courrier) first, then groups, then missions
|
||||||
const sortCalendars = (cals: typeof initialCalendars) => {
|
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 aIsSynced = a.syncConfig?.syncEnabled && a.syncConfig?.mailCredential;
|
||||||
const bIsSynced = b.syncConfig?.syncEnabled && b.syncConfig?.mailCredential;
|
const bIsSynced = b.syncConfig?.syncEnabled && b.syncConfig?.mailCredential;
|
||||||
const aIsGroup = a.name?.startsWith("Groupe:");
|
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
|
// For non-synced calendars, use the calendar name
|
||||||
// Legacy default name handling
|
// Don't show "Privée" for non-synced calendars - they should be filtered out
|
||||||
if (calendar.name === "Default" || calendar.name === "Privée") {
|
|
||||||
return "Privée";
|
|
||||||
}
|
|
||||||
|
|
||||||
return calendar.name;
|
return calendar.name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user