"use client"; import type React from "react"; import { useState } from "react"; import { cn } from "@/lib/utils"; import { BookOpen, Share2, Palette, GitFork, Building2, Calendar, Target, Mail, HardDrive, GraduationCap, MessageSquare, FileText, Calculator, Users, Kanban, ChevronLeft, ChevronRight, } from "lucide-react"; import { Button } from "@/components/ui/button"; import { ScrollArea } from "@/components/ui/scroll-area"; import { useRouter, usePathname } from "next/navigation"; import Link from "next/link"; import Image from "next/image"; import { useSession } from "next-auth/react"; interface SidebarProps { isOpen: boolean; onClose: () => void; } interface MenuItem { title: string; icon: any; href: string; iframe?: string; external?: boolean; requiredRole?: string; } export function Sidebar({ isOpen, onClose }: SidebarProps) { const { data: session } = useSession(); const router = useRouter(); const pathname = usePathname(); // Function to check if user has a specific role const hasRole = (requiredRole: string) => { if (!session?.user?.role) return false; const userRoles = Array.isArray(session.user.role) ? session.user.role : [session.user.role]; // Add console.log to debug roles console.log('User roles:', userRoles); console.log('Required role:', requiredRole); return userRoles.some(role => { // Remove ROLE_ prefix if it exists const cleanRole = role.replace('ROLE_', ''); return cleanRole === requiredRole || cleanRole === 'Admin'; }); }; // Base menu items (available for everyone) const baseMenuItems: MenuItem[] = [ { title: "Diary", icon: BookOpen, href: "/diary", iframe: process.env.NEXT_PUBLIC_IFRAME_DIARY_URL, }, { title: "Calendar", icon: Calendar, href: "/calendar", external: false, }, { title: "Email", icon: Mail, href: "/email", iframe: process.env.NEXT_PUBLIC_IFRAME_MAIL_URL, }, { title: "Drive", icon: HardDrive, href: "/drive", iframe: process.env.NEXT_PUBLIC_IFRAME_DRIVE_URL, }, { title: "Contacts", icon: Users, href: "/contacts", iframe: process.env.NEXT_PUBLIC_IFRAME_CONTACTS_URL, }, { title: "Learn", icon: GraduationCap, href: "/learn", iframe: process.env.NEXT_PUBLIC_IFRAME_LEARN_URL, }, { title: "Parole", icon: MessageSquare, href: "/parole", iframe: process.env.NEXT_PUBLIC_IFRAME_PAROLE_URL, }, { title: "MissionsBoard", icon: Kanban, href: "/missions-board", iframe: process.env.NEXT_PUBLIC_IFRAME_MISSIONSBOARD_URL, }, { title: "Chapter", icon: FileText, href: "/chapter", iframe: process.env.NEXT_PUBLIC_IFRAME_CHAPTER_URL, }, { title: "Agility", icon: Share2, href: "/flow", iframe: process.env.NEXT_PUBLIC_IFRAME_AGILITY_URL, }, ]; // Role-specific menu items const roleSpecificItems: MenuItem[] = [ { title: "Artlab", icon: Palette, href: "/design", iframe: process.env.NEXT_PUBLIC_IFRAME_ARTLAB_URL, requiredRole: "Expression", }, { title: "Gite", icon: GitFork, href: "/gite", iframe: process.env.NEXT_PUBLIC_IFRAME_GITE_URL, requiredRole: "Coding", }, { title: "Calculation", icon: Calculator, href: "/calculation", iframe: process.env.NEXT_PUBLIC_IFRAME_CALCULATION_URL, requiredRole: "DataIntelligence", }, { title: "Mediations", icon: Building2, href: "/crm", iframe: process.env.NEXT_PUBLIC_IFRAME_MEDIATIONS_URL, requiredRole: "Mediation", }, ]; // Combine base items with role-specific items based on user roles const visibleMenuItems = [ ...baseMenuItems, ...roleSpecificItems.filter(item => hasRole(item.requiredRole)) ]; const handleNavigation = (href: string, external?: boolean) => { if (external && href) { window.open(href, "_blank"); } else { router.push(href); } onClose(); }; return ( <> {/* Backdrop */} {isOpen && (
)} {/* Sidebar */}
{/* Hide Button */} {/* Logo */}
Neah Logo
{/* Menu Items */}
{visibleMenuItems.map((item) => ( ))}
); }