From f18000c0508b4e154a30fa42024766d80f19b297 Mon Sep 17 00:00:00 2001 From: alma Date: Thu, 17 Apr 2025 16:52:15 +0200 Subject: [PATCH] clean pages 2 --- app/calendar/page.tsx | 117 +++++------------------------------------ components/sidebar.tsx | 19 ++++--- 2 files changed, 25 insertions(+), 111 deletions(-) diff --git a/app/calendar/page.tsx b/app/calendar/page.tsx index c876b973..25ef6171 100644 --- a/app/calendar/page.tsx +++ b/app/calendar/page.tsx @@ -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 ( -
- -
+
+
+ +
+
); } diff --git a/components/sidebar.tsx b/components/sidebar.tsx index 09950de9..9a909500 100644 --- a/components/sidebar.tsx +++ b/components/sidebar.tsx @@ -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"], }, ];