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:
@@ -1,10 +1,12 @@
|
||||
"use client"
|
||||
|
||||
import { useQueryState, parseAsString } from "nuqs"
|
||||
import { useTranslations } from "next-intl"
|
||||
|
||||
import { FilterBar, FilterSearchInput } from "@/shared/components/ui/filter-bar"
|
||||
|
||||
export function CourseFilters() {
|
||||
const t = useTranslations("student")
|
||||
const [search, setSearch] = useQueryState("q", parseAsString.withDefault(""))
|
||||
|
||||
const hasFilters = Boolean(search)
|
||||
@@ -18,7 +20,7 @@ export function CourseFilters() {
|
||||
<FilterSearchInput
|
||||
value={search}
|
||||
onChange={(v) => setSearch(v || null)}
|
||||
placeholder="Search by class name, teacher, school..."
|
||||
placeholder={t("courseFilters.searchPlaceholder")}
|
||||
/>
|
||||
</FilterBar>
|
||||
)
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -2,21 +2,23 @@
|
||||
|
||||
import { useMemo } from "react"
|
||||
import { useQueryState, parseAsString } from "nuqs"
|
||||
import { useTranslations } from "next-intl"
|
||||
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/shared/components/ui/select"
|
||||
import type { StudentEnrolledClass } from "@/modules/classes/types"
|
||||
|
||||
export function StudentScheduleFilters({ classes }: { classes: StudentEnrolledClass[] }) {
|
||||
const t = useTranslations("student")
|
||||
const [classId, setClassId] = useQueryState("classId", parseAsString.withDefault("all"))
|
||||
|
||||
const options = useMemo(() => [{ id: "all", name: "All classes" }, ...classes], [classes])
|
||||
const options = useMemo(() => [{ id: "all", name: t("scheduleFilters.allClasses") }, ...classes], [classes, t])
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div className="w-full sm:w-60">
|
||||
<Select value={classId} onValueChange={setClassId}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select class" />
|
||||
<SelectValue placeholder={t("scheduleFilters.selectClass")} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{options.map((c) => (
|
||||
@@ -30,4 +32,3 @@ export function StudentScheduleFilters({ classes }: { classes: StudentEnrolledCl
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,17 +3,18 @@ import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { CalendarX } from "lucide-react"
|
||||
import { ScheduleList } from "@/shared/components/schedule/schedule-list"
|
||||
import { cn } from "@/shared/lib/utils"
|
||||
import { useTranslations } from "next-intl"
|
||||
|
||||
import type { StudentScheduleItem } from "@/modules/classes/types"
|
||||
|
||||
const WEEKDAYS: Array<{ key: 1 | 2 | 3 | 4 | 5 | 6 | 7; label: string }> = [
|
||||
{ key: 1, label: "Mon" },
|
||||
{ key: 2, label: "Tue" },
|
||||
{ key: 3, label: "Wed" },
|
||||
{ key: 4, label: "Thu" },
|
||||
{ key: 5, label: "Fri" },
|
||||
{ key: 6, label: "Sat" },
|
||||
{ key: 7, label: "Sun" },
|
||||
const WEEKDAY_KEYS: Array<{ key: 1 | 2 | 3 | 4 | 5 | 6 | 7; label: string }> = [
|
||||
{ key: 1, label: "mon" },
|
||||
{ key: 2, label: "tue" },
|
||||
{ key: 3, label: "wed" },
|
||||
{ key: 4, label: "thu" },
|
||||
{ key: 5, label: "fri" },
|
||||
{ key: 6, label: "sat" },
|
||||
{ key: 7, label: "sun" },
|
||||
]
|
||||
|
||||
const getTodayWeekday = (): 1 | 2 | 3 | 4 | 5 | 6 | 7 => {
|
||||
@@ -27,12 +28,14 @@ const getTodayWeekday = (): 1 | 2 | 3 | 4 | 5 | 6 | 7 => {
|
||||
}
|
||||
|
||||
export function StudentScheduleView({ items }: { items: StudentScheduleItem[] }) {
|
||||
const t = useTranslations("student")
|
||||
|
||||
if (items.length === 0) {
|
||||
return (
|
||||
<EmptyState
|
||||
icon={CalendarX}
|
||||
title="No schedule"
|
||||
description="No timetable entries found for your enrolled classes."
|
||||
title={t("scheduleView.noSchedule")}
|
||||
description={t("scheduleView.noScheduleDesc")}
|
||||
className="h-80"
|
||||
/>
|
||||
)
|
||||
@@ -52,7 +55,7 @@ export function StudentScheduleView({ items }: { items: StudentScheduleItem[] })
|
||||
|
||||
return (
|
||||
<div className="grid gap-4 lg:grid-cols-2">
|
||||
{WEEKDAYS.map((d) => {
|
||||
{WEEKDAY_KEYS.map((d) => {
|
||||
const dayItems = itemsByDay.get(d.key) ?? []
|
||||
const isToday = d.key === todayKey
|
||||
return (
|
||||
@@ -64,17 +67,17 @@ export function StudentScheduleView({ items }: { items: StudentScheduleItem[] })
|
||||
>
|
||||
<CardHeader className="pb-3">
|
||||
<CardTitle className="flex items-center gap-2 text-sm font-medium">
|
||||
<span>{d.label}</span>
|
||||
<span>{t(`weekdays.${d.label}`)}</span>
|
||||
{isToday && (
|
||||
<span className="rounded-full bg-primary px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-primary-foreground">
|
||||
Today
|
||||
{t("scheduleView.today")}
|
||||
</span>
|
||||
)}
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{dayItems.length === 0 ? (
|
||||
<div className="text-sm text-muted-foreground">No classes.</div>
|
||||
<div className="text-sm text-muted-foreground">{t("scheduleView.noClasses")}</div>
|
||||
) : (
|
||||
<ScheduleList
|
||||
items={dayItems.map((item) => ({
|
||||
|
||||
Reference in New Issue
Block a user