Agenda Sync refactor
This commit is contained in:
parent
8304e3c9e9
commit
bf36a05eb6
@ -45,18 +45,23 @@ 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)
|
// Exclude "Privée" and "Default" 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: [
|
OR: [
|
||||||
// Keep calendars that are not "Privée" or "Default"
|
// Keep calendars that are not "Privée" or "Default"
|
||||||
{ name: { notIn: ["Privée", "Default"] } },
|
{ name: { notIn: ["Privée", "Default"] } },
|
||||||
// Or keep "Privée"/"Default" calendars that have sync config
|
// Or keep "Privée"/"Default" calendars that have active sync config
|
||||||
{
|
{
|
||||||
AND: [
|
AND: [
|
||||||
{ name: { in: ["Privée", "Default"] } },
|
{ name: { in: ["Privée", "Default"] } },
|
||||||
{ syncConfig: { isNot: null } }
|
{
|
||||||
|
syncConfig: {
|
||||||
|
isNot: null,
|
||||||
|
syncEnabled: true
|
||||||
|
}
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -181,18 +186,23 @@ export default async function CalendarPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Refresh calendars after auto-setup
|
// Refresh calendars after auto-setup
|
||||||
// Exclude "Privée" calendars that are not synced
|
// Exclude "Privée" and "Default" 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: [
|
OR: [
|
||||||
// Keep calendars that are not "Privée" or "Default"
|
// Keep calendars that are not "Privée" or "Default"
|
||||||
{ name: { notIn: ["Privée", "Default"] } },
|
{ name: { notIn: ["Privée", "Default"] } },
|
||||||
// Or keep "Privée"/"Default" calendars that have sync config
|
// Or keep "Privée"/"Default" calendars that have active sync config
|
||||||
{
|
{
|
||||||
AND: [
|
AND: [
|
||||||
{ name: { in: ["Privée", "Default"] } },
|
{ name: { in: ["Privée", "Default"] } },
|
||||||
{ syncConfig: { isNot: null } }
|
{
|
||||||
|
syncConfig: {
|
||||||
|
isNot: null,
|
||||||
|
syncEnabled: true
|
||||||
|
}
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@ -688,16 +688,17 @@ 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
|
// Filter out "Privée" and "Default" calendars that are not synced
|
||||||
const filterCalendars = (cals: typeof initialCalendars) => {
|
const filterCalendars = (cals: typeof initialCalendars) => {
|
||||||
return cals.filter(cal => {
|
return cals.filter(cal => {
|
||||||
// Keep calendars that are synced, groups, missions, or have a different name
|
// Keep calendars that are synced, groups, missions, or have a different name
|
||||||
const isSynced = cal.syncConfig?.syncEnabled && cal.syncConfig?.mailCredential;
|
const isSynced = cal.syncConfig?.syncEnabled && cal.syncConfig?.mailCredential;
|
||||||
const isGroup = cal.name?.startsWith("Groupe:");
|
const isGroup = cal.name?.startsWith("Groupe:");
|
||||||
const isMission = cal.name?.startsWith("Mission:");
|
const isMission = cal.name?.startsWith("Mission:");
|
||||||
const isPrivateNotSynced = (cal.name === "Privée" || cal.name === "Default") && !isSynced;
|
const isPrivateOrDefault = cal.name === "Privée" || cal.name === "Default";
|
||||||
|
const isPrivateNotSynced = isPrivateOrDefault && !isSynced;
|
||||||
|
|
||||||
// Exclude "Privée" calendars that are not synced
|
// Exclude "Privée" and "Default" calendars that are not synced
|
||||||
return !isPrivateNotSynced;
|
return !isPrivateNotSynced;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user