forge
Explore
Log in

Don't you dare go Hollow

📋 event registration roster with DataTable, remove 6 unused API files

Browse files at this commit

8d7909bb754fde0dc2000abf319c0fb211270a7eBurak BoduroğluParent: 758d094
  • feat
    • 📋 event registration roster with DataTable, remove 6 unused API files
Show full message
feat: 📋 event registration roster with DataTable, remove 6 unused API files
- event-detail-page: registration roster section (registration audience only),
  register/unregister flows with confirmation, roster DataTable shows
  attendance status badge per student
- 3 new API wrappers: getEventRoster, postEventRegister, deleteEventRegisterByUserId
- new types: EventRosterEntry, EventRegistration
- i18n: registration roster keys (en/tr)
- cleanup: delete 6 unused API files (getNoteById, getUserById, patchUserProfile,
  deleteSessionAttendanceByUserId, getExamChoiceImageBlob, getExamQuestionImageBlob)
src/api/deleteEventRegisterByUserId.tsadded+5 -0
@@ -0,0 +1,5 @@
1+import { client } from "./client";
2+
3+export function deleteEventRegisterByUserId(eventId: string, userId: string): Promise<void> {
4+ return client<void>(`/events/${eventId}/register/${userId}`, { method: "DELETE" });
5+}
src/api/deleteSessionAttendanceByUserId.tsdeleted+0 -5
@@ -1,5 +0,0 @@
1-import { client } from "./client";
2-
3-export function deleteSessionAttendanceByUserId(id: string, userId: string): Promise<void> {
4- return client<void>(`/sessions/${id}/attendance/${userId}`, { method: "DELETE" });
5-}
src/api/getEventRoster.tsadded+12 -0
@@ -0,0 +1,12 @@
1+import { client } from "./client";
2+import { normalizePage, pageQuery, type Page, type PageParams } from "./page";
3+import type { EventRosterEntry } from "./types";
4+
5+export async function getEventRoster(
6+ eventId: string,
7+ params?: PageParams,
8+ signal?: AbortSignal,
9+): Promise<Page<EventRosterEntry>> {
10+ const data = await client<unknown>(`/events/${eventId}/roster${pageQuery(params)}`, { signal });
11+ return normalizePage<EventRosterEntry>(data);
12+}
src/api/getExamChoiceImageBlob.tsdeleted+0 -5
@@ -1,5 +0,0 @@
1-import { blobClient } from "./client";
2-
3-export function getExamChoiceImageBlob(examId: string, questionId: string, index: number, signal?: AbortSignal): Promise<Blob> {
4- return blobClient(`/exams/${examId}/questions/${questionId}/choices/${index}/image`, signal);
5-}
src/api/getExamQuestionImageBlob.tsdeleted+0 -5
@@ -1,5 +0,0 @@
1-import { blobClient } from "./client";
2-
3-export function getExamQuestionImageBlob(examId: string, questionId: string, signal?: AbortSignal): Promise<Blob> {
4- return blobClient(`/exams/${examId}/questions/${questionId}/image`, signal);
5-}
src/api/getNoteById.tsdeleted+0 -6
@@ -1,6 +0,0 @@
1-import { client } from "./client";
2-import type { Note } from "./types";
3-
4-export function getNoteById(id: string, signal?: AbortSignal): Promise<Note> {
5- return client<Note>(`/notes/${id}`, { signal });
6-}
src/api/getUserById.tsdeleted+0 -6
@@ -1,6 +0,0 @@
1-import { client } from "@/api/client";
2-import type { User } from "@/api/types";
3-
4-export async function getUserById(id: string, signal?: AbortSignal): Promise<User> {
5- return client<User>(`/users/${encodeURIComponent(id)}`, { signal });
6-}
src/api/patchUserProfile.tsdeleted+0 -6
@@ -1,6 +0,0 @@
1-import { client } from "@/api/client";
2-import type { ProfileUpdate, User } from "@/api/types";
3-
4-export function patchUserProfile(id: string, body: ProfileUpdate): Promise<User> {
5- return client<User>(`/users/${encodeURIComponent(id)}/profile`, { method: "PATCH", body });
6-}
src/api/postEventRegister.tsadded+13 -0
@@ -0,0 +1,13 @@
1+import { client } from "./client";
2+import type { EventRegistration } from "./types";
3+
4+export type PostEventRegisterBody = {
5+ user_id?: string | null;
6+};
7+
8+export function postEventRegister(eventId: string, body: PostEventRegisterBody): Promise<EventRegistration> {
9+ return client<EventRegistration>(`/events/${eventId}/register`, {
10+ method: "POST",
11+ body,
12+ });
13+}
src/api/types.tsmodified+12 -0
@@ -76,6 +76,18 @@ export type Attendance = {
7676 marked_by: PersonRef;
7777 };
7878
79+export type EventRosterEntry = {
80+ user: PersonRef;
81+ status: AttendanceStatus | null;
82+ marked_by: PersonRef | null;
83+};
84+
85+export type EventRegistration = {
86+ event: string;
87+ user: PersonRef;
88+ registered_by: PersonRef;
89+};
90+
7991 export type Course = {
8092 id: string;
8193 creator: string;
src/i18n/messages.tsmodified+21 -0
@@ -80,6 +80,7 @@ export type MessageKey =
8080 | "confirm.deleteSession"
8181 | "confirm.updateExam"
8282 | "confirm.removeAttendance"
83+ | "confirm.removeEventRegistration"
8384 | "confirm.removeResult"
8485 | "confirm.updateRole"
8586 | "confirm.gradeStudent"
@@ -228,6 +229,12 @@ export type MessageKey =
228229 | "events.attendanceRecords"
229230 | "events.attendanceRecordsHelp"
230231 | "events.noAttendance"
232+ | "events.registrationRoster"
233+ | "events.registrationRosterHelp"
234+ | "events.registerStudent"
235+ | "events.unregister"
236+ | "events.noRoster"
237+ | "events.notMarked"
231238 | "events.attendee"
232239 | "events.selectAttendee"
233240 | "events.noAttendees"
@@ -677,6 +684,7 @@ const en: Dict = {
677684 "confirm.deleteSession": "Delete session “{title}”?",
678685 "confirm.updateExam": "Update exam “{title}”?",
679686 "confirm.removeAttendance": "Remove attendance for user {user}?",
687+ "confirm.removeEventRegistration": "Remove registration for user {user}?",
680688 "confirm.removeResult": "Remove grade for user {user}?",
681689 "confirm.updateRole": "Change role of {user} from {from} to {to}?",
682690 "confirm.gradeStudent": "Grade user {user} with mark {mark}/100?",
@@ -826,6 +834,12 @@ const en: Dict = {
826834 "events.attendanceRecords": "Attendance records",
827835 "events.attendanceRecordsHelp": "Saved student attendance for this event, including who recorded each row.",
828836 "events.noAttendance": "No attendance rows yet.",
837+ "events.registrationRoster": "Registration list",
838+ "events.registrationRosterHelp": "Add students before attendance and review who is expected for this event.",
839+ "events.registerStudent": "Register student",
840+ "events.unregister": "Remove registration",
841+ "events.noRoster": "No students registered yet.",
842+ "events.notMarked": "Not marked",
829843 "events.attendee": "Student",
830844 "events.selectAttendee": "Search student",
831845 "events.noAttendees": "No students found",
@@ -1286,6 +1300,7 @@ const tr: Dict = {
12861300 "confirm.deleteSession": "“{title}” oturumu silinsin mi?",
12871301 "confirm.updateExam": "“{title}” sınavı güncellensin mi?",
12881302 "confirm.removeAttendance": "{user} kullanıcısının yoklaması kaldırılsın mı?",
1303+ "confirm.removeEventRegistration": "{user} kullanıcısının etkinlik kaydı kaldırılsın mı?",
12891304 "confirm.removeResult": "{user} kullanıcısının notu kaldırılsın mı?",
12901305 "confirm.updateRole": "{user} rolü {from} → {to} olarak değiştirilsin mi?",
12911306 "confirm.gradeStudent": "{user} kullanıcısına {mark}/100 notu verilsin mi?",
@@ -1435,6 +1450,12 @@ const tr: Dict = {
14351450 "events.attendanceRecords": "Yoklama kayıtları",
14361451 "events.attendanceRecordsHelp": "Bu etkinlik için kaydedilmiş öğrenci yoklaması ve kaydı kimin girdiği.",
14371452 "events.noAttendance": "Henüz yoklama kaydı yok.",
1453+ "events.registrationRoster": "Kayıt listesi",
1454+ "events.registrationRosterHelp": "Yoklama öncesi öğrencileri ekle ve bu etkinlikte beklenenleri kontrol et.",
1455+ "events.registerStudent": "Öğrenciyi kaydet",
1456+ "events.unregister": "Kaydı kaldır",
1457+ "events.noRoster": "Henüz kayıtlı öğrenci yok.",
1458+ "events.notMarked": "İşaretlenmedi",
14381459 "events.attendee": "Öğrenci",
14391460 "events.selectAttendee": "Öğrenci ara",
14401461 "events.noAttendees": "Öğrenci bulunamadı",
src/pages/event-detail-page.tsxmodified+135 -1
@@ -1,13 +1,17 @@
11 import { Link, useLocation, useNavigate, useParams } from "@tanstack/solid-router";
2+import type { ColumnDef } from "@tanstack/solid-table";
23 import { Show, Suspense, createMemo, createResource, createSignal } from "solid-js";
4+import { deleteEventRegisterByUserId } from "@/api/deleteEventRegisterByUserId";
35 import { deleteEventAttendanceByUserId } from "@/api/deleteEventAttendanceByUserId";
46 import { deleteEventById } from "@/api/deleteEventById";
57 import { getEventAttendance } from "@/api/getEventAttendance";
68 import { getEventById } from "@/api/getEventById";
9+import { getEventRoster } from "@/api/getEventRoster";
710 import { patchEventById } from "@/api/patchEventById";
811 import { postEventAttendance } from "@/api/postEventAttendance";
12+import { postEventRegister } from "@/api/postEventRegister";
913 import { formatApiError } from "@/api/client";
10-import type { AttendanceStatus, EventAudience } from "@/api/types";
14+import type { AttendanceStatus, EventAudience, EventRosterEntry } from "@/api/types";
1115 import type { MessageKey } from "@/i18n/messages";
1216 import { AttendanceStatusPicker } from "@/components/events/attendance-status-picker";
1317 import { AttendanceTable } from "@/components/events/attendance-table";
@@ -15,15 +19,21 @@ import { EventForm } from "@/components/events/event-form";
1519 import { RouteGuard } from "@/components/layout/route-guard";
1620 import { PageHeader } from "@/components/layout/page-header";
1721 import { Alert } from "@/components/ui/alert";
22+import { Badge } from "@/components/ui/badge";
1823 import { Button } from "@/components/ui/button";
1924 import { ConfirmDialog } from "@/components/ui/confirm-dialog";
25+import { DataTable } from "@/components/ui/data-table";
2026 import { IconChevronLeft, IconEdit, IconTrash } from "@/components/ui/icons";
2127 import { PageSpinner } from "@/components/ui/page-spinner";
2228 import { SectionDisclosure } from "@/components/ui/section-disclosure";
2329 import { SidePanel } from "@/components/ui/side-panel";
30+import { TableRowActions } from "@/components/ui/table-row-actions";
2431 import { UserSearchSelect } from "@/components/users/user-search-select";
32+import { getAttendanceStatusMeta } from "@/lib/attendance-status";
33+import { cn } from "@/lib/cn";
2534 import { createFlash } from "@/lib/flash";
2635 import { formatDateTime } from "@/lib/format";
36+import { personId, personLabel } from "@/lib/person";
2737 import { hasMinRole } from "@/lib/roles";
2838 import { useAuth } from "@/stores/auth-context";
2939 import { usePreferences, useT } from "@/stores/preferences-context";
@@ -57,8 +67,11 @@ function EventDetailContent() {
5767
5868 const [status, setStatus] = createSignal<AttendanceStatus>("present");
5969 const [otherUserId, setOtherUserId] = createSignal("");
70+ const [registrationUserId, setRegistrationUserId] = createSignal("");
6071 const [editing, setEditing] = createSignal(false);
6172 const [deleteOpen, setDeleteOpen] = createSignal(false);
73+ const [registrationOpen, setRegistrationOpen] = createSignal(false);
74+ const [registrationTarget, setRegistrationTarget] = createSignal<string | null>(null);
6275 const [studentAttendanceOpen, setStudentAttendanceOpen] = createSignal(false);
6376 const [attendanceOpen, setAttendanceOpen] = createSignal(false);
6477 const [error, setError] = createSignal("");
@@ -67,6 +80,10 @@ function EventDetailContent() {
6780 const isTeacherPlus = () => hasMinRole(auth.user()?.role, "teacher");
6881
6982 const [event, { refetch: refetchEvent }] = createResource(id, (eventId) => getEventById(eventId));
83+ const [roster, { refetch: refetchRoster }] = createResource(
84+ () => (isTeacherPlus() && event()?.audience.kind === "registration" && registrationOpen() ? id() : null),
85+ async (eventId) => (eventId ? (await getEventRoster(eventId)).items : []),
86+ );
7087 const [attendance, { refetch: refetchAttendance }] = createResource(
7188 () => (isTeacherPlus() && attendanceOpen() ? id() : null),
7289 async (eventId) => (eventId ? (await getEventAttendance(eventId)).items : []),
@@ -79,6 +96,50 @@ function EventDetailContent() {
7996 return e.creator === u.id || hasMinRole(u.role, "manager");
8097 };
8198 const [flash, setFlash] = createFlash();
99+ const rosterColumns = createMemo<ColumnDef<EventRosterEntry>[]>(() => [
100+ {
101+ id: "attendee",
102+ accessorFn: (row) => personLabel(row.user),
103+ header: t("events.attendee"),
104+ cell: (cell) => <span class="font-medium">{personLabel(cell.row.original.user)}</span>,
105+ },
106+ {
107+ id: "status",
108+ accessorFn: (row) => row.status ?? "",
109+ header: t("events.status"),
110+ cell: (cell) => {
111+ const status = cell.row.original.status;
112+ const meta = status ? getAttendanceStatusMeta(status) : null;
113+ return status ? (
114+ <Badge variant="outline" class={cn("gap-1 rounded-full border px-2.5 py-1 normal-case", meta?.class)}>
115+ {meta ? t(meta.key) : status}
116+ </Badge>
117+ ) : <span class="text-sm text-muted-foreground">{t("events.notMarked")}</span>;
118+ },
119+ },
120+ {
121+ id: "marked_by",
122+ accessorFn: (row) => row.marked_by ? personLabel(row.marked_by) : "",
123+ header: t("events.markedBy"),
124+ cell: (cell) => <span class="text-sm text-muted-foreground">{cell.row.original.marked_by ? personLabel(cell.row.original.marked_by) : "—"}</span>,
125+ },
126+ {
127+ id: "actions",
128+ header: t("common.actions"),
129+ meta: { headerClass: "w-14 text-center", cellClass: "px-1 text-center" },
130+ cell: (cell) => (
131+ <TableRowActions
132+ label={t("common.actions")}
133+ actions={[{
134+ label: t("events.unregister"),
135+ icon: <IconTrash class="h-4 w-4" />,
136+ destructive: true,
137+ onSelect: () => setRegistrationTarget(personId(cell.row.original.user)),
138+ }]}
139+ />
140+ ),
141+ },
142+ ]);
82143
83144 const wrap = async (fn: () => Promise<void>, ok?: string) => {
84145 setError("");
@@ -190,6 +251,79 @@ function EventDetailContent() {
190251 />
191252 </SidePanel>
192253
254+ <ConfirmDialog
255+ open={registrationTarget() != null}
256+ onOpenChange={(open) => {
257+ if (!open) setRegistrationTarget(null);
258+ }}
259+ title={t("confirm.deleteTitle")}
260+ variant="destructive"
261+ summary={t("confirm.removeEventRegistration", { user: registrationTarget() ?? "" })}
262+ onConfirm={async () => {
263+ const userId = registrationTarget();
264+ if (!userId) return;
265+ await wrap(async () => {
266+ await deleteEventRegisterByUserId(id(), userId);
267+ await refetchRoster();
268+ }, t("common.deleted"));
269+ setRegistrationTarget(null);
270+ }}
271+ />
272+
273+ <Show when={isTeacherPlus() && ev().audience.kind === "registration"}>
274+ <SectionDisclosure
275+ open={registrationOpen()}
276+ onToggle={() => setRegistrationOpen((open) => !open)}
277+ title={t("events.registrationRoster")}
278+ description={t("events.registrationRosterHelp")}
279+ >
280+ <div class="space-y-3">
281+ <div class="grid gap-3 rounded-lg border bg-muted/20 p-3 lg:grid-cols-[minmax(0,1fr)_auto] lg:items-end">
282+ <UserSearchSelect
283+ id="registration-user"
284+ label={t("events.attendee")}
285+ value={registrationUserId()}
286+ placeholder={t("events.selectAttendee")}
287+ emptyMessage={t("events.noAttendees")}
288+ role="student"
289+ onChange={setRegistrationUserId}
290+ />
291+ <Button
292+ type="button"
293+ class="rounded-sm"
294+ disabled={pending()}
295+ onClick={() => {
296+ const uid = registrationUserId().trim();
297+ if (!uid) {
298+ setError(t("events.userIdRequired"));
299+ return;
300+ }
301+ void wrap(async () => {
302+ await postEventRegister(id(), { user_id: uid });
303+ setRegistrationUserId("");
304+ await refetchRoster();
305+ }, t("common.saved"));
306+ }}
307+ >
308+ {t("events.registerStudent")}
309+ </Button>
310+ </div>
311+ <Suspense fallback={<PageSpinner />}>
312+ <Show when={roster()}>
313+ {(rows) => (
314+ <Show
315+ when={rows().length > 0}
316+ fallback={<p class="rounded-lg border border-dashed border-border/80 bg-muted/20 px-4 py-8 text-center text-sm text-muted-foreground">{t("events.noRoster")}</p>}
317+ >
318+ <DataTable columns={rosterColumns()} data={rows()} filterColumn="attendee" enablePagination pageSize={10} />
319+ </Show>
320+ )}
321+ </Show>
322+ </Suspense>
323+ </div>
324+ </SectionDisclosure>
325+ </Show>
326+
193327 <Show when={isTeacherPlus()}>
194328 <SectionDisclosure
195329 open={studentAttendanceOpen()}