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

59 lines
2.6 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 { Link } from 'react-router-dom'
import { modulesApi } from '../api/client'
import { useAuth } from '../contexts/AuthContext'
import { Package, ExternalLink } from 'lucide-react'
export default function Dashboard() {
const { user } = useAuth()
const [modules, setModules] = useState<any[]>([])
useEffect(() => {
modulesApi.list().then(res => setModules(res.data.filter((m: any) => m.is_active))).catch(() => {})
}, [])
return (
<div>
<h1 className="text-2xl font-bold text-gray-900 mb-2">Добро пожаловать, {user?.first_name}!</h1>
<p className="text-gray-500 mb-8">Выберите модуль для работы</p>
{modules.length === 0 ? (
<div className="bg-white rounded-lg shadow p-8 text-center">
<Package className="w-12 h-12 text-gray-300 mx-auto mb-4" />
<p className="text-gray-500">Нет доступных модулей</p>
<p className="text-sm text-gray-400 mt-1">Обратитесь к администратору для подключения модулей</p>
</div>
) : (
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
{modules.map(mod => {
const userRoles = user?.module_roles?.[mod.slug] || []
return (
<Link key={mod.slug} to={`/module/${mod.slug}`}
className="bg-white rounded-lg shadow hover:shadow-md transition-shadow p-6 group">
<div className="flex items-start justify-between mb-4">
<div className="w-12 h-12 bg-blue-100 rounded-lg flex items-center justify-center">
<Package className="w-6 h-6 text-blue-600" />
</div>
<ExternalLink className="w-4 h-4 text-gray-400 group-hover:text-blue-600 transition-colors" />
</div>
<h3 className="font-semibold text-lg text-gray-900 mb-1">{mod.name}</h3>
<p className="text-sm text-gray-500 mb-3">{mod.description || 'Без описания'}</p>
{userRoles.length > 0 && (
<div className="flex gap-1 flex-wrap">
{userRoles.map((r: string) => (
<span key={r} className="px-2 py-0.5 text-xs bg-green-100 text-green-800 rounded-full">{r}</span>
))}
</div>
)}
{userRoles.length === 0 && (
<span className="text-xs text-gray-400">Нет ролей в модуле</span>
)}
</Link>
)
})}
</div>
)}
</div>
)
}