calendar 7
This commit is contained in:
parent
1317a36665
commit
f6b451a388
@ -4,12 +4,37 @@ import { redirect } from "next/navigation";
|
|||||||
import { prisma } from "@/lib/prisma";
|
import { prisma } from "@/lib/prisma";
|
||||||
import { CalendarClient } from "@/components/calendar/calendar-client";
|
import { CalendarClient } from "@/components/calendar/calendar-client";
|
||||||
import { Metadata } from "next";
|
import { Metadata } from "next";
|
||||||
|
import { CalendarDays, Users, Bookmark, Clock } from "lucide-react";
|
||||||
|
import Image from "next/image";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { add } from 'date-fns';
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "Enkun - Calendrier",
|
title: "Enkun - Calendrier | Gestion d'événements professionnelle",
|
||||||
description: "Gérez vos rendez-vous et événements",
|
description: "Plateforme avancée pour la gestion de vos rendez-vous, réunions et événements professionnels",
|
||||||
|
keywords: "calendrier, rendez-vous, événements, gestion du temps, enkun",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface Event {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
description?: string | null;
|
||||||
|
start: Date;
|
||||||
|
end: Date;
|
||||||
|
location?: string | null;
|
||||||
|
isAllDay: boolean;
|
||||||
|
type?: string;
|
||||||
|
attendees?: { id: string; name: string }[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Calendar {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
color: string;
|
||||||
|
description?: string | null;
|
||||||
|
events: Event[];
|
||||||
|
}
|
||||||
|
|
||||||
export default async function CalendarPage() {
|
export default async function CalendarPage() {
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
|
|
||||||
@ -18,11 +43,11 @@ export default async function CalendarPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const userId = session.user.username || session.user.email || '';
|
const userId = session.user.username || session.user.email || '';
|
||||||
|
|
||||||
// Get user's calendars
|
// Get all calendars for the user
|
||||||
const userCalendars = await prisma.calendar.findMany({
|
let calendars = await prisma.calendar.findMany({
|
||||||
where: {
|
where: {
|
||||||
userId: userId,
|
userId: session?.user?.id || '',
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
events: {
|
events: {
|
||||||
@ -30,43 +55,62 @@ export default async function CalendarPage() {
|
|||||||
start: 'asc'
|
start: 'asc'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
orderBy: {
|
|
||||||
createdAt: "desc",
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create default calendar if none exists
|
// If no calendars exist, create default ones
|
||||||
let calendars = userCalendars;
|
|
||||||
if (calendars.length === 0) {
|
if (calendars.length === 0) {
|
||||||
const defaultCalendar = await prisma.calendar.create({
|
const defaultCalendars = [
|
||||||
data: {
|
{
|
||||||
name: "Calendrier principal",
|
name: "Default",
|
||||||
color: "#0082c9",
|
color: "#4F46E5",
|
||||||
description: "Calendrier par défaut",
|
description: "Your default calendar"
|
||||||
userId: userId,
|
|
||||||
},
|
|
||||||
include: {
|
|
||||||
events: true
|
|
||||||
}
|
}
|
||||||
});
|
];
|
||||||
calendars = [defaultCalendar];
|
|
||||||
|
calendars = await Promise.all(
|
||||||
|
defaultCalendars.map(async (cal) => {
|
||||||
|
return prisma.calendar.create({
|
||||||
|
data: {
|
||||||
|
...cal,
|
||||||
|
userId: session?.user?.id || '',
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
events: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const now = new Date();
|
||||||
|
const nextWeek = add(now, { days: 7 });
|
||||||
|
|
||||||
|
const upcomingEvents = calendars.flatMap(cal =>
|
||||||
|
cal.events.filter(event =>
|
||||||
|
new Date(event.start) >= now &&
|
||||||
|
new Date(event.start) <= nextWeek
|
||||||
|
)
|
||||||
|
).sort((a, b) => new Date(a.start).getTime() - new Date(b.start).getTime());
|
||||||
|
|
||||||
|
// Calculate statistics
|
||||||
|
const totalEvents = calendars.flatMap(cal => cal.events).length;
|
||||||
|
|
||||||
|
const totalMeetingHours = calendars
|
||||||
|
.flatMap(cal => cal.events)
|
||||||
|
.reduce((total, event) => {
|
||||||
|
const start = new Date(event.start);
|
||||||
|
const end = new Date(event.end);
|
||||||
|
const hours = (end.getTime() - start.getTime()) / (1000 * 60 * 60);
|
||||||
|
return total + (isNaN(hours) ? 0 : hours);
|
||||||
|
}, 0);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='container mx-auto py-8'>
|
<div className="container mx-auto py-10">
|
||||||
<div className='mb-6'>
|
<CalendarClient
|
||||||
<h1 className='text-3xl font-bold'>Calendrier</h1>
|
initialCalendars={calendars}
|
||||||
<p className='text-muted-foreground'>
|
userId={session.user.id}
|
||||||
Gérez vos rendez-vous et événements
|
/>
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div className="bg-white rounded-lg shadow">
|
|
||||||
<CalendarClient
|
|
||||||
initialCalendars={calendars}
|
|
||||||
userId={userId}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user