Spaces:
Sleeping
Sleeping
File size: 43,606 Bytes
d97b8f9 | 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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 | import React, { useEffect, useState } from "react";
import { cn } from "@/lib/utils";
import { NavLink, useLocation } from "react-router-dom";
import { getVersionString } from "@/lib/version";
import {
BarChart3,
Briefcase,
Calendar,
CheckSquare,
Clipboard,
ClipboardCheck,
Grid3x3,
Layers,
LayoutDashboard,
MessageSquare,
Settings,
Users,
ShieldCheck,
Package,
Clock,
Key,
Shield,
Bell,
FileText,
Link,
FolderOpen,
Loader2,
CalendarRange,
CalendarClock,
Bug,
Award,
Gauge,
BadgeCheck,
ListChecks,
CalendarDays,
MessageCircle,
CalendarCheck,
BookOpen,
ChevronDown,
ChevronRight,
User,
Download,
ActivitySquare,
Heart,
Search,
X,
CalendarPlus
} from "lucide-react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import Logo from "@/components/ui/logo";
import { Separator } from "@/components/ui/separator";
import { ScrollArea } from "@/components/ui/scroll-area";
import { useAuth } from "@/lib/auth-context";
import { roleFeatureApi } from "@/services/roleFeatureApi";
import { useIsMobile } from "@/hooks/use-mobile";
interface SidebarProps {
isOpen: boolean;
setIsOpen: (value: boolean) => void;
}
// Map of feature IDs to their respective icon components
const featureIconMap: Record<number, React.ReactNode> = {
1: <LayoutDashboard className="w-5 h-5" />, // Dashboard
2: <Briefcase className="w-5 h-5" />, // Projects
3: <Package className="w-5 h-5" />, // Deliverables
4: <Users className="w-5 h-5" />, // Teams
5: <Users className="w-5 h-5" />, // Employees
6: <ShieldCheck className="w-5 h-5" />, // Roles
7: <Key className="w-5 h-5" />, // Permissions
8: <Shield className="w-5 h-5" />, // Role Features
9: <Clipboard className="w-5 h-5" />, // Backlog
10: <Grid3x3 className="w-5 h-5" />, // Issues
11: <CheckSquare className="w-5 h-5" />, // Tasks
12: <Clock className="w-5 h-5" />, // Time Logs
13: <Calendar className="w-5 h-5" />, // Calendar
14: <BarChart3 className="w-5 h-5" />, // Reports
15: <MessageSquare className="w-5 h-5" />, // Messages
16: <Settings className="w-5 h-5" />, // Settings
17: <Bell className="w-5 h-5" />, // Notifications
18: <FileText className="w-5 h-5" />, // Audit Logs
19: <Link className="w-5 h-5" />, // Integrations
20: <FolderOpen className="w-5 h-5" />, // File Management
21: <ClipboardCheck className="w-5 h-5" />, // Attendance
22: <Calendar className="w-5 h-5" />, // Leaves
23: <CalendarRange className="w-5 h-5" />, // Leaves Admin
24: <Layers className="w-5 h-5" />, // Leave Types
25: <CheckSquare className="w-5 h-5" />, // Todos
26: <CalendarClock className="w-5 h-5" />, // Holidays
27: <Bug className="w-5 h-5" />, // Bugs & Defects
28: <Award className="w-5 h-5" />, // Appraisals
29: <Gauge className="w-5 h-5" />, // Appraisal Cycles
30: <ListChecks className="w-5 h-5" />, // Assessment Areas
31: <BadgeCheck className="w-5 h-5" />, // Competencies
32: <BarChart3 className="w-5 h-5" />, // Manager Dashboard
33: <CalendarCheck className="w-5 h-5" />, // Meeting Rooms
34: <BookOpen className="w-5 h-5" />,
35: <MessageCircle className="w-5 h-5" />, // Communications
36: <ClipboardCheck className="w-5 h-5" />, // Role Assessment Questions
37: <MessageSquare className="w-5 h-5" />, // HR Remarks
38: <MessageSquare className="w-5 h-5" />, // Management Remarks
39: <Bug className="w-5 h-5" />, // Production Bugs
40: <CheckSquare className="w-5 h-5" />, // Test Cases
41: <User className="w-5 h-5" />, // My Profile
42: <CalendarRange className="w-5 h-5" />, // Leave Balances
43: <Briefcase className="w-5 h-5" />, // Employee Projects
44: <Heart className="w-5 h-5" />, // Health Dashboard
45: <Package className="w-5 h-5" />, // Asset Management
46: <Package className="w-5 h-5" />, // System Details
47: <Package className="w-5 h-5" />, // Asset Assignments
48: <ClipboardCheck className="w-5 h-5" />, // Asset Requests (Employee)
49: <ShieldCheck className="w-5 h-5" />, // Asset Request Management (Admin)
50: <BarChart3 className="w-5 h-5" />, // Gantt Chart
51: <Users className="w-5 h-5" />, // Resource Allocation
52: <Layers className="w-5 h-5" />, // Feature Management
53: <ShieldCheck className="w-5 h-5" />, // Role Permissions
54: <CalendarDays className="w-5 h-5" />, // Work From Home
55: <CalendarPlus className="w-5 h-5" />, // Add Comp Off Request
56: <BarChart3 className="w-5 h-5" />, // PMP (Project Management Plan)
};
// Map of feature IDs to their respective paths
const featurePathMap: Record<number, string> = {
1: "/dashboard",
2: "/projects",
3: "/deliverables",
4: "/teams",
5: "/employees",
6: "/roles",
7: "/permissions",
8: "/role-features",
9: "/backlog",
10: "/issues",
11: "/tasks",
12: "/time-logs",
13: "/calendar",
14: "/reports",
15: "/messages",
16: "/settings",
17: "/notifications",
18: "/audit-logs",
19: "/integrations",
20: "/file-management",
21: "/attendance",
22: "/leaves",
23: "/leaves-admin",
24: "/leave-types",
25: "/todos",
26: "/holidays",
27: "/bugs",
28: "/appraisals/my-appraisals",
29: "/appraisals/cycles",
30: "/appraisals/assessment-areas",
31: "/appraisals/competencies",
32: "/appraisals/manager-dashboard",
33: "/meeting-room/rooms",
34: "/meeting-room/bookings",
35: "/communications",
36: "/appraisals/role-questions",
37: "/appraisals/hr-remarks",
38: "/appraisals/management-remarks",
39: "/production-bugs",
40: "/test-cases",
41: "/my-profile",
42: "/leave-balances",
43: "/employee-projects",
44: "/health-dashboard",
45: "/assets",
46: "/system-details",
47: "/asset-assignments",
48: "/asset-requests",
49: "/admin/asset-requests",
50: "/gantt-chart",
51: "/resource-allocation",
52: "/features",
53: "/role-permissions",
54: "/leaves?wfh=true",
55: "/leaves?compoff=true",
56: "/pmp",
};
// Map of feature IDs to their titles
const featureTitleMap: Record<number, string> = {
1: "Dashboard",
2: "Projects",
3: "Deliverables",
4: "Teams",
5: "Employees",
6: "Roles",
7: "Permissions",
8: "Role Features",
9: "Backlog",
10: "Features",
11: "Tasks",
12: "Time Logs",
13: "Calendar",
14: "Reports",
15: "Messages",
16: "Settings",
17: "Notifications",
18: "Audit Logs",
19: "Integrations",
20: "File Management",
21: "Attendance",
22: "My Leaves",
23: "Leaves Management",
24: "Leave Types",
25: "Todos",
26: "Holidays",
27: "Bugs",
28: "My Appraisals",
29: "Appraisal Cycles",
30: "Assessment Areas",
31: "Competencies",
32: "Manager Appraisals",
33: "Meeting Rooms",
34: "Room Bookings",
35: "Communications",
36: "Role Questions",
37: "HR Remarks",
38: "Management Remarks",
39: "Production Bugs",
40: "Test Cases",
41: "My Profile",
42: "Leave Balances",
43: "Employee Projects",
44: "System Health",
45: "Assets",
46: "System Details",
47: "Asset Assignments",
48: "My Asset Requests",
49: "Asset Request Management",
50: "Gantt Chart",
51: "Resource Allocation",
52: "Feature Management",
53: "Role Permissions",
54: "Work From Home",
55: "Add Comp Off Request",
56: "PMP",
};
// Feature categories for grouped sidebar
const featureCategories = {
dashboard: {
title: "Dashboard",
icon: <LayoutDashboard className="w-5 h-5" />,
features: [1]
},
projects: {
title: "Project Management",
icon: <Briefcase className="w-5 h-5" />,
features: [2, 3, 4, 9, 10, 50, 56]
},
tasks: {
title: "Task Management",
icon: <CheckSquare className="w-5 h-5" />,
features: [11, 12, 25]
},
bugs: {
title: "QA Management",
icon: <Bug className="w-5 h-5" />,
features: [27, 39, 40]
},
hr: {
title: "HR Management",
icon: <Users className="w-5 h-5" />,
features: [5, 21, 22, 23, 24, 26, 42, 43, 51, 54, 55]
},
appraisal: {
title: "Appraisals",
icon: <Award className="w-5 h-5" />,
features: [28, 29, 30, 31, 32, 36, 37, 38]
},
meeting: {
title: "Meetings",
icon: <CalendarCheck className="w-5 h-5" />,
features: [33, 34]
},
communication: {
title: "Communication",
icon: <MessageCircle className="w-5 h-5" />,
features: [15, 35]
},
assets: {
title: "Asset Management",
icon: <Package className="w-5 h-5" />,
features: [45, 46, 47, 48, 49]
},
admin: {
title: "Administration",
icon: <Settings className="w-5 h-5" />,
features: [6, 7, 8, 16, 17, 18, 19, 20, 44, 52, 53] // Added health dashboard, features, and role permissions to admin category
},
reports: {
title: "Reports & Analytics",
icon: <BarChart3 className="w-5 h-5" />,
features: [13, 14]
}
};
// Function to get the category for a feature
const getFeatureCategory = (featureId: number): string => {
for (const [category, details] of Object.entries(featureCategories)) {
if (details.features.includes(featureId)) {
return category;
}
}
return "other"; // Default category
};
// Type definitions for grouped navigation items
interface NavItem {
title: string;
icon: React.ReactNode;
path: string;
featureId: number;
}
interface NavGroup {
title: string;
icon: React.ReactNode;
items: NavItem[];
}
const Sidebar = ({ isOpen, setIsOpen }: SidebarProps) => {
const { userData, isAuthenticated } = useAuth();
const [navItems, setNavItems] = useState<NavItem[]>([]);
const [groupedNavItems, setGroupedNavItems] = useState<Record<string, NavGroup>>({});
const [expandedGroups, setExpandedGroups] = useState<Record<string, boolean>>({
// Default expanded groups
dashboard: true,
tasks: true,
bugs: true
});
const [isLoading, setIsLoading] = useState(true);
const [searchQuery, setSearchQuery] = useState("");
const location = useLocation();
const isMobile = useIsMobile();
// Filter nav items based on search query
const filteredGroupedNavItems = React.useMemo(() => {
if (!searchQuery.trim()) return groupedNavItems;
const query = searchQuery.toLowerCase();
const filtered: Record<string, NavGroup> = {};
Object.entries(groupedNavItems).forEach(([category, group]) => {
const filteredItems = group.items.filter(item =>
item.title.toLowerCase().includes(query)
);
if (filteredItems.length > 0) {
filtered[category] = {
...group,
items: filteredItems
};
}
});
return filtered;
}, [groupedNavItems, searchQuery]);
// Auto-expand groups when searching
useEffect(() => {
if (searchQuery.trim()) {
const newExpandedGroups: Record<string, boolean> = { ...expandedGroups };
Object.keys(filteredGroupedNavItems).forEach(category => {
newExpandedGroups[category] = true;
});
setExpandedGroups(newExpandedGroups);
}
}, [searchQuery, filteredGroupedNavItems]);
// Check if we're on the download app page
const isDownloadPage = location.pathname === "/download-app";
// Initialize expanded state for all categories
useEffect(() => {
const initialExpandedState: Record<string, boolean> = {};
const currentPath = window.location.pathname;
// Find the active item's category
let activeCategory = "";
Object.entries(featureCategories).forEach(([category, details]) => {
// First, mark all categories as collapsed
initialExpandedState[category] = false;
// Then find which category has the active item
if (details.features.some(featureId => {
const path = featurePathMap[featureId] || "";
return isNavItemActive(path);
})) {
activeCategory = category;
}
});
// Only expand the category containing the active item (and dashboard)
initialExpandedState["dashboard"] = true; // Dashboard always open
if (activeCategory) {
initialExpandedState[activeCategory] = true;
}
setExpandedGroups(initialExpandedState);
}, []);
// Monitor path changes to update expanded groups
useEffect(() => {
const handleRouteChange = () => {
const currentPath = window.location.pathname;
let activeCategory = "";
// Find which category contains the active item
Object.entries(featureCategories).forEach(([category, details]) => {
if (details.features.some(featureId => {
const path = featurePathMap[featureId] || "";
return isNavItemActive(path);
})) {
activeCategory = category;
}
});
// Update expanded state
if (activeCategory) {
setExpandedGroups(prev => ({
...prev,
[activeCategory]: true
}));
}
};
// Call once to set initial state
handleRouteChange();
// Add event listener for navigation changes
window.addEventListener('popstate', handleRouteChange);
return () => {
window.removeEventListener('popstate', handleRouteChange);
};
}, [window.location.pathname]);
// Effect to fetch role features when authentication state changes
useEffect(() => {
if (isAuthenticated) {
fetchRoleFeatures();
}
}, [isAuthenticated, userData?.roleId]);
// Toggle group expansion
const toggleGroup = (category: string) => {
setExpandedGroups(prev => ({
...prev,
[category]: !prev[category]
}));
};
const fetchRoleFeatures = async () => {
try {
setIsLoading(true);
// Admin (roleId 21) gets access to all features
if (userData?.roleId === 21) {
const allNavItems = Object.keys(featurePathMap).map(featureId => {
const id = parseInt(featureId);
return {
title: featureTitleMap[id] || "Unknown",
icon: featureIconMap[id] || <Layers className="w-5 h-5" />,
path: featurePathMap[id] || "/",
featureId: id
};
});
// Sort navigation items by feature ID
allNavItems.sort((a, b) => a.featureId - b.featureId);
setNavItems(allNavItems);
// Group the nav items by category
const grouped = groupNavItems(allNavItems);
setGroupedNavItems(grouped);
setIsLoading(false);
return;
}
// For client role, only show the Production Bugs module
if (userData?.roleName?.toLowerCase() === "client" || userData?.roleId === 7) { // Assuming 7 is the client roleId, but also check roleName
const clientNavItems = [
{
title: featureTitleMap[39] || "Production Bugs", // Production Bugs feature
icon: featureIconMap[39] || <Bug className="w-5 h-5" />,
path: featurePathMap[39] || "/production-bugs",
featureId: 39
},
// Add Dashboard as well
{
title: featureTitleMap[1] || "Dashboard",
icon: featureIconMap[1] || <LayoutDashboard className="w-5 h-5" />,
path: featurePathMap[1] || "/",
featureId: 1
}
];
setNavItems(clientNavItems);
// Group the nav items by category
const grouped = groupNavItems(clientNavItems);
setGroupedNavItems(grouped);
setIsLoading(false);
return;
}
// For other roles, fetch their specific features
if (userData?.roleId) {
const roleFeatures = await roleFeatureApi.getByRoleId(userData.roleId);
// Get unique feature IDs (a role might have multiple permissions for the same feature)
const uniqueFeatureIds = Array.from(new Set(roleFeatures.map(rf => rf.featureId)));
// Make sure we have at least the Dashboard, Issues, Leaves, and Todos
const essentialFeatures = [1, 10, 22, 25, 26, 27, 33, 34, 35, 39, 40, 42, 43, 45, 46, 47, 48, 50, 51, 54, 55, 56]; // Dashboard, Issues, Leaves, Todos, Holidays, Bugs, Meeting Rooms, Room Bookings, Communications, Production Bugs, Test Cases, Leave Balances, Employee Projects, Assets, System Details, Asset Assignments, My Asset Requests, Gantt Chart, Resource Allocation, Work From Home, Add Comp Off Request, PMP
essentialFeatures.forEach(featId => {
if (!uniqueFeatureIds.includes(featId)) {
uniqueFeatureIds.push(featId);
}
});
// Add Asset Request Management only for admin roles
const isAssetAdmin = userData.roleId === 1 || userData.roleId === 21 ||
userData.roleName?.toLowerCase() === "admin";
if (isAssetAdmin && !uniqueFeatureIds.includes(49)) {
uniqueFeatureIds.push(49); // Asset Request Management
}
// Add health dashboard only for CEO, COO, and Admin roles
// Assuming roleId 1 = CEO, roleId 2 = COO, roleId 21 = Admin
const isExecutive = userData.roleId === 1 || userData.roleId === 2 || userData.roleId === 21 ||
userData.roleName?.toLowerCase() === "ceo" ||
userData.roleName?.toLowerCase() === "coo" ||
userData.roleName?.toLowerCase() === "admin";
if (isExecutive && !uniqueFeatureIds.includes(44)) {
uniqueFeatureIds.push(44); // Health Dashboard
}
// Always include Appraisal features for HR roles (HR and HR Manager)
if (userData.roleId === 10 || userData.roleId === 11) { // Assuming roleId 10 and 11 for HR and HR Manager
const appraisalFeatures = [28, 29, 30, 31, 32, 36, 37, 38]; // My Appraisals, Cycles, Areas, Competencies, Manager Dashboard, Role Questions, HR Remarks, Management Remarks
appraisalFeatures.forEach(featId => {
if (!uniqueFeatureIds.includes(featId)) {
uniqueFeatureIds.push(featId);
}
});
} else {
// For non-HR roles, at least add My Appraisals
if (!uniqueFeatureIds.includes(28)) {
uniqueFeatureIds.push(28); // My Appraisals
}
}
// Map feature IDs to nav items
const userNavItems = uniqueFeatureIds.map(featureId => ({
title: featureTitleMap[featureId] || "Unknown",
icon: featureIconMap[featureId] || <Layers className="w-5 h-5" />,
path: featurePathMap[featureId] || "/",
featureId: featureId
}));
// Sort navigation items by featureId
userNavItems.sort((a, b) => a.featureId - b.featureId);
setNavItems(userNavItems);
// Group the nav items by category
const grouped = groupNavItems(userNavItems);
setGroupedNavItems(grouped);
}
} catch (error) {
console.error("Error fetching role features:", error);
// If there's an error in fetching role features, add these essential items
const fallbackItems = [
{
title: "Dashboard",
icon: <LayoutDashboard className="w-5 h-5" />,
path: "/dashboard",
featureId: 1
},
{
title: "Features",
icon: <Grid3x3 className="w-5 h-5" />,
path: "/issues",
featureId: 10
},
{
title: "Meeting Rooms",
icon: <CalendarCheck className="w-5 h-5" />,
path: "/meeting-room/rooms",
featureId: 33
},
{
title: "Room Bookings",
icon: <BookOpen className="w-5 h-5" />,
path: "/meeting-room/bookings",
featureId: 34
},
{
title: "Communications",
icon: <MessageCircle className="w-5 h-5" />,
path: "/communications",
featureId: 35
},
{
title: "Bugs",
icon: <Bug className="w-5 h-5" />,
path: "/bugs",
featureId: 27
},
{
title: "Production Bugs",
icon: <Bug className="w-5 h-5" />,
path: "/production-bugs",
featureId: 39
},
{
title: "Test Cases",
icon: <CheckSquare className="w-5 h-5" />,
path: "/test-cases",
featureId: 40
},
{
title: "My Appraisals",
icon: <Award className="w-5 h-5" />,
path: "/appraisals/my-appraisals",
featureId: 28
},
{
title: "My Leaves",
icon: <Calendar className="w-5 h-5" />,
path: "/leaves",
featureId: 22
},
{
title: "Leave Balances",
icon: <CalendarRange className="w-5 h-5" />,
path: "/leave-balances",
featureId: 42
},
{
title: "Assets",
icon: <Package className="w-5 h-5" />,
path: "/assets",
featureId: 45
},
{
title: "System Details",
icon: <Package className="w-5 h-5" />,
path: "/system-details",
featureId: 46
},
{
title: "Asset Assignments",
icon: <Package className="w-5 h-5" />,
path: "/asset-assignments",
featureId: 47
},
{
title: "My Asset Requests",
icon: <ClipboardCheck className="w-5 h-5" />,
path: "/asset-requests",
featureId: 48
},
{
title: "Gantt Chart",
icon: <BarChart3 className="w-5 h-5" />,
path: "/gantt-chart",
featureId: 50
},
{
title: "Resource Allocation",
icon: <Users className="w-5 h-5" />,
path: "/resource-allocation",
featureId: 51
},
{
title: "Employee Projects",
icon: <Briefcase className="w-5 h-5" />,
path: "/employee-projects",
featureId: 43
},
];
// Add Asset Request Management for admin users
if (userData?.roleId === 1 || userData?.roleId === 21 || userData?.roleName?.toLowerCase() === 'admin') {
fallbackItems.push({
title: "Asset Request Management",
icon: <ShieldCheck className="w-5 h-5" />,
path: "/admin/asset-requests",
featureId: 49
});
}
// Add HR-specific appraisal features for HR roles
if (userData?.roleId === 10 || userData?.roleId === 11) { // Assuming roleId 10 and 11 for HR and HR Manager
// Add essential appraisal management features for HR
const hrAppraisalFeatures = [
{
title: "Appraisal Cycles",
icon: <Gauge className="w-5 h-5" />,
path: "/appraisals/cycles",
featureId: 29
},
{
title: "Assessment Areas",
icon: <ListChecks className="w-5 h-5" />,
path: "/appraisals/assessment-areas",
featureId: 30
},
{
title: "Competencies",
icon: <BadgeCheck className="w-5 h-5" />,
path: "/appraisals/competencies",
featureId: 31
},
{
title: "Role Questions",
icon: <ClipboardCheck className="w-5 h-5" />,
path: "/appraisals/role-questions",
featureId: 36
},
{
title: "HR Remarks",
icon: <MessageSquare className="w-5 h-5" />,
path: "/appraisals/hr-remarks",
featureId: 37
},
{
title: "Management Remarks",
icon: <MessageSquare className="w-5 h-5" />,
path: "/appraisals/management-remarks",
featureId: 38
},
{
title: "Manager Appraisals",
icon: <BarChart3 className="w-5 h-5" />,
path: "/appraisals/manager-dashboard",
featureId: 32
}
];
fallbackItems.push(...hrAppraisalFeatures);
}
setNavItems(fallbackItems);
// Group the fallback items by category
const grouped = groupNavItems(fallbackItems);
setGroupedNavItems(grouped);
} finally {
setIsLoading(false);
}
};
// Function to group nav items by category
const groupNavItems = (items: NavItem[]): Record<string, NavGroup> => {
const grouped: Record<string, NavGroup> = {};
// Initialize groups from featureCategories
Object.entries(featureCategories).forEach(([category, details]) => {
grouped[category] = {
title: details.title,
icon: details.icon,
items: []
};
});
// Add a generic "Other" category for any items that don't fit into predefined categories
grouped["other"] = {
title: "Other",
icon: <Layers className="w-5 h-5" />,
items: []
};
// Categorize each nav item
items.forEach(item => {
const category = getFeatureCategory(item.featureId);
if (grouped[category]) {
grouped[category].items.push(item);
} else {
grouped["other"].items.push(item);
}
});
// Remove empty categories
Object.keys(grouped).forEach(category => {
if (grouped[category].items.length === 0) {
delete grouped[category];
}
});
return grouped;
};
// Function to check if a nav item is active
const isNavItemActive = (path: string): boolean => {
const currentPath = window.location.pathname;
// Check for special menu highlight override
const activeMenu = document.body.getAttribute('data-active-menu');
if (activeMenu === 'production-bugs' && path === "/production-bugs") {
return true;
}
// If we're on production-bugs page and have the dashboard flag set,
// the dashboard should be active and production-bugs should not be
if (currentPath.includes('production-bugs')) {
if (document.body.getAttribute('data-active-tab') === 'dashboard') {
// Only highlight Dashboard when the special attribute is set
return path === "/";
} else {
// Otherwise highlight Production Bugs
return path === "/production-bugs";
}
}
// For dashboard path specifically - only active when actually on the dashboard
if (path === "/" && currentPath === "/") {
return true;
}
// Check for exact match
if (path === currentPath) return true;
// Special cases for various paths - only highlight if we're actually on these paths
if (path === "/employees" && currentPath.includes("employee") && !currentPath.includes("production-bugs")) return true;
if (path === "/deliverables" && currentPath.includes("deliverable") && !currentPath.includes("production-bugs")) return true;
if (path === "/bugs" && currentPath.includes("bugs") && !currentPath.includes("production-bugs")) return true;
if (path === "/appraisals/my-appraisals" &&
(currentPath === "/appraisals/my-appraisals" || currentPath.includes("/appraisals/view")) &&
!currentPath.includes("production-bugs")) return true;
if (path === "/appraisals/cycles" && currentPath.includes("/appraisals/cycles") && !currentPath.includes("production-bugs")) return true;
if (path === "/appraisals/assessment-areas" && currentPath.includes("/appraisals/assessment-areas") && !currentPath.includes("production-bugs")) return true;
if (path === "/appraisals/competencies" && currentPath.includes("/appraisals/competencies") && !currentPath.includes("production-bugs")) return true;
if (path === "/appraisals/manager-dashboard" && currentPath.includes("/appraisals/manager-dashboard") && !currentPath.includes("production-bugs")) return true;
if (path === "/appraisals/role-questions" && currentPath.includes("/appraisals/role-questions") && !currentPath.includes("production-bugs")) return true;
if (path === "/appraisals/hr-remarks" && currentPath.includes("/appraisals/hr-remarks") && !currentPath.includes("production-bugs")) return true;
if (path === "/appraisals/management-remarks" && currentPath.includes("/appraisals/management-remarks") && !currentPath.includes("production-bugs")) return true;
if (path === "/meeting-room/rooms" && currentPath.includes("/meeting-room/rooms") && !currentPath.includes("production-bugs")) return true;
if (path === "/meeting-room/bookings" && currentPath.includes("/meeting-room/bookings") && !currentPath.includes("production-bugs")) return true;
if (path === "/communications" && currentPath.includes("/communications") && !currentPath.includes("production-bugs")) return true;
return false;
};
return (
<aside
className={cn(
"fixed inset-y-0 left-0 z-40 w-64 bg-sidebar text-sidebar-foreground border-r border-sidebar-border transition-transform duration-300 ease-in-out transform",
isOpen ? "translate-x-0" : "-translate-x-full"
)}
>
<div className="flex flex-col h-full">
<div className="h-16 flex items-center px-4 border-b border-sidebar-border">
<Logo className="text-sidebar-foreground" />
</div>
{isAuthenticated && !isDownloadPage && (
<div className="px-4 py-3 border-b border-sidebar-border/50">
<div className="relative">
<Search className="absolute left-2.5 top-2.5 h-4 w-4 text-sidebar-foreground/50" />
<Input
type="text"
placeholder="Search menu..."
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
className="pl-9 h-9 bg-sidebar-accent/30 border-sidebar-border/50 text-sidebar-foreground placeholder:text-sidebar-foreground/40 focus-visible:ring-sidebar-primary"
/>
{searchQuery && (
<button
onClick={() => setSearchQuery("")}
className="absolute right-2.5 top-2.5 text-sidebar-foreground/50 hover:text-sidebar-foreground"
>
<X className="h-4 w-4" />
</button>
)}
</div>
</div>
)}
<ScrollArea className="flex-1 px-3 py-4">
{isLoading && isAuthenticated && !isDownloadPage ? (
<div className="flex flex-col items-center justify-center py-4 space-y-2">
<Loader2 className="h-5 w-5 animate-spin text-sidebar-foreground" />
<span className="text-xs text-sidebar-foreground/70">Loading menu items...</span>
</div>
) : (
<nav className="flex flex-col gap-1">
{!isAuthenticated ? (
// Unauthenticated user view
<div className="mt-6 pt-4">
<NavLink
to="/download-app"
className={({ isActive }) =>
cn(
"flex items-center gap-3 px-3 py-2 rounded-md text-sm font-medium transition-all",
isActive || location.pathname.includes("/download-app")
? "bg-sidebar-primary text-sidebar-primary-foreground"
: "text-primary hover:bg-sidebar-accent/50 hover:text-primary-foreground"
)
}
>
<Download className="w-5 h-5" />
<span>Download Mobile App</span>
</NavLink>
<div className="mt-6">
<NavLink
to="/login"
className="flex items-center gap-3 px-3 py-2 rounded-md text-sm font-medium transition-all bg-primary text-primary-foreground hover:bg-primary/90"
>
<span>Log In</span>
</NavLink>
</div>
</div>
) : (
// Authenticated user view - always show full menu regardless of page
<>
{/* Dashboard (often kept separate at the top) */}
{filteredGroupedNavItems["dashboard"] && (
<div className="mb-2">
{filteredGroupedNavItems["dashboard"].items.map((item) => (
<NavLink
key={item.path}
to={item.path}
onClick={() => {
// When going to dashboard, clear any attributes that might affect highlighting
document.body.removeAttribute('data-active-tab');
document.body.removeAttribute('data-active-menu');
sessionStorage.removeItem('from-dashboard');
sessionStorage.removeItem('from-sidebar');
sessionStorage.removeItem('manual-view-selection');
// Close the Bug Tracking menu group
setExpandedGroups(prev => ({
...prev,
bugs: false // "bugs" is the category key for Bug Tracking
}));
}}
className={({ isActive }) =>
cn(
"flex items-center gap-3 px-3 py-2 rounded-md text-sm font-medium transition-all",
isActive || isNavItemActive(item.path)
? "bg-sidebar-primary text-sidebar-primary-foreground"
: "text-sidebar-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground"
)
}
>
{item.icon}
<span>{item.title}</span>
</NavLink>
))}
</div>
)}
{/* My Profile Link */}
{(!searchQuery || "my profile".includes(searchQuery.toLowerCase())) && (
<div className="mb-4">
<NavLink
to={`/my-profile`}
className={({ isActive }) =>
cn(
"flex items-center gap-3 px-3 py-2 rounded-md text-sm font-medium transition-all",
isActive || window.location.pathname.includes('/my-profile') || window.location.pathname.includes('/profile')
? "bg-sidebar-primary text-sidebar-primary-foreground"
: "text-sidebar-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground"
)
}
>
<User className="w-5 h-5" />
<span>My Profile</span>
</NavLink>
</div>
)}
{/* Grouped menu items */}
{Object.entries(filteredGroupedNavItems)
.filter(([category]) => category !== "dashboard") // Skip dashboard as it's already shown above
.map(([category, group]) => (
<div key={category} className="mb-1">
{/* Group Header */}
<button
onClick={() => toggleGroup(category)}
className="w-full flex items-center justify-between px-3 py-2 text-sm font-medium text-sidebar-foreground/80 hover:text-sidebar-foreground transition-colors"
>
<div className="flex items-center gap-3">
{group.icon}
<span>{group.title}</span>
</div>
{expandedGroups[category] ?
<ChevronDown className="h-4 w-4" /> :
<ChevronRight className="h-4 w-4" />
}
</button>
{/* Group Items */}
{expandedGroups[category] && (
<div className="ml-4 mt-1 space-y-1 border-l-2 border-sidebar-border/50 pl-3">
{group.items.map((item) => (
<NavLink
key={item.path}
to={item.path}
state={item.path === "/production-bugs" ? { source: "sidebar" } : undefined}
onClick={() => {
// Close sidebar on mobile
if (isMobile) {
setIsOpen(false);
}
// For any non-dashboard item, always clear the dashboard highlighting
document.body.removeAttribute('data-active-tab');
if (item.path === "/production-bugs") {
// Clear dashboard marker and set sidebar marker
sessionStorage.removeItem('from-dashboard');
sessionStorage.setItem('from-sidebar', 'true');
// Ensure only Production Bugs is highlighted
document.body.setAttribute('data-active-menu', 'production-bugs');
} else {
// For other menu items, clear any special attributes
sessionStorage.removeItem('from-dashboard');
sessionStorage.removeItem('from-sidebar');
document.body.removeAttribute('data-active-menu');
}
}}
className={({ isActive }) =>
cn(
"flex items-center gap-3 px-3 py-2 rounded-md text-sm font-medium transition-all",
isActive || isNavItemActive(item.path)
? "bg-sidebar-primary text-sidebar-primary-foreground"
: "text-sidebar-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground"
)
}
>
{item.icon}
<span>{item.title}</span>
</NavLink>
))}
</div>
)}
</div>
))
}
{/* Empty state for search results */}
{searchQuery && Object.keys(filteredGroupedNavItems).length === 0 && !("my profile".includes(searchQuery.toLowerCase())) && (
<div className="px-3 py-8 text-center">
<p className="text-sm text-sidebar-foreground/50">No results found for "{searchQuery}"</p>
</div>
)}
{/* Admin Section - Only visible to admins */}
{userData?.roleId === 21 && (!searchQuery || "features".includes(searchQuery.toLowerCase())) && (
<>
<div className="mt-4 mb-2">
<div className="text-xs font-semibold text-sidebar-foreground/50 uppercase px-3">
Admin Tools
</div>
</div>
<NavLink
to="/features"
className={({ isActive }) =>
cn(
"flex items-center gap-3 px-3 py-2 rounded-md text-sm font-medium transition-all",
isActive || window.location.pathname.includes("/features")
? "bg-sidebar-primary text-sidebar-primary-foreground"
: "text-sidebar-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground"
)
}
>
<Key className="w-5 h-5" />
<span>Features</span>
</NavLink>
</>
)}
{/* Download App Section - Visible to all users */}
{(!searchQuery || "download mobile app".includes(searchQuery.toLowerCase())) && (
<div className="mt-6 pt-4 border-t border-sidebar-border/30">
<NavLink
to="/download-app"
className={({ isActive }) =>
cn(
"flex items-center gap-3 px-3 py-2 rounded-md text-sm font-medium transition-all",
isActive || window.location.pathname.includes("/download-app")
? "bg-sidebar-primary text-sidebar-primary-foreground"
: "text-primary hover:bg-sidebar-accent/50 hover:text-primary-foreground"
)
}
>
<Download className="w-5 h-5" />
<span>Download Mobile App</span>
</NavLink>
</div>
)}
</>
)}
</nav>
)}
</ScrollArea>
<Separator className="bg-sidebar-border/50" />
<div className="p-4 text-xs text-sidebar-foreground/70">
<div className="font-medium">Synthesys PM Tool</div>
<div className="mt-1">v{getVersionString()}</div>
</div>
</div>
</aside>
);
};
export default Sidebar;
|