Files
platform-project/platform/frontend-user/src/components/Layout.tsx
T
Арсентьев Александр 07dbde2a0e Initial monorepo structure
2026-08-06 11:23:37 +03:00

67 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useState, useEffect } from 'react'
import { Outlet, Link, useLocation, useNavigate } from 'react-router-dom'
import { useAuth } from '../contexts/AuthContext'
import { modulesApi } from '../api/client'
import { Package, LogOut } from 'lucide-react'
export default function Layout() {
const { user, logout } = useAuth()
const location = useLocation()
const navigate = useNavigate()
const [modules, setModules] = useState<any[]>([])
const isModuleView = location.pathname.startsWith('/module/')
useEffect(() => {
modulesApi.list().then(res => setModules(res.data.filter((m: any) => m.is_active))).catch(() => {})
}, [])
const handleLogout = () => { logout(); navigate('/login') }
return (
<div className="flex flex-col h-screen bg-gray-100">
{/* Top header */}
<header className="bg-white shadow-sm flex-shrink-0">
<div className="flex items-center justify-between h-12 px-4">
{/* Left: logo + home */}
<div className="flex items-center gap-6">
<Link to="/" className="text-lg font-bold text-gray-800 whitespace-nowrap">Платформа</Link>
<Link to="/"
className={`px-3 py-1.5 text-sm rounded-md transition-colors ${location.pathname === '/' ? 'bg-blue-50 text-blue-700 font-medium' : 'text-gray-600 hover:bg-gray-100'}`}>
Мои модули
</Link>
</div>
{/* Center: module tabs */}
{modules.length > 0 && (
<div className="flex items-center gap-1">
{modules.map(mod => (
<Link key={mod.slug} to={`/module/${mod.slug}`}
className={`px-3 py-1.5 text-sm rounded-md transition-colors flex items-center gap-1.5 ${location.pathname === `/module/${mod.slug}` ? 'bg-blue-600 text-white font-medium' : 'text-gray-600 hover:bg-gray-100'}`}>
<Package className="w-3.5 h-3.5" />{mod.name}
</Link>
))}
</div>
)}
{/* Right: logout */}
<button onClick={handleLogout} className="flex items-center gap-1.5 px-3 py-1.5 text-sm text-gray-600 hover:bg-gray-100 rounded-md">
<LogOut className="w-4 h-4" />Выход
</button>
</div>
</header>
{/* Content */}
<div className="flex-1 flex flex-col min-w-0 overflow-hidden">
{isModuleView ? (
<Outlet />
) : (
<div className="flex-1 overflow-auto p-6">
<Outlet />
</div>
)}
</div>
</div>
)
}