🍽️ class-source roster badge and manager booking cancel (phase 4)
Browse files at this commit6195b47b497bb71280cac92b3c0aae4385e3b95fParent: 47cb8e8- feat
- 🍽️ class-source roster badge and manager booking cancel (phase 4)
3 changed files +22 -2
- src/i18n/messages.ts +3 -0
- src/pages/course-detail-page.tsx +14 -1
- src/pages/meal-detail-page.tsx +5 -1
src/i18n/messages.tsmodified+3 -0
| @@ -875,6 +875,7 @@ export type MessageKey = | |||
| 875 | | "ws.error" | 875 | | "ws.error" |
| 876 | | "ws.ping" | 876 | | "ws.ping" |
| 877 | | "course.removeStudent" | 877 | | "course.removeStudent" |
| 878 | + | "course.fromClass" | ||
| 878 | | "course.removeStudentConfirm" | 879 | | "course.removeStudentConfirm" |
| 879 | | "events.userIdRequired" | 880 | | "events.userIdRequired" |
| 880 | | "settings.title" | 881 | | "settings.title" |
| @@ -2211,6 +2212,7 @@ const en: Dict = { | |||
| 2211 | "ws.error": "Connection error", | 2212 | "ws.error": "Connection error", |
| 2212 | "ws.ping": "Ping", | 2213 | "ws.ping": "Ping", |
| 2213 | "course.removeStudent": "Remove student", | 2214 | "course.removeStudent": "Remove student", |
| 2215 | + "course.fromClass": "from {name}", | ||
| 2214 | "course.removeStudentConfirm": "Are you sure you want to remove", | 2216 | "course.removeStudentConfirm": "Are you sure you want to remove", |
| 2215 | "events.userIdRequired": "Please select a student first.", | 2217 | "events.userIdRequired": "Please select a student first.", |
| 2216 | "settings.title": "School settings", | 2218 | "settings.title": "School settings", |
| @@ -3473,6 +3475,7 @@ const tr: Dict = { | |||
| 3473 | "ws.error": "Bağlantı hatası", | 3475 | "ws.error": "Bağlantı hatası", |
| 3474 | "ws.ping": "Ping", | 3476 | "ws.ping": "Ping", |
| 3475 | "course.removeStudent": "Öğrenciyi çıkar", | 3477 | "course.removeStudent": "Öğrenciyi çıkar", |
| 3478 | + "course.fromClass": "{name} şubesinden", | ||
| 3476 | "course.removeStudentConfirm": "Bu öğrenciyi çıkarmak istediğine emin misin?", | 3479 | "course.removeStudentConfirm": "Bu öğrenciyi çıkarmak istediğine emin misin?", |
| 3477 | "events.userIdRequired": "Önce bir öğrenci seçmelisin.", | 3480 | "events.userIdRequired": "Önce bir öğrenci seçmelisin.", |
| 3478 | "settings.title": "Okul ayarları", | 3481 | "settings.title": "Okul ayarları", |
src/pages/course-detail-page.tsxmodified+14 -1
| @@ -6,6 +6,7 @@ import { deleteCourseEnrollmentByUserId } from "@/api/courses"; | |||
| 6 | import { getCourseById } from "@/api/courses"; | 6 | import { getCourseById } from "@/api/courses"; |
| 7 | import { getCourseEnrollments } from "@/api/courses"; | 7 | import { getCourseEnrollments } from "@/api/courses"; |
| 8 | import { getCourseExams } from "@/api/courses"; | 8 | import { getCourseExams } from "@/api/courses"; |
| 9 | +import { getClasses } from "@/api/classes"; | ||
| 9 | import { getMyCourses } from "@/api/reports"; | 10 | import { getMyCourses } from "@/api/reports"; |
| 10 | import { getSettings } from "@/api/settings"; | 11 | import { getSettings } from "@/api/settings"; |
| 11 | import { getTerms } from "@/api/terms"; | 12 | import { getTerms } from "@/api/terms"; |
| @@ -159,13 +160,25 @@ function CourseDetailContent() { | |||
| 159 | const countDescription = (count: number, item: string) => t("common.countItem", { count, item }); | 160 | const countDescription = (count: number, item: string) => t("common.countItem", { count, item }); |
| 160 | 161 | ||
| 161 | const enrolledUserIds = () => (roster() ?? []).map((row) => row.user.id); | 162 | const enrolledUserIds = () => (roster() ?? []).map((row) => row.user.id); |
| 163 | + // Resolve a pumped enrollment's `source` (class id) to a class name so a | ||
| 164 | + // manager can see which rows a class change will sweep. One list call, | ||
| 165 | + // teacher+ only (matches roster visibility); null-source rows show nothing. | ||
| 166 | + const [classList] = createResource(() => hasCourseManagementRights() ? getClasses().then((page) => page.items) : null); | ||
| 167 | + const className = (source: string | null) => source ? (classList.latest?.find((c) => c.id === source)?.name ?? null) : null; | ||
| 162 | const rosterColumns = createMemo<ColumnDef<Enrollment>[]>(() => [ | 168 | const rosterColumns = createMemo<ColumnDef<Enrollment>[]>(() => [ |
| 163 | { | 169 | { |
| 164 | id: "username", | 170 | id: "username", |
| 165 | accessorFn: (row) => row.user.display_name || row.user.username, | 171 | accessorFn: (row) => row.user.display_name || row.user.username, |
| 166 | header: t("admin.username"), | 172 | header: t("admin.username"), |
| 167 | meta: { cellClass: "font-medium" }, | 173 | meta: { cellClass: "font-medium" }, |
| 168 | - cell: (cell) => cell.row.original.user.display_name || cell.row.original.user.username, | 174 | + cell: (cell) => ( |
| 175 | + <span class="flex items-center gap-2"> | ||
| 176 | + {cell.row.original.user.display_name || cell.row.original.user.username} | ||
| 177 | + <Show when={className(cell.row.original.source)}> | ||
| 178 | + {(name) => <Badge variant="secondary" class="rounded-full text-xs font-normal">{t("course.fromClass", { name: name() })}</Badge>} | ||
| 179 | + </Show> | ||
| 180 | + </span> | ||
| 181 | + ), | ||
| 169 | }, | 182 | }, |
| 170 | { | 183 | { |
| 171 | id: "actions", | 184 | id: "actions", |
src/pages/meal-detail-page.tsxmodified+5 -1
| @@ -86,6 +86,9 @@ function MealDetailContent() { | |||
| 86 | const [success, setSuccess] = createSignal(""); | 86 | const [success, setSuccess] = createSignal(""); |
| 87 | const [pending, setPending] = createSignal(false); | 87 | const [pending, setPending] = createSignal(false); |
| 88 | const [cancelOpen, setCancelOpen] = createSignal(false); | 88 | const [cancelOpen, setCancelOpen] = createSignal(false); |
| 89 | + // Manager-only: cancel any student's booking from the service list (backend | ||
| 90 | + // lets manager+ bypass the cutoff). Holds the booking pending confirmation. | ||
| 91 | + const [cancelBooking, setCancelBooking] = createSignal<MealBooking | null>(null); | ||
| 89 | const [deleteMenuOpen, setDeleteMenuOpen] = createSignal(false); | 92 | const [deleteMenuOpen, setDeleteMenuOpen] = createSignal(false); |
| 90 | const [deleteDish, setDeleteDish] = createSignal<MealDish | null>(null); | 93 | const [deleteDish, setDeleteDish] = createSignal<MealDish | null>(null); |
| 91 | 94 | ||
| @@ -247,7 +250,7 @@ function MealDetailContent() { | |||
| 247 | </div> | 250 | </div> |
| 248 | <Show when={serviceAttendance.error || serviceBookings.error}><ErrorAlert message={formatApiError(serviceAttendance.error || serviceBookings.error)} onRetry={() => void refetchService()} /></Show> | 251 | <Show when={serviceAttendance.error || serviceBookings.error}><ErrorAlert message={formatApiError(serviceAttendance.error || serviceBookings.error)} onRetry={() => void refetchService()} /></Show> |
| 249 | <div class="space-y-2"> | 252 | <div class="space-y-2"> |
| 250 | - <For each={serviceEntries()}>{(entry) => <div class="data-shell flex flex-wrap items-center justify-between gap-3 p-3"><div><p class="font-medium">{personLabel(entry.student)}</p><p class="text-xs text-muted-foreground">{entry.booking ? t("meals.booked") : t("meals.walkIn")} · {entry.attendance?.status ?? t("meals.notMarked")}</p></div><div class="flex gap-2"><Button size="sm" variant={entry.attendance?.status === "served" ? "default" : "outline"} onClick={() => void run(async () => { await postMealAttendance(id(), entry.student.id, "served"); await refetchService(); })}>{t("meals.served")}</Button><Button size="sm" variant={entry.attendance?.status === "missed" ? "destructive" : "outline"} onClick={() => void run(async () => { await postMealAttendance(id(), entry.student.id, "missed"); await refetchService(); })}>{t("meals.missed")}</Button></div></div>}</For> | 253 | + <For each={serviceEntries()}>{(entry) => <div class="data-shell flex flex-wrap items-center justify-between gap-3 p-3"><div><p class="font-medium">{personLabel(entry.student)}</p><p class="text-xs text-muted-foreground">{entry.booking ? t("meals.booked") : t("meals.walkIn")} · {entry.attendance?.status ?? t("meals.notMarked")}</p></div><div class="flex gap-2"><Button size="sm" variant={entry.attendance?.status === "served" ? "default" : "outline"} onClick={() => void run(async () => { await postMealAttendance(id(), entry.student.id, "served"); await refetchService(); })}>{t("meals.served")}</Button><Button size="sm" variant={entry.attendance?.status === "missed" ? "destructive" : "outline"} onClick={() => void run(async () => { await postMealAttendance(id(), entry.student.id, "missed"); await refetchService(); })}>{t("meals.missed")}</Button><Show when={canManage() && entry.booking?.status === "booked"}><Button size="sm" variant="ghost" class="text-destructive" onClick={() => setCancelBooking(entry.booking)}>{t("meals.cancelBooking")}</Button></Show></div></div>}</For> |
| 251 | </div> | 254 | </div> |
| 252 | </TabsContent> | 255 | </TabsContent> |
| 253 | 256 | ||
| @@ -272,6 +275,7 @@ function MealDetailContent() { | |||
| 272 | </Tabs> | 275 | </Tabs> |
| 273 | 276 | ||
| 274 | <ConfirmDialog open={cancelOpen()} onOpenChange={setCancelOpen} title={t("meals.cancelBooking")} variant="destructive" summary={t("meals.cancelSummary")} onConfirm={() => run(async () => { const booking = activeBooking(); if (!booking) return; await deleteMealBookingById(booking.id); await Promise.all([refetchBookings(), refetchBalance(), refetchLedger()]); }, t("meals.cancelled"))} /> | 277 | <ConfirmDialog open={cancelOpen()} onOpenChange={setCancelOpen} title={t("meals.cancelBooking")} variant="destructive" summary={t("meals.cancelSummary")} onConfirm={() => run(async () => { const booking = activeBooking(); if (!booking) return; await deleteMealBookingById(booking.id); await Promise.all([refetchBookings(), refetchBalance(), refetchLedger()]); }, t("meals.cancelled"))} /> |
| 278 | + <ConfirmDialog open={cancelBooking() !== null} onOpenChange={(open) => !open && setCancelBooking(null)} title={t("meals.cancelBooking")} variant="destructive" summary={cancelBooking() ? `${t("meals.cancelSummary")} · ${personLabel(cancelBooking()!.student)}` : ""} onConfirm={() => run(async () => { const booking = cancelBooking(); if (!booking) return; await deleteMealBookingById(booking.id); setCancelBooking(null); await Promise.all([refetchService(), refetchServiceBookings()]); }, t("meals.cancelled"))} /> | ||
| 275 | <ConfirmDialog open={deleteMenuOpen()} onOpenChange={setDeleteMenuOpen} title={t("meals.deleteMenu")} variant="destructive" summary={`${current().date} · ${current().slot}`} onConfirm={() => run(async () => { await deleteMealMenuById(id()); void navigate({ to: "/meals" }); }, t("common.deleted"))} /> | 279 | <ConfirmDialog open={deleteMenuOpen()} onOpenChange={setDeleteMenuOpen} title={t("meals.deleteMenu")} variant="destructive" summary={`${current().date} · ${current().slot}`} onConfirm={() => run(async () => { await deleteMealMenuById(id()); void navigate({ to: "/meals" }); }, t("common.deleted"))} /> |
| 276 | <ConfirmDialog open={deleteDish() !== null} onOpenChange={(open) => !open && setDeleteDish(null)} title={t("meals.deleteDish")} variant="destructive" summary={deleteDish()?.name ?? ""} onConfirm={() => run(async () => { if (!deleteDish()) return; await deleteMealDishById(deleteDish()!.id); setDeleteDish(null); await refetchMenu(); }, t("common.deleted"))} /> | 280 | <ConfirmDialog open={deleteDish() !== null} onOpenChange={(open) => !open && setDeleteDish(null)} title={t("meals.deleteDish")} variant="destructive" summary={deleteDish()?.name ?? ""} onConfirm={() => run(async () => { if (!deleteDish()) return; await deleteMealDishById(deleteDish()!.id); setDeleteDish(null); await refetchMenu(); }, t("common.deleted"))} /> |
| 277 | 281 | ||