File size: 6,878 Bytes
191b322 | 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 |
import React from 'react';
import {
LayoutDashboard,
FileText,
HardHat,
DollarSign,
AlertTriangle,
FolderOpen,
Menu,
X,
ChevronLeft,
UserCircle,
LogOut,
Bell,
CheckCircle2,
Users,
Calendar,
BarChart3,
ShoppingCart,
ShieldCheck,
Camera,
FileBarChart,
Truck,
UserCheck,
Box,
Globe
} from 'lucide-react';
import { UserRole, User } from '../types';
import { NotificationCenter } from './Collaboration';
interface LayoutProps {
children: React.ReactNode;
activeTab: string;
setActiveTab: (tab: string) => void;
onSwitchProject: () => void;
projectName: string;
user: User;
onLogout: () => void;
}
const Layout: React.FC<LayoutProps> = ({
children,
activeTab,
setActiveTab,
onSwitchProject,
projectName,
user,
onLogout
}) => {
const [isMobileMenuOpen, setIsMobileMenuOpen] = React.useState(false);
const navItems = [
{ id: 'dashboard', label: 'Dashboard', icon: LayoutDashboard },
{ id: 'master', label: 'Master Control', icon: FileText },
{ id: 'site', label: 'Site Execution', icon: HardHat },
{ id: 'finance', label: 'Financial Control', icon: DollarSign },
{ id: 'analytics', label: 'Financial Analytics', icon: BarChart3 },
{ id: 'procurement', label: 'Procurement', icon: ShoppingCart },
{ id: 'equipment', label: 'Equipment', icon: Truck },
{ id: 'labor', label: 'Labor & Attendance', icon: UserCheck },
{ id: 'subcontractors', label: 'Sub-contractors', icon: Users },
{ id: 'qc-safety', label: 'QC & Safety', icon: ShieldCheck },
{ id: 'tasks', label: 'Tasks', icon: CheckCircle2 },
{ id: 'gantt', label: 'Timeline', icon: Calendar },
{ id: 'bim', label: 'BIM Viewer', icon: Box },
{ id: 'photos', label: 'Photo Logs', icon: Camera },
{ id: 'reports', label: 'Reports', icon: FileBarChart },
{ id: 'client', label: 'Client Portal', icon: Globe },
{ id: 'team', label: 'Team', icon: Users },
{ id: 'documents', label: 'Documents', icon: FolderOpen },
];
const getRoleLabel = (role: string) => {
switch(role) {
case 'DIRECTOR': return 'Project Director';
case 'MANAGER': return 'Project Manager';
case 'ENGINEER': return 'Site Engineer';
case 'ACCOUNTANT': return 'Accountant';
default: return role;
}
};
const renderNav = () => (
<nav className="flex flex-col h-full">
<div className="p-4 border-b border-slate-100">
<div className="flex items-center gap-2 mb-2 text-slate-800">
<div className="w-8 h-8 bg-blue-600 rounded-lg flex items-center justify-center shrink-0">
<span className="text-white font-bold text-lg">B</span>
</div>
<span className="text-xl font-bold tracking-tight">Project Management AI</span>
</div>
<button
onClick={onSwitchProject}
className="w-full flex items-center gap-2 text-xs font-medium text-slate-500 hover:text-blue-600 hover:bg-blue-50 p-2 rounded transition-colors mt-2"
>
<ChevronLeft className="w-3 h-3" />
Switch Project
</button>
<div className="mt-2 text-sm font-semibold text-slate-800 truncate" title={projectName}>
{projectName}
</div>
</div>
<div className="flex-1 p-4 space-y-1 overflow-y-auto">
{navItems.map((item) => (
<button
key={item.id}
onClick={() => {
setActiveTab(item.id);
setIsMobileMenuOpen(false);
}}
className={`w-full sidebar-item ${
activeTab === item.id ? 'sidebar-item-active' : ''
}`}
>
<item.icon className="w-4 h-4 shrink-0 transition-transform group-hover:scale-110" />
<span className="font-medium tracking-tight">{item.label}</span>
</button>
))}
</div>
<div className="p-4 border-t border-slate-200">
<div className="flex items-center gap-3 px-3 py-2 bg-white border border-slate-200 rounded-xl shadow-sm">
{user.avatar ? (
<img src={user.avatar} alt={user.name} className="w-8 h-8 rounded-full border border-slate-100" referrerPolicy="no-referrer" />
) : (
<div className="w-8 h-8 bg-blue-100 text-blue-600 rounded-full flex items-center justify-center font-bold text-xs">
{user.name.charAt(0)}
</div>
)}
<div className="flex-1 min-w-0">
<p className="text-xs font-bold text-slate-800 truncate">{user.name}</p>
<p className="text-[9px] font-bold text-slate-500 uppercase tracking-wider">{getRoleLabel(user.role)}</p>
</div>
<button
onClick={onLogout}
className="p-1.5 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-lg transition-all"
title="Logout"
>
<LogOut className="w-3.5 h-3.5" />
</button>
</div>
</div>
</nav>
);
return (
<div className="flex min-h-screen bg-slate-50">
{/* Mobile Header */}
<div className="lg:hidden fixed top-0 left-0 right-0 h-16 bg-white border-b z-20 flex items-center justify-between px-4">
<div className="flex items-center gap-3">
<button onClick={() => setIsMobileMenuOpen(!isMobileMenuOpen)} className="p-2 text-slate-600">
{isMobileMenuOpen ? <X /> : <Menu />}
</button>
<div className="flex flex-col">
<span className="font-bold text-lg text-slate-800">Project Management AI</span>
<span className="text-xs text-slate-500 truncate max-w-[150px]">{projectName}</span>
</div>
</div>
<div className="flex items-center gap-2">
<NotificationCenter uid={user.uid || ''} />
{user.avatar && <img src={user.avatar} alt="User" className="w-8 h-8 rounded-full border border-slate-200" referrerPolicy="no-referrer" />}
</div>
</div>
{/* Sidebar Desktop */}
<aside className="hidden lg:block w-64 bg-white border-r border-slate-200 fixed h-full z-10">
{renderNav()}
</aside>
{/* Sidebar Mobile */}
{isMobileMenuOpen && (
<aside className="lg:hidden fixed inset-0 z-30 bg-white shadow-xl">
<div className="flex justify-end p-4">
<button onClick={() => setIsMobileMenuOpen(false)}><X /></button>
</div>
{renderNav()}
</aside>
)}
{/* Main Content */}
<main className="flex-1 lg:ml-64 p-4 lg:p-8 pt-20 lg:pt-8 transition-all">
<div className="max-w-7xl mx-auto">
<div className="hidden lg:flex justify-end mb-6">
<NotificationCenter uid={user.uid || ''} />
</div>
{children}
</div>
</main>
</div>
);
};
export default Layout;
|