// frontend/app/(protected)/dashboard/page.jsx 'use client'; import { useState, useEffect } from 'react'; import Link from 'next/link'; import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Activity, File, FilePlus, ArrowRight, BellDot, Settings } from 'lucide-react'; import { api } from '@/lib/api'; import { useAuth } from '@/lib/auth'; import { can } from '@/lib/rbac'; export default function DashboardPage() { const { user } = useAuth(); const [stats, setStats] = useState(null); const [myTasks, setMyTasks] = useState([]); const [recentActivity, setRecentActivity] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { const fetchData = async () => { try { setLoading(true); // เรียก API ที่จำเป็นสำหรับ Dashboard พร้อมกัน // หมายเหตุ: Endpoint เหล่านี้อาจจะต้องสร้างเพิ่มเติมในฝั่ง Backend const [statsRes, tasksRes, activityRes] = await Promise.all([ api.get('/dashboard/stats').catch(e => ({ data: { totalDocuments: 0, newThisWeek: 0, pendingRfas: 0 }})), // สมมติ endpoint สำหรับ KPI api.get('/dashboard/my-tasks').catch(e => ({ data: [] })), // สมมติ endpoint สำหรับ Action Items api.get('/dashboard/recent-activity').catch(e => ({ data: [] })), // สมมติ endpoint สำหรับ Recent Activity ]); setStats(statsRes.data); setMyTasks(tasksRes.data); setRecentActivity(activityRes.data); } catch (error) { console.error("Failed to fetch dashboard data:", error); } finally { setLoading(false); } }; fetchData(); }, []); if (loading) { // อาจจะใช้ Skeleton UI ที่นี่เพื่อให้ UX ดีขึ้น return
Welcome back, {user?.username || 'User'}!
+{stats?.newThisWeek || 0} this week
Require your attention
No pending tasks. You're all caught up!
)}{new Date(activity.timestamp).toLocaleString()}
No recent activity.
)}