clean pages 2
This commit is contained in:
parent
2709ba645d
commit
f18000c050
@ -1,116 +1,23 @@
|
||||
import { getServerSession } from "next-auth/next";
|
||||
import { authOptions } from "@/app/api/auth/[...nextauth]/route";
|
||||
import { redirect } from "next/navigation";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { CalendarClient } from "@/components/calendar/calendar-client";
|
||||
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';
|
||||
import { ResponsiveIframe } from "@/app/components/responsive-iframe";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Enkun - Calendrier | Gestion d'événements professionnelle",
|
||||
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 Page() {
|
||||
const session = await getServerSession(authOptions);
|
||||
|
||||
if (!session?.user) {
|
||||
redirect("/api/auth/signin");
|
||||
if (!session) {
|
||||
redirect("/signin");
|
||||
}
|
||||
|
||||
const userId = session.user.username || session.user.email || '';
|
||||
|
||||
// Get all calendars for the user
|
||||
let calendars = await prisma.calendar.findMany({
|
||||
where: {
|
||||
userId: session?.user?.id || '',
|
||||
},
|
||||
include: {
|
||||
events: {
|
||||
orderBy: {
|
||||
start: 'asc'
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// If no calendars exist, create default ones
|
||||
if (calendars.length === 0) {
|
||||
const defaultCalendars = [
|
||||
{
|
||||
name: "Default",
|
||||
color: "#4F46E5",
|
||||
description: "Your default calendar"
|
||||
}
|
||||
];
|
||||
|
||||
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 (
|
||||
<div className="container mx-auto py-10">
|
||||
<CalendarClient
|
||||
initialCalendars={calendars}
|
||||
userId={session.user.id}
|
||||
/>
|
||||
</div>
|
||||
<main className="w-full h-screen bg-black">
|
||||
<div className="w-full h-full px-4 pt-12 pb-4">
|
||||
<ResponsiveIframe
|
||||
src={process.env.NEXT_PUBLIC_IFRAME_CALENDAR_URL || ''}
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
||||
/>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ interface MenuItem {
|
||||
href: string;
|
||||
iframe?: string;
|
||||
external?: boolean;
|
||||
requiredRole?: string;
|
||||
requiredRole?: string | string[];
|
||||
}
|
||||
|
||||
export function Sidebar({ isOpen, onClose }: SidebarProps) {
|
||||
@ -49,7 +49,7 @@ export function Sidebar({ isOpen, onClose }: SidebarProps) {
|
||||
const pathname = usePathname();
|
||||
|
||||
// Function to check if user has a specific role
|
||||
const hasRole = (requiredRole: string) => {
|
||||
const hasRole = (requiredRole: string | string[]) => {
|
||||
if (!session?.user?.role) return false;
|
||||
const userRoles = Array.isArray(session.user.role) ? session.user.role : [session.user.role];
|
||||
|
||||
@ -57,8 +57,14 @@ export function Sidebar({ isOpen, onClose }: SidebarProps) {
|
||||
console.log('User roles:', userRoles);
|
||||
console.log('Required role:', requiredRole);
|
||||
|
||||
if (Array.isArray(requiredRole)) {
|
||||
return userRoles.some(role => {
|
||||
const cleanRole = role.replace('ROLE_', '');
|
||||
return requiredRole.includes(cleanRole) || cleanRole === 'Admin';
|
||||
});
|
||||
}
|
||||
|
||||
return userRoles.some(role => {
|
||||
// Remove ROLE_ prefix if it exists
|
||||
const cleanRole = role.replace('ROLE_', '');
|
||||
return cleanRole === requiredRole || cleanRole === 'Admin';
|
||||
});
|
||||
@ -110,7 +116,8 @@ export function Sidebar({ isOpen, onClose }: SidebarProps) {
|
||||
{
|
||||
title: "Calendrier",
|
||||
icon: Calendar,
|
||||
href: "/calendar"
|
||||
href: "/calendar",
|
||||
iframe: process.env.NEXT_PUBLIC_IFRAME_CALENDAR_URL,
|
||||
},
|
||||
];
|
||||
|
||||
@ -128,7 +135,7 @@ export function Sidebar({ isOpen, onClose }: SidebarProps) {
|
||||
icon: GitFork,
|
||||
href: "/gite",
|
||||
iframe: process.env.NEXT_PUBLIC_IFRAME_GITE_URL,
|
||||
requiredRole: "Coding",
|
||||
requiredRole: ["Coding", "DataIntelligence"],
|
||||
},
|
||||
{
|
||||
title: "Calculation",
|
||||
@ -142,7 +149,7 @@ export function Sidebar({ isOpen, onClose }: SidebarProps) {
|
||||
icon: Building2,
|
||||
href: "/crm",
|
||||
iframe: process.env.NEXT_PUBLIC_IFRAME_MEDIATIONS_URL,
|
||||
requiredRole: "Mediation",
|
||||
requiredRole: ["Mediation", "Expression"],
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user