File size: 5,817 Bytes
d1a980e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
"use client";

import Link from "next/link";
import { usePathname } from "next/navigation";
import {
    LayoutDashboard,
    ListTodo,
    Timer,
    CalendarDays,
    Users,
    Settings,
    LogOut,
    Coffee,
    ClipboardCheck,
    Activity
} from "lucide-react";
import { signOut, useSession } from "next-auth/react";

const menuItems = [
    { name: "Dashboard", href: "/dashboard", icon: LayoutDashboard },
    { name: "Sprints", href: "/sprints", icon: Timer },
    { name: "Tasks", href: "/tasks", icon: ListTodo },
    { name: "Timesheets", href: "/timesheets", icon: CalendarDays },
    { name: "Daily Scrum", href: "/scrum", icon: Coffee },
];

const adminItems = [
    { name: "User Management", href: "/admin/users", icon: Users },
    { name: "Attendance", href: "/admin/attendance", icon: ClipboardCheck },
    { name: "Activity Log", href: "/admin/activity", icon: Activity }, // Activity Log Access
    { name: "Settings", href: "/admin/settings", icon: Settings },
];

export default function Sidebar() {
    const pathname = usePathname();
    const { data: session } = useSession();

    // Allow admin access if role is ADMIN
    const isAdmin = session?.user?.role === "ADMIN";

    return (
        <aside className="fixed left-0 top-0 h-full w-64 bg-[hsl(var(--card))] border-r border-[hsl(var(--border))] flex flex-col z-50">

            <div className="p-6 flex items-center gap-3 border-b border-[hsl(var(--border))]">

                <div className="w-8 h-8 rounded-lg bg-[hsl(var(--primary))] flex items-center justify-center">

                    <span className="text-white font-bold">TM</span>

                </div>

                <span className="font-bold text-lg tracking-tight">TaskManager</span>

            </div>



            <nav className="flex-1 overflow-y-auto py-6 px-3 space-y-1">

                <div className="text-xs font-semibold text-[hsl(var(--muted-foreground))] uppercase tracking-wider mb-2 px-3">

                    Overview

                </div>

                {menuItems.map((item) => {

                    const isActive = pathname.startsWith(item.href);

                    return (

                        <Link

                            key={item.href}

                            href={item.href}

                            className={`flex items-center gap-3 px-3 py-2.5 rounded-md transition-all duration-200 group ${isActive

                                ? "bg-[hsl(var(--primary)/0.1)] text-[hsl(var(--primary))]"

                                : "text-[hsl(var(--muted-foreground))] hover:bg-[hsl(var(--muted))]/50 hover:text-[hsl(var(--foreground))]"

                                }`}

                        >

                            <item.icon className="w-5 h-5" />

                            <span className="font-medium text-sm">{item.name}</span>

                        </Link>

                    );

                })}



                {isAdmin && (

                    <>

                        <div className="mt-8 mb-2 px-3 text-xs font-semibold text-[hsl(var(--muted-foreground))] uppercase tracking-wider">

                            Administration

                        </div>

                        {adminItems.map((item) => {

                            const isActive = pathname.startsWith(item.href);

                            return (

                                <Link

                                    key={item.href}

                                    href={item.href}

                                    className={`flex items-center gap-3 px-3 py-2.5 rounded-md transition-all duration-200 ${isActive

                                        ? "bg-[hsl(var(--primary)/0.1)] text-[hsl(var(--primary))]"

                                        : "text-[hsl(var(--muted-foreground))] hover:bg-[hsl(var(--muted))]/50 hover:text-[hsl(var(--foreground))]"

                                        }`}

                                >

                                    <item.icon className="w-5 h-5" />

                                    <span className="font-medium text-sm">{item.name}</span>

                                </Link>

                            );

                        })}

                    </>

                )}

            </nav>

            <div className="p-4 border-t border-[hsl(var(--border))]">

                <Link href="/settings/profile" className="flex items-center gap-3 mb-4 px-2 hover:bg-[hsl(var(--muted)/0.5)] p-2 rounded-md transition-colors cursor-pointer group">

                    <div className="w-8 h-8 rounded-full bg-[hsl(var(--muted))] flex items-center justify-center text-xs font-bold group-hover:bg-[hsl(var(--primary)/0.2)] group-hover:text-[hsl(var(--primary))] transition-colors">

                        {session?.user?.name?.[0] || "U"}

                    </div>

                    <div className="flex-1 min-w-0">

                        <p className="text-sm font-medium truncate group-hover:text-[hsl(var(--primary))]">{session?.user?.name || "Guest"}</p>

                        <p className="text-xs text-[hsl(var(--muted-foreground))] truncate">{session?.user?.email}</p>

                    </div>

                </Link>

                <button

                    onClick={() => signOut()}

                    className="w-full flex items-center justify-center gap-2 px-3 py-2 rounded-md text-sm font-medium text-[hsl(var(--destructive-foreground))] bg-[hsl(var(--destructive))] hover:bg-[hsl(var(--destructive)/0.9)] transition-colors"

                >

                    <LogOut className="w-4 h-4" />

                    Sign Out

                </button>

            </div>
        </aside>
    );
}