✅ student pomodoro lookup, admin user prefs, missing GET wrappers
Browse files at this commitcbcc77f84a9b72edd98afb36af6b290054b94568Parent: 8d7909b- feat
- ✅ student pomodoro lookup, admin user prefs, missing GET wrappers
14 changed files +319 -7
- src/api/getPomodoroByUser.ts +7 -0
- src/api/getSessionById.ts +6 -0
- src/api/getSubjectById.ts +6 -0
- src/api/getTermById.ts +6 -0
- src/api/patchUserPreferences.ts +14 -0
- src/components/layout/app-shell.tsx +1 -0
- src/components/layout/side-nav.tsx +1 -0
- src/components/users/user-preferences-actions.tsx +39 -0
- src/components/users/user-table.tsx +12 -2
- src/i18n/messages.ts +10 -1
- src/pages/admin-users-page.tsx +14 -2
- src/pages/dashboard-page.tsx +5 -2
- src/pages/student-pomodoro-page.tsx +190 -0
- src/routes/router.tsx +8 -0
src/api/getPomodoroByUser.tsadded+7 -0
| @@ -0,0 +1,7 @@ | ||
| 1 | +import { client } from "./client"; | |
| 2 | +import { pageQuery, type PageParams } from "./page"; | |
| 3 | +import type { PomodoroLog } from "./types"; | |
| 4 | + | |
| 5 | +export function getPomodoroByUser(userId: string, params?: PageParams, signal?: AbortSignal): Promise<PomodoroLog> { | |
| 6 | + return client<PomodoroLog>(`/pomodoro/${userId}${pageQuery(params)}`, { signal }); | |
| 7 | +} |
src/api/getSessionById.tsadded+6 -0
| @@ -0,0 +1,6 @@ | ||
| 1 | +import { client } from "./client"; | |
| 2 | +import type { CourseSession } from "./types"; | |
| 3 | + | |
| 4 | +export function getSessionById(id: string, signal?: AbortSignal): Promise<CourseSession> { | |
| 5 | + return client<CourseSession>(`/sessions/${id}`, { signal }); | |
| 6 | +} |
src/api/getSubjectById.tsadded+6 -0
| @@ -0,0 +1,6 @@ | ||
| 1 | +import { client } from "./client"; | |
| 2 | +import type { Subject } from "./types"; | |
| 3 | + | |
| 4 | +export function getSubjectById(id: string, signal?: AbortSignal): Promise<Subject> { | |
| 5 | + return client<Subject>(`/subjects/${id}`, { signal }); | |
| 6 | +} |
src/api/getTermById.tsadded+6 -0
| @@ -0,0 +1,6 @@ | ||
| 1 | +import { client } from "./client"; | |
| 2 | +import type { Term } from "./types"; | |
| 3 | + | |
| 4 | +export function getTermById(id: string, signal?: AbortSignal): Promise<Term> { | |
| 5 | + return client<Term>(`/terms/${id}`, { signal }); | |
| 6 | +} |
src/api/patchUserPreferences.tsadded+14 -0
| @@ -0,0 +1,14 @@ | ||
| 1 | +import { client } from "./client"; | |
| 2 | +import type { User, UserLanguage, UserTheme } from "./types"; | |
| 3 | + | |
| 4 | +export type PatchUserPreferencesBody = { | |
| 5 | + theme?: UserTheme | null; | |
| 6 | + language?: UserLanguage | null; | |
| 7 | +}; | |
| 8 | + | |
| 9 | +export function patchUserPreferences(id: string, body: PatchUserPreferencesBody): Promise<User> { | |
| 10 | + return client<User>(`/users/${id}/preferences`, { | |
| 11 | + method: "PATCH", | |
| 12 | + body, | |
| 13 | + }); | |
| 14 | +} |
src/components/layout/app-shell.tsxmodified+1 -0
| @@ -43,6 +43,7 @@ export function AppShell(props: ParentProps) { | ||
| 43 | 43 | if (path === "/work") return `${t("nav.group.reports")} / ${t("nav.work")}`; |
| 44 | 44 | if (path === "/management/student-marks") return `${t("nav.group.reports")} / ${t("nav.studentMarks")}`; |
| 45 | 45 | if (path === "/management/student-attendance") return `${t("nav.group.reports")} / ${t("nav.studentAttendance")}`; |
| 46 | + if (path === "/management/pomodoros") return `${t("nav.group.reports")} / ${t("nav.studentPomodoro")}`; | |
| 46 | 47 | if (path === "/management/staff-work") return `${t("nav.group.reports")} / ${t("nav.staffWork")}`; |
| 47 | 48 | if (path === "/management/settings") return `${t("nav.group.settings")} / ${t("nav.settings")}`; |
| 48 | 49 | if (path === "/management/terms") return `${t("nav.group.settings")} / ${t("nav.terms")}`; |
src/components/layout/side-nav.tsxmodified+1 -0
| @@ -85,6 +85,7 @@ const NAV_GROUPS: NavGroup[] = [ | ||
| 85 | 85 | items: [ |
| 86 | 86 | { to: "/management/student-marks", labelKey: "nav.studentMarks", Icon: IconChart, minRole: "teacher" }, |
| 87 | 87 | { to: "/management/student-attendance", labelKey: "nav.studentAttendance", Icon: IconClipboardCheck, minRole: "teacher" }, |
| 88 | + { to: "/management/pomodoros", labelKey: "nav.studentPomodoro", Icon: IconClock, minRole: "teacher" }, | |
| 88 | 89 | { to: "/work", labelKey: "nav.work", Icon: IconBriefcase, minRole: "teacher", maxRole: "manager" }, |
| 89 | 90 | { to: "/management/staff-work", labelKey: "nav.staffWork", Icon: IconBriefcase, minRole: "manager" }, |
| 90 | 91 | ], |
src/components/users/user-preferences-actions.tsxadded+39 -0
| @@ -0,0 +1,39 @@ | ||
| 1 | +import { Show, createSignal } from "solid-js"; | |
| 2 | +import type { User, UserLanguage, UserTheme } from "@/api/types"; | |
| 3 | +import { Button } from "@/components/ui/button"; | |
| 4 | +import { IconCheck } from "@/components/ui/icons"; | |
| 5 | +import { Select } from "@/components/ui/select"; | |
| 6 | +import { useT } from "@/stores/preferences-context"; | |
| 7 | + | |
| 8 | +export function UserPreferencesActions(props: { | |
| 9 | + user: User; | |
| 10 | + onPreferencesChange: (userId: string, body: { theme?: UserTheme | null; language?: UserLanguage | null }) => Promise<void>; | |
| 11 | +}) { | |
| 12 | + const t = useT(); | |
| 13 | + const [theme, setTheme] = createSignal<UserTheme | "">(props.user.theme ?? ""); | |
| 14 | + const [language, setLanguage] = createSignal<UserLanguage | "">(props.user.language ?? ""); | |
| 15 | + const dirty = () => theme() !== (props.user.theme ?? "") || language() !== (props.user.language ?? ""); | |
| 16 | + | |
| 17 | + return ( | |
| 18 | + <div class="grid gap-2"> | |
| 19 | + <div class="grid grid-cols-2 gap-2"> | |
| 20 | + <Select class="h-8 rounded-sm text-xs" value={theme()} aria-label={t("theme.toggle")} onChange={(e) => setTheme(e.currentTarget.value as UserTheme | "")}> | |
| 21 | + <option value="">—</option> | |
| 22 | + <option value="light">{t("theme.light")}</option> | |
| 23 | + <option value="dark">{t("theme.dark")}</option> | |
| 24 | + </Select> | |
| 25 | + <Select class="h-8 rounded-sm text-xs" value={language()} aria-label={t("lang.label")} onChange={(e) => setLanguage(e.currentTarget.value as UserLanguage | "")}> | |
| 26 | + <option value="">—</option> | |
| 27 | + <option value="tr">{t("lang.tr")}</option> | |
| 28 | + <option value="en">{t("lang.en")}</option> | |
| 29 | + </Select> | |
| 30 | + </div> | |
| 31 | + <Show when={dirty()}> | |
| 32 | + <Button type="button" size="sm" class="h-7 rounded-sm px-2" onClick={() => props.onPreferencesChange(props.user.id, { theme: theme() || null, language: language() || null })}> | |
| 33 | + <IconCheck /> | |
| 34 | + {t("common.save")} | |
| 35 | + </Button> | |
| 36 | + </Show> | |
| 37 | + </div> | |
| 38 | + ); | |
| 39 | +} |
src/components/users/user-table.tsxmodified+12 -2
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | import { createMemo, createSignal, Show } from "solid-js"; |
| 2 | 2 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 3 | -import type { Role, User } from "@/api/types"; | |
| 3 | +import type { Role, User, UserLanguage, UserTheme } from "@/api/types"; | |
| 4 | 4 | import type { MessageKey } from "@/i18n/messages"; |
| 5 | 5 | import { Select } from "@/components/ui/select"; |
| 6 | 6 | import { Button } from "@/components/ui/button"; |
| @@ -8,6 +8,7 @@ import { Badge } from "@/components/ui/badge"; | ||
| 8 | 8 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; |
| 9 | 9 | import { DataTable } from "@/components/ui/data-table"; |
| 10 | 10 | import { IconCheck } from "@/components/ui/icons"; |
| 11 | +import { UserPreferencesActions } from "@/components/users/user-preferences-actions"; | |
| 11 | 12 | import { ROLES } from "@/lib/roles"; |
| 12 | 13 | import { cn } from "@/lib/cn"; |
| 13 | 14 | import { useT } from "@/stores/preferences-context"; |
| @@ -74,6 +75,7 @@ export function UserTable(props: { | ||
| 74 | 75 | users: User[]; |
| 75 | 76 | currentUserId: string; |
| 76 | 77 | onRoleChange: (userId: string, role: Role) => Promise<void>; |
| 78 | + onPreferencesChange?: (userId: string, body: { theme?: UserTheme | null; language?: UserLanguage | null }) => Promise<void>; | |
| 77 | 79 | }) { |
| 78 | 80 | const t = useT(); |
| 79 | 81 | const searchUser = (user: User, query: string) => |
| @@ -114,6 +116,14 @@ export function UserTable(props: { | ||
| 114 | 116 | header: t("admin.id"), |
| 115 | 117 | meta: { cellClass: "mono truncate text-xs text-muted-foreground" }, |
| 116 | 118 | }, |
| 119 | + { | |
| 120 | + id: "preferences", | |
| 121 | + header: t("nav.preferences"), | |
| 122 | + meta: { headerClass: "w-56", cellClass: "w-56" }, | |
| 123 | + cell: (cell) => props.onPreferencesChange | |
| 124 | + ? <UserPreferencesActions user={cell.row.original} onPreferencesChange={props.onPreferencesChange} /> | |
| 125 | + : "—", | |
| 126 | + }, | |
| 117 | 127 | { |
| 118 | 128 | id: "update", |
| 119 | 129 | header: t("common.update"), |
| @@ -125,6 +135,6 @@ export function UserTable(props: { | ||
| 125 | 135 | ]); |
| 126 | 136 | |
| 127 | 137 | return ( |
| 128 | - <DataTable columns={columns()} data={props.users} tableClass="table-fixed min-w-[58rem]" searchPredicate={searchUser} enablePagination pageSize={20} /> | |
| 138 | + <DataTable columns={columns()} data={props.users} tableClass="table-fixed min-w-[70rem]" searchPredicate={searchUser} enablePagination pageSize={20} /> | |
| 129 | 139 | ); |
| 130 | 140 | } |
src/i18n/messages.tsmodified+10 -1
| @@ -26,6 +26,7 @@ export type MessageKey = | ||
| 26 | 26 | | "nav.users" |
| 27 | 27 | | "nav.studentMarks" |
| 28 | 28 | | "nav.studentAttendance" |
| 29 | + | "nav.studentPomodoro" | |
| 29 | 30 | | "nav.settings" |
| 30 | 31 | | "nav.terms" |
| 31 | 32 | | "nav.guide" |
| @@ -344,6 +345,8 @@ export type MessageKey = | ||
| 344 | 345 | | "pomodoro.finished" |
| 345 | 346 | | "pomodoro.history" |
| 346 | 347 | | "pomodoro.empty" |
| 348 | + | "pomodoro.lookup" | |
| 349 | + | "pomodoro.forUser" | |
| 347 | 350 | | "pomodoro.startedAt" |
| 348 | 351 | | "pomodoro.finishedAt" |
| 349 | 352 | | "pomodoro.duration" |
| @@ -630,6 +633,7 @@ const en: Dict = { | ||
| 630 | 633 | "nav.users": "Users", |
| 631 | 634 | "nav.studentMarks": "Student marks", |
| 632 | 635 | "nav.studentAttendance": "Student attendance", |
| 636 | + "nav.studentPomodoro": "Pomodoros", | |
| 633 | 637 | "nav.settings": "Settings", |
| 634 | 638 | "nav.terms": "Terms", |
| 635 | 639 | "nav.guide": "Guide", |
| @@ -950,6 +954,8 @@ const en: Dict = { | ||
| 950 | 954 | "pomodoro.finished": "Focus session finished.", |
| 951 | 955 | "pomodoro.history": "Recent sessions", |
| 952 | 956 | "pomodoro.empty": "No focus sessions yet.", |
| 957 | + "pomodoro.lookup": "Select a student to review their pomodoro focus history.", | |
| 958 | + "pomodoro.forUser": "Pomodoros for {user}", | |
| 953 | 959 | "pomodoro.startedAt": "Started", |
| 954 | 960 | "pomodoro.finishedAt": "Finished", |
| 955 | 961 | "pomodoro.duration": "Duration", |
| @@ -1231,7 +1237,7 @@ const tr: Dict = { | ||
| 1231 | 1237 | "ai.send": "Gönder", |
| 1232 | 1238 | "ai.unavailable": "Çelebi henüz bağlı değil. Gerçek yanıtlar için backend AI endpoint’i gerekli.", |
| 1233 | 1239 | "nav.home": "Ana sayfa", |
| 1234 | - "nav.notes": "Notlar", | |
| 1240 | + "nav.notes": "Defter", | |
| 1235 | 1241 | "nav.events": "Etkinlikler", |
| 1236 | 1242 | "nav.exams": "Sınavlar", |
| 1237 | 1243 | "nav.courses": "Ders", |
| @@ -1246,6 +1252,7 @@ const tr: Dict = { | ||
| 1246 | 1252 | "nav.users": "Kullanıcılar", |
| 1247 | 1253 | "nav.studentMarks": "Notlar", |
| 1248 | 1254 | "nav.studentAttendance": "Yoklamalar", |
| 1255 | + "nav.studentPomodoro": "Pomodorolar", | |
| 1249 | 1256 | "nav.settings": "Ayarlar", |
| 1250 | 1257 | "nav.terms": "Dönemler", |
| 1251 | 1258 | "nav.guide": "Rehber", |
| @@ -1566,6 +1573,8 @@ const tr: Dict = { | ||
| 1566 | 1573 | "pomodoro.finished": "Odak oturumu bitti.", |
| 1567 | 1574 | "pomodoro.history": "Son oturumlar", |
| 1568 | 1575 | "pomodoro.empty": "Henüz odak oturumu yok.", |
| 1576 | + "pomodoro.lookup": "Öğrencinin pomodoro odak geçmişini görmek için öğrenci seç.", | |
| 1577 | + "pomodoro.forUser": "{user} için pomodorolar", | |
| 1569 | 1578 | "pomodoro.startedAt": "Başlangıç", |
| 1570 | 1579 | "pomodoro.finishedAt": "Bitiş", |
| 1571 | 1580 | "pomodoro.duration": "Süre", |
src/pages/admin-users-page.tsxmodified+14 -2
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | import { For, Show, Suspense, createResource, createSignal } from "solid-js"; |
| 2 | 2 | import { getUsers } from "@/api/getUsers"; |
| 3 | +import { patchUserPreferences } from "@/api/patchUserPreferences"; | |
| 3 | 4 | import { patchUserRole } from "@/api/patchUserRole"; |
| 4 | 5 | import { formatApiError } from "@/api/client"; |
| 5 | -import type { Role, User } from "@/api/types"; | |
| 6 | +import type { Role, User, UserLanguage, UserTheme } from "@/api/types"; | |
| 6 | 7 | import { RouteGuard } from "@/components/layout/route-guard"; |
| 7 | 8 | import { PageHeader } from "@/components/layout/page-header"; |
| 8 | 9 | import { UserTable } from "@/components/users/user-table"; |
| @@ -45,6 +46,17 @@ function AdminUsersContent() { | ||
| 45 | 46 | } |
| 46 | 47 | }; |
| 47 | 48 | |
| 49 | + const onPreferencesChange = async (userId: string, body: { theme?: UserTheme | null; language?: UserLanguage | null }) => { | |
| 50 | + setError(""); | |
| 51 | + try { | |
| 52 | + await patchUserPreferences(userId, body); | |
| 53 | + await refetch(); | |
| 54 | + setFlash(t("common.saved")); | |
| 55 | + } catch (err) { | |
| 56 | + setError(formatApiError(err)); | |
| 57 | + } | |
| 58 | + }; | |
| 59 | + | |
| 48 | 60 | return ( |
| 49 | 61 | <div class="space-y-6"> |
| 50 | 62 | <div class="space-y-2"> |
| @@ -76,7 +88,7 @@ function AdminUsersContent() { | ||
| 76 | 88 | <Suspense fallback={<DataTableSkeleton columns={6} rows={8} />}> |
| 77 | 89 | <Show when={list()}> |
| 78 | 90 | <Show when={visibleUsers().length > 0} fallback={<DataTableEmpty>{t("admin.noUsers")}</DataTableEmpty>}> |
| 79 | - <UserTable users={visibleUsers() as User[]} currentUserId={auth.user()!.id} onRoleChange={onRoleChange} /> | |
| 91 | + <UserTable users={visibleUsers() as User[]} currentUserId={auth.user()!.id} onRoleChange={onRoleChange} onPreferencesChange={onPreferencesChange} /> | |
| 80 | 92 | </Show> |
| 81 | 93 | </Show> |
| 82 | 94 | </Suspense> |
src/pages/dashboard-page.tsxmodified+5 -2
| @@ -216,8 +216,9 @@ function DashboardContent() { | ||
| 216 | 216 | { Icon: IconCalendar, titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: evc, minRole: "teacher" }, |
| 217 | 217 | { Icon: IconChart, titleKey: "nav.studentMarks", to: "/management/student-marks", descKey: "dashboard.portal.studentMarksDesc", minRole: "teacher" }, |
| 218 | 218 | { Icon: IconClipboardCheck, titleKey: "nav.studentAttendance", to: "/management/student-attendance", descKey: "dashboard.portal.attendanceDesc", minRole: "teacher" }, |
| 219 | - { Icon: IconNote, titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: nc }, | |
| 219 | + { Icon: IconClock, titleKey: "nav.studentPomodoro", to: "/management/pomodoros", descKey: "dashboard.portal.pomodoroDesc", minRole: "teacher" }, | |
| 220 | 220 | { Icon: IconBriefcase, titleKey: "nav.work", to: "/work", descKey: "dashboard.portal.workDesc", minRole: "teacher" }, |
| 221 | + { Icon: IconNote, titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: nc }, | |
| 221 | 222 | ); |
| 222 | 223 | return list; |
| 223 | 224 | } |
| @@ -229,9 +230,10 @@ function DashboardContent() { | ||
| 229 | 230 | { Icon: IconUsers, titleKey: "nav.clubs", to: "/clubs", descKey: "dashboard.portal.clubsDesc", stat: clc }, |
| 230 | 231 | { Icon: IconExam, titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: ec }, |
| 231 | 232 | { Icon: IconCalendar, titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: evc }, |
| 232 | - { Icon: IconNote, titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: nc }, | |
| 233 | 233 | { Icon: IconChart, titleKey: "nav.studentMarks", to: "/management/student-marks", descKey: "dashboard.portal.studentMarksDesc", minRole: "teacher" }, |
| 234 | 234 | { Icon: IconClipboardCheck, titleKey: "nav.studentAttendance", to: "/management/student-attendance", descKey: "dashboard.portal.attendanceDesc", minRole: "teacher" }, |
| 235 | + { Icon: IconClock, titleKey: "nav.studentPomodoro", to: "/management/pomodoros", descKey: "dashboard.portal.pomodoroDesc", minRole: "teacher" }, | |
| 236 | + { Icon: IconNote, titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: nc }, | |
| 235 | 237 | { Icon: IconSettings, titleKey: "nav.settings", to: "/management/settings", descKey: "dashboard.portal.settingsDesc", minRole: "manager" }, |
| 236 | 238 | { Icon: IconCalendarDays, titleKey: "nav.terms", to: "/management/terms", descKey: "dashboard.portal.termsDesc", minRole: "manager" }, |
| 237 | 239 | ); |
| @@ -248,6 +250,7 @@ function DashboardContent() { | ||
| 248 | 250 | const orderedPortalCards = createMemo(() => { |
| 249 | 251 | const cards = portalCards(); |
| 250 | 252 | const byId = new Map(cards.map((card) => [card.to, card])); |
| 253 | + if (portalOrder().some((id) => !byId.has(id)) || portalOrder().length !== cards.length) return cards; | |
| 251 | 254 | const ordered = portalOrder().flatMap((id) => byId.get(id) ? [byId.get(id)!] : []); |
| 252 | 255 | const seen = new Set(ordered.map((card) => card.to)); |
| 253 | 256 | return [...ordered, ...cards.filter((card) => !seen.has(card.to))]; |
src/pages/student-pomodoro-page.tsxadded+190 -0
| @@ -0,0 +1,190 @@ | ||
| 1 | +import { Show, createMemo, createResource, createSignal } from "solid-js"; | |
| 2 | +import type { ColumnDef } from "@tanstack/solid-table"; | |
| 3 | +import { getPomodoroByUser } from "@/api/getPomodoroByUser"; | |
| 4 | +import { getUserSearch } from "@/api/getUserSearch"; | |
| 5 | +import type { PersonRef, PomodoroSession } from "@/api/types"; | |
| 6 | +import { ApiError, formatApiError } from "@/api/client"; | |
| 7 | +import { RouteGuard } from "@/components/layout/route-guard"; | |
| 8 | +import { PageHeader } from "@/components/layout/page-header"; | |
| 9 | +import { Alert } from "@/components/ui/alert"; | |
| 10 | +import { DataTable, DataTableSkeleton } from "@/components/ui/data-table"; | |
| 11 | +import { ErrorAlert } from "@/components/ui/error-alert"; | |
| 12 | +import { IconEye } from "@/components/ui/icons"; | |
| 13 | +import { SidePanel } from "@/components/ui/side-panel"; | |
| 14 | +import { TableRowActions } from "@/components/ui/table-row-actions"; | |
| 15 | +import { formatDateTime, formatDurationMinutes } from "@/lib/format"; | |
| 16 | +import { personLabel } from "@/lib/person"; | |
| 17 | +import { usePreferences, useT } from "@/stores/preferences-context"; | |
| 18 | + | |
| 19 | +const PAGE_SIZE = 12; | |
| 20 | + | |
| 21 | +export default function StudentPomodoroPage() { | |
| 22 | + return ( | |
| 23 | + <RouteGuard minRole="teacher"> | |
| 24 | + <StudentPomodoroContent /> | |
| 25 | + </RouteGuard> | |
| 26 | + ); | |
| 27 | +} | |
| 28 | + | |
| 29 | +function StudentPomodoroContent() { | |
| 30 | + const t = useT(); | |
| 31 | + const { locale } = usePreferences(); | |
| 32 | + const [viewUser, setViewUser] = createSignal<PersonRef | null>(null); | |
| 33 | + const [error, setError] = createSignal(""); | |
| 34 | + | |
| 35 | + const [list] = createResource( | |
| 36 | + async () => { | |
| 37 | + try { | |
| 38 | + setError(""); | |
| 39 | + return (await getUserSearch("", undefined, "student")).items; | |
| 40 | + } catch (err) { | |
| 41 | + setError(formatApiError(err)); | |
| 42 | + return []; | |
| 43 | + } | |
| 44 | + }, | |
| 45 | + { initialValue: [] }, | |
| 46 | + ); | |
| 47 | + | |
| 48 | + const [log, { refetch: refetchLog }] = createResource( | |
| 49 | + () => viewUser()?.id ?? null, | |
| 50 | + async (id) => { | |
| 51 | + if (!id) return null; | |
| 52 | + try { | |
| 53 | + return await getPomodoroByUser(id, { limit: 20 }); | |
| 54 | + } catch (err) { | |
| 55 | + if (err instanceof ApiError && err.status === 404) { | |
| 56 | + setError(t("common.notFound")); | |
| 57 | + return null; | |
| 58 | + } | |
| 59 | + setError(formatApiError(err)); | |
| 60 | + return null; | |
| 61 | + } | |
| 62 | + }, | |
| 63 | + ); | |
| 64 | + | |
| 65 | + const total = () => list().length; | |
| 66 | + const rows = () => list(); | |
| 67 | + const listLoading = () => list.loading; | |
| 68 | + const searchPerson = (person: PersonRef, query: string) => | |
| 69 | + [person.username, person.display_name, person.id].join(" ").toLocaleLowerCase().includes(query.toLocaleLowerCase()); | |
| 70 | + const studentColumns = createMemo<ColumnDef<PersonRef>[]>(() => [ | |
| 71 | + { | |
| 72 | + accessorKey: "username", | |
| 73 | + header: t("admin.username"), | |
| 74 | + cell: (cell) => <span class="font-medium">{cell.row.original.username}</span>, | |
| 75 | + }, | |
| 76 | + { | |
| 77 | + accessorKey: "display_name", | |
| 78 | + header: t("profile.name"), | |
| 79 | + cell: (cell) => <span class="text-muted-foreground">{cell.row.original.display_name || "—"}</span>, | |
| 80 | + }, | |
| 81 | + { | |
| 82 | + accessorKey: "id", | |
| 83 | + header: t("admin.id"), | |
| 84 | + cell: (cell) => <span class="mono text-xs text-muted-foreground">{cell.row.original.id}</span>, | |
| 85 | + }, | |
| 86 | + { | |
| 87 | + id: "actions", | |
| 88 | + header: t("common.actions"), | |
| 89 | + meta: { headerClass: "w-14 text-center" }, | |
| 90 | + cell: (cell) => ( | |
| 91 | + <TableRowActions | |
| 92 | + label={t("common.actions")} | |
| 93 | + actions={[ | |
| 94 | + { | |
| 95 | + label: t("common.view"), | |
| 96 | + icon: <IconEye class="h-4 w-4" />, | |
| 97 | + onSelect: () => { | |
| 98 | + setError(""); | |
| 99 | + setViewUser(cell.row.original); | |
| 100 | + }, | |
| 101 | + }, | |
| 102 | + ]} | |
| 103 | + /> | |
| 104 | + ), | |
| 105 | + }, | |
| 106 | + ]); | |
| 107 | + const logColumns = createMemo<ColumnDef<PomodoroSession>[]>(() => [ | |
| 108 | + { | |
| 109 | + accessorKey: "started_at", | |
| 110 | + header: t("pomodoro.startedAt"), | |
| 111 | + cell: (cell) => <span class="mono whitespace-nowrap">{formatDateTime(cell.row.original.started_at, locale())}</span>, | |
| 112 | + }, | |
| 113 | + { | |
| 114 | + accessorKey: "finished_at", | |
| 115 | + header: t("pomodoro.finishedAt"), | |
| 116 | + cell: (cell) => <span class="mono whitespace-nowrap">{formatDateTime(cell.row.original.finished_at, locale())}</span>, | |
| 117 | + }, | |
| 118 | + { | |
| 119 | + accessorKey: "duration_ms", | |
| 120 | + header: t("pomodoro.duration"), | |
| 121 | + cell: (cell) => formatDurationMinutes(cell.row.original.duration_ms, locale()), | |
| 122 | + }, | |
| 123 | + ]); | |
| 124 | + | |
| 125 | + return ( | |
| 126 | + <div class="space-y-6"> | |
| 127 | + <PageHeader accent="mint" eyebrow={t("nav.admin")} title={t("nav.studentPomodoro")} description={t("pomodoro.lookup")} /> | |
| 128 | + | |
| 129 | + <section class="data-shell space-y-4 p-4"> | |
| 130 | + <div class="flex flex-wrap items-center justify-between gap-3"> | |
| 131 | + <div> | |
| 132 | + <h2 class="font-display text-lg font-semibold">{t("nav.studentPomodoro")}</h2> | |
| 133 | + <p class="mt-1 text-sm text-muted-foreground"> | |
| 134 | + {rows().length} / {total()} | |
| 135 | + </p> | |
| 136 | + </div> | |
| 137 | + </div> | |
| 138 | + | |
| 139 | + <Show when={error() && !viewUser()}> | |
| 140 | + <Alert variant="destructive">{error()}</Alert> | |
| 141 | + </Show> | |
| 142 | + | |
| 143 | + <Show when={!listLoading()} fallback={<DataTableSkeleton columns={4} rows={6} />}> | |
| 144 | + <DataTable | |
| 145 | + columns={studentColumns()} | |
| 146 | + data={rows()} | |
| 147 | + tableClass="min-w-[36rem]" | |
| 148 | + empty={t("form.noStudents")} | |
| 149 | + searchPredicate={searchPerson} | |
| 150 | + enablePagination | |
| 151 | + pageSize={PAGE_SIZE} | |
| 152 | + /> | |
| 153 | + </Show> | |
| 154 | + </section> | |
| 155 | + | |
| 156 | + <SidePanel | |
| 157 | + size="wide" | |
| 158 | + open={viewUser() != null} | |
| 159 | + onOpenChange={(open) => { | |
| 160 | + if (!open) { | |
| 161 | + setViewUser(null); | |
| 162 | + setError(""); | |
| 163 | + } | |
| 164 | + }} | |
| 165 | + title={t("pomodoro.forUser", { user: personLabel(viewUser()) })} | |
| 166 | + description={t("pomodoro.lookup")} | |
| 167 | + > | |
| 168 | + <div class="min-w-0 space-y-3"> | |
| 169 | + <Show when={error()}> | |
| 170 | + <ErrorAlert message={error()} onRetry={() => void refetchLog()} /> | |
| 171 | + </Show> | |
| 172 | + <Show when={log.loading}> | |
| 173 | + <p class="text-sm text-muted-foreground">{t("common.loading")}</p> | |
| 174 | + </Show> | |
| 175 | + <Show when={log()}> | |
| 176 | + {(p) => ( | |
| 177 | + <div class="space-y-4"> | |
| 178 | + <div class="detail-metric-card"> | |
| 179 | + <p class="text-xs font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("pomodoro.total")}</p> | |
| 180 | + <p class="mono mt-2 text-3xl font-semibold tabular-nums">{formatDurationMinutes(p().total_focus_ms, locale())}</p> | |
| 181 | + </div> | |
| 182 | + <DataTable columns={logColumns()} data={p().items} empty={t("pomodoro.empty")} enablePagination pageSize={10} /> | |
| 183 | + </div> | |
| 184 | + )} | |
| 185 | + </Show> | |
| 186 | + </div> | |
| 187 | + </SidePanel> | |
| 188 | + </div> | |
| 189 | + ); | |
| 190 | +} |
src/routes/router.tsxmodified+8 -0
| @@ -36,6 +36,7 @@ const MarksPage = lazyRoute(() => import("@/pages/marks-page")); | ||
| 36 | 36 | const MessagesPage = lazyRoute(() => import("@/pages/messages-page")); |
| 37 | 37 | const PomodoroPage = lazyRoute(() => import("@/pages/pomodoro-page")); |
| 38 | 38 | const StudentMarksPage = lazyRoute(() => import("@/pages/student-marks-page")); |
| 39 | +const StudentPomodoroPage = lazyRoute(() => import("@/pages/student-pomodoro-page")); | |
| 39 | 40 | const AttendancePage = lazyRoute(() => import("@/pages/attendance-page")); |
| 40 | 41 | const StudentAttendancePage = lazyRoute(() => import("@/pages/student-attendance-page")); |
| 41 | 42 | const WorkLogPage = lazyRoute(() => import("@/pages/work-log-page")); |
| @@ -173,6 +174,12 @@ const studentMarksRoute = createRoute({ | ||
| 173 | 174 | component: StudentMarksPage, |
| 174 | 175 | }); |
| 175 | 176 | |
| 177 | +const studentPomodoroRoute = createRoute({ | |
| 178 | + getParentRoute: () => rootRoute, | |
| 179 | + path: "/management/pomodoros", | |
| 180 | + component: StudentPomodoroPage, | |
| 181 | +}); | |
| 182 | + | |
| 176 | 183 | const attendanceRoute = createRoute({ |
| 177 | 184 | getParentRoute: () => rootRoute, |
| 178 | 185 | path: "/attendance", |
| @@ -252,6 +259,7 @@ const routeTree = rootRoute.addChildren([ | ||
| 252 | 259 | messagesRoute, |
| 253 | 260 | pomodoroRoute, |
| 254 | 261 | studentMarksRoute, |
| 262 | + studentPomodoroRoute, | |
| 255 | 263 | attendanceRoute, |
| 256 | 264 | studentAttendanceRoute, |
| 257 | 265 | workRoute, |