forge
Explore
Log in

Don't you dare go Hollow

✨ manager-assigned course teachers and role-aware empty search messages

Browse files at this commit

ca3a4d4efc9662cef2ebd37f9e6a179a562a63e2Burak BoduroğluParent: 8cf1466
  • feat
    • ✨ manager-assigned course teachers and role-aware empty search messages
Show full message
feat: ✨ manager-assigned course teachers and role-aware empty search messages

- mirror backend course teacher contract: teachers array on Course, POST/DELETE /courses/{id}/teachers
- allow manager+ users to select an initial teacher when creating a course in courses-page
- extend course-management rights to assigned teachers while restricting course deletion to creator or manager+
- add CourseTeachersPanel component with teacher search select and confirmation dialogs
- make UserSearchSelect empty messages role-aware (display 'Uygun öğretmen yok' or 'Uygun öğrenci yok')
- style empty search results with destructive red and medium font weight
- add Turkish and English translations for course teacher staffing workflow
- add Vitest API unit tests for postCourseTeacher and deleteCourseTeacherByUserId
src/api/__tests__/courses/courses.test.tsmodified+26 -0
@@ -13,6 +13,8 @@ import { getCourseSubjects } from "../../courses";
13 import { postCourseSubject } from "../../courses";13 import { postCourseSubject } from "../../courses";
14 import { getCourseExams } from "../../courses";14 import { getCourseExams } from "../../courses";
15 import { postCourseExam } from "../../courses";15 import { postCourseExam } from "../../courses";
16+import { postCourseTeacher } from "../../courses";
17+import { deleteCourseTeacherByUserId } from "../../courses";
16 import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch";18 import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch";
17 19
18 describe("courses API", () => {20 describe("courses API", () => {
@@ -20,6 +22,30 @@ describe("courses API", () => {
20 vi.restoreAllMocks();22 vi.restoreAllMocks();
21 });23 });
22 24
25+ it("postCourseTeacher calls /courses/:id/teachers", async () => {
26+ const mockCourse = { id: "c1", title: "Course", teachers: [{ id: "t1", username: "teacher1", display_name: "Teacher 1" }] };
27+ mockFetchSuccess(mockCourse);
28+
29+ const result = await postCourseTeacher("c1", "t1");
30+ expect(result).toEqual(mockCourse);
31+
32+ const [url, init] = lastFetchCall();
33+ expect(url).toBe("/api/courses/c1/teachers");
34+ expect(init?.method).toBe("POST");
35+ expect(init?.body).toBe(JSON.stringify({ user_id: "t1" }));
36+ });
37+
38+ it("deleteCourseTeacherByUserId calls /courses/:id/teachers/:userId", async () => {
39+ mockFetch204();
40+
41+ await deleteCourseTeacherByUserId("c1", "t1");
42+
43+ const [url, init] = lastFetchCall();
44+ expect(url).toBe("/api/courses/c1/teachers/t1");
45+ expect(init?.method).toBe("DELETE");
46+ });
47+
48+
23 it("getCourses calls /courses with pagination", async () => {49 it("getCourses calls /courses with pagination", async () => {
24 const mockPage = { items: [{ id: "c1" }], total: 1 };50 const mockPage = { items: [{ id: "c1" }], total: 1 };
25 mockFetchSuccess(mockPage);51 mockFetchSuccess(mockPage);
src/api/client/types.tsmodified+1 -0
@@ -91,6 +91,7 @@ export type EventRegistration = {
91 export type Course = {91 export type Course = {
92 id: string;92 id: string;
93 creator: PersonRef;93 creator: PersonRef;
94+ teachers?: PersonRef[];
94 title: string;95 title: string;
95 description: string;96 description: string;
96 kind: CourseKind;97 kind: CourseKind;
src/api/courses/deleteCourseTeacherByUserId.tsadded+10 -0
@@ -0,0 +1,10 @@
1+import { client } from "../client";
2+
3+export function deleteCourseTeacherByUserId(
4+ courseId: string,
5+ userId: string,
6+): Promise<void> {
7+ return client<void>(`/courses/${courseId}/teachers/${userId}`, {
8+ method: "DELETE",
9+ });
10+}
src/api/courses/index.tsmodified+3 -0
@@ -12,3 +12,6 @@ export * from "./getCourseSubjects";
12 export * from "./postCourseSubject";12 export * from "./postCourseSubject";
13 export * from "./getCourseExams";13 export * from "./getCourseExams";
14 export * from "./postCourseExam";14 export * from "./postCourseExam";
15+export * from "./postCourseTeacher";
16+export * from "./deleteCourseTeacherByUserId";
17+
src/api/courses/postCourseTeacher.tsadded+12 -0
@@ -0,0 +1,12 @@
1+import { client } from "../client";
2+import type { Course } from "../client";
3+
4+export function postCourseTeacher(
5+ courseId: string,
6+ userId: string,
7+): Promise<Course> {
8+ return client<Course>(`/courses/${courseId}/teachers`, {
9+ method: "POST",
10+ body: { user_id: userId },
11+ });
12+}
src/components/courses/course-teachers-panel.tsxadded+205 -0
@@ -0,0 +1,205 @@
1+import { Show, createMemo, createSignal } from "solid-js";
2+import type { ColumnDef } from "@tanstack/solid-table";
3+import { deleteCourseTeacherByUserId, postCourseTeacher } from "@/api/courses";
4+import { formatApiError } from "@/api/client";
5+import type { PersonRef } from "@/api/client";
6+import { Alert } from "@/components/ui/alert";
7+import { Button } from "@/components/ui/button";
8+import { ConfirmDialog } from "@/components/ui/confirm-dialog";
9+import { DataTable } from "@/components/ui/data-table";
10+import { EmptyState } from "@/components/ui/empty-state";
11+import { IconPlus, IconTrash } from "@/components/ui/icons";
12+import { SidePanel } from "@/components/ui/side-panel";
13+import { UserSearchSelect } from "@/components/users/user-search-select";
14+import { createFlash } from "@/lib/flash";
15+import { useT } from "@/stores/preferences-context";
16+
17+export function CourseTeachersPanel(props: {
18+ courseId: string;
19+ teachers: PersonRef[];
20+ canStaff: boolean;
21+ onCourseUpdated: () => void;
22+}) {
23+ const t = useT();
24+ const [showAssignPanel, setShowAssignPanel] = createSignal(false);
25+ const [selectedTeacherId, setSelectedTeacherId] = createSignal("");
26+ const [removeTarget, setRemoveTarget] = createSignal<PersonRef | null>(null);
27+ const [error, setError] = createSignal("");
28+ const [pending, setPending] = createSignal(false);
29+ const [flash, setFlash] = createFlash();
30+
31+ const assignedUserIds = createMemo(() => props.teachers.map((teacher) => teacher.id));
32+
33+ const columns = createMemo<ColumnDef<PersonRef>[]>(() => [
34+ {
35+ id: "name",
36+ accessorFn: (row) => row.display_name || row.username,
37+ header: t("admin.username"),
38+ meta: { cellClass: "font-medium" },
39+ cell: (cell) => cell.row.original.display_name || cell.row.original.username,
40+ },
41+ {
42+ id: "id",
43+ accessorFn: (row) => row.id,
44+ header: t("admin.id"),
45+ meta: { cellClass: "mono text-xs text-muted-foreground" },
46+ cell: (cell) => cell.row.original.id,
47+ },
48+ ...(props.canStaff
49+ ? [
50+ {
51+ id: "actions",
52+ header: t("common.actions"),
53+ meta: { headerClass: "w-14 text-center", cellClass: "px-1 text-center" },
54+ cell: (cell: { row: { original: PersonRef } }) => (
55+ <Button
56+ variant="ghost"
57+ size="sm"
58+ class="h-8 w-8 p-0 text-destructive hover:bg-destructive/10"
59+ onClick={() => setRemoveTarget(cell.row.original)}
60+ >
61+ <IconTrash class="h-4 w-4" />
62+ <span class="sr-only">{t("courses.unassignTeacher")}</span>
63+ </Button>
64+ ),
65+ },
66+ ]
67+ : []),
68+ ]);
69+
70+ const handleAssign = async (e: Event) => {
71+ e.preventDefault();
72+ const teacherId = selectedTeacherId();
73+ if (!teacherId) return;
74+
75+ setPending(true);
76+ setError("");
77+
78+ try {
79+ await postCourseTeacher(props.courseId, teacherId);
80+ setFlash(t("courses.teacherAssigned"));
81+ setSelectedTeacherId("");
82+ setShowAssignPanel(false);
83+ props.onCourseUpdated();
84+ } catch (err) {
85+ setError(formatApiError(err));
86+ } finally {
87+ setPending(false);
88+ }
89+ };
90+
91+ const handleUnassign = async () => {
92+ const target = removeTarget();
93+ if (!target) return;
94+
95+ setPending(true);
96+ setError("");
97+
98+ try {
99+ await deleteCourseTeacherByUserId(props.courseId, target.id);
100+ setFlash(t("courses.teacherUnassigned"));
101+ setRemoveTarget(null);
102+ props.onCourseUpdated();
103+ } catch (err) {
104+ setError(formatApiError(err));
105+ } finally {
106+ setPending(false);
107+ }
108+ };
109+
110+ return (
111+ <div class="space-y-4">
112+ <Show when={flash()}>
113+ <Alert variant="success">{flash()}</Alert>
114+ </Show>
115+ <Show when={error()}>
116+ <Alert variant="destructive">{error()}</Alert>
117+ </Show>
118+
119+ <div class="flex items-center justify-between">
120+ <h3 class="text-sm font-semibold">{t("courses.teachers")}</h3>
121+ <Show when={props.canStaff}>
122+ <Button size="sm" onClick={() => setShowAssignPanel(true)}>
123+ <IconPlus class="mr-1.5 h-4 w-4" />
124+ {t("courses.assignTeacher")}
125+ </Button>
126+ </Show>
127+ </div>
128+
129+ <Show
130+ when={props.teachers.length > 0}
131+ fallback={
132+ <EmptyState
133+ title={t("courses.noTeachers")}
134+ description=""
135+ action={
136+ props.canStaff ? (
137+ <Button size="sm" onClick={() => setShowAssignPanel(true)}>
138+ <IconPlus class="mr-1.5 h-4 w-4" />
139+ {t("courses.assignTeacher")}
140+ </Button>
141+ ) : undefined
142+ }
143+ />
144+ }
145+ >
146+ <DataTable columns={columns()} data={props.teachers} />
147+ </Show>
148+
149+ <SidePanel
150+ open={showAssignPanel()}
151+ onOpenChange={(open) => {
152+ setShowAssignPanel(open);
153+ if (!open) {
154+ setSelectedTeacherId("");
155+ setError("");
156+ }
157+ }}
158+ title={t("courses.assignTeacher")}
159+ >
160+ <form onSubmit={handleAssign} class="space-y-4">
161+ <Show when={error()}>
162+ <Alert variant="destructive">{error()}</Alert>
163+ </Show>
164+
165+ <div class="space-y-1.5">
166+ <UserSearchSelect
167+ id="course-teacher-select"
168+ role="teacher"
169+ value={selectedTeacherId()}
170+ onChange={setSelectedTeacherId}
171+ excludeIds={assignedUserIds()}
172+ placeholder={t("courses.assignTeacher")}
173+ />
174+ </div>
175+
176+ <div class="flex justify-end gap-2 pt-2">
177+ <Button
178+ type="button"
179+ variant="outline"
180+ onClick={() => setShowAssignPanel(false)}
181+ disabled={pending()}
182+ >
183+ {t("common.cancel")}
184+ </Button>
185+ <Button type="submit" disabled={pending() || !selectedTeacherId()}>
186+ {pending() ? t("common.loading") : t("courses.assignTeacher")}
187+ </Button>
188+ </div>
189+ </form>
190+ </SidePanel>
191+
192+ <ConfirmDialog
193+ open={Boolean(removeTarget())}
194+ onOpenChange={(open) => {
195+ if (!open) setRemoveTarget(null);
196+ }}
197+ title={t("courses.unassignTeacher")}
198+ summary={t("courses.confirmUnassignTeacher")}
199+ confirmLabel={t("common.remove")}
200+ variant="destructive"
201+ onConfirm={handleUnassign}
202+ />
203+ </div>
204+ );
205+}
src/components/users/user-search-select.tsxmodified+2 -2
@@ -41,7 +41,7 @@ export function UserSearchSelect(props: {
41 if (q.length === 0) return "";41 if (q.length === 0) return "";
42 if (loading()) return t("common.loading");42 if (loading()) return t("common.loading");
43 if (selectedUser() && selectedUser()!.id === props.value) return "";43 if (selectedUser() && selectedUser()!.id === props.value) return "";
44- if (options().length === 0) return props.emptyMessage ?? t("form.noStudents");44+ if (options().length === 0) return props.emptyMessage ?? (props.role === "teacher" ? t("form.noTeachers") : t("form.noStudents"));
45 return "";45 return "";
46 });46 });
47 47
@@ -174,7 +174,7 @@ export function UserSearchSelect(props: {
174 </div>174 </div>
175 </Show>175 </Show>
176 <Show when={hintText()}>176 <Show when={hintText()}>
177- <p class="text-xs text-muted-foreground">{hintText()}</p>177+ <p class={query().trim().length > 0 && options().length === 0 && !loading() ? "text-xs text-destructive font-medium mt-1" : "text-xs text-muted-foreground mt-1"}>{hintText()}</p>
178 </Show>178 </Show>
179 </div>179 </div>
180 );180 );
src/i18n/messages.tsmodified+24 -0
@@ -461,6 +461,7 @@ export type MessageKey =
461 | "form.studentId"461 | "form.studentId"
462 | "form.selectStudent"462 | "form.selectStudent"
463 | "form.noStudents"463 | "form.noStudents"
464+ | "form.noTeachers"
464 | "form.titleRequired"465 | "form.titleRequired"
465 | "form.titleMax"466 | "form.titleMax"
466 | "form.contentMax"467 | "form.contentMax"
@@ -511,6 +512,13 @@ export type MessageKey =
511 | "courses.kind.club"512 | "courses.kind.club"
512 | "courses.capacity"513 | "courses.capacity"
513 | "courses.capacityOptional"514 | "courses.capacityOptional"
515+ | "courses.teachers"
516+ | "courses.assignTeacher"
517+ | "courses.unassignTeacher"
518+ | "courses.confirmUnassignTeacher"
519+ | "courses.teacherAssigned"
520+ | "courses.teacherUnassigned"
521+ | "courses.noTeachers"
514 | "marks.title"522 | "marks.title"
515 | "marks.subtitle"523 | "marks.subtitle"
516 | "marks.overall"524 | "marks.overall"
@@ -1155,6 +1163,7 @@ const en: Dict = {
1155 "form.studentId": "Student user id",1163 "form.studentId": "Student user id",
1156 "form.selectStudent": "Select student",1164 "form.selectStudent": "Select student",
1157 "form.noStudents": "No available students",1165 "form.noStudents": "No available students",
1166+ "form.noTeachers": "No available teachers",
1158 "form.titleRequired": "Title is required",1167 "form.titleRequired": "Title is required",
1159 "form.titleMax": "Title must be at most 200 characters",1168 "form.titleMax": "Title must be at most 200 characters",
1160 "form.contentMax": "Content must be at most 10 000 characters",1169 "form.contentMax": "Content must be at most 10 000 characters",
@@ -1205,6 +1214,13 @@ const en: Dict = {
1205 "courses.kind.club": "Club",1214 "courses.kind.club": "Club",
1206 "courses.capacity": "Capacity",1215 "courses.capacity": "Capacity",
1207 "courses.capacityOptional": "Optional seat cap",1216 "courses.capacityOptional": "Optional seat cap",
1217+ "courses.teachers": "Teachers",
1218+ "courses.assignTeacher": "Assign teacher",
1219+ "courses.unassignTeacher": "Unassign teacher",
1220+ "courses.confirmUnassignTeacher": "Are you sure you want to remove this teacher from the course?",
1221+ "courses.teacherAssigned": "Teacher assigned successfully.",
1222+ "courses.teacherUnassigned": "Teacher unassigned successfully.",
1223+ "courses.noTeachers": "No assigned teachers.",
1208 "marks.title": "Report card",1224 "marks.title": "Report card",
1209 "marks.subtitle": "Weighted averages across enrolled courses.",1225 "marks.subtitle": "Weighted averages across enrolled courses.",
1210 "marks.overall": "Overall average",1226 "marks.overall": "Overall average",
@@ -1843,6 +1859,7 @@ const tr: Dict = {
1843 "form.studentId": "Öğrenci kullanıcı id",1859 "form.studentId": "Öğrenci kullanıcı id",
1844 "form.selectStudent": "Öğrenci seç",1860 "form.selectStudent": "Öğrenci seç",
1845 "form.noStudents": "Uygun öğrenci yok",1861 "form.noStudents": "Uygun öğrenci yok",
1862+ "form.noTeachers": "Uygun öğretmen yok",
1846 "form.titleRequired": "Başlık gerekli",1863 "form.titleRequired": "Başlık gerekli",
1847 "form.titleMax": "Başlık en fazla 200 karakter olmalı",1864 "form.titleMax": "Başlık en fazla 200 karakter olmalı",
1848 "form.contentMax": "İçerik en fazla 10 000 karakter olmalı",1865 "form.contentMax": "İçerik en fazla 10 000 karakter olmalı",
@@ -1893,6 +1910,13 @@ const tr: Dict = {
1893 "courses.kind.club": "Kulüp",1910 "courses.kind.club": "Kulüp",
1894 "courses.capacity": "Kapasite",1911 "courses.capacity": "Kapasite",
1895 "courses.capacityOptional": "İsteğe bağlı kontenjan",1912 "courses.capacityOptional": "İsteğe bağlı kontenjan",
1913+ "courses.teachers": "Öğretmenler",
1914+ "courses.assignTeacher": "Öğretmen ata",
1915+ "courses.unassignTeacher": "Öğretmeni çıkar",
1916+ "courses.confirmUnassignTeacher": "Bu öğretmeni dersten çıkarmak istediğinize emin misiniz?",
1917+ "courses.teacherAssigned": "Öğretmen başarıyla atandı.",
1918+ "courses.teacherUnassigned": "Öğretmen başarıyla çıkarıldı.",
1919+ "courses.noTeachers": "Atanmış öğretmen yok.",
1896 "marks.title": "Karnem",1920 "marks.title": "Karnem",
1897 "marks.subtitle": "Kayıtlı derslerdeki ağırlıklı ortalamalar.",1921 "marks.subtitle": "Kayıtlı derslerdeki ağırlıklı ortalamalar.",
1898 "marks.overall": "Genel ortalama",1922 "marks.overall": "Genel ortalama",
src/pages/course-detail-page.tsxmodified+37 -6
@@ -19,6 +19,7 @@ import { ExamLink } from "@/components/exams/exam-link";
19 import { ExamForm, type ExamFormValues } from "@/components/exams/exam-form";19 import { ExamForm, type ExamFormValues } from "@/components/exams/exam-form";
20 import { ExamQuestionsPanel } from "@/components/exams/exam-questions-panel";20 import { ExamQuestionsPanel } from "@/components/exams/exam-questions-panel";
21 import { CourseSubjectsPanel } from "@/components/courses/course-subjects-panel";21 import { CourseSubjectsPanel } from "@/components/courses/course-subjects-panel";
22+import { CourseTeachersPanel } from "@/components/courses/course-teachers-panel";
22 import { CourseSessionsPanel } from "@/components/sessions/course-sessions-panel";23 import { CourseSessionsPanel } from "@/components/sessions/course-sessions-panel";
23 import { RouteGuard } from "@/components/layout/route-guard";24 import { RouteGuard } from "@/components/layout/route-guard";
24 import { PageHeader } from "@/components/layout/page-header";25 import { PageHeader } from "@/components/layout/page-header";
@@ -72,11 +73,23 @@ function CourseDetailContent() {
72 const [settings] = createResource(() => getSettings());73 const [settings] = createResource(() => getSettings());
73 const [exams, { refetch: refetchExams }] = createResource(id, async (courseId) => (await getCourseExams(courseId)).items);74 const [exams, { refetch: refetchExams }] = createResource(id, async (courseId) => (await getCourseExams(courseId)).items);
74 const hasCourseManagementRights = () => {75 const hasCourseManagementRights = () => {
76+ const c = course();
77+ const u = auth.user();
78+ if (!c || !u) return false;
79+ const isAssigned = (c.teachers ?? []).some((t) => t.id === u.id);
80+ return c.creator.id === u.id || isAssigned || hasMinRole(u.role, "manager");
81+ };
82+ const canDeleteCourse = () => {
75 const c = course();83 const c = course();
76 const u = auth.user();84 const u = auth.user();
77 if (!c || !u) return false;85 if (!c || !u) return false;
78 return c.creator.id === u.id || hasMinRole(u.role, "manager");86 return c.creator.id === u.id || hasMinRole(u.role, "manager");
79 };87 };
88+ const canStaffCourse = () => {
89+ const u = auth.user();
90+ if (!u) return false;
91+ return hasMinRole(u.role, "manager");
92+ };
80 const [roster, { refetch: refetchRoster }] = createResource(93 const [roster, { refetch: refetchRoster }] = createResource(
81 () => (hasCourseManagementRights() ? id() : null),94 () => (hasCourseManagementRights() ? id() : null),
82 async (courseId) => (courseId ? (await getCourseEnrollments(courseId)).items : []),95 async (courseId) => (courseId ? (await getCourseEnrollments(courseId)).items : []),
@@ -98,7 +111,7 @@ function CourseDetailContent() {
98 const [showSubjectForm, setShowSubjectForm] = createSignal(false);111 const [showSubjectForm, setShowSubjectForm] = createSignal(false);
99 const [showSessionForm, setShowSessionForm] = createSignal(false);112 const [showSessionForm, setShowSessionForm] = createSignal(false);
100 const [showEnrollPanel, setShowEnrollPanel] = createSignal(false);113 const [showEnrollPanel, setShowEnrollPanel] = createSignal(false);
101- const [openSections, setOpenSections] = createSignal({ subjects: false, exams: false, sessions: false, roster: false });114+ const [openSections, setOpenSections] = createSignal({ teachers: false, subjects: false, exams: false, sessions: false, roster: false });
102 const [subjectCount, setSubjectCount] = createSignal(0);115 const [subjectCount, setSubjectCount] = createSignal(0);
103 const [sessionCount, setSessionCount] = createSignal(0);116 const [sessionCount, setSessionCount] = createSignal(0);
104 const [enrollUserId, setEnrollUserId] = createSignal("");117 const [enrollUserId, setEnrollUserId] = createSignal("");
@@ -215,7 +228,7 @@ function CourseDetailContent() {
215 ),228 ),
216 },229 },
217 ]);230 ]);
218- const toggleSection = (section: "subjects" | "exams" | "sessions" | "roster") => {231+ const toggleSection = (section: "teachers" | "subjects" | "exams" | "sessions" | "roster") => {
219 setOpenSections((current) => ({ ...current, [section]: !current[section] }));232 setOpenSections((current) => ({ ...current, [section]: !current[section] }));
220 };233 };
221 234
@@ -279,10 +292,12 @@ function CourseDetailContent() {
279 <IconEdit class="h-4 w-4" />292 <IconEdit class="h-4 w-4" />
280 {t("common.edit")}293 {t("common.edit")}
281 </Button>294 </Button>
282- <Button type="button" variant="destructive" size="sm" class="flex-1 rounded-sm sm:flex-none" onClick={() => setDeleteOpen(true)}>295+ <Show when={canDeleteCourse()}>
283- <IconTrash class="h-4 w-4" />296+ <Button type="button" variant="destructive" size="sm" class="flex-1 rounded-sm sm:flex-none" onClick={() => setDeleteOpen(true)}>
284- {t("courses.delete")}297+ <IconTrash class="h-4 w-4" />
285- </Button>298+ {t("courses.delete")}
299+ </Button>
300+ </Show>
286 </div>301 </div>
287 </Show>302 </Show>
288 </div>303 </div>
@@ -533,6 +548,22 @@ function CourseDetailContent() {
533 <p class="rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive">{error()}</p>548 <p class="rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive">{error()}</p>
534 )}549 )}
535 550
551+ <Show when={hasCourseManagementRights()}>
552+ <SectionDisclosure
553+ open={openSections().teachers}
554+ onToggle={() => toggleSection("teachers")}
555+ title={t("courses.teachers")}
556+ description={countDescription((c().teachers ?? []).length, t("courses.teachers"))}
557+ >
558+ <CourseTeachersPanel
559+ courseId={id()}
560+ teachers={c().teachers ?? []}
561+ canStaff={canStaffCourse()}
562+ onCourseUpdated={refetchCourse}
563+ />
564+ </SectionDisclosure>
565+ </Show>
566+
536 <SectionDisclosure567 <SectionDisclosure
537 open={openSections().subjects}568 open={openSections().subjects}
538 onToggle={() => toggleSection("subjects")}569 onToggle={() => toggleSection("subjects")}
src/pages/courses-page.tsxmodified+21 -3
@@ -1,10 +1,9 @@
1 import { For, Show, Suspense, createMemo, createResource, createSignal } from "solid-js";1 import { For, Show, Suspense, createMemo, createResource, createSignal } from "solid-js";
2 import type { ColumnDef } from "@tanstack/solid-table";2 import type { ColumnDef } from "@tanstack/solid-table";
3 import { useLocation, useNavigate } from "@tanstack/solid-router";3 import { useLocation, useNavigate } from "@tanstack/solid-router";
4-import { getCourses } from "@/api/courses";4+import { getCourses, postCourse, postCourseTeacher } from "@/api/courses";
5 import { getMyCourses } from "@/api/reports";5 import { getMyCourses } from "@/api/reports";
6 import { getTerms } from "@/api/terms";6 import { getTerms } from "@/api/terms";
7-import { postCourse } from "@/api/courses";
8 import { formatApiError } from "@/api/client";7 import { formatApiError } from "@/api/client";
9 import type { Course, CourseKind } from "@/api/client";8 import type { Course, CourseKind } from "@/api/client";
10 import { Alert } from "@/components/ui/alert";9 import { Alert } from "@/components/ui/alert";
@@ -20,6 +19,7 @@ import { Select } from "@/components/ui/select";
20 import { SidePanel } from "@/components/ui/side-panel";19 import { SidePanel } from "@/components/ui/side-panel";
21 import { TableRowActions } from "@/components/ui/table-row-actions";20 import { TableRowActions } from "@/components/ui/table-row-actions";
22 import { Textarea } from "@/components/ui/textarea";21 import { Textarea } from "@/components/ui/textarea";
22+import { UserSearchSelect } from "@/components/users/user-search-select";
23 import { createFlash } from "@/lib/flash";23 import { createFlash } from "@/lib/flash";
24 import { personLabel } from "@/lib/person";24 import { personLabel } from "@/lib/person";
25 import { useAuth } from "@/stores/auth-context";25 import { useAuth } from "@/stores/auth-context";
@@ -46,6 +46,7 @@ function CoursesContent() {
46 const [description, setDescription] = createSignal("");46 const [description, setDescription] = createSignal("");
47 const [termId, setTermId] = createSignal("");47 const [termId, setTermId] = createSignal("");
48 const [capacity, setCapacity] = createSignal("");48 const [capacity, setCapacity] = createSignal("");
49+ const [teacherId, setTeacherId] = createSignal("");
49 const [error, setError] = createSignal("");50 const [error, setError] = createSignal("");
50 const [flash, setFlash] = createFlash();51 const [flash, setFlash] = createFlash();
51 const [pending, setPending] = createSignal(false);52 const [pending, setPending] = createSignal(false);
@@ -143,17 +144,22 @@ function CoursesContent() {
143 setPending(true);144 setPending(true);
144 try {145 try {
145 const cap = capacity().trim();146 const cap = capacity().trim();
146- await postCourse({147+ const newCourse = await postCourse({
147 title: title().trim(),148 title: title().trim(),
148 description: description().trim() || undefined,149 description: description().trim() || undefined,
149 kind: pageKind(),150 kind: pageKind(),
150 term_id: termId() || null,151 term_id: termId() || null,
151 capacity: cap ? Number(cap) : null,152 capacity: cap ? Number(cap) : null,
152 });153 });
154+ const tid = teacherId();
155+ if (tid && hasMinRole(auth.user()?.role, "manager")) {
156+ await postCourseTeacher(newCourse.id, tid);
157+ }
153 setTitle("");158 setTitle("");
154 setDescription("");159 setDescription("");
155 setTermId("");160 setTermId("");
156 setCapacity("");161 setCapacity("");
162+ setTeacherId("");
157 setShowForm(false);163 setShowForm(false);
158 await refetch();164 await refetch();
159 setFlash(t("common.created"));165 setFlash(t("common.created"));
@@ -204,6 +210,18 @@ function CoursesContent() {
204 <Label for="course-capacity">{t("courses.capacity")}</Label>210 <Label for="course-capacity">{t("courses.capacity")}</Label>
205 <Input id="course-capacity" type="number" min={1} value={capacity()} placeholder={t("courses.capacityOptional")} onInput={(e) => setCapacity(e.currentTarget.value)} />211 <Input id="course-capacity" type="number" min={1} value={capacity()} placeholder={t("courses.capacityOptional")} onInput={(e) => setCapacity(e.currentTarget.value)} />
206 </div>212 </div>
213+ <Show when={hasMinRole(auth.user()?.role, "manager")}>
214+ <div class="space-y-1.5">
215+ <UserSearchSelect
216+ id="course-create-teacher"
217+ role="teacher"
218+ value={teacherId()}
219+ onChange={setTeacherId}
220+ placeholder={t("courses.assignTeacher")}
221+ label={t("courses.teachers")}
222+ />
223+ </div>
224+ </Show>
207 {error() && <p class="text-sm text-destructive">{error()}</p>}225 {error() && <p class="text-sm text-destructive">{error()}</p>}
208 <div class="flex flex-wrap gap-2">226 <div class="flex flex-wrap gap-2">
209 <Button type="submit" class="rounded-sm" disabled={pending()}>227 <Button type="submit" class="rounded-sm" disabled={pending()}>