👨👩👧👦 parent role, question pool, and student management
Browse files at this commit8bd96bf5abe810c736e6a55d2cc34b17045992d3Parent: 8382995- feat
- 👨👩👧👦 parent role, question pool, and student management
21 changed files +1177 -19
- src/api/deleteParentStudent.ts +7 -0
- src/api/getMyStudents.ts +14 -0
- src/api/getParentStudents.ts +14 -0
- src/api/postParentStudent.ts +15 -0
- src/api/questions.ts +76 -0
- src/api/solutions.ts +75 -0
- src/api/types.ts +1 -1
- src/components/layout/app-shell.tsx +1 -0
- src/components/layout/role-badge.tsx +1 -0
- src/components/layout/side-nav.tsx +26 -1
- src/components/ui/icons.tsx +41 -0
- src/components/users/parent-students-panel.tsx +119 -0
- src/components/users/user-table.tsx +9 -2
- src/i18n/messages.ts +79 -13
- src/lib/roles.ts +2 -1
- src/pages/admin-users-page.tsx +19 -1
- src/pages/dashboard-page.tsx +1 -0
- src/pages/my-students-page.tsx +110 -0
- src/pages/question-detail-page.tsx +322 -0
- src/pages/questions-page.tsx +221 -0
- src/routes/router.tsx +24 -0
src/api/deleteParentStudent.tsadded+7 -0
| @@ -0,0 +1,7 @@ | ||
| 1 | +import { client } from "./client"; | |
| 2 | + | |
| 3 | +export async function deleteParentStudent(id: string, student_id: string): Promise<void> { | |
| 4 | + return client(`/users/${id}/students/${student_id}`, { | |
| 5 | + method: "DELETE", | |
| 6 | + }); | |
| 7 | +} |
src/api/getMyStudents.tsadded+14 -0
| @@ -0,0 +1,14 @@ | ||
| 1 | +import { client } from "./client"; | |
| 2 | +import type { Page, PageParams } from "./page"; | |
| 3 | +import type { PersonRef } from "./types"; | |
| 4 | + | |
| 5 | +export async function getMyStudents(params?: PageParams): Promise<Page<PersonRef>> { | |
| 6 | + const searchParams = new URLSearchParams(); | |
| 7 | + if (params?.limit !== undefined) searchParams.set("limit", params.limit.toString()); | |
| 8 | + if (params?.offset !== undefined) searchParams.set("offset", params.offset.toString()); | |
| 9 | + | |
| 10 | + const query = searchParams.toString(); | |
| 11 | + const url = query ? `/users/me/students?${query}` : "/users/me/students"; | |
| 12 | + | |
| 13 | + return client(url); | |
| 14 | +} |
src/api/getParentStudents.tsadded+14 -0
| @@ -0,0 +1,14 @@ | ||
| 1 | +import { client } from "./client"; | |
| 2 | +import type { Page, PageParams } from "./page"; | |
| 3 | +import type { PersonRef } from "./types"; | |
| 4 | + | |
| 5 | +export async function getParentStudents(id: string, params?: PageParams): Promise<Page<PersonRef>> { | |
| 6 | + const searchParams = new URLSearchParams(); | |
| 7 | + if (params?.limit !== undefined) searchParams.set("limit", params.limit.toString()); | |
| 8 | + if (params?.offset !== undefined) searchParams.set("offset", params.offset.toString()); | |
| 9 | + | |
| 10 | + const query = searchParams.toString(); | |
| 11 | + const url = query ? `/users/${id}/students?${query}` : `/users/${id}/students`; | |
| 12 | + | |
| 13 | + return client(url); | |
| 14 | +} |
src/api/postParentStudent.tsadded+15 -0
| @@ -0,0 +1,15 @@ | ||
| 1 | +import { client } from "./client"; | |
| 2 | +import type { PersonRef } from "./types"; | |
| 3 | + | |
| 4 | +export interface ParentLinkResponse { | |
| 5 | + parent: PersonRef; | |
| 6 | + student: PersonRef; | |
| 7 | + linked_by: PersonRef; | |
| 8 | +} | |
| 9 | + | |
| 10 | +export async function postParentStudent(id: string, user_id: string): Promise<ParentLinkResponse> { | |
| 11 | + return client(`/users/${id}/students`, { | |
| 12 | + method: "POST", | |
| 13 | + body: JSON.stringify({ user_id }), | |
| 14 | + }); | |
| 15 | +} |
src/api/questions.tsadded+76 -0
| @@ -0,0 +1,76 @@ | ||
| 1 | +import { client, formClient } from "./client"; | |
| 2 | +import type { Page, PageParams } from "./page"; | |
| 3 | +import type { PersonRef } from "./types"; | |
| 4 | + | |
| 5 | +export interface PoolImageMeta { | |
| 6 | + content_type: string; | |
| 7 | + size: number; | |
| 8 | +} | |
| 9 | + | |
| 10 | +export interface PoolQuestionResponse { | |
| 11 | + id: string; | |
| 12 | + /** The student who asked — field is `asker` on the backend */ | |
| 13 | + asker: PersonRef; | |
| 14 | + title: string; | |
| 15 | + body: string; | |
| 16 | + status: "pending" | "approved"; | |
| 17 | + asked_at: number; | |
| 18 | + approved_by: PersonRef | null; | |
| 19 | + /** null when there is no image */ | |
| 20 | + image: PoolImageMeta | null; | |
| 21 | + solution_count: number; | |
| 22 | +} | |
| 23 | + | |
| 24 | +export interface AskQuestion { | |
| 25 | + title: string; | |
| 26 | + body: string; | |
| 27 | +} | |
| 28 | + | |
| 29 | +export async function getQuestions( | |
| 30 | + status?: "pending" | "approved", | |
| 31 | + params?: PageParams | |
| 32 | +): Promise<Page<PoolQuestionResponse>> { | |
| 33 | + const searchParams = new URLSearchParams(); | |
| 34 | + if (status) searchParams.set("status", status); | |
| 35 | + if (params?.limit !== undefined) searchParams.set("limit", params.limit.toString()); | |
| 36 | + if (params?.offset !== undefined) searchParams.set("offset", params.offset.toString()); | |
| 37 | + | |
| 38 | + const query = searchParams.toString(); | |
| 39 | + const url = query ? `/questions?${query}` : "/questions"; | |
| 40 | + return client(url); | |
| 41 | +} | |
| 42 | + | |
| 43 | +export async function getQuestionById(id: string): Promise<PoolQuestionResponse> { | |
| 44 | + return client(`/questions/${id}`); | |
| 45 | +} | |
| 46 | + | |
| 47 | +export async function postQuestion(body: AskQuestion, image?: File): Promise<PoolQuestionResponse> { | |
| 48 | + const res = await client<PoolQuestionResponse>("/questions", { | |
| 49 | + method: "POST", | |
| 50 | + body, | |
| 51 | + }); | |
| 52 | + | |
| 53 | + if (image) { | |
| 54 | + const fd = new FormData(); | |
| 55 | + fd.append("file", image); | |
| 56 | + await formClient(`/questions/${res.id}/image`, fd); | |
| 57 | + } | |
| 58 | + | |
| 59 | + return res; | |
| 60 | +} | |
| 61 | + | |
| 62 | +export async function postQuestionApprove(id: string): Promise<PoolQuestionResponse> { | |
| 63 | + return client(`/questions/${id}/approve`, { | |
| 64 | + method: "POST", | |
| 65 | + }); | |
| 66 | +} | |
| 67 | + | |
| 68 | +export async function deleteQuestionById(id: string): Promise<void> { | |
| 69 | + return client(`/questions/${id}`, { | |
| 70 | + method: "DELETE", | |
| 71 | + }); | |
| 72 | +} | |
| 73 | + | |
| 74 | +export function getQuestionImageUrl(id: string): string { | |
| 75 | + return `/api/questions/${id}/image`; | |
| 76 | +} |
src/api/solutions.tsadded+75 -0
| @@ -0,0 +1,75 @@ | ||
| 1 | +import { client, formClient } from "./client"; | |
| 2 | +import type { Page, PageParams } from "./page"; | |
| 3 | +import type { PersonRef } from "./types"; | |
| 4 | + | |
| 5 | +export interface PoolImageMeta { | |
| 6 | + content_type: string; | |
| 7 | + size: number; | |
| 8 | +} | |
| 9 | + | |
| 10 | +export interface SolutionResponse { | |
| 11 | + id: string; | |
| 12 | + question: string; | |
| 13 | + author: PersonRef; | |
| 14 | + body: string; | |
| 15 | + offered_at: number; | |
| 16 | + /** null when there is no image */ | |
| 17 | + image: PoolImageMeta | null; | |
| 18 | +} | |
| 19 | + | |
| 20 | +export interface OfferSolution { | |
| 21 | + body: string; | |
| 22 | +} | |
| 23 | + | |
| 24 | +export async function getSolutions( | |
| 25 | + id: string, | |
| 26 | + params?: PageParams | |
| 27 | +): Promise<Page<SolutionResponse>> { | |
| 28 | + const searchParams = new URLSearchParams(); | |
| 29 | + if (params?.limit !== undefined) searchParams.set("limit", params.limit.toString()); | |
| 30 | + if (params?.offset !== undefined) searchParams.set("offset", params.offset.toString()); | |
| 31 | + | |
| 32 | + const query = searchParams.toString(); | |
| 33 | + const url = query ? `/questions/${id}/solutions?${query}` : `/questions/${id}/solutions`; | |
| 34 | + return client(url); | |
| 35 | +} | |
| 36 | + | |
| 37 | +export async function postSolution( | |
| 38 | + id: string, | |
| 39 | + body: OfferSolution, | |
| 40 | + image?: File | |
| 41 | +): Promise<SolutionResponse> { | |
| 42 | + const res = await client<SolutionResponse>(`/questions/${id}/solutions`, { | |
| 43 | + method: "POST", | |
| 44 | + body, | |
| 45 | + }); | |
| 46 | + | |
| 47 | + if (image) { | |
| 48 | + const fd = new FormData(); | |
| 49 | + fd.append("file", image); | |
| 50 | + await formClient(`/questions/${id}/solutions/${res.id}/image`, fd); | |
| 51 | + } | |
| 52 | + | |
| 53 | + return res; | |
| 54 | +} | |
| 55 | + | |
| 56 | +export async function patchSolutionById( | |
| 57 | + id: string, | |
| 58 | + sid: string, | |
| 59 | + body: OfferSolution | |
| 60 | +): Promise<SolutionResponse> { | |
| 61 | + return client(`/questions/${id}/solutions/${sid}`, { | |
| 62 | + method: "PATCH", | |
| 63 | + body, | |
| 64 | + }); | |
| 65 | +} | |
| 66 | + | |
| 67 | +export async function deleteSolutionById(id: string, sid: string): Promise<void> { | |
| 68 | + return client(`/questions/${id}/solutions/${sid}`, { | |
| 69 | + method: "DELETE", | |
| 70 | + }); | |
| 71 | +} | |
| 72 | + | |
| 73 | +export function getSolutionImageUrl(id: string, sid: string): string { | |
| 74 | + return `/api/questions/${id}/solutions/${sid}/image`; | |
| 75 | +} |
src/api/types.tsmodified+1 -1
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | export type { Page, PageParams } from "./page"; |
| 2 | 2 | |
| 3 | -export type Role = "student" | "teacher" | "manager" | "admin"; | |
| 3 | +export type Role = "student" | "parent" | "teacher" | "manager" | "admin"; | |
| 4 | 4 | export type UserTheme = "light" | "dark"; |
| 5 | 5 | export type UserLanguage = "tr" | "en"; |
| 6 | 6 | export type CourseKind = "course" | "study" | "club" | string; |
src/components/layout/app-shell.tsxmodified+1 -0
| @@ -39,6 +39,7 @@ export function AppShell(props: ParentProps) { | ||
| 39 | 39 | if (path === "/clubs") return `${t("nav.group.classes")} / ${t("nav.clubs")}`; |
| 40 | 40 | if (path === "/events" || path.startsWith("/events/")) return `${t("nav.group.classes")} / ${t("nav.events")}`; |
| 41 | 41 | if (path === "/exams" || path.startsWith("/exams/")) return `${t("nav.group.classes")} / ${t("nav.exams")}`; |
| 42 | + if (path === "/questions" || path.startsWith("/questions/")) return `${t("nav.group.community")} / ${t("pool.title")}`; | |
| 42 | 43 | if (path.startsWith("/exam-room/")) return t("nav.exams"); |
| 43 | 44 | if (path === "/work") return `${t("nav.group.reports")} / ${t("nav.work")}`; |
| 44 | 45 | if (path === "/management/student-marks") return `${t("nav.group.reports")} / ${t("nav.studentMarks")}`; |
src/components/layout/role-badge.tsxmodified+1 -0
| @@ -5,6 +5,7 @@ import { useT } from "@/stores/preferences-context"; | ||
| 5 | 5 | |
| 6 | 6 | const VARIANT: Record<Role, "default" | "secondary" | "outline" | "destructive"> = { |
| 7 | 7 | student: "secondary", |
| 8 | + parent: "secondary", | |
| 8 | 9 | teacher: "default", |
| 9 | 10 | manager: "outline", |
| 10 | 11 | admin: "destructive", |
src/components/layout/side-nav.tsxmodified+26 -1
| @@ -22,6 +22,8 @@ import { | ||
| 22 | 22 | IconClock, |
| 23 | 23 | IconClipboardCheck, |
| 24 | 24 | IconExam, |
| 25 | + IconGlobe, | |
| 26 | + IconHelpCircle, | |
| 25 | 27 | IconHome, |
| 26 | 28 | IconMessage, |
| 27 | 29 | IconNote, |
| @@ -49,6 +51,7 @@ type NavGroup = { | ||
| 49 | 51 | labelKey: MessageKey; |
| 50 | 52 | Icon: Component<{ class?: string }>; |
| 51 | 53 | minRole?: Role; |
| 54 | + exactRole?: Role; | |
| 52 | 55 | items: NavItem[]; |
| 53 | 56 | }; |
| 54 | 57 | |
| @@ -65,6 +68,15 @@ const NAV_GROUPS: NavGroup[] = [ | ||
| 65 | 68 | { to: "/events", labelKey: "nav.events", Icon: IconCalendar }, |
| 66 | 69 | ], |
| 67 | 70 | }, |
| 71 | + { | |
| 72 | + id: "students", | |
| 73 | + labelKey: "nav.group.students", | |
| 74 | + Icon: IconUsers, | |
| 75 | + exactRole: "parent", | |
| 76 | + items: [ | |
| 77 | + { to: "/students", labelKey: "nav.myStudents", Icon: IconUsers, exactRole: "parent" }, | |
| 78 | + ], | |
| 79 | + }, | |
| 68 | 80 | { |
| 69 | 81 | id: "grades", |
| 70 | 82 | labelKey: "nav.group.grades", |
| @@ -90,6 +102,14 @@ const NAV_GROUPS: NavGroup[] = [ | ||
| 90 | 102 | { to: "/management/staff-work", labelKey: "nav.staffWork", Icon: IconBriefcase, minRole: "manager" }, |
| 91 | 103 | ], |
| 92 | 104 | }, |
| 105 | + { | |
| 106 | + id: "community", | |
| 107 | + labelKey: "nav.group.community", | |
| 108 | + Icon: IconGlobe, | |
| 109 | + items: [ | |
| 110 | + { to: "/questions", labelKey: "nav.questions", Icon: IconHelpCircle }, | |
| 111 | + ], | |
| 112 | + }, | |
| 93 | 113 | { |
| 94 | 114 | id: "settings", |
| 95 | 115 | labelKey: "nav.group.settings", |
| @@ -170,7 +190,12 @@ export function SideNav(props: { onNavigate?: () => void; collapsed?: boolean }) | ||
| 170 | 190 | |
| 171 | 191 | const visibleGroups = createMemo(() => |
| 172 | 192 | NAV_GROUPS |
| 173 | - .filter((group) => !group.minRole || hasMinRole(auth.user()?.role, group.minRole)) | |
| 193 | + .filter((group) => { | |
| 194 | + const r = auth.user()?.role; | |
| 195 | + if (group.exactRole && !hasExactRole(r, group.exactRole)) return false; | |
| 196 | + if (group.minRole && !hasMinRole(r, group.minRole)) return false; | |
| 197 | + return true; | |
| 198 | + }) | |
| 174 | 199 | .map((group) => ({ |
| 175 | 200 | ...group, |
| 176 | 201 | items: group.items.filter(itemVisible), |
src/components/ui/icons.tsxmodified+41 -0
| @@ -161,6 +161,47 @@ export function IconMoon(props: IconProps) { | ||
| 161 | 161 | ); |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | +export function IconZoomIn(props: IconProps) { | |
| 165 | + return ( | |
| 166 | + <Svg {...props}> | |
| 167 | + <circle cx="11" cy="11" r="8" /> | |
| 168 | + <line x1="21" x2="16.65" y1="21" y2="16.65" /> | |
| 169 | + <line x1="11" x2="11" y1="8" y2="14" /> | |
| 170 | + <line x1="8" x2="14" y1="11" y2="11" /> | |
| 171 | + </Svg> | |
| 172 | + ); | |
| 173 | +} | |
| 174 | + | |
| 175 | +export function IconHelpCircle(props: IconProps) { | |
| 176 | + return ( | |
| 177 | + <Svg {...props}> | |
| 178 | + <circle cx="12" cy="12" r="10" /> | |
| 179 | + <path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3" /> | |
| 180 | + <path d="M12 17h.01" /> | |
| 181 | + </Svg> | |
| 182 | + ); | |
| 183 | +} | |
| 184 | + | |
| 185 | +export function IconMessagePlus(props: IconProps) { | |
| 186 | + return ( | |
| 187 | + <Svg {...props}> | |
| 188 | + <path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" /> | |
| 189 | + <path d="M12 7v6" /> | |
| 190 | + <path d="M9 10h6" /> | |
| 191 | + </Svg> | |
| 192 | + ); | |
| 193 | +} | |
| 194 | + | |
| 195 | +export function IconPhoto(props: IconProps) { | |
| 196 | + return ( | |
| 197 | + <Svg {...props}> | |
| 198 | + <rect x="3" y="3" width="18" height="18" rx="2" ry="2" /> | |
| 199 | + <circle cx="8.5" cy="8.5" r="1.5" /> | |
| 200 | + <polyline points="21 15 16 10 5 21" /> | |
| 201 | + </Svg> | |
| 202 | + ); | |
| 203 | +} | |
| 204 | + | |
| 164 | 205 | export function IconGlobe(props: IconProps) { |
| 165 | 206 | return ( |
| 166 | 207 | <Svg {...props}> |
src/components/users/parent-students-panel.tsxadded+119 -0
| @@ -0,0 +1,119 @@ | ||
| 1 | +import { For, Show, Suspense, createResource, createSignal } from "solid-js"; | |
| 2 | +import { getParentStudents } from "@/api/getParentStudents"; | |
| 3 | +import { postParentStudent } from "@/api/postParentStudent"; | |
| 4 | +import { deleteParentStudent } from "@/api/deleteParentStudent"; | |
| 5 | +import { formatApiError } from "@/api/client"; | |
| 6 | +import type { PersonRef } from "@/api/types"; | |
| 7 | +import { SidePanel } from "@/components/ui/side-panel"; | |
| 8 | +import { Button } from "@/components/ui/button"; | |
| 9 | +import { IconTrash, IconPlus } from "@/components/ui/icons"; | |
| 10 | +import { personLabel } from "@/lib/person"; | |
| 11 | +import { useT } from "@/stores/preferences-context"; | |
| 12 | +import { UserSearchSelect } from "@/components/users/user-search-select"; | |
| 13 | +import { createFlash } from "@/lib/flash"; | |
| 14 | +import { Alert } from "@/components/ui/alert"; | |
| 15 | +import { PageSpinner } from "@/components/ui/page-spinner"; | |
| 16 | + | |
| 17 | +export function ParentStudentsPanel(props: { | |
| 18 | + open: boolean; | |
| 19 | + onOpenChange: (open: boolean) => void; | |
| 20 | + parent: PersonRef | null; | |
| 21 | +}) { | |
| 22 | + const t = useT(); | |
| 23 | + const [error, setError] = createSignal(""); | |
| 24 | + const [flash, setFlash] = createFlash(); | |
| 25 | + | |
| 26 | + const [students, { refetch }] = createResource( | |
| 27 | + () => (props.open && props.parent ? props.parent.id : null), | |
| 28 | + async (id) => (await getParentStudents(id)).items | |
| 29 | + ); | |
| 30 | + | |
| 31 | + const [selectedStudentId, setSelectedStudentId] = createSignal(""); | |
| 32 | + | |
| 33 | + const handleAdd = async () => { | |
| 34 | + if (!props.parent || !selectedStudentId()) return; | |
| 35 | + setError(""); | |
| 36 | + try { | |
| 37 | + await postParentStudent(props.parent.id, selectedStudentId()); | |
| 38 | + await refetch(); | |
| 39 | + setSelectedStudentId(""); | |
| 40 | + setFlash(t("common.saved")); | |
| 41 | + } catch (err) { | |
| 42 | + setError(formatApiError(err)); | |
| 43 | + } | |
| 44 | + }; | |
| 45 | + | |
| 46 | + const handleRemove = async (studentId: string) => { | |
| 47 | + if (!props.parent) return; | |
| 48 | + setError(""); | |
| 49 | + try { | |
| 50 | + await deleteParentStudent(props.parent.id, studentId); | |
| 51 | + await refetch(); | |
| 52 | + setFlash(t("common.deleted")); | |
| 53 | + } catch (err) { | |
| 54 | + setError(formatApiError(err)); | |
| 55 | + } | |
| 56 | + }; | |
| 57 | + | |
| 58 | + return ( | |
| 59 | + <SidePanel | |
| 60 | + open={props.open} | |
| 61 | + onOpenChange={(open) => { | |
| 62 | + if (!open) { | |
| 63 | + setError(""); | |
| 64 | + setSelectedStudentId(""); | |
| 65 | + } | |
| 66 | + props.onOpenChange(open); | |
| 67 | + }} | |
| 68 | + title={t("nav.myStudents")} | |
| 69 | + description={props.parent ? personLabel(props.parent) : ""} | |
| 70 | + > | |
| 71 | + <div class="flex flex-col h-full space-y-6 p-4"> | |
| 72 | + <Show when={flash()}> | |
| 73 | + <Alert variant="success">{flash()}</Alert> | |
| 74 | + </Show> | |
| 75 | + {error() && <p class="rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive">{error()}</p>} | |
| 76 | + | |
| 77 | + <div class="flex items-end gap-2"> | |
| 78 | + <div class="flex-1"> | |
| 79 | + <UserSearchSelect | |
| 80 | + id="parent-student-select" | |
| 81 | + role={undefined} | |
| 82 | + value={selectedStudentId()} | |
| 83 | + onChange={setSelectedStudentId} | |
| 84 | + label={t("events.selectAttendee")} | |
| 85 | + /> | |
| 86 | + </div> | |
| 87 | + <Button onClick={handleAdd} disabled={!selectedStudentId()}> | |
| 88 | + <IconPlus class="mr-2 h-4 w-4" /> | |
| 89 | + {t("common.create")} | |
| 90 | + </Button> | |
| 91 | + </div> | |
| 92 | + | |
| 93 | + <div class="flex-1 overflow-auto rounded-md border"> | |
| 94 | + <Suspense fallback={<div class="p-8"><PageSpinner /></div>}> | |
| 95 | + <Show when={students()}> | |
| 96 | + <Show when={students()!.length > 0} fallback={<div class="p-8 text-center text-sm text-muted-foreground">{t("common.noResults")}</div>}> | |
| 97 | + <div class="divide-y"> | |
| 98 | + <For each={students()}> | |
| 99 | + {(student) => ( | |
| 100 | + <div class="flex items-center justify-between p-3"> | |
| 101 | + <div class="min-w-0"> | |
| 102 | + <div class="truncate text-sm font-medium">{personLabel(student)}</div> | |
| 103 | + <div class="truncate text-xs text-muted-foreground">@{student.username}</div> | |
| 104 | + </div> | |
| 105 | + <Button variant="ghost" size="icon" class="text-destructive hover:bg-destructive/10 hover:text-destructive" onClick={() => handleRemove(student.id)}> | |
| 106 | + <IconTrash class="h-4 w-4" /> | |
| 107 | + </Button> | |
| 108 | + </div> | |
| 109 | + )} | |
| 110 | + </For> | |
| 111 | + </div> | |
| 112 | + </Show> | |
| 113 | + </Show> | |
| 114 | + </Suspense> | |
| 115 | + </div> | |
| 116 | + </div> | |
| 117 | + </SidePanel> | |
| 118 | + ); | |
| 119 | +} |
src/components/users/user-table.tsxmodified+9 -2
| @@ -27,6 +27,7 @@ function UserRoleActions(props: { | ||
| 27 | 27 | user: User; |
| 28 | 28 | currentUserId: string; |
| 29 | 29 | onRoleChange: (userId: string, role: Role) => Promise<void>; |
| 30 | + onParentClick?: (user: User) => void; | |
| 30 | 31 | }) { |
| 31 | 32 | const t = useT(); |
| 32 | 33 | const isSelf = () => props.user.id === props.currentUserId; |
| @@ -48,11 +49,16 @@ function UserRoleActions(props: { | ||
| 48 | 49 | ))} |
| 49 | 50 | </Select> |
| 50 | 51 | <Show when={!isSelf() && dirty()}> |
| 51 | - <Button type="button" size="sm" class="mt-2 h-7 rounded-sm px-2" onClick={() => setConfirmOpen(true)}> | |
| 52 | + <Button type="button" size="sm" class="mt-2 h-7 rounded-sm px-2" onClick={(e) => { e.stopPropagation(); setConfirmOpen(true); }}> | |
| 52 | 53 | <IconCheck /> |
| 53 | 54 | {t("common.update")} |
| 54 | 55 | </Button> |
| 55 | 56 | </Show> |
| 57 | + <Show when={props.user.role === "parent"}> | |
| 58 | + <Button variant="outline" size="sm" class="ml-2 h-7 rounded-sm px-2" onClick={(e) => { e.stopPropagation(); props.onParentClick?.(props.user); }}> | |
| 59 | + {t("nav.group.students")} | |
| 60 | + </Button> | |
| 61 | + </Show> | |
| 56 | 62 | <ConfirmDialog |
| 57 | 63 | open={confirmOpen()} |
| 58 | 64 | onOpenChange={setConfirmOpen} |
| @@ -75,6 +81,7 @@ export function UserTable(props: { | ||
| 75 | 81 | currentUserId: string; |
| 76 | 82 | onRoleChange: (userId: string, role: Role) => Promise<void>; |
| 77 | 83 | onUserClick?: (user: User) => void; |
| 84 | + onParentClick?: (user: User) => void; | |
| 78 | 85 | }) { |
| 79 | 86 | const t = useT(); |
| 80 | 87 | const searchUser = (user: User, query: string) => |
| @@ -120,7 +127,7 @@ export function UserTable(props: { | ||
| 120 | 127 | header: t("common.update"), |
| 121 | 128 | meta: { headerClass: "w-52", cellClass: "w-52" }, |
| 122 | 129 | cell: (cell) => ( |
| 123 | - <UserRoleActions user={cell.row.original} currentUserId={props.currentUserId} onRoleChange={props.onRoleChange} /> | |
| 130 | + <UserRoleActions user={cell.row.original} currentUserId={props.currentUserId} onRoleChange={props.onRoleChange} onParentClick={props.onParentClick} /> | |
| 124 | 131 | ), |
| 125 | 132 | }, |
| 126 | 133 | ]); |
src/i18n/messages.tsmodified+79 -13
| @@ -21,6 +21,7 @@ export type MessageKey = | ||
| 21 | 21 | | "nav.messages" |
| 22 | 22 | | "nav.pomodoro" |
| 23 | 23 | | "nav.attendance" |
| 24 | + | "nav.questions" | |
| 24 | 25 | | "nav.work" |
| 25 | 26 | | "nav.staffWork" |
| 26 | 27 | | "nav.users" |
| @@ -43,6 +44,10 @@ export type MessageKey = | ||
| 43 | 44 | | "nav.group.grades" |
| 44 | 45 | | "nav.group.reports" |
| 45 | 46 | | "nav.group.settings" |
| 47 | + | "nav.group.community" | |
| 48 | + | "nav.myStudents" | |
| 49 | + | "parents.title" | |
| 50 | + | "parents.subtitle" | |
| 46 | 51 | | "common.loading" |
| 47 | 52 | | "common.cancel" |
| 48 | 53 | | "common.save" |
| @@ -54,6 +59,9 @@ export type MessageKey = | ||
| 54 | 59 | | "common.remove" |
| 55 | 60 | | "common.back" |
| 56 | 61 | | "common.view" |
| 62 | + | "common.reply" | |
| 63 | + | "common.approve" | |
| 64 | + | "common.reject" | |
| 57 | 65 | | "common.actions" |
| 58 | 66 | | "common.columns" |
| 59 | 67 | | "common.moreFilters" |
| @@ -98,6 +106,19 @@ export type MessageKey = | ||
| 98 | 106 | | "common.saved" |
| 99 | 107 | | "common.createItem" |
| 100 | 108 | | "common.countItem" |
| 109 | + | "pool.title" | |
| 110 | + | "pool.subtitle" | |
| 111 | + | "pool.ask" | |
| 112 | + | "pool.subject" | |
| 113 | + | "pool.body" | |
| 114 | + | "pool.image" | |
| 115 | + | "pool.status" | |
| 116 | + | "pool.pending" | |
| 117 | + | "pool.approved" | |
| 118 | + | "pool.author" | |
| 119 | + | "pool.solutions" | |
| 120 | + | "pool.offerSolution" | |
| 121 | + | "pool.noQuestions" | |
| 101 | 122 | | "theme.light" |
| 102 | 123 | | "theme.dark" |
| 103 | 124 | | "theme.toggle" |
| @@ -445,6 +466,7 @@ export type MessageKey = | ||
| 445 | 466 | | "auth.featurePrefs" |
| 446 | 467 | | "app.workspace" |
| 447 | 468 | | "role.student" |
| 469 | + | "role.parent" | |
| 448 | 470 | | "role.teacher" |
| 449 | 471 | | "role.manager" |
| 450 | 472 | | "role.admin" |
| @@ -649,7 +671,8 @@ const en: Dict = { | ||
| 649 | 671 | "nav.messages": "Messages", |
| 650 | 672 | "nav.pomodoro": "Pomodoro", |
| 651 | 673 | "nav.attendance": "Attendance", |
| 652 | - "nav.work": "Work logs", | |
| 674 | + "nav.questions": "Question Pool", | |
| 675 | + "nav.work": "Work Log", | |
| 653 | 676 | "nav.staffWork": "Staff work", |
| 654 | 677 | "nav.users": "Users", |
| 655 | 678 | "nav.studentMarks": "Student marks", |
| @@ -668,9 +691,13 @@ const en: Dict = { | ||
| 668 | 691 | "nav.preferences": "Preferences", |
| 669 | 692 | "nav.group.students": "Students", |
| 670 | 693 | "nav.group.classes": "Education", |
| 671 | - "nav.group.grades": "My space", | |
| 694 | + "nav.group.grades": "Grades", | |
| 672 | 695 | "nav.group.reports": "Reports", |
| 673 | 696 | "nav.group.settings": "Settings", |
| 697 | + "nav.group.community": "Community", | |
| 698 | + "nav.myStudents": "My Students", | |
| 699 | + "parents.title": "My Students", | |
| 700 | + "parents.subtitle": "View records for your linked students.", | |
| 674 | 701 | "common.loading": "Loading…", |
| 675 | 702 | "common.cancel": "Cancel", |
| 676 | 703 | "common.save": "Save", |
| @@ -682,6 +709,9 @@ const en: Dict = { | ||
| 682 | 709 | "common.remove": "Remove", |
| 683 | 710 | "common.back": "Back", |
| 684 | 711 | "common.view": "View", |
| 712 | + "common.reply": "Reply", | |
| 713 | + "common.approve": "Approve", | |
| 714 | + "common.reject": "Reject", | |
| 685 | 715 | "common.actions": "Actions", |
| 686 | 716 | "common.columns": "Columns", |
| 687 | 717 | "common.moreFilters": "More filters", |
| @@ -694,7 +724,7 @@ const en: Dict = { | ||
| 694 | 724 | "common.goHome": "Go home", |
| 695 | 725 | "common.learnMore": "Learn more", |
| 696 | 726 | "common.gotIt": "Got it", |
| 697 | - "confirm.review": "Please review the details before continuing.", | |
| 727 | + "confirm.review": "Please review your changes before saving.", | |
| 698 | 728 | "confirm.summary": "Summary", |
| 699 | 729 | "confirm.confirmDelete": "Yes, delete", |
| 700 | 730 | "confirm.confirmUpdate": "Yes, update", |
| @@ -723,9 +753,22 @@ const en: Dict = { | ||
| 723 | 753 | "common.saveAttendance": "Save my attendance", |
| 724 | 754 | "common.created": "Created.", |
| 725 | 755 | "common.deleted": "Deleted.", |
| 726 | - "common.saved": "Saved.", | |
| 727 | - "common.createItem": "Create {item}", | |
| 756 | + "common.saved": "Saved successfully.", | |
| 757 | + "common.createItem": "Create new {item}", | |
| 728 | 758 | "common.countItem": "{count} {item}", |
| 759 | + "pool.title": "Question Pool", | |
| 760 | + "pool.subtitle": "Ask questions and discuss solutions.", | |
| 761 | + "pool.ask": "Ask Question", | |
| 762 | + "pool.subject": "Subject", | |
| 763 | + "pool.body": "Question details", | |
| 764 | + "pool.image": "Attachment (Image)", | |
| 765 | + "pool.status": "Status", | |
| 766 | + "pool.pending": "Pending", | |
| 767 | + "pool.approved": "Approved", | |
| 768 | + "pool.author": "Author", | |
| 769 | + "pool.solutions": "Solutions", | |
| 770 | + "pool.offerSolution": "Offer a solution", | |
| 771 | + "pool.noQuestions": "No questions found.", | |
| 729 | 772 | "theme.light": "Light", |
| 730 | 773 | "theme.dark": "Dark", |
| 731 | 774 | "theme.toggle": "Toggle theme", |
| @@ -1086,6 +1129,7 @@ const en: Dict = { | ||
| 1086 | 1129 | "auth.featurePrefs": "TR / EN · light / dark", |
| 1087 | 1130 | "app.workspace": "@Hezarfen - 2026", |
| 1088 | 1131 | "role.student": "Student", |
| 1132 | + "role.parent": "Parent", | |
| 1089 | 1133 | "role.teacher": "Teacher", |
| 1090 | 1134 | "role.manager": "Manager", |
| 1091 | 1135 | "role.admin": "ADMIN", |
| @@ -1288,8 +1332,9 @@ const tr: Dict = { | ||
| 1288 | 1332 | "nav.marks": "Notlar", |
| 1289 | 1333 | "nav.messages": "Mesajlar", |
| 1290 | 1334 | "nav.pomodoro": "Pomodoro", |
| 1291 | - "nav.attendance": "Yoklamalar", | |
| 1292 | - "nav.work": "Mesailer", | |
| 1335 | + "nav.attendance": "Yoklama", | |
| 1336 | + "nav.questions": "Soru Havuzu", | |
| 1337 | + "nav.work": "Çalışma Kaydı", | |
| 1293 | 1338 | "nav.staffWork": "Mesailer", |
| 1294 | 1339 | "nav.users": "Kullanıcılar", |
| 1295 | 1340 | "nav.studentMarks": "Notlar", |
| @@ -1308,9 +1353,13 @@ const tr: Dict = { | ||
| 1308 | 1353 | "nav.preferences": "Tercihler", |
| 1309 | 1354 | "nav.group.students": "Öğrenciler", |
| 1310 | 1355 | "nav.group.classes": "Eğitim", |
| 1311 | - "nav.group.grades": "Benim Alanım", | |
| 1356 | + "nav.group.grades": "Notlar", | |
| 1312 | 1357 | "nav.group.reports": "Raporlar", |
| 1313 | 1358 | "nav.group.settings": "Ayarlar", |
| 1359 | + "nav.group.community": "Topluluk", | |
| 1360 | + "nav.myStudents": "Öğrencilerim", | |
| 1361 | + "parents.title": "Öğrencilerim", | |
| 1362 | + "parents.subtitle": "Size bağlı öğrencilerin akademik kayıtlarını inceleyin.", | |
| 1314 | 1363 | "common.loading": "Yükleniyor…", |
| 1315 | 1364 | "common.cancel": "Vazgeç", |
| 1316 | 1365 | "common.save": "Kaydet", |
| @@ -1322,7 +1371,10 @@ const tr: Dict = { | ||
| 1322 | 1371 | "common.remove": "Kaldır", |
| 1323 | 1372 | "common.back": "Geri", |
| 1324 | 1373 | "common.view": "Görüntüle", |
| 1325 | - "common.actions": "İşlem", | |
| 1374 | + "common.reply": "Yanıtla", | |
| 1375 | + "common.approve": "Onayla", | |
| 1376 | + "common.reject": "Reddet", | |
| 1377 | + "common.actions": "İşlemler", | |
| 1326 | 1378 | "common.columns": "Kolonlar", |
| 1327 | 1379 | "common.moreFilters": "Daha fazla filtre", |
| 1328 | 1380 | "common.lessFilters": "Daha az filtre", |
| @@ -1334,7 +1386,7 @@ const tr: Dict = { | ||
| 1334 | 1386 | "common.goHome": "Ana sayfaya dön", |
| 1335 | 1387 | "common.learnMore": "Daha fazla", |
| 1336 | 1388 | "common.gotIt": "Anladım", |
| 1337 | - "confirm.review": "Devam etmeden önce işlem özetini kontrol edin.", | |
| 1389 | + "confirm.review": "Lütfen kaydetmeden önce değişiklikleri gözden geçirin.", | |
| 1338 | 1390 | "confirm.summary": "İşlem özeti", |
| 1339 | 1391 | "confirm.confirmDelete": "Evet, sil", |
| 1340 | 1392 | "confirm.confirmUpdate": "Evet, güncelle", |
| @@ -1363,9 +1415,22 @@ const tr: Dict = { | ||
| 1363 | 1415 | "common.saveAttendance": "Yoklamamı kaydet", |
| 1364 | 1416 | "common.created": "Oluşturuldu.", |
| 1365 | 1417 | "common.deleted": "Silindi.", |
| 1366 | - "common.saved": "Kaydedildi.", | |
| 1367 | - "common.createItem": "{item} oluştur", | |
| 1368 | - "common.countItem": "{count} Adet {item}", | |
| 1418 | + "common.saved": "Başarıyla kaydedildi.", | |
| 1419 | + "common.createItem": "Yeni {item} oluştur", | |
| 1420 | + "common.countItem": "{count} {item}", | |
| 1421 | + "pool.title": "Soru Havuzu", | |
| 1422 | + "pool.subtitle": "Soru sorun ve çözümleri tartışın.", | |
| 1423 | + "pool.ask": "Soru Sor", | |
| 1424 | + "pool.subject": "Konu", | |
| 1425 | + "pool.body": "Soru detayı", | |
| 1426 | + "pool.image": "Görsel (İsteğe bağlı)", | |
| 1427 | + "pool.status": "Durum", | |
| 1428 | + "pool.pending": "Bekliyor", | |
| 1429 | + "pool.approved": "Onaylandı", | |
| 1430 | + "pool.author": "Yazar", | |
| 1431 | + "pool.solutions": "Çözümler", | |
| 1432 | + "pool.offerSolution": "Çözüm Gönder", | |
| 1433 | + "pool.noQuestions": "Soru bulunamadı.", | |
| 1369 | 1434 | "theme.light": "Açık", |
| 1370 | 1435 | "theme.dark": "Koyu", |
| 1371 | 1436 | "theme.toggle": "Tema", |
| @@ -1726,6 +1791,7 @@ const tr: Dict = { | ||
| 1726 | 1791 | "auth.featurePrefs": "TR / EN · açık / koyu", |
| 1727 | 1792 | "app.workspace": "@Hezarfen - 2026", |
| 1728 | 1793 | "role.student": "Öğrenci", |
| 1794 | + "role.parent": "Veli", | |
| 1729 | 1795 | "role.teacher": "Öğretmen", |
| 1730 | 1796 | "role.manager": "Yönetici", |
| 1731 | 1797 | "role.admin": "ADMIN", |
src/lib/roles.tsmodified+2 -1
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | import type { Role } from "@/api/types"; |
| 2 | 2 | |
| 3 | 3 | const RANK: Record<Role, number> = { |
| 4 | + parent: -1, | |
| 4 | 5 | student: 0, |
| 5 | 6 | teacher: 1, |
| 6 | 7 | manager: 2, |
| @@ -33,4 +34,4 @@ export function roleInRange( | ||
| 33 | 34 | return true; |
| 34 | 35 | } |
| 35 | 36 | |
| 36 | -export const ROLES: Role[] = ["student", "teacher", "manager", "admin"]; | |
| 37 | +export const ROLES: Role[] = ["student", "parent", "teacher", "manager", "admin"]; |
src/pages/admin-users-page.tsxmodified+19 -1
| @@ -8,6 +8,7 @@ import { RouteGuard } from "@/components/layout/route-guard"; | ||
| 8 | 8 | import { PageHeader } from "@/components/layout/page-header"; |
| 9 | 9 | import { ProfileForm } from "@/components/users/profile-form"; |
| 10 | 10 | import { UserTable } from "@/components/users/user-table"; |
| 11 | +import { ParentStudentsPanel } from "@/components/users/parent-students-panel"; | |
| 11 | 12 | import { Alert } from "@/components/ui/alert"; |
| 12 | 13 | import { Badge } from "@/components/ui/badge"; |
| 13 | 14 | import { DataTableEmpty, DataTableSkeleton } from "@/components/ui/data-table"; |
| @@ -31,6 +32,7 @@ function AdminUsersContent() { | ||
| 31 | 32 | const t = useT(); |
| 32 | 33 | const [error, setError] = createSignal(""); |
| 33 | 34 | const [editUser, setEditUser] = createSignal<User | null>(null); |
| 35 | + const [selectedParent, setSelectedParent] = createSignal<User | null>(null); | |
| 34 | 36 | |
| 35 | 37 | const [list, { refetch }] = createResource(async () => (await getUsers()).items); |
| 36 | 38 | const visibleUsers = () => list() ?? []; |
| @@ -80,7 +82,13 @@ function AdminUsersContent() { | ||
| 80 | 82 | <Suspense fallback={<DataTableSkeleton columns={6} rows={8} />}> |
| 81 | 83 | <Show when={list()}> |
| 82 | 84 | <Show when={visibleUsers().length > 0} fallback={<DataTableEmpty>{t("admin.noUsers")}</DataTableEmpty>}> |
| 83 | - <UserTable users={visibleUsers() as User[]} currentUserId={auth.user()!.id} onRoleChange={onRoleChange} onUserClick={setEditUser} /> | |
| 85 | + <UserTable | |
| 86 | + users={visibleUsers() as User[]} | |
| 87 | + currentUserId={auth.user()!.id} | |
| 88 | + onRoleChange={onRoleChange} | |
| 89 | + onUserClick={setEditUser} | |
| 90 | + onParentClick={setSelectedParent} | |
| 91 | + /> | |
| 84 | 92 | </Show> |
| 85 | 93 | </Show> |
| 86 | 94 | </Suspense> |
| @@ -100,6 +108,16 @@ function AdminUsersContent() { | ||
| 100 | 108 | </FormDialog> |
| 101 | 109 | )} |
| 102 | 110 | </Show> |
| 111 | + | |
| 112 | + <Show when={selectedParent()} keyed> | |
| 113 | + {(u) => ( | |
| 114 | + <ParentStudentsPanel | |
| 115 | + parent={{ id: u.id, username: u.username, display_name: u.name || u.username }} | |
| 116 | + open | |
| 117 | + onOpenChange={() => setSelectedParent(null)} | |
| 118 | + /> | |
| 119 | + )} | |
| 120 | + </Show> | |
| 103 | 121 | </div> |
| 104 | 122 | ); |
| 105 | 123 | } |
src/pages/dashboard-page.tsxmodified+1 -0
| @@ -65,6 +65,7 @@ type PortalCardDef = { | ||
| 65 | 65 | |
| 66 | 66 | const ROLE_KEY: Record<Role, MessageKey> = { |
| 67 | 67 | student: "role.student", |
| 68 | + parent: "role.parent", | |
| 68 | 69 | teacher: "role.teacher", |
| 69 | 70 | manager: "role.manager", |
| 70 | 71 | admin: "role.admin", |
src/pages/my-students-page.tsxadded+110 -0
| @@ -0,0 +1,110 @@ | ||
| 1 | +import { For, Show, Suspense, createResource, createSignal } from "solid-js"; | |
| 2 | +import { getMyStudents } from "@/api/getMyStudents"; | |
| 3 | +import { getUserMarks } from "@/api/getUserMarks"; | |
| 4 | +import { getUserAttendance } from "@/api/getUserAttendance"; | |
| 5 | +import type { PersonRef } from "@/api/types"; | |
| 6 | +import { RouteGuard } from "@/components/layout/route-guard"; | |
| 7 | +import { PageHeader } from "@/components/layout/page-header"; | |
| 8 | +import { EmptyState } from "@/components/ui/empty-state"; | |
| 9 | +import { PageSpinner } from "@/components/ui/page-spinner"; | |
| 10 | +import { SidePanel } from "@/components/ui/side-panel"; | |
| 11 | +import { Button } from "@/components/ui/button"; | |
| 12 | +import { personLabel } from "@/lib/person"; | |
| 13 | +import { useT } from "@/stores/preferences-context"; | |
| 14 | +import { IconChevronRight, IconChart, IconCalendar } from "@/components/ui/icons"; | |
| 15 | +import { MarksReportView } from "@/components/marks/marks-report-view"; | |
| 16 | +import { AttendanceReportView } from "@/components/attendance/attendance-report-view"; | |
| 17 | + | |
| 18 | +export default function MyStudentsPage() { | |
| 19 | + return ( | |
| 20 | + <RouteGuard exactRole="parent"> | |
| 21 | + <MyStudentsContent /> | |
| 22 | + </RouteGuard> | |
| 23 | + ); | |
| 24 | +} | |
| 25 | + | |
| 26 | +function MyStudentsContent() { | |
| 27 | + const t = useT(); | |
| 28 | + const [list] = createResource(async () => (await getMyStudents()).items); | |
| 29 | + const [selectedStudent, setSelectedStudent] = createSignal<PersonRef | null>(null); | |
| 30 | + | |
| 31 | + return ( | |
| 32 | + <div class="space-y-6"> | |
| 33 | + <div class="space-y-2"> | |
| 34 | + <PageHeader accent="violet" eyebrow={t("nav.myStudents")} title={t("parents.title")} description={t("parents.subtitle")} /> | |
| 35 | + </div> | |
| 36 | + | |
| 37 | + <Suspense fallback={<PageSpinner />}> | |
| 38 | + <Show when={list()}> | |
| 39 | + <Show when={list()!.length > 0} fallback={<EmptyState title={t("common.noResults")} />}> | |
| 40 | + <div class="grid gap-4 sm:grid-cols-2 lg:grid-cols-3"> | |
| 41 | + <For each={list()}> | |
| 42 | + {(student) => ( | |
| 43 | + <button | |
| 44 | + type="button" | |
| 45 | + class="group flex items-center justify-between rounded-lg border bg-card p-4 text-left transition-colors hover:border-primary/50 hover:bg-muted/40" | |
| 46 | + onClick={() => setSelectedStudent(student)} | |
| 47 | + > | |
| 48 | + <div class="min-w-0"> | |
| 49 | + <div class="truncate font-medium text-foreground">{personLabel(student)}</div> | |
| 50 | + <div class="truncate text-sm text-muted-foreground">@{student.username}</div> | |
| 51 | + </div> | |
| 52 | + <IconChevronRight class="h-5 w-5 text-muted-foreground/50 transition-colors group-hover:text-primary" /> | |
| 53 | + </button> | |
| 54 | + )} | |
| 55 | + </For> | |
| 56 | + </div> | |
| 57 | + </Show> | |
| 58 | + </Show> | |
| 59 | + </Suspense> | |
| 60 | + | |
| 61 | + <StudentDetailPanel student={selectedStudent()} onClose={() => setSelectedStudent(null)} /> | |
| 62 | + </div> | |
| 63 | + ); | |
| 64 | +} | |
| 65 | + | |
| 66 | +function StudentDetailPanel(props: { student: PersonRef | null; onClose: () => void }) { | |
| 67 | + const t = useT(); | |
| 68 | + const [activeTab, setActiveTab] = createSignal<"marks" | "attendance">("marks"); | |
| 69 | + | |
| 70 | + const [marksRes] = createResource( | |
| 71 | + () => props.student?.id, | |
| 72 | + async (id) => getUserMarks(id) | |
| 73 | + ); | |
| 74 | + | |
| 75 | + const [attendanceRes] = createResource( | |
| 76 | + () => props.student?.id, | |
| 77 | + async (id) => getUserAttendance(id) | |
| 78 | + ); | |
| 79 | + | |
| 80 | + return ( | |
| 81 | + <SidePanel open={!!props.student} onOpenChange={(open) => !open && props.onClose()} title={props.student ? personLabel(props.student) : ""} description={`@${props.student?.username}`}> | |
| 82 | + <div class="flex flex-col h-full"> | |
| 83 | + <div class="flex gap-2 border-b p-4"> | |
| 84 | + <Button variant={activeTab() === "marks" ? "default" : "outline"} size="sm" onClick={() => setActiveTab("marks")}> | |
| 85 | + <IconChart class="mr-2 h-4 w-4" /> | |
| 86 | + {t("nav.marks")} | |
| 87 | + </Button> | |
| 88 | + <Button variant={activeTab() === "attendance" ? "default" : "outline"} size="sm" onClick={() => setActiveTab("attendance")}> | |
| 89 | + <IconCalendar class="mr-2 h-4 w-4" /> | |
| 90 | + {t("nav.attendance")} | |
| 91 | + </Button> | |
| 92 | + </div> | |
| 93 | + <div class="flex-1 overflow-auto p-4"> | |
| 94 | + <Suspense fallback={<PageSpinner />}> | |
| 95 | + <Show when={activeTab() === "marks"}> | |
| 96 | + <Show when={marksRes()} fallback={<PageSpinner />}> | |
| 97 | + <MarksReportView report={marksRes()!} /> | |
| 98 | + </Show> | |
| 99 | + </Show> | |
| 100 | + <Show when={activeTab() === "attendance"}> | |
| 101 | + <Show when={attendanceRes()} fallback={<PageSpinner />}> | |
| 102 | + <AttendanceReportView report={attendanceRes()!} /> | |
| 103 | + </Show> | |
| 104 | + </Show> | |
| 105 | + </Suspense> | |
| 106 | + </div> | |
| 107 | + </div> | |
| 108 | + </SidePanel> | |
| 109 | + ); | |
| 110 | +} |
src/pages/question-detail-page.tsxadded+322 -0
| @@ -0,0 +1,322 @@ | ||
| 1 | +import { For, Show, Suspense, createResource, createSignal } from "solid-js"; | |
| 2 | +import { useParams, useRouter } from "@tanstack/solid-router"; | |
| 3 | +import { getQuestionById, deleteQuestionById, postQuestionApprove, getQuestionImageUrl } from "@/api/questions"; | |
| 4 | +import { getSolutions, postSolution, patchSolutionById, deleteSolutionById, getSolutionImageUrl } from "@/api/solutions"; | |
| 5 | +import type { SolutionResponse } from "@/api/solutions"; | |
| 6 | +import { formatApiError } from "@/api/client"; | |
| 7 | +import { RouteGuard } from "@/components/layout/route-guard"; | |
| 8 | +import { PageSpinner } from "@/components/ui/page-spinner"; | |
| 9 | +import { Button } from "@/components/ui/button"; | |
| 10 | +import { FormDialog } from "@/components/ui/form-dialog"; | |
| 11 | +import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | |
| 12 | +import { Label } from "@/components/ui/label"; | |
| 13 | +import { Textarea } from "@/components/ui/textarea"; | |
| 14 | +import { IconTrash, IconCheck, IconX, IconEdit, IconMessage, IconPhoto } from "@/components/ui/icons"; | |
| 15 | +import { personLabel } from "@/lib/person"; | |
| 16 | + | |
| 17 | +import { ErrorAlert } from "@/components/ui/error-alert"; | |
| 18 | +import { showToast } from "@/components/ui/toast"; | |
| 19 | +import { useT } from "@/stores/preferences-context"; | |
| 20 | +import { useAuth } from "@/stores/auth-context"; | |
| 21 | +import { hasMinRole } from "@/lib/roles"; | |
| 22 | + | |
| 23 | +export default function QuestionDetailPage() { | |
| 24 | + return ( | |
| 25 | + <RouteGuard minRole="student"> | |
| 26 | + <QuestionDetailContent /> | |
| 27 | + </RouteGuard> | |
| 28 | + ); | |
| 29 | +} | |
| 30 | + | |
| 31 | +function QuestionDetailContent() { | |
| 32 | + const t = useT(); | |
| 33 | + const auth = useAuth(); | |
| 34 | + const router = useRouter(); | |
| 35 | + const params = useParams({ from: "/questions/$id" }); | |
| 36 | + const [error, setError] = createSignal(""); | |
| 37 | + | |
| 38 | + const [question, { refetch: refetchQ }] = createResource(() => params().id, getQuestionById); | |
| 39 | + const [solutions, { refetch: refetchS }] = createResource( | |
| 40 | + () => params().id, | |
| 41 | + async (id) => (await getSolutions(id, { limit: 100, offset: 0 })).items | |
| 42 | + ); | |
| 43 | + | |
| 44 | + const [offerOpen, setOfferOpen] = createSignal(false); | |
| 45 | + const [editSolution, setEditSolution] = createSignal<SolutionResponse | null>(null); | |
| 46 | + const [deleteConfirmQ, setDeleteConfirmQ] = createSignal(false); | |
| 47 | + const [deleteConfirmS, setDeleteConfirmS] = createSignal<SolutionResponse | null>(null); | |
| 48 | + | |
| 49 | + const isModerator = () => hasMinRole(auth.user()?.role, "teacher"); | |
| 50 | + | |
| 51 | + const handleApprove = async () => { | |
| 52 | + setError(""); | |
| 53 | + try { | |
| 54 | + await postQuestionApprove(params().id); | |
| 55 | + await refetchQ(); | |
| 56 | + showToast({ title: t("common.saved") }); | |
| 57 | + } catch (err) { | |
| 58 | + setError(formatApiError(err)); | |
| 59 | + } | |
| 60 | + }; | |
| 61 | + | |
| 62 | + const handleDeleteQ = async () => { | |
| 63 | + setError(""); | |
| 64 | + try { | |
| 65 | + await deleteQuestionById(params().id); | |
| 66 | + router.navigate({ to: "/questions" }); | |
| 67 | + } catch (err) { | |
| 68 | + setError(formatApiError(err)); | |
| 69 | + setDeleteConfirmQ(false); | |
| 70 | + } | |
| 71 | + }; | |
| 72 | + | |
| 73 | + const handleDeleteS = async (s: SolutionResponse) => { | |
| 74 | + setError(""); | |
| 75 | + try { | |
| 76 | + await deleteSolutionById(params().id, s.id); | |
| 77 | + await refetchS(); | |
| 78 | + setDeleteConfirmS(null); | |
| 79 | + showToast({ title: t("common.deleted") }); | |
| 80 | + } catch (err) { | |
| 81 | + setError(formatApiError(err)); | |
| 82 | + setDeleteConfirmS(null); | |
| 83 | + } | |
| 84 | + }; | |
| 85 | + | |
| 86 | + return ( | |
| 87 | + <div class="space-y-6 max-w-4xl mx-auto"> | |
| 88 | + <Suspense fallback={<PageSpinner />}> | |
| 89 | + <Show when={question()}> | |
| 90 | + {(q) => ( | |
| 91 | + <> | |
| 92 | + <div class="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between"> | |
| 93 | + <div> | |
| 94 | + <Button variant="link" class="px-0 h-auto text-muted-foreground mb-2" onClick={() => router.history.back()}>← {t("common.back")}</Button> | |
| 95 | + <h1 class="text-2xl font-bold font-display">{q().title}</h1> | |
| 96 | + <div class="mt-2 flex items-center gap-2 text-sm text-muted-foreground"> | |
| 97 | + <span>{personLabel(q().asker)}</span> | |
| 98 | + <span>•</span> | |
| 99 | + <span>{new Date(q().asked_at).toLocaleString()}</span> | |
| 100 | + </div> | |
| 101 | + </div> | |
| 102 | + <Show when={q().status === "pending" && isModerator()}> | |
| 103 | + <div class="flex gap-2"> | |
| 104 | + <Button variant="destructive" onClick={() => setDeleteConfirmQ(true)}> | |
| 105 | + <IconX class="mr-2 h-4 w-4" /> | |
| 106 | + {t("common.reject")} | |
| 107 | + </Button> | |
| 108 | + <Button onClick={handleApprove}> | |
| 109 | + <IconCheck class="mr-2 h-4 w-4" /> | |
| 110 | + {t("common.approve")} | |
| 111 | + </Button> | |
| 112 | + </div> | |
| 113 | + </Show> | |
| 114 | + </div> | |
| 115 | + | |
| 116 | + {error() && <p class="rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive">{error()}</p>} | |
| 117 | + | |
| 118 | + <div class="rounded-xl border bg-card p-6 shadow-sm"> | |
| 119 | + <p class="whitespace-pre-wrap text-foreground">{q().body}</p> | |
| 120 | + <Show when={q().image}> | |
| 121 | + <div class="mt-4 overflow-hidden rounded-lg border bg-muted/30"> | |
| 122 | + <img src={getQuestionImageUrl(q().id)} alt="Question Attachment" class="max-h-[500px] w-auto object-contain mx-auto" /> | |
| 123 | + </div> | |
| 124 | + </Show> | |
| 125 | + </div> | |
| 126 | + | |
| 127 | + <Show when={q().status === "approved"}> | |
| 128 | + <div class="mt-8"> | |
| 129 | + <div class="flex items-center justify-between mb-4"> | |
| 130 | + <h2 class="text-xl font-semibold font-display">{t("pool.solutions")}</h2> | |
| 131 | + <Button variant="outline" onClick={() => setOfferOpen(true)}> | |
| 132 | + <IconMessage class="mr-2 h-4 w-4" /> | |
| 133 | + {t("pool.offerSolution")} | |
| 134 | + </Button> | |
| 135 | + </div> | |
| 136 | + | |
| 137 | + <div class="space-y-4"> | |
| 138 | + <For each={solutions()}> | |
| 139 | + {(sol) => { | |
| 140 | + const isMine = sol.author.id === auth.user()?.id; | |
| 141 | + return ( | |
| 142 | + <div class="rounded-xl border bg-card/50 p-5"> | |
| 143 | + <div class="flex items-center justify-between"> | |
| 144 | + <div class="flex items-center gap-2 text-sm font-medium"> | |
| 145 | + <div class="flex h-6 w-6 items-center justify-center rounded-full bg-primary/10 text-[10px] text-primary"> | |
| 146 | + {sol.author.display_name?.[0] || sol.author.username[0].toUpperCase()} | |
| 147 | + </div> | |
| 148 | + {personLabel(sol.author)} | |
| 149 | + <span class="text-xs font-normal text-muted-foreground ml-2">{new Date(sol.offered_at).toLocaleString()}</span> | |
| 150 | + </div> | |
| 151 | + <Show when={isMine || isModerator()}> | |
| 152 | + <div class="flex items-center gap-1"> | |
| 153 | + <Show when={isMine}> | |
| 154 | + <Button variant="ghost" size="icon" class="h-8 w-8 text-muted-foreground hover:text-foreground" onClick={() => setEditSolution(sol)}> | |
| 155 | + <IconEdit class="h-4 w-4" /> | |
| 156 | + </Button> | |
| 157 | + </Show> | |
| 158 | + <Button variant="ghost" size="icon" class="h-8 w-8 text-destructive hover:bg-destructive/10" onClick={() => setDeleteConfirmS(sol)}> | |
| 159 | + <IconTrash class="h-4 w-4" /> | |
| 160 | + </Button> | |
| 161 | + </div> | |
| 162 | + </Show> | |
| 163 | + </div> | |
| 164 | + <p class="mt-3 whitespace-pre-wrap text-sm text-foreground">{sol.body}</p> | |
| 165 | + <Show when={sol.image}> | |
| 166 | + <div class="mt-3 overflow-hidden rounded-lg border border-border/50"> | |
| 167 | + <img src={getSolutionImageUrl(q().id, sol.id)} alt="Solution Attachment" class="max-h-[300px] w-auto object-contain mx-auto" /> | |
| 168 | + </div> | |
| 169 | + </Show> | |
| 170 | + </div> | |
| 171 | + ); | |
| 172 | + }} | |
| 173 | + </For> | |
| 174 | + </div> | |
| 175 | + </div> | |
| 176 | + </Show> | |
| 177 | + </> | |
| 178 | + )} | |
| 179 | + </Show> | |
| 180 | + </Suspense> | |
| 181 | + | |
| 182 | + <ConfirmDialog | |
| 183 | + open={deleteConfirmQ()} | |
| 184 | + onOpenChange={setDeleteConfirmQ} | |
| 185 | + title={t("confirm.deleteTitle")} | |
| 186 | + summary={t("confirm.confirmDelete")} | |
| 187 | + onConfirm={handleDeleteQ} | |
| 188 | + variant="destructive" | |
| 189 | + /> | |
| 190 | + | |
| 191 | + <Show when={deleteConfirmS()} keyed> | |
| 192 | + {(sol) => ( | |
| 193 | + <ConfirmDialog | |
| 194 | + open | |
| 195 | + onOpenChange={(open) => !open && setDeleteConfirmS(null)} | |
| 196 | + title={t("confirm.deleteTitle")} | |
| 197 | + summary={t("confirm.confirmDelete")} | |
| 198 | + onConfirm={() => handleDeleteS(sol)} | |
| 199 | + variant="destructive" | |
| 200 | + /> | |
| 201 | + )} | |
| 202 | + </Show> | |
| 203 | + | |
| 204 | + <Show when={offerOpen()}> | |
| 205 | + <SolutionFormDialog | |
| 206 | + questionId={params().id} | |
| 207 | + onClose={() => setOfferOpen(false)} | |
| 208 | + onSuccess={() => { | |
| 209 | + setOfferOpen(false); | |
| 210 | + showToast({ title: t("common.saved") }); | |
| 211 | + refetchS(); | |
| 212 | + }} | |
| 213 | + /> | |
| 214 | + </Show> | |
| 215 | + | |
| 216 | + <Show when={editSolution()} keyed> | |
| 217 | + {(sol) => ( | |
| 218 | + <SolutionFormDialog | |
| 219 | + questionId={params().id} | |
| 220 | + initialData={sol} | |
| 221 | + onClose={() => setEditSolution(null)} | |
| 222 | + onSuccess={() => { | |
| 223 | + setEditSolution(null); | |
| 224 | + showToast({ title: t("common.saved") }); | |
| 225 | + refetchS(); | |
| 226 | + }} | |
| 227 | + /> | |
| 228 | + )} | |
| 229 | + </Show> | |
| 230 | + </div> | |
| 231 | + ); | |
| 232 | +} | |
| 233 | + | |
| 234 | +function SolutionFormDialog(props: { questionId: string; initialData?: SolutionResponse; onClose: () => void; onSuccess: () => void }) { | |
| 235 | + const t = useT(); | |
| 236 | + const [error, setError] = createSignal(""); | |
| 237 | + const [body, setBody] = createSignal(props.initialData?.body || ""); | |
| 238 | + const [file, setFile] = createSignal<File | null>(null); | |
| 239 | + | |
| 240 | + const handleSubmit = async (e: Event) => { | |
| 241 | + e.preventDefault(); | |
| 242 | + if (!body().trim()) return; | |
| 243 | + setError(""); | |
| 244 | + try { | |
| 245 | + if (props.initialData) { | |
| 246 | + await patchSolutionById(props.questionId, props.initialData.id, { body: body().trim() }); | |
| 247 | + } else { | |
| 248 | + await postSolution(props.questionId, { body: body().trim() }, file() || undefined); | |
| 249 | + } | |
| 250 | + props.onSuccess(); | |
| 251 | + } catch (err) { | |
| 252 | + setError(formatApiError(err)); | |
| 253 | + } | |
| 254 | + }; | |
| 255 | + | |
| 256 | + return ( | |
| 257 | + <FormDialog open onOpenChange={(open) => !open && props.onClose()} title={props.initialData ? t("common.edit") : t("pool.offerSolution")} description=""> | |
| 258 | + <form onSubmit={handleSubmit} class="space-y-4"> | |
| 259 | + {error() && <ErrorAlert message={error()} />} | |
| 260 | + <div class="space-y-2"> | |
| 261 | + <Label for="s-body">{t("pool.body")}</Label> | |
| 262 | + <Textarea id="s-body" value={body()} onInput={(e) => setBody(e.currentTarget.value)} required rows={5} /> | |
| 263 | + </div> | |
| 264 | + <Show when={!props.initialData}> | |
| 265 | + <div class="space-y-2"> | |
| 266 | + <Label>{t("pool.image")}</Label> | |
| 267 | + <div class="relative flex flex-col items-center justify-center rounded-lg border-2 border-dashed border-border p-6 transition-colors hover:bg-muted/50 focus-within:ring-2 focus-within:ring-primary focus-within:ring-offset-2"> | |
| 268 | + <Show | |
| 269 | + when={!file()} | |
| 270 | + fallback={ | |
| 271 | + <div class="flex flex-col items-center gap-2"> | |
| 272 | + <div class="flex h-12 w-12 items-center justify-center rounded-full bg-primary/10"> | |
| 273 | + <IconPhoto class="h-6 w-6 text-primary" /> | |
| 274 | + </div> | |
| 275 | + <div class="flex items-center gap-2"> | |
| 276 | + <span class="text-sm font-medium text-foreground">{file()?.name}</span> | |
| 277 | + <Button | |
| 278 | + type="button" | |
| 279 | + variant="ghost" | |
| 280 | + size="icon" | |
| 281 | + class="h-6 w-6 rounded-full hover:bg-destructive/10 hover:text-destructive z-10" | |
| 282 | + onClick={(e) => { | |
| 283 | + e.stopPropagation(); | |
| 284 | + e.preventDefault(); | |
| 285 | + setFile(null); | |
| 286 | + }} | |
| 287 | + > | |
| 288 | + <IconX class="h-4 w-4" /> | |
| 289 | + </Button> | |
| 290 | + </div> | |
| 291 | + </div> | |
| 292 | + } | |
| 293 | + > | |
| 294 | + <div class="flex h-12 w-12 items-center justify-center rounded-full bg-muted"> | |
| 295 | + <IconPhoto class="h-6 w-6 text-muted-foreground" /> | |
| 296 | + </div> | |
| 297 | + <div class="mt-4 text-center"> | |
| 298 | + <p class="text-sm font-medium text-foreground">{t("pool.image")}</p> | |
| 299 | + <p class="mt-1 text-xs text-muted-foreground">PNG, JPG, GIF</p> | |
| 300 | + </div> | |
| 301 | + </Show> | |
| 302 | + <input | |
| 303 | + type="file" | |
| 304 | + accept="image/*" | |
| 305 | + class="absolute inset-0 z-0 h-full w-full cursor-pointer opacity-0" | |
| 306 | + onChange={(e) => setFile(e.currentTarget.files?.[0] || null)} | |
| 307 | + /> | |
| 308 | + </div> | |
| 309 | + </div> | |
| 310 | + </Show> | |
| 311 | + <div class="flex justify-end gap-3 pt-4"> | |
| 312 | + <Button type="button" variant="outline" onClick={props.onClose}> | |
| 313 | + {t("common.cancel")} | |
| 314 | + </Button> | |
| 315 | + <Button type="submit" disabled={!body().trim()}> | |
| 316 | + {t("common.save")} | |
| 317 | + </Button> | |
| 318 | + </div> | |
| 319 | + </form> | |
| 320 | + </FormDialog> | |
| 321 | + ); | |
| 322 | +} |
src/pages/questions-page.tsxadded+221 -0
| @@ -0,0 +1,221 @@ | ||
| 1 | +import { For, Show, Suspense, createResource, createSignal } from "solid-js"; | |
| 2 | +import { Link, useSearch, useNavigate } from "@tanstack/solid-router"; | |
| 3 | +import { getQuestions, postQuestion } from "@/api/questions"; | |
| 4 | +import { formatApiError } from "@/api/client"; | |
| 5 | +import { RouteGuard } from "@/components/layout/route-guard"; | |
| 6 | +import { PageHeader } from "@/components/layout/page-header"; | |
| 7 | +import { PageSpinner } from "@/components/ui/page-spinner"; | |
| 8 | +import { EmptyState } from "@/components/ui/empty-state"; | |
| 9 | +import { Button } from "@/components/ui/button"; | |
| 10 | +import { FormDialog } from "@/components/ui/form-dialog"; | |
| 11 | +import { Label } from "@/components/ui/label"; | |
| 12 | +import { Input } from "@/components/ui/input"; | |
| 13 | +import { Textarea } from "@/components/ui/textarea"; | |
| 14 | +import { IconPlus, IconClock, IconCheck, IconPhoto, IconX } from "@/components/ui/icons"; | |
| 15 | +import { personLabel } from "@/lib/person"; | |
| 16 | + | |
| 17 | +import { ErrorAlert } from "@/components/ui/error-alert"; | |
| 18 | +import { showToast } from "@/components/ui/toast"; | |
| 19 | +import { useT } from "@/stores/preferences-context"; | |
| 20 | +import { useAuth } from "@/stores/auth-context"; | |
| 21 | +import { cn } from "@/lib/cn"; | |
| 22 | + | |
| 23 | +export default function QuestionsPage() { | |
| 24 | + return ( | |
| 25 | + <RouteGuard minRole="student"> | |
| 26 | + <QuestionsContent /> | |
| 27 | + </RouteGuard> | |
| 28 | + ); | |
| 29 | +} | |
| 30 | + | |
| 31 | +function QuestionsContent() { | |
| 32 | + const t = useT(); | |
| 33 | + const auth = useAuth(); | |
| 34 | + const navigate = useNavigate(); | |
| 35 | + const searchParams = useSearch({ strict: false }); | |
| 36 | + | |
| 37 | + const statusFilter = () => ((searchParams() as any).status === "pending" ? "pending" : "approved"); | |
| 38 | + | |
| 39 | + const [list, { refetch }] = createResource( | |
| 40 | + () => ({ status: statusFilter(), limit: 50, offset: 0 }), | |
| 41 | + async (params) => (await getQuestions(params.status as "pending" | "approved", params)).items | |
| 42 | + ); | |
| 43 | + | |
| 44 | + const [askOpen, setAskOpen] = createSignal(false); | |
| 45 | + | |
| 46 | + return ( | |
| 47 | + <div class="space-y-6"> | |
| 48 | + <div class="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between"> | |
| 49 | + <PageHeader accent="violet" eyebrow={t("nav.group.community")} title={t("pool.title")} description={t("pool.subtitle")} /> | |
| 50 | + <Show when={auth.user()?.role === "student"}> | |
| 51 | + <Button onClick={() => setAskOpen(true)}> | |
| 52 | + <IconPlus class="mr-2 h-4 w-4" /> | |
| 53 | + {t("pool.ask")} | |
| 54 | + </Button> | |
| 55 | + </Show> | |
| 56 | + </div> | |
| 57 | + | |
| 58 | + <div class="flex gap-2 border-b"> | |
| 59 | + <Link | |
| 60 | + to="/questions" | |
| 61 | + search={{ status: "approved" }} | |
| 62 | + class={cn("pb-2 text-sm font-medium transition-colors hover:text-foreground", statusFilter() === "approved" ? "border-b-2 border-primary text-foreground" : "text-muted-foreground")} | |
| 63 | + > | |
| 64 | + {t("pool.approved")} | |
| 65 | + </Link> | |
| 66 | + <Link | |
| 67 | + to="/questions" | |
| 68 | + search={{ status: "pending" }} | |
| 69 | + class={cn("ml-4 pb-2 text-sm font-medium transition-colors hover:text-foreground", statusFilter() === "pending" ? "border-b-2 border-primary text-foreground" : "text-muted-foreground")} | |
| 70 | + > | |
| 71 | + {t("pool.pending")} | |
| 72 | + </Link> | |
| 73 | + </div> | |
| 74 | + | |
| 75 | + <div class="data-shell"> | |
| 76 | + <Suspense fallback={<PageSpinner />}> | |
| 77 | + <Show when={list()}> | |
| 78 | + <Show when={list()!.length > 0} fallback={<EmptyState title={t("pool.noQuestions")} />}> | |
| 79 | + <div class="divide-y divide-border"> | |
| 80 | + <For each={list()}> | |
| 81 | + {(question) => ( | |
| 82 | + <Link to="/questions/$id" params={{ id: question.id }} class="group flex flex-col gap-2 p-4 transition-colors hover:bg-muted/40 sm:flex-row sm:items-center sm:justify-between"> | |
| 83 | + <div class="min-w-0 flex-1"> | |
| 84 | + <div class="flex items-center gap-2"> | |
| 85 | + <h3 class="truncate text-base font-semibold text-foreground group-hover:text-primary transition-colors">{question.title}</h3> | |
| 86 | + <Show when={question.image}> | |
| 87 | + <IconPhoto class="h-4 w-4 text-muted-foreground" /> | |
| 88 | + </Show> | |
| 89 | + </div> | |
| 90 | + <p class="mt-1 line-clamp-2 text-sm text-muted-foreground">{question.body}</p> | |
| 91 | + <div class="mt-2 flex items-center gap-3 text-xs text-muted-foreground"> | |
| 92 | + <span class="flex items-center gap-1"> | |
| 93 | + <div class="flex h-4 w-4 items-center justify-center rounded-full bg-primary/10 text-[8px] font-bold text-primary"> | |
| 94 | + {question.asker.display_name?.[0] || question.asker.username[0].toUpperCase()} | |
| 95 | + </div> | |
| 96 | + {personLabel(question.asker)} | |
| 97 | + </span> | |
| 98 | + <span>•</span> | |
| 99 | + <span>{new Date(question.asked_at).toLocaleDateString()}</span> | |
| 100 | + </div> | |
| 101 | + </div> | |
| 102 | + <div class="mt-2 sm:mt-0 sm:pl-4"> | |
| 103 | + <Show | |
| 104 | + when={question.status === "approved"} | |
| 105 | + fallback={<span class="inline-flex items-center rounded-full bg-amber-500/10 px-2.5 py-0.5 text-xs font-medium text-amber-600 dark:text-amber-400"><IconClock class="mr-1 h-3 w-3" /> {t("pool.pending")}</span>} | |
| 106 | + > | |
| 107 | + <span class="inline-flex items-center rounded-full bg-emerald-500/10 px-2.5 py-0.5 text-xs font-medium text-emerald-600 dark:text-emerald-400"><IconCheck class="mr-1 h-3 w-3" /> {t("pool.approved")}</span> | |
| 108 | + </Show> | |
| 109 | + </div> | |
| 110 | + </Link> | |
| 111 | + )} | |
| 112 | + </For> | |
| 113 | + </div> | |
| 114 | + </Show> | |
| 115 | + </Show> | |
| 116 | + </Suspense> | |
| 117 | + </div> | |
| 118 | + | |
| 119 | + <Show when={askOpen()}> | |
| 120 | + <AskQuestionDialog | |
| 121 | + onClose={() => setAskOpen(false)} | |
| 122 | + onSuccess={() => { | |
| 123 | + setAskOpen(false); | |
| 124 | + showToast({ title: t("common.saved") }); | |
| 125 | + navigate({ to: "/questions", search: { status: "pending" }, replace: true }); | |
| 126 | + refetch(); | |
| 127 | + }} | |
| 128 | + /> | |
| 129 | + </Show> | |
| 130 | + </div> | |
| 131 | + ); | |
| 132 | +} | |
| 133 | + | |
| 134 | +function AskQuestionDialog(props: { onClose: () => void; onSuccess: () => void }) { | |
| 135 | + const t = useT(); | |
| 136 | + const [error, setError] = createSignal(""); | |
| 137 | + const [title, setTitle] = createSignal(""); | |
| 138 | + const [body, setBody] = createSignal(""); | |
| 139 | + const [file, setFile] = createSignal<File | null>(null); | |
| 140 | + | |
| 141 | + const handleSubmit = async (e: Event) => { | |
| 142 | + e.preventDefault(); | |
| 143 | + if (!title().trim() || !body().trim()) return; | |
| 144 | + setError(""); | |
| 145 | + try { | |
| 146 | + await postQuestion({ title: title().trim(), body: body().trim() }, file() || undefined); | |
| 147 | + props.onSuccess(); | |
| 148 | + } catch (err: unknown) { | |
| 149 | + setError(formatApiError(err)); | |
| 150 | + } | |
| 151 | + }; | |
| 152 | + | |
| 153 | + return ( | |
| 154 | + <FormDialog open onOpenChange={(open) => !open && props.onClose()} title={t("pool.ask")} description=""> | |
| 155 | + <form onSubmit={handleSubmit} class="space-y-4"> | |
| 156 | + {error() && <ErrorAlert message={error()} />} | |
| 157 | + <div class="space-y-2"> | |
| 158 | + <Label for="q-title">{t("pool.subject")}</Label> | |
| 159 | + <Input id="q-title" value={title()} onInput={(e) => setTitle(e.currentTarget.value)} required /> | |
| 160 | + </div> | |
| 161 | + <div class="space-y-2"> | |
| 162 | + <Label for="q-body">{t("pool.body")}</Label> | |
| 163 | + <Textarea id="q-body" value={body()} onInput={(e) => setBody(e.currentTarget.value)} required rows={5} /> | |
| 164 | + </div> | |
| 165 | + <div class="space-y-2"> | |
| 166 | + <Label>{t("pool.image")}</Label> | |
| 167 | + <div class="relative flex flex-col items-center justify-center rounded-lg border-2 border-dashed border-border p-6 transition-colors hover:bg-muted/50 focus-within:ring-2 focus-within:ring-primary focus-within:ring-offset-2"> | |
| 168 | + <Show | |
| 169 | + when={!file()} | |
| 170 | + fallback={ | |
| 171 | + <div class="flex flex-col items-center gap-2"> | |
| 172 | + <div class="flex h-12 w-12 items-center justify-center rounded-full bg-primary/10"> | |
| 173 | + <IconPhoto class="h-6 w-6 text-primary" /> | |
| 174 | + </div> | |
| 175 | + <div class="flex items-center gap-2"> | |
| 176 | + <span class="text-sm font-medium text-foreground">{file()?.name}</span> | |
| 177 | + <Button | |
| 178 | + type="button" | |
| 179 | + variant="ghost" | |
| 180 | + size="icon" | |
| 181 | + class="h-6 w-6 rounded-full hover:bg-destructive/10 hover:text-destructive z-10" | |
| 182 | + onClick={(e) => { | |
| 183 | + e.stopPropagation(); | |
| 184 | + e.preventDefault(); | |
| 185 | + setFile(null); | |
| 186 | + }} | |
| 187 | + > | |
| 188 | + <IconX class="h-4 w-4" /> | |
| 189 | + </Button> | |
| 190 | + </div> | |
| 191 | + </div> | |
| 192 | + } | |
| 193 | + > | |
| 194 | + <div class="flex h-12 w-12 items-center justify-center rounded-full bg-muted"> | |
| 195 | + <IconPhoto class="h-6 w-6 text-muted-foreground" /> | |
| 196 | + </div> | |
| 197 | + <div class="mt-4 text-center"> | |
| 198 | + <p class="text-sm font-medium text-foreground">{t("pool.image")}</p> | |
| 199 | + <p class="mt-1 text-xs text-muted-foreground">PNG, JPG, GIF</p> | |
| 200 | + </div> | |
| 201 | + </Show> | |
| 202 | + <input | |
| 203 | + type="file" | |
| 204 | + accept="image/*" | |
| 205 | + class="absolute inset-0 z-0 h-full w-full cursor-pointer opacity-0" | |
| 206 | + onChange={(e) => setFile(e.currentTarget.files?.[0] || null)} | |
| 207 | + /> | |
| 208 | + </div> | |
| 209 | + </div> | |
| 210 | + <div class="flex justify-end gap-3 pt-4"> | |
| 211 | + <Button type="button" variant="outline" onClick={props.onClose}> | |
| 212 | + {t("common.cancel")} | |
| 213 | + </Button> | |
| 214 | + <Button type="submit" disabled={!title().trim() || !body().trim()}> | |
| 215 | + {t("common.save")} | |
| 216 | + </Button> | |
| 217 | + </div> | |
| 218 | + </form> | |
| 219 | + </FormDialog> | |
| 220 | + ); | |
| 221 | +} |
src/routes/router.tsxmodified+24 -0
| @@ -46,6 +46,9 @@ const AdminUsersPage = lazyRoute(() => import("@/pages/admin-users-page")); | ||
| 46 | 46 | const SettingsPage = lazyRoute(() => import("@/pages/settings-page")); |
| 47 | 47 | const TermsPage = lazyRoute(() => import("@/pages/terms-page")); |
| 48 | 48 | const GuidePage = lazyRoute(() => import("@/pages/guide-page")); |
| 49 | +const MyStudentsPage = lazyRoute(() => import("@/pages/my-students-page")); | |
| 50 | +const QuestionsPage = lazyRoute(() => import("@/pages/questions-page")); | |
| 51 | +const QuestionDetailPage = lazyRoute(() => import("@/pages/question-detail-page")); | |
| 49 | 52 | |
| 50 | 53 | function RootComponent() { |
| 51 | 54 | return ( |
| @@ -233,6 +236,24 @@ const guideRoute = createRoute({ | ||
| 233 | 236 | component: GuidePage, |
| 234 | 237 | }); |
| 235 | 238 | |
| 239 | +const myStudentsRoute = createRoute({ | |
| 240 | + getParentRoute: () => rootRoute, | |
| 241 | + path: "/students", | |
| 242 | + component: MyStudentsPage, | |
| 243 | +}); | |
| 244 | + | |
| 245 | +const questionsRoute = createRoute({ | |
| 246 | + getParentRoute: () => rootRoute, | |
| 247 | + path: "/questions", | |
| 248 | + component: QuestionsPage, | |
| 249 | +}); | |
| 250 | + | |
| 251 | +const questionDetailRoute = createRoute({ | |
| 252 | + getParentRoute: () => rootRoute, | |
| 253 | + path: "/questions/$id", | |
| 254 | + component: QuestionDetailPage, | |
| 255 | +}); | |
| 256 | + | |
| 236 | 257 | const routeTree = rootRoute.addChildren([ |
| 237 | 258 | indexRoute, |
| 238 | 259 | loginRoute, |
| @@ -261,6 +282,9 @@ const routeTree = rootRoute.addChildren([ | ||
| 261 | 282 | termsRoute, |
| 262 | 283 | adminUsersRoute, |
| 263 | 284 | guideRoute, |
| 285 | + myStudentsRoute, | |
| 286 | + questionsRoute, | |
| 287 | + questionDetailRoute, | |
| 264 | 288 | ]); |
| 265 | 289 | |
| 266 | 290 | function RouterPending() { |