From 8bd96bf5abe810c736e6a55d2cc34b17045992d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Tue, 21 Jul 2026 14:00:32 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=91=A8=E2=80=8D=F0=9F=91=A9?= =?UTF-8?q?=E2=80=8D=F0=9F=91=A7=E2=80=8D=F0=9F=91=A6=20parent=20role,=20q?= =?UTF-8?q?uestion=20pool,=20and=20student=20management?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - add parent role to type system, rank, badge, and i18n labels - my-students page for parent role with nav group and route - admin users: parent-student link/unlink panel from user table - add getMyStudents, getParentStudents, postParentStudent, deleteParentStudent API files - question pool community feature: routes, pages, icons (IconZoomIn, IconHelpCircle, IconMessagePlus, IconPhoto), nav group "Community", full i18n - user-table: parent action column button for admin flow - dashboard: parent role key - various i18n polish: "Grades" nav label, "Saved successfully.", "Actions" plural, confirm review text --- src/api/deleteParentStudent.ts | 7 + src/api/getMyStudents.ts | 14 + src/api/getParentStudents.ts | 14 + src/api/postParentStudent.ts | 15 + src/api/questions.ts | 76 +++++ src/api/solutions.ts | 75 ++++ src/api/types.ts | 2 +- src/components/layout/app-shell.tsx | 1 + src/components/layout/role-badge.tsx | 1 + src/components/layout/side-nav.tsx | 27 +- src/components/ui/icons.tsx | 41 +++ .../users/parent-students-panel.tsx | 119 +++++++ src/components/users/user-table.tsx | 11 +- src/i18n/messages.ts | 92 ++++- src/lib/roles.ts | 3 +- src/pages/admin-users-page.tsx | 20 +- src/pages/dashboard-page.tsx | 1 + src/pages/my-students-page.tsx | 110 ++++++ src/pages/question-detail-page.tsx | 322 ++++++++++++++++++ src/pages/questions-page.tsx | 221 ++++++++++++ src/routes/router.tsx | 24 ++ 21 files changed, 1177 insertions(+), 19 deletions(-) create mode 100644 src/api/deleteParentStudent.ts create mode 100644 src/api/getMyStudents.ts create mode 100644 src/api/getParentStudents.ts create mode 100644 src/api/postParentStudent.ts create mode 100644 src/api/questions.ts create mode 100644 src/api/solutions.ts create mode 100644 src/components/users/parent-students-panel.tsx create mode 100644 src/pages/my-students-page.tsx create mode 100644 src/pages/question-detail-page.tsx create mode 100644 src/pages/questions-page.tsx diff --git a/src/api/deleteParentStudent.ts b/src/api/deleteParentStudent.ts new file mode 100644 index 0000000..0298546 --- /dev/null +++ b/src/api/deleteParentStudent.ts @@ -0,0 +1,7 @@ +import { client } from "./client"; + +export async function deleteParentStudent(id: string, student_id: string): Promise { + return client(`/users/${id}/students/${student_id}`, { + method: "DELETE", + }); +} diff --git a/src/api/getMyStudents.ts b/src/api/getMyStudents.ts new file mode 100644 index 0000000..1e81449 --- /dev/null +++ b/src/api/getMyStudents.ts @@ -0,0 +1,14 @@ +import { client } from "./client"; +import type { Page, PageParams } from "./page"; +import type { PersonRef } from "./types"; + +export async function getMyStudents(params?: PageParams): Promise> { + const searchParams = new URLSearchParams(); + if (params?.limit !== undefined) searchParams.set("limit", params.limit.toString()); + if (params?.offset !== undefined) searchParams.set("offset", params.offset.toString()); + + const query = searchParams.toString(); + const url = query ? `/users/me/students?${query}` : "/users/me/students"; + + return client(url); +} diff --git a/src/api/getParentStudents.ts b/src/api/getParentStudents.ts new file mode 100644 index 0000000..7e58c9f --- /dev/null +++ b/src/api/getParentStudents.ts @@ -0,0 +1,14 @@ +import { client } from "./client"; +import type { Page, PageParams } from "./page"; +import type { PersonRef } from "./types"; + +export async function getParentStudents(id: string, params?: PageParams): Promise> { + const searchParams = new URLSearchParams(); + if (params?.limit !== undefined) searchParams.set("limit", params.limit.toString()); + if (params?.offset !== undefined) searchParams.set("offset", params.offset.toString()); + + const query = searchParams.toString(); + const url = query ? `/users/${id}/students?${query}` : `/users/${id}/students`; + + return client(url); +} diff --git a/src/api/postParentStudent.ts b/src/api/postParentStudent.ts new file mode 100644 index 0000000..ad845f4 --- /dev/null +++ b/src/api/postParentStudent.ts @@ -0,0 +1,15 @@ +import { client } from "./client"; +import type { PersonRef } from "./types"; + +export interface ParentLinkResponse { + parent: PersonRef; + student: PersonRef; + linked_by: PersonRef; +} + +export async function postParentStudent(id: string, user_id: string): Promise { + return client(`/users/${id}/students`, { + method: "POST", + body: JSON.stringify({ user_id }), + }); +} diff --git a/src/api/questions.ts b/src/api/questions.ts new file mode 100644 index 0000000..b4413e6 --- /dev/null +++ b/src/api/questions.ts @@ -0,0 +1,76 @@ +import { client, formClient } from "./client"; +import type { Page, PageParams } from "./page"; +import type { PersonRef } from "./types"; + +export interface PoolImageMeta { + content_type: string; + size: number; +} + +export interface PoolQuestionResponse { + id: string; + /** The student who asked — field is `asker` on the backend */ + asker: PersonRef; + title: string; + body: string; + status: "pending" | "approved"; + asked_at: number; + approved_by: PersonRef | null; + /** null when there is no image */ + image: PoolImageMeta | null; + solution_count: number; +} + +export interface AskQuestion { + title: string; + body: string; +} + +export async function getQuestions( + status?: "pending" | "approved", + params?: PageParams +): Promise> { + const searchParams = new URLSearchParams(); + if (status) searchParams.set("status", status); + if (params?.limit !== undefined) searchParams.set("limit", params.limit.toString()); + if (params?.offset !== undefined) searchParams.set("offset", params.offset.toString()); + + const query = searchParams.toString(); + const url = query ? `/questions?${query}` : "/questions"; + return client(url); +} + +export async function getQuestionById(id: string): Promise { + return client(`/questions/${id}`); +} + +export async function postQuestion(body: AskQuestion, image?: File): Promise { + const res = await client("/questions", { + method: "POST", + body, + }); + + if (image) { + const fd = new FormData(); + fd.append("file", image); + await formClient(`/questions/${res.id}/image`, fd); + } + + return res; +} + +export async function postQuestionApprove(id: string): Promise { + return client(`/questions/${id}/approve`, { + method: "POST", + }); +} + +export async function deleteQuestionById(id: string): Promise { + return client(`/questions/${id}`, { + method: "DELETE", + }); +} + +export function getQuestionImageUrl(id: string): string { + return `/api/questions/${id}/image`; +} diff --git a/src/api/solutions.ts b/src/api/solutions.ts new file mode 100644 index 0000000..596d1af --- /dev/null +++ b/src/api/solutions.ts @@ -0,0 +1,75 @@ +import { client, formClient } from "./client"; +import type { Page, PageParams } from "./page"; +import type { PersonRef } from "./types"; + +export interface PoolImageMeta { + content_type: string; + size: number; +} + +export interface SolutionResponse { + id: string; + question: string; + author: PersonRef; + body: string; + offered_at: number; + /** null when there is no image */ + image: PoolImageMeta | null; +} + +export interface OfferSolution { + body: string; +} + +export async function getSolutions( + id: string, + params?: PageParams +): Promise> { + const searchParams = new URLSearchParams(); + if (params?.limit !== undefined) searchParams.set("limit", params.limit.toString()); + if (params?.offset !== undefined) searchParams.set("offset", params.offset.toString()); + + const query = searchParams.toString(); + const url = query ? `/questions/${id}/solutions?${query}` : `/questions/${id}/solutions`; + return client(url); +} + +export async function postSolution( + id: string, + body: OfferSolution, + image?: File +): Promise { + const res = await client(`/questions/${id}/solutions`, { + method: "POST", + body, + }); + + if (image) { + const fd = new FormData(); + fd.append("file", image); + await formClient(`/questions/${id}/solutions/${res.id}/image`, fd); + } + + return res; +} + +export async function patchSolutionById( + id: string, + sid: string, + body: OfferSolution +): Promise { + return client(`/questions/${id}/solutions/${sid}`, { + method: "PATCH", + body, + }); +} + +export async function deleteSolutionById(id: string, sid: string): Promise { + return client(`/questions/${id}/solutions/${sid}`, { + method: "DELETE", + }); +} + +export function getSolutionImageUrl(id: string, sid: string): string { + return `/api/questions/${id}/solutions/${sid}/image`; +} diff --git a/src/api/types.ts b/src/api/types.ts index b764649..916bf5d 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -1,6 +1,6 @@ export type { Page, PageParams } from "./page"; -export type Role = "student" | "teacher" | "manager" | "admin"; +export type Role = "student" | "parent" | "teacher" | "manager" | "admin"; export type UserTheme = "light" | "dark"; export type UserLanguage = "tr" | "en"; export type CourseKind = "course" | "study" | "club" | string; diff --git a/src/components/layout/app-shell.tsx b/src/components/layout/app-shell.tsx index c094287..412acb8 100644 --- a/src/components/layout/app-shell.tsx +++ b/src/components/layout/app-shell.tsx @@ -39,6 +39,7 @@ export function AppShell(props: ParentProps) { if (path === "/clubs") return `${t("nav.group.classes")} / ${t("nav.clubs")}`; if (path === "/events" || path.startsWith("/events/")) return `${t("nav.group.classes")} / ${t("nav.events")}`; if (path === "/exams" || path.startsWith("/exams/")) return `${t("nav.group.classes")} / ${t("nav.exams")}`; + if (path === "/questions" || path.startsWith("/questions/")) return `${t("nav.group.community")} / ${t("pool.title")}`; if (path.startsWith("/exam-room/")) return t("nav.exams"); if (path === "/work") return `${t("nav.group.reports")} / ${t("nav.work")}`; if (path === "/management/student-marks") return `${t("nav.group.reports")} / ${t("nav.studentMarks")}`; diff --git a/src/components/layout/role-badge.tsx b/src/components/layout/role-badge.tsx index 112ffad..bf05368 100644 --- a/src/components/layout/role-badge.tsx +++ b/src/components/layout/role-badge.tsx @@ -5,6 +5,7 @@ import { useT } from "@/stores/preferences-context"; const VARIANT: Record = { student: "secondary", + parent: "secondary", teacher: "default", manager: "outline", admin: "destructive", diff --git a/src/components/layout/side-nav.tsx b/src/components/layout/side-nav.tsx index 8986c6c..a6113c6 100644 --- a/src/components/layout/side-nav.tsx +++ b/src/components/layout/side-nav.tsx @@ -22,6 +22,8 @@ import { IconClock, IconClipboardCheck, IconExam, + IconGlobe, + IconHelpCircle, IconHome, IconMessage, IconNote, @@ -49,6 +51,7 @@ type NavGroup = { labelKey: MessageKey; Icon: Component<{ class?: string }>; minRole?: Role; + exactRole?: Role; items: NavItem[]; }; @@ -65,6 +68,15 @@ const NAV_GROUPS: NavGroup[] = [ { to: "/events", labelKey: "nav.events", Icon: IconCalendar }, ], }, + { + id: "students", + labelKey: "nav.group.students", + Icon: IconUsers, + exactRole: "parent", + items: [ + { to: "/students", labelKey: "nav.myStudents", Icon: IconUsers, exactRole: "parent" }, + ], + }, { id: "grades", labelKey: "nav.group.grades", @@ -90,6 +102,14 @@ const NAV_GROUPS: NavGroup[] = [ { to: "/management/staff-work", labelKey: "nav.staffWork", Icon: IconBriefcase, minRole: "manager" }, ], }, + { + id: "community", + labelKey: "nav.group.community", + Icon: IconGlobe, + items: [ + { to: "/questions", labelKey: "nav.questions", Icon: IconHelpCircle }, + ], + }, { id: "settings", labelKey: "nav.group.settings", @@ -170,7 +190,12 @@ export function SideNav(props: { onNavigate?: () => void; collapsed?: boolean }) const visibleGroups = createMemo(() => NAV_GROUPS - .filter((group) => !group.minRole || hasMinRole(auth.user()?.role, group.minRole)) + .filter((group) => { + const r = auth.user()?.role; + if (group.exactRole && !hasExactRole(r, group.exactRole)) return false; + if (group.minRole && !hasMinRole(r, group.minRole)) return false; + return true; + }) .map((group) => ({ ...group, items: group.items.filter(itemVisible), diff --git a/src/components/ui/icons.tsx b/src/components/ui/icons.tsx index 9858393..0440ed4 100644 --- a/src/components/ui/icons.tsx +++ b/src/components/ui/icons.tsx @@ -161,6 +161,47 @@ export function IconMoon(props: IconProps) { ); } +export function IconZoomIn(props: IconProps) { + return ( + + + + + + + ); +} + +export function IconHelpCircle(props: IconProps) { + return ( + + + + + + ); +} + +export function IconMessagePlus(props: IconProps) { + return ( + + + + + + ); +} + +export function IconPhoto(props: IconProps) { + return ( + + + + + + ); +} + export function IconGlobe(props: IconProps) { return ( diff --git a/src/components/users/parent-students-panel.tsx b/src/components/users/parent-students-panel.tsx new file mode 100644 index 0000000..9959b11 --- /dev/null +++ b/src/components/users/parent-students-panel.tsx @@ -0,0 +1,119 @@ +import { For, Show, Suspense, createResource, createSignal } from "solid-js"; +import { getParentStudents } from "@/api/getParentStudents"; +import { postParentStudent } from "@/api/postParentStudent"; +import { deleteParentStudent } from "@/api/deleteParentStudent"; +import { formatApiError } from "@/api/client"; +import type { PersonRef } from "@/api/types"; +import { SidePanel } from "@/components/ui/side-panel"; +import { Button } from "@/components/ui/button"; +import { IconTrash, IconPlus } from "@/components/ui/icons"; +import { personLabel } from "@/lib/person"; +import { useT } from "@/stores/preferences-context"; +import { UserSearchSelect } from "@/components/users/user-search-select"; +import { createFlash } from "@/lib/flash"; +import { Alert } from "@/components/ui/alert"; +import { PageSpinner } from "@/components/ui/page-spinner"; + +export function ParentStudentsPanel(props: { + open: boolean; + onOpenChange: (open: boolean) => void; + parent: PersonRef | null; +}) { + const t = useT(); + const [error, setError] = createSignal(""); + const [flash, setFlash] = createFlash(); + + const [students, { refetch }] = createResource( + () => (props.open && props.parent ? props.parent.id : null), + async (id) => (await getParentStudents(id)).items + ); + + const [selectedStudentId, setSelectedStudentId] = createSignal(""); + + const handleAdd = async () => { + if (!props.parent || !selectedStudentId()) return; + setError(""); + try { + await postParentStudent(props.parent.id, selectedStudentId()); + await refetch(); + setSelectedStudentId(""); + setFlash(t("common.saved")); + } catch (err) { + setError(formatApiError(err)); + } + }; + + const handleRemove = async (studentId: string) => { + if (!props.parent) return; + setError(""); + try { + await deleteParentStudent(props.parent.id, studentId); + await refetch(); + setFlash(t("common.deleted")); + } catch (err) { + setError(formatApiError(err)); + } + }; + + return ( + { + if (!open) { + setError(""); + setSelectedStudentId(""); + } + props.onOpenChange(open); + }} + title={t("nav.myStudents")} + description={props.parent ? personLabel(props.parent) : ""} + > +
+ + {flash()} + + {error() &&

{error()}

} + +
+
+ +
+ +
+ +
+
}> + + 0} fallback={
{t("common.noResults")}
}> +
+ + {(student) => ( +
+
+
{personLabel(student)}
+
@{student.username}
+
+ +
+ )} +
+
+
+
+ +
+ + + ); +} diff --git a/src/components/users/user-table.tsx b/src/components/users/user-table.tsx index 6b644d0..ba55086 100644 --- a/src/components/users/user-table.tsx +++ b/src/components/users/user-table.tsx @@ -27,6 +27,7 @@ function UserRoleActions(props: { user: User; currentUserId: string; onRoleChange: (userId: string, role: Role) => Promise; + onParentClick?: (user: User) => void; }) { const t = useT(); const isSelf = () => props.user.id === props.currentUserId; @@ -48,11 +49,16 @@ function UserRoleActions(props: { ))} - + + + Promise; onUserClick?: (user: User) => void; + onParentClick?: (user: User) => void; }) { const t = useT(); const searchUser = (user: User, query: string) => @@ -120,7 +127,7 @@ export function UserTable(props: { header: t("common.update"), meta: { headerClass: "w-52", cellClass: "w-52" }, cell: (cell) => ( - + ), }, ]); diff --git a/src/i18n/messages.ts b/src/i18n/messages.ts index e8349a1..b9d297d 100644 --- a/src/i18n/messages.ts +++ b/src/i18n/messages.ts @@ -21,6 +21,7 @@ export type MessageKey = | "nav.messages" | "nav.pomodoro" | "nav.attendance" + | "nav.questions" | "nav.work" | "nav.staffWork" | "nav.users" @@ -43,6 +44,10 @@ export type MessageKey = | "nav.group.grades" | "nav.group.reports" | "nav.group.settings" + | "nav.group.community" + | "nav.myStudents" + | "parents.title" + | "parents.subtitle" | "common.loading" | "common.cancel" | "common.save" @@ -54,6 +59,9 @@ export type MessageKey = | "common.remove" | "common.back" | "common.view" + | "common.reply" + | "common.approve" + | "common.reject" | "common.actions" | "common.columns" | "common.moreFilters" @@ -98,6 +106,19 @@ export type MessageKey = | "common.saved" | "common.createItem" | "common.countItem" + | "pool.title" + | "pool.subtitle" + | "pool.ask" + | "pool.subject" + | "pool.body" + | "pool.image" + | "pool.status" + | "pool.pending" + | "pool.approved" + | "pool.author" + | "pool.solutions" + | "pool.offerSolution" + | "pool.noQuestions" | "theme.light" | "theme.dark" | "theme.toggle" @@ -445,6 +466,7 @@ export type MessageKey = | "auth.featurePrefs" | "app.workspace" | "role.student" + | "role.parent" | "role.teacher" | "role.manager" | "role.admin" @@ -649,7 +671,8 @@ const en: Dict = { "nav.messages": "Messages", "nav.pomodoro": "Pomodoro", "nav.attendance": "Attendance", - "nav.work": "Work logs", + "nav.questions": "Question Pool", + "nav.work": "Work Log", "nav.staffWork": "Staff work", "nav.users": "Users", "nav.studentMarks": "Student marks", @@ -668,9 +691,13 @@ const en: Dict = { "nav.preferences": "Preferences", "nav.group.students": "Students", "nav.group.classes": "Education", - "nav.group.grades": "My space", + "nav.group.grades": "Grades", "nav.group.reports": "Reports", "nav.group.settings": "Settings", + "nav.group.community": "Community", + "nav.myStudents": "My Students", + "parents.title": "My Students", + "parents.subtitle": "View records for your linked students.", "common.loading": "Loading…", "common.cancel": "Cancel", "common.save": "Save", @@ -682,6 +709,9 @@ const en: Dict = { "common.remove": "Remove", "common.back": "Back", "common.view": "View", + "common.reply": "Reply", + "common.approve": "Approve", + "common.reject": "Reject", "common.actions": "Actions", "common.columns": "Columns", "common.moreFilters": "More filters", @@ -694,7 +724,7 @@ const en: Dict = { "common.goHome": "Go home", "common.learnMore": "Learn more", "common.gotIt": "Got it", - "confirm.review": "Please review the details before continuing.", + "confirm.review": "Please review your changes before saving.", "confirm.summary": "Summary", "confirm.confirmDelete": "Yes, delete", "confirm.confirmUpdate": "Yes, update", @@ -723,9 +753,22 @@ const en: Dict = { "common.saveAttendance": "Save my attendance", "common.created": "Created.", "common.deleted": "Deleted.", - "common.saved": "Saved.", - "common.createItem": "Create {item}", + "common.saved": "Saved successfully.", + "common.createItem": "Create new {item}", "common.countItem": "{count} {item}", + "pool.title": "Question Pool", + "pool.subtitle": "Ask questions and discuss solutions.", + "pool.ask": "Ask Question", + "pool.subject": "Subject", + "pool.body": "Question details", + "pool.image": "Attachment (Image)", + "pool.status": "Status", + "pool.pending": "Pending", + "pool.approved": "Approved", + "pool.author": "Author", + "pool.solutions": "Solutions", + "pool.offerSolution": "Offer a solution", + "pool.noQuestions": "No questions found.", "theme.light": "Light", "theme.dark": "Dark", "theme.toggle": "Toggle theme", @@ -1086,6 +1129,7 @@ const en: Dict = { "auth.featurePrefs": "TR / EN · light / dark", "app.workspace": "@Hezarfen - 2026", "role.student": "Student", + "role.parent": "Parent", "role.teacher": "Teacher", "role.manager": "Manager", "role.admin": "ADMIN", @@ -1288,8 +1332,9 @@ const tr: Dict = { "nav.marks": "Notlar", "nav.messages": "Mesajlar", "nav.pomodoro": "Pomodoro", - "nav.attendance": "Yoklamalar", - "nav.work": "Mesailer", + "nav.attendance": "Yoklama", + "nav.questions": "Soru Havuzu", + "nav.work": "Çalışma Kaydı", "nav.staffWork": "Mesailer", "nav.users": "Kullanıcılar", "nav.studentMarks": "Notlar", @@ -1308,9 +1353,13 @@ const tr: Dict = { "nav.preferences": "Tercihler", "nav.group.students": "Öğrenciler", "nav.group.classes": "Eğitim", - "nav.group.grades": "Benim Alanım", + "nav.group.grades": "Notlar", "nav.group.reports": "Raporlar", "nav.group.settings": "Ayarlar", + "nav.group.community": "Topluluk", + "nav.myStudents": "Öğrencilerim", + "parents.title": "Öğrencilerim", + "parents.subtitle": "Size bağlı öğrencilerin akademik kayıtlarını inceleyin.", "common.loading": "Yükleniyor…", "common.cancel": "Vazgeç", "common.save": "Kaydet", @@ -1322,7 +1371,10 @@ const tr: Dict = { "common.remove": "Kaldır", "common.back": "Geri", "common.view": "Görüntüle", - "common.actions": "İşlem", + "common.reply": "Yanıtla", + "common.approve": "Onayla", + "common.reject": "Reddet", + "common.actions": "İşlemler", "common.columns": "Kolonlar", "common.moreFilters": "Daha fazla filtre", "common.lessFilters": "Daha az filtre", @@ -1334,7 +1386,7 @@ const tr: Dict = { "common.goHome": "Ana sayfaya dön", "common.learnMore": "Daha fazla", "common.gotIt": "Anladım", - "confirm.review": "Devam etmeden önce işlem özetini kontrol edin.", + "confirm.review": "Lütfen kaydetmeden önce değişiklikleri gözden geçirin.", "confirm.summary": "İşlem özeti", "confirm.confirmDelete": "Evet, sil", "confirm.confirmUpdate": "Evet, güncelle", @@ -1363,9 +1415,22 @@ const tr: Dict = { "common.saveAttendance": "Yoklamamı kaydet", "common.created": "Oluşturuldu.", "common.deleted": "Silindi.", - "common.saved": "Kaydedildi.", - "common.createItem": "{item} oluştur", - "common.countItem": "{count} Adet {item}", + "common.saved": "Başarıyla kaydedildi.", + "common.createItem": "Yeni {item} oluştur", + "common.countItem": "{count} {item}", + "pool.title": "Soru Havuzu", + "pool.subtitle": "Soru sorun ve çözümleri tartışın.", + "pool.ask": "Soru Sor", + "pool.subject": "Konu", + "pool.body": "Soru detayı", + "pool.image": "Görsel (İsteğe bağlı)", + "pool.status": "Durum", + "pool.pending": "Bekliyor", + "pool.approved": "Onaylandı", + "pool.author": "Yazar", + "pool.solutions": "Çözümler", + "pool.offerSolution": "Çözüm Gönder", + "pool.noQuestions": "Soru bulunamadı.", "theme.light": "Açık", "theme.dark": "Koyu", "theme.toggle": "Tema", @@ -1726,6 +1791,7 @@ const tr: Dict = { "auth.featurePrefs": "TR / EN · açık / koyu", "app.workspace": "@Hezarfen - 2026", "role.student": "Öğrenci", + "role.parent": "Veli", "role.teacher": "Öğretmen", "role.manager": "Yönetici", "role.admin": "ADMIN", diff --git a/src/lib/roles.ts b/src/lib/roles.ts index 3d84176..17b68ba 100644 --- a/src/lib/roles.ts +++ b/src/lib/roles.ts @@ -1,6 +1,7 @@ import type { Role } from "@/api/types"; const RANK: Record = { + parent: -1, student: 0, teacher: 1, manager: 2, @@ -33,4 +34,4 @@ export function roleInRange( return true; } -export const ROLES: Role[] = ["student", "teacher", "manager", "admin"]; +export const ROLES: Role[] = ["student", "parent", "teacher", "manager", "admin"]; diff --git a/src/pages/admin-users-page.tsx b/src/pages/admin-users-page.tsx index f721280..d9e44a6 100644 --- a/src/pages/admin-users-page.tsx +++ b/src/pages/admin-users-page.tsx @@ -8,6 +8,7 @@ import { RouteGuard } from "@/components/layout/route-guard"; import { PageHeader } from "@/components/layout/page-header"; import { ProfileForm } from "@/components/users/profile-form"; import { UserTable } from "@/components/users/user-table"; +import { ParentStudentsPanel } from "@/components/users/parent-students-panel"; import { Alert } from "@/components/ui/alert"; import { Badge } from "@/components/ui/badge"; import { DataTableEmpty, DataTableSkeleton } from "@/components/ui/data-table"; @@ -31,6 +32,7 @@ function AdminUsersContent() { const t = useT(); const [error, setError] = createSignal(""); const [editUser, setEditUser] = createSignal(null); + const [selectedParent, setSelectedParent] = createSignal(null); const [list, { refetch }] = createResource(async () => (await getUsers()).items); const visibleUsers = () => list() ?? []; @@ -80,7 +82,13 @@ function AdminUsersContent() { }> 0} fallback={{t("admin.noUsers")}}> - + @@ -100,6 +108,16 @@ function AdminUsersContent() { )} + + + {(u) => ( + setSelectedParent(null)} + /> + )} + ); } diff --git a/src/pages/dashboard-page.tsx b/src/pages/dashboard-page.tsx index cb857ec..036f4c4 100644 --- a/src/pages/dashboard-page.tsx +++ b/src/pages/dashboard-page.tsx @@ -65,6 +65,7 @@ type PortalCardDef = { const ROLE_KEY: Record = { student: "role.student", + parent: "role.parent", teacher: "role.teacher", manager: "role.manager", admin: "role.admin", diff --git a/src/pages/my-students-page.tsx b/src/pages/my-students-page.tsx new file mode 100644 index 0000000..4bcf026 --- /dev/null +++ b/src/pages/my-students-page.tsx @@ -0,0 +1,110 @@ +import { For, Show, Suspense, createResource, createSignal } from "solid-js"; +import { getMyStudents } from "@/api/getMyStudents"; +import { getUserMarks } from "@/api/getUserMarks"; +import { getUserAttendance } from "@/api/getUserAttendance"; +import type { PersonRef } from "@/api/types"; +import { RouteGuard } from "@/components/layout/route-guard"; +import { PageHeader } from "@/components/layout/page-header"; +import { EmptyState } from "@/components/ui/empty-state"; +import { PageSpinner } from "@/components/ui/page-spinner"; +import { SidePanel } from "@/components/ui/side-panel"; +import { Button } from "@/components/ui/button"; +import { personLabel } from "@/lib/person"; +import { useT } from "@/stores/preferences-context"; +import { IconChevronRight, IconChart, IconCalendar } from "@/components/ui/icons"; +import { MarksReportView } from "@/components/marks/marks-report-view"; +import { AttendanceReportView } from "@/components/attendance/attendance-report-view"; + +export default function MyStudentsPage() { + return ( + + + + ); +} + +function MyStudentsContent() { + const t = useT(); + const [list] = createResource(async () => (await getMyStudents()).items); + const [selectedStudent, setSelectedStudent] = createSignal(null); + + return ( +
+
+ +
+ + }> + + 0} fallback={}> +
+ + {(student) => ( + + )} + +
+
+
+
+ + setSelectedStudent(null)} /> +
+ ); +} + +function StudentDetailPanel(props: { student: PersonRef | null; onClose: () => void }) { + const t = useT(); + const [activeTab, setActiveTab] = createSignal<"marks" | "attendance">("marks"); + + const [marksRes] = createResource( + () => props.student?.id, + async (id) => getUserMarks(id) + ); + + const [attendanceRes] = createResource( + () => props.student?.id, + async (id) => getUserAttendance(id) + ); + + return ( + !open && props.onClose()} title={props.student ? personLabel(props.student) : ""} description={`@${props.student?.username}`}> +
+
+ + +
+
+ }> + + }> + + + + + }> + + + + +
+
+
+ ); +} diff --git a/src/pages/question-detail-page.tsx b/src/pages/question-detail-page.tsx new file mode 100644 index 0000000..1b3721a --- /dev/null +++ b/src/pages/question-detail-page.tsx @@ -0,0 +1,322 @@ +import { For, Show, Suspense, createResource, createSignal } from "solid-js"; +import { useParams, useRouter } from "@tanstack/solid-router"; +import { getQuestionById, deleteQuestionById, postQuestionApprove, getQuestionImageUrl } from "@/api/questions"; +import { getSolutions, postSolution, patchSolutionById, deleteSolutionById, getSolutionImageUrl } from "@/api/solutions"; +import type { SolutionResponse } from "@/api/solutions"; +import { formatApiError } from "@/api/client"; +import { RouteGuard } from "@/components/layout/route-guard"; +import { PageSpinner } from "@/components/ui/page-spinner"; +import { Button } from "@/components/ui/button"; +import { FormDialog } from "@/components/ui/form-dialog"; +import { ConfirmDialog } from "@/components/ui/confirm-dialog"; +import { Label } from "@/components/ui/label"; +import { Textarea } from "@/components/ui/textarea"; +import { IconTrash, IconCheck, IconX, IconEdit, IconMessage, IconPhoto } from "@/components/ui/icons"; +import { personLabel } from "@/lib/person"; + +import { ErrorAlert } from "@/components/ui/error-alert"; +import { showToast } from "@/components/ui/toast"; +import { useT } from "@/stores/preferences-context"; +import { useAuth } from "@/stores/auth-context"; +import { hasMinRole } from "@/lib/roles"; + +export default function QuestionDetailPage() { + return ( + + + + ); +} + +function QuestionDetailContent() { + const t = useT(); + const auth = useAuth(); + const router = useRouter(); + const params = useParams({ from: "/questions/$id" }); + const [error, setError] = createSignal(""); + + const [question, { refetch: refetchQ }] = createResource(() => params().id, getQuestionById); + const [solutions, { refetch: refetchS }] = createResource( + () => params().id, + async (id) => (await getSolutions(id, { limit: 100, offset: 0 })).items + ); + + const [offerOpen, setOfferOpen] = createSignal(false); + const [editSolution, setEditSolution] = createSignal(null); + const [deleteConfirmQ, setDeleteConfirmQ] = createSignal(false); + const [deleteConfirmS, setDeleteConfirmS] = createSignal(null); + + const isModerator = () => hasMinRole(auth.user()?.role, "teacher"); + + const handleApprove = async () => { + setError(""); + try { + await postQuestionApprove(params().id); + await refetchQ(); + showToast({ title: t("common.saved") }); + } catch (err) { + setError(formatApiError(err)); + } + }; + + const handleDeleteQ = async () => { + setError(""); + try { + await deleteQuestionById(params().id); + router.navigate({ to: "/questions" }); + } catch (err) { + setError(formatApiError(err)); + setDeleteConfirmQ(false); + } + }; + + const handleDeleteS = async (s: SolutionResponse) => { + setError(""); + try { + await deleteSolutionById(params().id, s.id); + await refetchS(); + setDeleteConfirmS(null); + showToast({ title: t("common.deleted") }); + } catch (err) { + setError(formatApiError(err)); + setDeleteConfirmS(null); + } + }; + + return ( +
+ }> + + {(q) => ( + <> +
+
+ +

{q().title}

+
+ {personLabel(q().asker)} + • + {new Date(q().asked_at).toLocaleString()} +
+
+ +
+ + +
+
+
+ + {error() &&

{error()}

} + +
+

{q().body}

+ +
+ Question Attachment +
+
+
+ + +
+
+

{t("pool.solutions")}

+ +
+ +
+ + {(sol) => { + const isMine = sol.author.id === auth.user()?.id; + return ( +
+
+
+
+ {sol.author.display_name?.[0] || sol.author.username[0].toUpperCase()} +
+ {personLabel(sol.author)} + {new Date(sol.offered_at).toLocaleString()} +
+ +
+ + + + +
+
+
+

{sol.body}

+ +
+ Solution Attachment +
+
+
+ ); + }} +
+
+
+
+ + )} +
+
+ + + + + {(sol) => ( + !open && setDeleteConfirmS(null)} + title={t("confirm.deleteTitle")} + summary={t("confirm.confirmDelete")} + onConfirm={() => handleDeleteS(sol)} + variant="destructive" + /> + )} + + + + setOfferOpen(false)} + onSuccess={() => { + setOfferOpen(false); + showToast({ title: t("common.saved") }); + refetchS(); + }} + /> + + + + {(sol) => ( + setEditSolution(null)} + onSuccess={() => { + setEditSolution(null); + showToast({ title: t("common.saved") }); + refetchS(); + }} + /> + )} + +
+ ); +} + +function SolutionFormDialog(props: { questionId: string; initialData?: SolutionResponse; onClose: () => void; onSuccess: () => void }) { + const t = useT(); + const [error, setError] = createSignal(""); + const [body, setBody] = createSignal(props.initialData?.body || ""); + const [file, setFile] = createSignal(null); + + const handleSubmit = async (e: Event) => { + e.preventDefault(); + if (!body().trim()) return; + setError(""); + try { + if (props.initialData) { + await patchSolutionById(props.questionId, props.initialData.id, { body: body().trim() }); + } else { + await postSolution(props.questionId, { body: body().trim() }, file() || undefined); + } + props.onSuccess(); + } catch (err) { + setError(formatApiError(err)); + } + }; + + return ( + !open && props.onClose()} title={props.initialData ? t("common.edit") : t("pool.offerSolution")} description=""> +
+ {error() && } +
+ +