Spaces:
Running
Running
File size: 3,737 Bytes
17bca00 | 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 | // src/components/Sidebar/Sidebar.jsx
import React, { useState, useEffect } from 'react';
import UserInfo from './UserInfo';
import NavLinks from './NavLinks';
import DepartmentQuickAccess from './DepartmentQuickAccess';
const Sidebar = ({
initialUser,
initialDepartments, // Prop này sẽ nhận danh sách phòng ban từ App.jsx
initialActiveSection,
onNavigate,
isMobileMenuOpen,
setMobileMenuOpen,
}) => {
// ... (navItems và các state khác giữ nguyên) ...
const navItems = [
{ id: 'dashboard-section', label: 'Dashboard', icon: 'fa-tachometer-alt' },
{ id: 'tasks-section', label: 'Công việc', icon: 'fa-tasks' },
{ id: 'personnel-section', label: 'Nhân sự', icon: 'fa-users' },
{ id: 'departments-section', label: 'Phòng ban', icon: 'fa-building' },
{ id: 'reports-section', label: 'Báo cáo', icon: 'fa-chart-line' },
{ id: 'calendar-section', label: 'Lịch làm việc', icon: 'fa-calendar-alt' },
{ id: 'settings-section', label: 'Cài đặt', icon: 'fa-cog' },
];
const [currentUser, setCurrentUser] = useState(initialUser);
const [departments, setDepartments] = useState(initialDepartments); // State này sẽ được cập nhật
const [activeSection, setActiveSection] = useState(initialActiveSection);
useEffect(() => {
setCurrentUser(initialUser);
}, [initialUser]);
useEffect(() => {
setDepartments(initialDepartments); // Cập nhật state departments khi prop thay đổi
}, [initialDepartments]);
useEffect(() => {
setActiveSection(initialActiveSection);
}, [initialActiveSection]);
const handleNavigation = (sectionId) => {
// ... (giữ nguyên) ...
setActiveSection(sectionId);
if (onNavigate) {
onNavigate(sectionId);
}
if (window.innerWidth < 768) { // md breakpoint
setMobileMenuOpen(false);
}
};
const sidebarClasses = `
md:flex md:flex-shrink-0 fixed md:relative inset-y-0 left-0 z-50
transform ${isMobileMenuOpen ? 'translate-x-0' : '-translate-x-full'} md:translate-x-0
transition-transform duration-300 ease-in-out
`;
return (
<>
{isMobileMenuOpen && (
<div
className="fixed inset-0 bg-black opacity-50 z-40 md:hidden"
onClick={() => setMobileMenuOpen(false)}
></div>
)}
<div id="sidebar" className={sidebarClasses}>
<div className="flex flex-col w-64 bg-gradient-to-b from-blue-600 to-blue-800 h-full">
<div className="flex items-center justify-between h-16 px-4 flex-shrink-0">
<div className="flex items-center">
<i className="fas fa-tooth text-white text-2xl mr-2"></i>
<span className="text-white font-bold text-xl">Nha Khoa TTL</span>
</div>
<button
id="close-sidebar-button"
className="md:hidden text-white ml-auto focus:outline-none"
onClick={() => setMobileMenuOpen(false)}
>
<i className="fas fa-times text-xl"></i>
</button>
</div>
<div className="flex flex-col flex-grow px-4 py-4 overflow-y-auto">
<UserInfo currentUser={currentUser} />
<NavLinks
navItems={navItems}
activeSection={activeSection}
onNavigate={handleNavigation}
/>
{/* DepartmentQuickAccess sẽ nhận `departments` từ state của Sidebar */}
<DepartmentQuickAccess
departments={departments}
// onNavigateToDepartment={ (deptId) => handleNavigation(`departments-section?deptId=${deptId}`)}
/>
</div>
</div>
</div>
</>
);
};
export default Sidebar; |