refactor(modules): update classes, course-plans, diagnostic, questions, settings, student, layout

- Update classes data-access (invitations, main) for invitation management

- Update course-plans actions, data-access, and types

- Update diagnostic data-access for report queries

- Update questions data-access for question bank queries

- Update settings actions, ai-provider-settings-card, data-access, and types

- Update student course-filters, student-courses-view, student-schedule-filters, student-schedule-view

- Update layout app-sidebar, site-header, and navigation config
This commit is contained in:
SpecialX
2026-06-24 12:03:35 +08:00
parent c9e46f9f80
commit 8c2fe14c20
18 changed files with 712 additions and 189 deletions

View File

@@ -4,6 +4,7 @@ import * as React from "react"
import Link from "next/link"
import { usePathname } from "next/navigation"
import { ChevronRight } from "lucide-react"
import { useTranslations } from "next-intl"
import {
Collapsible,
@@ -31,6 +32,8 @@ export function AppSidebar({ mode }: AppSidebarProps) {
const { expanded, toggleSidebar, isMobile } = useSidebar()
const pathname = usePathname()
const { permissions, hasRole } = usePermission()
const tNav = useTranslations("nav")
const tCommon = useTranslations("common")
// 自动检测当前角色(优先级 admin > student > parent > teacher
// 注意grade_head / teaching_head 统一归入 teacher因为 teacher 导航已通过
@@ -86,6 +89,7 @@ export function AppSidebar({ mode }: AppSidebarProps) {
{navItems.map((item, index) => {
const isActive = pathname.startsWith(item.href)
const hasChildren = item.items && item.items.length > 0
const title = tNav(item.title)
if (!expanded && !isMobile) {
// Collapsed Mode (Icon Only + Tooltip)
@@ -100,10 +104,10 @@ export function AppSidebar({ mode }: AppSidebarProps) {
)}
>
<item.icon className="size-5" />
<span className="sr-only">{item.title}</span>
<span className="sr-only">{title}</span>
</Link>
</TooltipTrigger>
<TooltipContent side="right">{item.title}</TooltipContent>
<TooltipContent side="right">{title}</TooltipContent>
</Tooltip>
)
}
@@ -121,7 +125,7 @@ export function AppSidebar({ mode }: AppSidebarProps) {
>
<div className="flex items-center gap-2">
<item.icon className="size-4" />
<span>{item.title}</span>
<span>{title}</span>
</div>
<ChevronRight className="text-muted-foreground size-4 transition-transform duration-200 group-data-[state=open]/collapsible:rotate-90" />
</button>
@@ -137,7 +141,7 @@ export function AppSidebar({ mode }: AppSidebarProps) {
pathname === subItem.href && "text-foreground font-medium"
)}
>
{subItem.title}
{tNav(subItem.title)}
</Link>
))}
</div>
@@ -156,7 +160,7 @@ export function AppSidebar({ mode }: AppSidebarProps) {
)}
>
<item.icon className="size-4" />
<span>{item.title}</span>
<span>{title}</span>
{item.href === "/messages" ? <UnreadMessageBadge /> : null}
</Link>
)
@@ -172,7 +176,7 @@ export function AppSidebar({ mode }: AppSidebarProps) {
onClick={toggleSidebar}
className="hover:bg-sidebar-accent text-sidebar-foreground flex w-full items-center justify-center rounded-md border p-2 text-sm transition-colors"
>
{expanded ? "收起" : <ChevronRight className="size-4" />}
{expanded ? tCommon("sidebar.collapse") : <ChevronRight className="size-4" />}
</button>
)}
</div>

View File

@@ -5,6 +5,7 @@ import Link from "next/link"
import { usePathname } from "next/navigation"
import { Menu } from "lucide-react"
import { signOut, useSession } from "next-auth/react"
import { useTranslations } from "next-intl"
import { Button } from "@/shared/components/ui/button"
import { Separator } from "@/shared/components/ui/separator"
@@ -31,7 +32,7 @@ import { NotificationDropdown } from "@/modules/notifications/components/notific
import { useSidebar } from "./sidebar-provider"
import { NAV_CONFIG } from "../config/navigation"
// Build lookup map for breadcrumbs
// Build lookup map for breadcrumbs: href → i18n key
const BREADCRUMB_MAP = new Map<string, string>()
Object.values(NAV_CONFIG).forEach((items) => {
items?.forEach((item) => {
@@ -46,10 +47,12 @@ export function SiteHeader() {
const pathname = usePathname()
const { toggleSidebar, isMobile } = useSidebar()
const { data: session, status } = useSession()
const tNav = useTranslations("nav")
const tCommon = useTranslations("common")
const name = session?.user?.name ?? ""
const email = session?.user?.email ?? ""
const displayName = name || email || (status === "loading" ? "加载中..." : "未登录")
const displayName = name || email || (status === "loading" ? tCommon("user.loading") : tCommon("user.notLoggedIn"))
const fallbackBase = name || email || "?"
const avatarFallback = fallbackBase
@@ -65,7 +68,10 @@ export function SiteHeader() {
const breadcrumbs = segments
.map((segment, index) => {
const href = `/${segments.slice(0, index + 1).join("/")}`
const title = BREADCRUMB_MAP.get(href) || segment.charAt(0).toUpperCase() + segment.slice(1)
const titleKey = BREADCRUMB_MAP.get(href)
const title = titleKey
? tNav(titleKey)
: segment.charAt(0).toUpperCase() + segment.slice(1)
return { href, title, isLast: index === segments.length - 1, isRole: roleSegments.has(segment.toLowerCase()) }
})
.filter((b, idx) => {
@@ -83,7 +89,7 @@ export function SiteHeader() {
{isMobile && (
<Button variant="ghost" size="icon" onClick={toggleSidebar} className="mr-2">
<Menu className="size-5" />
<span className="sr-only">Toggle Sidebar</span>
<span className="sr-only">{tCommon("sidebar.toggleSidebar")}</span>
</Button>
)}
@@ -109,7 +115,7 @@ export function SiteHeader() {
))
) : (
<BreadcrumbItem>
<BreadcrumbPage>Home</BreadcrumbPage>
<BreadcrumbPage>{tCommon("breadcrumb.home")}</BreadcrumbPage>
</BreadcrumbItem>
)}
</BreadcrumbList>
@@ -143,10 +149,10 @@ export function SiteHeader() {
</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuItem asChild>
<Link href="/profile">Profile</Link>
<Link href="/profile">{tCommon("user.profile")}</Link>
</DropdownMenuItem>
<DropdownMenuItem asChild>
<Link href="/settings">Settings</Link>
<Link href="/settings">{tCommon("user.settings")}</Link>
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
@@ -156,7 +162,7 @@ export function SiteHeader() {
signOut({ callbackUrl: "/login" })
}}
>
Log out
{tCommon("user.logout")}
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>