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 Link from "next/link"
import { memo, useState, useTransition } from "react"
import { useRouter } from "next/navigation"
import { toast } from "sonner"
import { useTranslations } from "next-intl"
import { Card, CardContent, CardHeader, CardTitle, CardDescription, CardFooter } from "@/shared/components/ui/card"
import { Badge } from "@/shared/components/ui/badge"
@@ -17,6 +18,7 @@ import type { StudentEnrolledClass } from "@/modules/classes/types"
import { joinClassByInvitationCodeAction } from "@/modules/classes/actions"
const ClassCard = memo(function ClassCard({ c }: { c: StudentEnrolledClass }) {
const t = useTranslations("student")
return (
<Card className="flex flex-col overflow-hidden transition-all hover:shadow-md">
<CardHeader className="bg-muted/30 pb-4">
@@ -30,7 +32,7 @@ const ClassCard = memo(function ClassCard({ c }: { c: StudentEnrolledClass }) {
<CardDescription className="flex items-center gap-2 text-xs">
<span className="flex items-center gap-1">
<BookOpen className="h-3 w-3" />
Grade {c.grade}
{t("coursesView.grade", { grade: c.grade })}
</span>
{c.homeroom && (
<>
@@ -41,7 +43,7 @@ const ClassCard = memo(function ClassCard({ c }: { c: StudentEnrolledClass }) {
</CardDescription>
</div>
<Badge variant="secondary" className="shrink-0">
Active
{t("coursesView.active")}
</Badge>
</div>
</CardHeader>
@@ -71,7 +73,7 @@ const ClassCard = memo(function ClassCard({ c }: { c: StudentEnrolledClass }) {
{c.room && (
<div className="flex items-center gap-2 text-muted-foreground">
<Building2 className="h-4 w-4" />
<span>Room {c.room}</span>
<span>{t("coursesView.room", { room: c.room })}</span>
</div>
)}
</div>
@@ -81,19 +83,19 @@ const ClassCard = memo(function ClassCard({ c }: { c: StudentEnrolledClass }) {
<Button asChild variant="outline" size="sm" className="flex-1">
<Link href={`/student/learning/courses/${encodeURIComponent(c.id)}`}>
<BookOpen className="mr-2 h-4 w-4" />
Details
{t("coursesView.details")}
</Link>
</Button>
<Button asChild variant="outline" size="sm" className="flex-1">
<Link href={`/student/schedule?classId=${encodeURIComponent(c.id)}`}>
<CalendarDays className="mr-2 h-4 w-4" />
Schedule
{t("coursesView.schedule")}
</Link>
</Button>
<Button asChild size="sm" className="flex-1">
<Link href="/student/learning/assignments">
<PenTool className="mr-2 h-4 w-4" />
Assignments
{t("coursesView.assignments")}
</Link>
</Button>
</CardFooter>
@@ -106,6 +108,7 @@ export function StudentCoursesView({
}: {
classes: StudentEnrolledClass[]
}) {
const t = useTranslations("student")
const router = useRouter()
const [code, setCode] = useState("")
const [isPending, startTransition] = useTransition()
@@ -115,15 +118,15 @@ export function StudentCoursesView({
try {
const res = await joinClassByInvitationCodeAction(null, formData)
if (res.success) {
toast.success(res.message || "Joined class")
toast.success(res.message || t("coursesView.joinedSuccess"))
setCode("")
router.refresh()
} else {
toast.error(res.message || "Failed to join class")
toast.error(res.message || t("coursesView.joinFailed"))
}
} catch (err) {
console.error("[joinClass] failed:", err)
toast.error("Failed to join class")
toast.error(t("coursesView.joinFailed"))
}
})
}
@@ -141,8 +144,8 @@ export function StudentCoursesView({
{classes.length === 0 && (
<EmptyState
icon={Inbox}
title="No courses yet"
description="You are not enrolled in any classes. Join a class below to get started."
title={t("coursesView.noCourses")}
description={t("coursesView.noCoursesDesc")}
className="py-12"
/>
)}
@@ -155,9 +158,9 @@ export function StudentCoursesView({
<PlusCircle className="h-5 w-5 text-primary" />
</div>
<div>
<h3 className="text-lg font-semibold">Join a Class</h3>
<h3 className="text-lg font-semibold">{t("coursesView.joinClass")}</h3>
<p className="text-sm text-muted-foreground">
Enter the invitation code provided by your teacher to enroll.
{t("coursesView.joinClassDesc")}
</p>
</div>
</div>
@@ -165,13 +168,13 @@ export function StudentCoursesView({
<form action={handleJoin} className="flex flex-col gap-4 sm:flex-row sm:items-end">
<div className="flex-1 space-y-2">
<Label htmlFor="join-invitation-code">Invitation Code</Label>
<Label htmlFor="join-invitation-code">{t("coursesView.invitationCode")}</Label>
<Input
id="join-invitation-code"
name="code"
inputMode="numeric"
autoComplete="one-time-code"
placeholder="Enter 6-digit code"
placeholder={t("coursesView.invitationCodePlaceholder")}
value={code}
onChange={(e) => setCode(e.target.value)}
maxLength={6}
@@ -181,7 +184,7 @@ export function StudentCoursesView({
/>
</div>
<Button type="submit" disabled={isPending} size="lg">
{isPending ? "Joining..." : "Join Class"}
{isPending ? t("coursesView.joining") : t("coursesView.joinButton")}
</Button>
</form>
</div>