feat(web): add role-aware React dashboards
Add student and teacher dashboard variants backed by existing APIs, retain the administrative overview for management roles, and provide responsive navigation back to legacy routes that have not migrated yet.
This commit is contained in:
1 parent
1ab9b76101
commit
44f09cec1d
7 files changed
+269
-5
No files matched your search
@@ -2,6 +2,10 @@ import { Alert, Button, Progress, Skeleton } from 'antd'
|
||||
import { ArrowRightOutlined, ReloadOutlined } from '@ant-design/icons'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import http from '../api/http'
|
||||
import { useAuthStore } from '../stores/auth'
|
||||
import StudentDashboardPage from './dashboard/StudentDashboardPage'
|
||||
import TeacherDashboardPage from './dashboard/TeacherDashboardPage'
|
||||
import './dashboard/role-dashboard.css'
|
||||
|
||||
interface DashboardData {
|
||||
audience: {
|
||||
@@ -49,7 +53,7 @@ function formatDate(value?: string) {
|
||||
return new Intl.DateTimeFormat('zh-CN', { month: 'long', day: 'numeric' }).format(date)
|
||||
}
|
||||
|
||||
export default function DashboardPage() {
|
||||
function AdminDashboardPage() {
|
||||
const query = useQuery({
|
||||
queryKey: ['dashboard'],
|
||||
queryFn: async () => (await http.get<DashboardData>('/dashboard')).data,
|
||||
@@ -131,3 +135,15 @@ export default function DashboardPage() {
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
export default function DashboardPage() {
|
||||
const roles = useAuthStore((state) => state.user?.roles ?? [])
|
||||
const isStudent = roles.includes('Student') &&
|
||||
!roles.some((role) => ['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin', 'Counselor'].includes(role))
|
||||
const isTeacher = roles.includes('Teacher') &&
|
||||
!roles.some((role) => ['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin', 'Counselor', 'Student'].includes(role))
|
||||
|
||||
if (isStudent) return <StudentDashboardPage />
|
||||
if (isTeacher) return <TeacherDashboardPage />
|
||||
return <AdminDashboardPage />
|
||||
}
|
||||
Reference in new issue
Block a user