🍽️ reorganize meal menus and service views
Browse files at this commitabf1dc098fc742f147e627da5375c134622bd5d5Parent: fe60954- feat
- 🍽️ reorganize meal menus and service views
27 changed files +1488 -306
- src/components/meals/meal-account-card.tsx +36 -0
- src/components/meals/meal-attendance-table.tsx +40 -0
- src/components/meals/meal-booking-card.tsx +59 -0
- src/components/meals/meal-day-group.tsx +29 -0
- src/components/meals/meal-dish-list.tsx +63 -0
- src/components/meals/meal-dish-panel.tsx +64 -0
- src/components/meals/meal-dish-row.tsx +51 -0
- src/components/meals/meal-fact.tsx +11 -0
- src/components/meals/meal-ledger-table.tsx +53 -0
- src/components/meals/meal-menu-card.tsx +0 -62
- src/components/meals/meal-menu-edit-panel.tsx +42 -0
- src/components/meals/meal-menu-row.tsx +41 -0
- src/components/meals/meal-publish-panel.tsx +76 -0
- src/components/meals/meal-section-heading.tsx +16 -0
- src/components/meals/meal-service-table.tsx +143 -0
- src/components/meals/meal-service-table.types.ts +4 -0
- src/components/meals/meal-student-record-panel.tsx +105 -0
- src/components/meals/meal-tag-checkboxes.tsx +22 -0
- src/components/meals/meal-walk-in-panel.tsx +40 -0
- src/components/meals/meal-week-nav.tsx +51 -0
- src/i18n/locales/en.ts +27 -1
- src/i18n/locales/tr.ts +27 -1
- src/i18n/messages.ts +26 -0
- src/lib/meals.test.ts +39 -1
- src/lib/meals.ts +73 -0
- src/pages/meal-detail-page.tsx +279 -164
- src/pages/meals-page.tsx +71 -77
src/components/meals/meal-account-card.tsxadded+36 -0
| @@ -0,0 +1,36 @@ | ||
| 1 | +import { For, Show } from "solid-js"; | |
| 2 | +import type { DietaryProfile } from "@/api/client"; | |
| 3 | +import { Badge } from "@/components/ui/badge"; | |
| 4 | +import { dietaryTagLabel, formatTry } from "@/lib/meals"; | |
| 5 | +import { useT } from "@/stores/preferences-context"; | |
| 6 | + | |
| 7 | +/** Balance (when the viewer may read money) and the dietary profile, side by side in one card. */ | |
| 8 | +export function MealAccountCard(props: { | |
| 9 | + showBalance: boolean; | |
| 10 | + balanceMinor?: number; | |
| 11 | + profile?: DietaryProfile | null; | |
| 12 | + moneyLocale: string; | |
| 13 | +}) { | |
| 14 | + const t = useT(); | |
| 15 | + return ( | |
| 16 | + <section class="data-shell divide-y divide-border-hairline" aria-label={t("meals.myAccount")}> | |
| 17 | + <Show when={props.showBalance}> | |
| 18 | + <div class="p-4"> | |
| 19 | + <h2 class="text-xs text-muted-foreground">{t("meals.balance")}</h2> | |
| 20 | + <p class="mt-1 text-2xl font-semibold tabular-nums text-text-strong"> | |
| 21 | + {props.balanceMinor == null ? "—" : formatTry(props.balanceMinor, props.moneyLocale)} | |
| 22 | + </p> | |
| 23 | + </div> | |
| 24 | + </Show> | |
| 25 | + <div class="space-y-2 p-4"> | |
| 26 | + <h2 class="text-xs text-muted-foreground">{t("meals.dietaryProfile")}</h2> | |
| 27 | + <Show when={(props.profile?.tags.length ?? 0) > 0}> | |
| 28 | + <div class="flex flex-wrap gap-1.5"> | |
| 29 | + <For each={props.profile?.tags ?? []}>{(tag) => <Badge variant="warning">{dietaryTagLabel(tag, t)}</Badge>}</For> | |
| 30 | + </div> | |
| 31 | + </Show> | |
| 32 | + <p class="text-sm text-muted-foreground">{props.profile?.note || t("meals.noDietaryNotes")}</p> | |
| 33 | + </div> | |
| 34 | + </section> | |
| 35 | + ); | |
| 36 | +} |
src/components/meals/meal-attendance-table.tsxadded+40 -0
| @@ -0,0 +1,40 @@ | ||
| 1 | +import type { ColumnDef } from "@tanstack/solid-table"; | |
| 2 | +import type { MealAttendance } from "@/api/client"; | |
| 3 | +import type { Locale } from "@/i18n/messages"; | |
| 4 | +import { MealSectionHeading } from "@/components/meals/meal-section-heading"; | |
| 5 | +import { DataTable } from "@/components/ui/data-table"; | |
| 6 | +import { formatDateTime } from "@/lib/format"; | |
| 7 | +import { mealServiceStatusLabel } from "@/lib/meals"; | |
| 8 | +import { useT } from "@/stores/preferences-context"; | |
| 9 | + | |
| 10 | +/** The student's recent meal service marks (served / missed) across menus. */ | |
| 11 | +export function MealAttendanceTable(props: { items: MealAttendance[]; locale: Locale }) { | |
| 12 | + const t = useT(); | |
| 13 | + const columns: ColumnDef<MealAttendance>[] = [ | |
| 14 | + { | |
| 15 | + id: "status", | |
| 16 | + accessorFn: (row) => mealServiceStatusLabel(row.status, t), | |
| 17 | + header: t("meals.status"), | |
| 18 | + meta: { cellClass: "whitespace-nowrap font-medium" }, | |
| 19 | + }, | |
| 20 | + { | |
| 21 | + id: "when", | |
| 22 | + accessorFn: (row) => row.marked_at, | |
| 23 | + header: t("meals.when"), | |
| 24 | + meta: { cellClass: "whitespace-nowrap" }, | |
| 25 | + cell: (cell) => formatDateTime(cell.row.original.marked_at, props.locale), | |
| 26 | + }, | |
| 27 | + ]; | |
| 28 | + return ( | |
| 29 | + <section class="space-y-3" aria-labelledby="meal-attendance-title"> | |
| 30 | + <MealSectionHeading id="meal-attendance-title" title={t("meals.attendance")} /> | |
| 31 | + <DataTable | |
| 32 | + columns={columns} | |
| 33 | + data={props.items} | |
| 34 | + pageSize={5} | |
| 35 | + emptyIllustration="meals" | |
| 36 | + empty={t("meals.noAttendance")} | |
| 37 | + /> | |
| 38 | + </section> | |
| 39 | + ); | |
| 40 | +} |
src/components/meals/meal-booking-card.tsxadded+59 -0
| @@ -0,0 +1,59 @@ | ||
| 1 | +import { Show } from "solid-js"; | |
| 2 | +import type { PersonRef } from "@/api/client"; | |
| 3 | +import { Badge } from "@/components/ui/badge"; | |
| 4 | +import { Button } from "@/components/ui/button"; | |
| 5 | +import { Label } from "@/components/ui/label"; | |
| 6 | +import { SearchableSelect } from "@/components/ui/searchable-select"; | |
| 7 | +import { personLabel } from "@/lib/person"; | |
| 8 | +import { useT } from "@/stores/preferences-context"; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * The student/parent's main task on a menu: am I booked, and the one button | |
| 12 | + * that books or cancels. A parent picks which child first. | |
| 13 | + */ | |
| 14 | +export function MealBookingCard(props: { | |
| 15 | + isParent: boolean; | |
| 16 | + children: PersonRef[]; | |
| 17 | + selectedChild: string; | |
| 18 | + onSelectChild: (id: string) => void; | |
| 19 | + canBook: boolean; | |
| 20 | + booked: boolean; | |
| 21 | + cutoffClosed: boolean; | |
| 22 | + pending: boolean; | |
| 23 | + onBook: () => void; | |
| 24 | + onCancel: () => void; | |
| 25 | +}) { | |
| 26 | + const t = useT(); | |
| 27 | + return ( | |
| 28 | + <section class="data-shell space-y-4 p-4" aria-labelledby="meal-booking-title"> | |
| 29 | + <div class="flex items-center justify-between gap-3"> | |
| 30 | + <h2 id="meal-booking-title" class="font-semibold text-text-strong">{t("meals.bookingStatus")}</h2> | |
| 31 | + <Show when={props.canBook}> | |
| 32 | + <Badge variant={props.booked ? "success" : "secondary"}>{props.booked ? t("meals.booked") : t("meals.notBooked")}</Badge> | |
| 33 | + </Show> | |
| 34 | + </div> | |
| 35 | + <Show when={props.isParent}> | |
| 36 | + <div class="space-y-1.5"> | |
| 37 | + <Label for="meal-child">{t("meals.child")}</Label> | |
| 38 | + <SearchableSelect | |
| 39 | + id="meal-child" | |
| 40 | + value={props.selectedChild} | |
| 41 | + onChange={props.onSelectChild} | |
| 42 | + options={props.children.map((child) => ({ value: child.id, label: personLabel(child) }))} | |
| 43 | + /> | |
| 44 | + </div> | |
| 45 | + </Show> | |
| 46 | + <Show when={props.canBook}> | |
| 47 | + <p class="text-sm text-muted-foreground">{props.cutoffClosed ? t("meals.cutoffPassed") : t("meals.bookingHelp")}</p> | |
| 48 | + <Show | |
| 49 | + when={props.booked} | |
| 50 | + fallback={<Button class="w-full" disabled={props.pending || props.cutoffClosed} onClick={props.onBook}>{t("meals.book")}</Button>} | |
| 51 | + > | |
| 52 | + <Button class="w-full" variant="outline" disabled={props.pending || props.cutoffClosed} onClick={props.onCancel}> | |
| 53 | + <span class="text-destructive-text">{t("meals.cancelBooking")}</span> | |
| 54 | + </Button> | |
| 55 | + </Show> | |
| 56 | + </Show> | |
| 57 | + </section> | |
| 58 | + ); | |
| 59 | +} |
src/components/meals/meal-day-group.tsxadded+29 -0
| @@ -0,0 +1,29 @@ | ||
| 1 | +import { For, Show } from "solid-js"; | |
| 2 | +import type { MealMenu } from "@/api/client"; | |
| 3 | +import { Badge } from "@/components/ui/badge"; | |
| 4 | +import { MealMenuRow } from "@/components/meals/meal-menu-row"; | |
| 5 | +import { formatMealDay } from "@/lib/meals"; | |
| 6 | +import { useT } from "@/stores/preferences-context"; | |
| 7 | + | |
| 8 | +/** A day heading and its meals in one hairline list — no card per meal. */ | |
| 9 | +export function MealDayGroup(props: { | |
| 10 | + date: string; | |
| 11 | + menus: MealMenu[]; | |
| 12 | + locale: string; | |
| 13 | + isToday: boolean; | |
| 14 | +}) { | |
| 15 | + const t = useT(); | |
| 16 | + return ( | |
| 17 | + <section aria-labelledby={`meal-day-${props.date}`} class="space-y-2"> | |
| 18 | + <h3 id={`meal-day-${props.date}`} class="flex items-center gap-2 text-sm font-semibold text-text-strong"> | |
| 19 | + <span class="first-letter:uppercase">{formatMealDay(props.date, props.locale)}</span> | |
| 20 | + <Show when={props.isToday}><Badge variant="info">{t("meals.today")}</Badge></Show> | |
| 21 | + </h3> | |
| 22 | + <div class="divide-y divide-border-hairline overflow-hidden rounded-xl border border-border-line"> | |
| 23 | + <For each={props.menus}> | |
| 24 | + {(menu) => <MealMenuRow menu={menu} locale={props.locale} />} | |
| 25 | + </For> | |
| 26 | + </div> | |
| 27 | + </section> | |
| 28 | + ); | |
| 29 | +} |
src/components/meals/meal-dish-list.tsxadded+63 -0
| @@ -0,0 +1,63 @@ | ||
| 1 | +import { For, Show } from "solid-js"; | |
| 2 | +import type { MealDish } from "@/api/client"; | |
| 3 | +import { MealDishRow } from "@/components/meals/meal-dish-row"; | |
| 4 | +import { Button } from "@/components/ui/button"; | |
| 5 | +import { EmptyInline } from "@/components/ui/empty-inline"; | |
| 6 | +import { IconAlert, IconPlus } from "@/components/ui/icons"; | |
| 7 | +import { dietaryTagLabel, formatTry } from "@/lib/meals"; | |
| 8 | +import { useT } from "@/stores/preferences-context"; | |
| 9 | + | |
| 10 | +/** The menu itself: every dish on one hairline list, the total at the foot. */ | |
| 11 | +export function MealDishList(props: { | |
| 12 | + dishes: MealDish[]; | |
| 13 | + moneyLocale: string; | |
| 14 | + canManage: boolean; | |
| 15 | + onAdd: () => void; | |
| 16 | + onEdit: (dish: MealDish) => void; | |
| 17 | + onDelete: (dish: MealDish) => void; | |
| 18 | +}) { | |
| 19 | + const t = useT(); | |
| 20 | + const total = () => props.dishes.reduce((sum, dish) => sum + dish.price_minor, 0); | |
| 21 | + const conflicts = () => [...new Set(props.dishes.flatMap((dish) => dish.conflicts))]; | |
| 22 | + return ( | |
| 23 | + <section class="data-shell overflow-hidden" aria-labelledby="meal-dishes-title"> | |
| 24 | + <div class="flex flex-wrap items-start justify-between gap-3 p-4"> | |
| 25 | + <div class="min-w-0"> | |
| 26 | + <h2 id="meal-dishes-title" class="text-lg font-semibold tracking-tight text-foreground">{t("meals.menu")}</h2> | |
| 27 | + <p class="mt-1 text-sm text-muted-foreground">{t("meals.dishCount", { count: props.dishes.length })}</p> | |
| 28 | + </div> | |
| 29 | + <Show when={props.canManage}> | |
| 30 | + <Button variant="outline" size="sm" class="rounded-lg" onClick={props.onAdd}> | |
| 31 | + <IconPlus class="h-4 w-4" /> | |
| 32 | + {t("meals.addDish")} | |
| 33 | + </Button> | |
| 34 | + </Show> | |
| 35 | + </div> | |
| 36 | + <Show when={conflicts().length > 0}> | |
| 37 | + <p class="mx-4 mb-3 flex items-start gap-2 rounded-lg bg-warning/10 px-3 py-2 text-sm text-warning-text"> | |
| 38 | + <IconAlert class="mt-0.5 h-4 w-4 shrink-0" /> | |
| 39 | + <span>{t("meals.conflict")}: {conflicts().map((tag) => dietaryTagLabel(tag, t)).join(", ")}</span> | |
| 40 | + </p> | |
| 41 | + </Show> | |
| 42 | + <Show when={props.dishes.length > 0} fallback={<EmptyInline illustration="meals" title={t("meals.noDishes")} class="border-t border-border-hairline" />}> | |
| 43 | + <ul class="divide-y divide-border-hairline border-t border-border-hairline"> | |
| 44 | + <For each={props.dishes}> | |
| 45 | + {(dish) => ( | |
| 46 | + <MealDishRow | |
| 47 | + dish={dish} | |
| 48 | + moneyLocale={props.moneyLocale} | |
| 49 | + canManage={props.canManage} | |
| 50 | + onEdit={() => props.onEdit(dish)} | |
| 51 | + onDelete={() => props.onDelete(dish)} | |
| 52 | + /> | |
| 53 | + )} | |
| 54 | + </For> | |
| 55 | + </ul> | |
| 56 | + <div class="flex items-center justify-between border-t border-border-hairline bg-surface-tint/50 px-4 py-3 text-sm"> | |
| 57 | + <span class="text-muted-foreground">{t("meals.total")}</span> | |
| 58 | + <span class="font-semibold tabular-nums">{formatTry(total(), props.moneyLocale)}</span> | |
| 59 | + </div> | |
| 60 | + </Show> | |
| 61 | + </section> | |
| 62 | + ); | |
| 63 | +} |
src/components/meals/meal-dish-panel.tsxadded+64 -0
| @@ -0,0 +1,64 @@ | ||
| 1 | +import { Show, createEffect, createSignal, on } from "solid-js"; | |
| 2 | +import type { Limits, MealDish } from "@/api/client"; | |
| 3 | +import type { MealDishBody } from "@/api/meals"; | |
| 4 | +import { MealTagCheckboxes } from "@/components/meals/meal-tag-checkboxes"; | |
| 5 | +import { Alert } from "@/components/ui/alert"; | |
| 6 | +import { Button } from "@/components/ui/button"; | |
| 7 | +import { Input } from "@/components/ui/input"; | |
| 8 | +import { Label } from "@/components/ui/label"; | |
| 9 | +import { SidePanel } from "@/components/ui/side-panel"; | |
| 10 | +import { Textarea } from "@/components/ui/textarea"; | |
| 11 | +import { useT } from "@/stores/preferences-context"; | |
| 12 | + | |
| 13 | +/** Add a dish, or edit one (`dish` set). Prices are typed in TRY, sent in minor units. */ | |
| 14 | +export function MealDishPanel(props: { | |
| 15 | + open: boolean; | |
| 16 | + onOpenChange: (open: boolean) => void; | |
| 17 | + dish: MealDish | null; | |
| 18 | + description: string; | |
| 19 | + dietaryTags: string[]; | |
| 20 | + limits?: Limits | null; | |
| 21 | + pending: boolean; | |
| 22 | + error: string; | |
| 23 | + onSave: (body: MealDishBody) => Promise<boolean>; | |
| 24 | +}) { | |
| 25 | + const t = useT(); | |
| 26 | + const [name, setName] = createSignal(""); | |
| 27 | + const [text, setText] = createSignal(""); | |
| 28 | + const [price, setPrice] = createSignal(""); | |
| 29 | + const [tags, setTags] = createSignal<string[]>([]); | |
| 30 | + createEffect(on(() => [props.open, props.dish] as const, ([open, dish]) => { | |
| 31 | + if (!open) return; | |
| 32 | + setName(dish?.name ?? ""); setText(dish?.description ?? ""); | |
| 33 | + setPrice(dish ? String(dish.price_minor / 100) : ""); setTags(dish?.tags ?? []); | |
| 34 | + })); | |
| 35 | + const submit = async (event: SubmitEvent) => { | |
| 36 | + event.preventDefault(); | |
| 37 | + const body = { name: name().trim(), description: text().trim() || null, price_minor: Math.round(Number(price()) * 100), tags: tags() }; | |
| 38 | + if (await props.onSave(body)) props.onOpenChange(false); | |
| 39 | + }; | |
| 40 | + return ( | |
| 41 | + <SidePanel guardUnsaved open={props.open} onOpenChange={props.onOpenChange} title={props.dish ? t("meals.editDish") : t("meals.addDish")} description={props.description}> | |
| 42 | + <form class="space-y-4" onSubmit={submit}> | |
| 43 | + <div class="space-y-1.5"> | |
| 44 | + <Label for="dish-name">{t("meals.dishName")}</Label> | |
| 45 | + <Input id="dish-name" required maxlength={props.limits?.meal.max_dish_name_len} value={name()} onInput={(e) => setName(e.currentTarget.value)} /> | |
| 46 | + </div> | |
| 47 | + <div class="space-y-1.5"> | |
| 48 | + <Label for="dish-description">{t("form.description")}</Label> | |
| 49 | + <Textarea id="dish-description" maxlength={props.limits?.meal.max_dish_description_len} value={text()} onInput={(e) => setText(e.currentTarget.value)} /> | |
| 50 | + </div> | |
| 51 | + <div class="space-y-1.5"> | |
| 52 | + <Label for="dish-price">{t("meals.priceTry")}</Label> | |
| 53 | + <Input id="dish-price" required type="number" min={0} step={0.01} value={price()} onInput={(e) => setPrice(e.currentTarget.value)} /> | |
| 54 | + </div> | |
| 55 | + <MealTagCheckboxes tags={props.dietaryTags} selected={tags()} onChange={setTags} /> | |
| 56 | + <Show when={props.error}><Alert variant="destructive">{props.error}</Alert></Show> | |
| 57 | + <div class="flex gap-2 border-t border-border-hairline pt-4"> | |
| 58 | + <Button type="submit" disabled={props.pending}>{t("common.save")}</Button> | |
| 59 | + <Button type="button" variant="outline" onClick={() => props.onOpenChange(false)}>{t("common.cancel")}</Button> | |
| 60 | + </div> | |
| 61 | + </form> | |
| 62 | + </SidePanel> | |
| 63 | + ); | |
| 64 | +} |
src/components/meals/meal-dish-row.tsxadded+51 -0
| @@ -0,0 +1,51 @@ | ||
| 1 | +import { For, Show } from "solid-js"; | |
| 2 | +import type { MealDish } from "@/api/client"; | |
| 3 | +import { IconAlert, IconEdit, IconTrash } from "@/components/ui/icons"; | |
| 4 | +import { TableRowActions } from "@/components/ui/table-row-actions"; | |
| 5 | +import { dietaryTagLabel, formatTry } from "@/lib/meals"; | |
| 6 | +import { useT } from "@/stores/preferences-context"; | |
| 7 | + | |
| 8 | +/** A dish line: name, optional description, tags, price; managers get a row menu. */ | |
| 9 | +export function MealDishRow(props: { | |
| 10 | + dish: MealDish; | |
| 11 | + moneyLocale: string; | |
| 12 | + canManage: boolean; | |
| 13 | + onEdit: () => void; | |
| 14 | + onDelete: () => void; | |
| 15 | +}) { | |
| 16 | + const t = useT(); | |
| 17 | + const conflicting = (tag: string) => props.dish.conflicts.includes(tag); | |
| 18 | + return ( | |
| 19 | + <li class="flex items-start gap-4 px-4 py-2.5"> | |
| 20 | + <div class="min-w-0 flex-1"> | |
| 21 | + <p class="font-medium text-text-strong">{props.dish.name}</p> | |
| 22 | + <Show when={props.dish.description}> | |
| 23 | + <p class="mt-0.5 text-sm text-muted-foreground">{props.dish.description}</p> | |
| 24 | + </Show> | |
| 25 | + <Show when={props.dish.tags.length > 0}> | |
| 26 | + <p class="mt-1 flex flex-wrap gap-x-3 gap-y-1 text-xs text-muted-foreground"> | |
| 27 | + <For each={props.dish.tags}> | |
| 28 | + {(tag) => ( | |
| 29 | + <span class={conflicting(tag) ? "inline-flex items-center gap-1 font-medium text-warning-text" : undefined}> | |
| 30 | + <Show when={conflicting(tag)}><IconAlert class="h-3.5 w-3.5" /></Show> | |
| 31 | + {dietaryTagLabel(tag, t)} | |
| 32 | + </span> | |
| 33 | + )} | |
| 34 | + </For> | |
| 35 | + </p> | |
| 36 | + </Show> | |
| 37 | + </div> | |
| 38 | + <span class="shrink-0 font-medium tabular-nums">{formatTry(props.dish.price_minor, props.moneyLocale)}</span> | |
| 39 | + <Show when={props.canManage}> | |
| 40 | + <TableRowActions | |
| 41 | + compact | |
| 42 | + label={t("common.actions")} | |
| 43 | + actions={[ | |
| 44 | + { label: t("common.edit"), icon: <IconEdit class="h-4 w-4" />, onSelect: props.onEdit }, | |
| 45 | + { label: t("common.delete"), icon: <IconTrash class="h-4 w-4" />, destructive: true, onSelect: props.onDelete }, | |
| 46 | + ]} | |
| 47 | + /> | |
| 48 | + </Show> | |
| 49 | + </li> | |
| 50 | + ); | |
| 51 | +} |
src/components/meals/meal-fact.tsxadded+11 -0
| @@ -0,0 +1,11 @@ | ||
| 1 | +import type { ParentProps } from "solid-js"; | |
| 2 | + | |
| 3 | +/** One label/value pair in a detail header's fact row — text, not a card. */ | |
| 4 | +export function MealFact(props: ParentProps<{ label: string }>) { | |
| 5 | + return ( | |
| 6 | + <div class="min-w-0"> | |
| 7 | + <dt class="text-xs text-muted-foreground">{props.label}</dt> | |
| 8 | + <dd class="mt-0.5 truncate text-sm font-medium text-text-strong tabular-nums">{props.children}</dd> | |
| 9 | + </div> | |
| 10 | + ); | |
| 11 | +} |
src/components/meals/meal-ledger-table.tsxadded+53 -0
| @@ -0,0 +1,53 @@ | ||
| 1 | +import type { ColumnDef } from "@tanstack/solid-table"; | |
| 2 | +import type { MealLedgerEntry } from "@/api/client"; | |
| 3 | +import type { Locale } from "@/i18n/messages"; | |
| 4 | +import { MealSectionHeading } from "@/components/meals/meal-section-heading"; | |
| 5 | +import { DataTable } from "@/components/ui/data-table"; | |
| 6 | +import { formatDateTime } from "@/lib/format"; | |
| 7 | +import { formatTry, mealLedgerKindLabel } from "@/lib/meals"; | |
| 8 | +import { useT } from "@/stores/preferences-context"; | |
| 9 | + | |
| 10 | +/** The student's latest canteen account movements (charges, credits, reversals). */ | |
| 11 | +export function MealLedgerTable(props: { items: MealLedgerEntry[]; locale: Locale; moneyLocale: string }) { | |
| 12 | + const t = useT(); | |
| 13 | + const columns: ColumnDef<MealLedgerEntry>[] = [ | |
| 14 | + { | |
| 15 | + id: "kind", | |
| 16 | + accessorFn: (row) => mealLedgerKindLabel(row.kind, t), | |
| 17 | + header: t("meals.kind"), | |
| 18 | + meta: { cellClass: "whitespace-nowrap font-medium" }, | |
| 19 | + }, | |
| 20 | + { | |
| 21 | + id: "detail", | |
| 22 | + accessorFn: (row) => row.note || row.method || "—", | |
| 23 | + header: t("meals.detail"), | |
| 24 | + meta: { cellClass: "max-w-0 truncate text-muted-foreground" }, | |
| 25 | + }, | |
| 26 | + { | |
| 27 | + id: "when", | |
| 28 | + accessorFn: (row) => row.created_at, | |
| 29 | + header: t("meals.when"), | |
| 30 | + meta: { cellClass: "whitespace-nowrap" }, | |
| 31 | + cell: (cell) => formatDateTime(cell.row.original.created_at, props.locale), | |
| 32 | + }, | |
| 33 | + { | |
| 34 | + id: "amount", | |
| 35 | + accessorFn: (row) => row.amount_minor, | |
| 36 | + header: t("meals.amount"), | |
| 37 | + meta: { cellClass: "whitespace-nowrap font-medium tabular-nums" }, | |
| 38 | + cell: (cell) => `${cell.row.original.kind === "charge" ? "−" : "+"}${formatTry(cell.row.original.amount_minor, props.moneyLocale)}`, | |
| 39 | + }, | |
| 40 | + ]; | |
| 41 | + return ( | |
| 42 | + <section class="space-y-3" aria-labelledby="meal-ledger-title"> | |
| 43 | + <MealSectionHeading id="meal-ledger-title" title={t("meals.ledger")} /> | |
| 44 | + <DataTable | |
| 45 | + columns={columns} | |
| 46 | + data={props.items} | |
| 47 | + pageSize={5} | |
| 48 | + emptyIllustration="meals" | |
| 49 | + empty={t("meals.noLedger")} | |
| 50 | + /> | |
| 51 | + </section> | |
| 52 | + ); | |
| 53 | +} |
src/components/meals/meal-menu-card.tsxdeleted+0 -62
| @@ -1,62 +0,0 @@ | ||
| 1 | -import { For, Show } from "solid-js"; | |
| 2 | -import { Link } from "@tanstack/solid-router"; | |
| 3 | -import type { MealMenu } from "@/api/client"; | |
| 4 | -import { Badge } from "@/components/ui/badge"; | |
| 5 | -import { IconAlert, IconUtensils } from "@/components/ui/icons"; | |
| 6 | -import { dietaryTagLabel, formatTry, mealSlotLabel } from "@/lib/meals"; | |
| 7 | -import { useT } from "@/stores/preferences-context"; | |
| 8 | - | |
| 9 | -export function MealMenuCard(props: { | |
| 10 | - menu: MealMenu; | |
| 11 | - locale: string; | |
| 12 | - labels: { dishes: string; capacity: string; conflict: string; reservations?: string }; | |
| 13 | - /** | |
| 14 | - * Confirmed booking count for this menu (`getMealMenuBookings(...).total`), | |
| 15 | - * manager+ only per the backend's booking-audit scope. Undefined for | |
| 16 | - * everyone else — the reservation line and occupancy bar simply don't | |
| 17 | - * render rather than showing a made-up number. | |
| 18 | - */ | |
| 19 | - reservationCount?: number; | |
| 20 | -}) { | |
| 21 | - const t = useT(); | |
| 22 | - const total = () => props.menu.dishes.reduce((sum, dish) => sum + dish.price_minor, 0); | |
| 23 | - const conflicts = () => [...new Set(props.menu.dishes.flatMap((dish) => dish.conflicts))]; | |
| 24 | - const occupancyPct = () => { | |
| 25 | - const cap = props.menu.capacity; | |
| 26 | - if (cap == null || cap <= 0 || props.reservationCount == null) return null; | |
| 27 | - return Math.min(100, Math.round((props.reservationCount / cap) * 100)); | |
| 28 | - }; | |
| 29 | - | |
| 30 | - return ( | |
| 31 | - <Link to="/meals/$id" params={{ id: props.menu.id }} class="group flex min-h-56 flex-col rounded-xl border border-border-line bg-surface-base p-4 transition hover:-translate-y-0.5 hover:border-primary/40 hover:shadow-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"> | |
| 32 | - <div class="flex items-start justify-between gap-3"> | |
| 33 | - <div class="flex min-w-0 items-center gap-3"> | |
| 34 | - <span class="flex h-10 w-10 shrink-0 items-center justify-center rounded-xl border border-border-hairline bg-surface-tint"><IconUtensils class="h-5 w-5" /></span> | |
| 35 | - <div class="min-w-0"><h2 class="truncate font-semibold text-text-strong">{mealSlotLabel(props.menu.slot, t)}</h2><time class="text-xs text-text-subtle" datetime={props.menu.date}>{props.menu.date}</time></div> | |
| 36 | - </div> | |
| 37 | - <span class="shrink-0 font-semibold tabular-nums">{formatTry(total(), props.locale)}</span> | |
| 38 | - </div> | |
| 39 | - <div class="mt-4 flex flex-wrap gap-1.5"><For each={props.menu.dishes}>{(dish) => <Badge variant="outline">{dish.name}</Badge>}</For></div> | |
| 40 | - <Show when={conflicts().length > 0}> | |
| 41 | - <div class="mt-3 flex items-start gap-2 rounded-xl border border-warning/50 bg-warning/10 p-2 text-xs text-warning-text"> | |
| 42 | - <IconAlert class="mt-0.5 h-4 w-4" /><span>{props.labels.conflict}: {conflicts().map((tag) => dietaryTagLabel(tag, t)).join(", ")}</span> | |
| 43 | - </div> | |
| 44 | - </Show> | |
| 45 | - <Show when={occupancyPct() != null}> | |
| 46 | - <div class="mt-3 space-y-1"> | |
| 47 | - <div class="flex justify-between text-xs text-text-subtle"> | |
| 48 | - <span>{props.labels.reservations}: {props.reservationCount}</span> | |
| 49 | - <span>%{occupancyPct()}</span> | |
| 50 | - </div> | |
| 51 | - <div class="h-1.5 overflow-hidden rounded-full bg-surface-fill"> | |
| 52 | - <div class="h-full rounded-full bg-success" style={{ width: `${occupancyPct()}%` }} /> | |
| 53 | - </div> | |
| 54 | - </div> | |
| 55 | - </Show> | |
| 56 | - <div class="mt-auto flex justify-between border-t border-border-hairline pt-3 text-xs text-text-subtle"> | |
| 57 | - <span>{props.menu.dishes.length} {props.labels.dishes}</span> | |
| 58 | - <span>{props.labels.capacity}: <span>{props.menu.capacity ?? "∞"}</span></span> | |
| 59 | - </div> | |
| 60 | - </Link> | |
| 61 | - ); | |
| 62 | -} |
src/components/meals/meal-menu-edit-panel.tsxadded+42 -0
| @@ -0,0 +1,42 @@ | ||
| 1 | +import { Show, createEffect, createSignal, on } from "solid-js"; | |
| 2 | +import { Alert } from "@/components/ui/alert"; | |
| 3 | +import { Button } from "@/components/ui/button"; | |
| 4 | +import { Input } from "@/components/ui/input"; | |
| 5 | +import { Label } from "@/components/ui/label"; | |
| 6 | +import { SidePanel } from "@/components/ui/side-panel"; | |
| 7 | +import { useT } from "@/stores/preferences-context"; | |
| 8 | + | |
| 9 | +/** Edit a menu's capacity (the one mutable menu field). Empty = unlimited. */ | |
| 10 | +export function MealMenuEditPanel(props: { | |
| 11 | + open: boolean; | |
| 12 | + onOpenChange: (open: boolean) => void; | |
| 13 | + description: string; | |
| 14 | + capacity: number | null; | |
| 15 | + maxCapacity?: number; | |
| 16 | + pending: boolean; | |
| 17 | + error: string; | |
| 18 | + onSave: (capacity: number | null) => Promise<boolean>; | |
| 19 | +}) { | |
| 20 | + const t = useT(); | |
| 21 | + const [capacity, setCapacity] = createSignal(""); | |
| 22 | + createEffect(on(() => props.open, (open) => { if (open) setCapacity(props.capacity == null ? "" : String(props.capacity)); })); | |
| 23 | + const submit = async (event: SubmitEvent) => { | |
| 24 | + event.preventDefault(); | |
| 25 | + if (await props.onSave(capacity() ? Number(capacity()) : null)) props.onOpenChange(false); | |
| 26 | + }; | |
| 27 | + return ( | |
| 28 | + <SidePanel guardUnsaved open={props.open} onOpenChange={props.onOpenChange} title={t("meals.editMenu")} description={props.description}> | |
| 29 | + <form class="space-y-4" onSubmit={submit}> | |
| 30 | + <div class="space-y-1.5"> | |
| 31 | + <Label for="menu-capacity">{t("meals.capacity")}</Label> | |
| 32 | + <Input id="menu-capacity" type="number" min={0} max={props.maxCapacity} value={capacity()} onInput={(e) => setCapacity(e.currentTarget.value)} /> | |
| 33 | + </div> | |
| 34 | + <Show when={props.error}><Alert variant="destructive">{props.error}</Alert></Show> | |
| 35 | + <div class="flex gap-2 border-t border-border-hairline pt-4"> | |
| 36 | + <Button type="submit" disabled={props.pending}>{t("common.save")}</Button> | |
| 37 | + <Button type="button" variant="outline" onClick={() => props.onOpenChange(false)}>{t("common.cancel")}</Button> | |
| 38 | + </div> | |
| 39 | + </form> | |
| 40 | + </SidePanel> | |
| 41 | + ); | |
| 42 | +} |
src/components/meals/meal-menu-row.tsxadded+41 -0
| @@ -0,0 +1,41 @@ | ||
| 1 | +import { Show } from "solid-js"; | |
| 2 | +import { Link } from "@tanstack/solid-router"; | |
| 3 | +import type { MealMenu } from "@/api/client"; | |
| 4 | +import { IconAlert, IconChevronRight } from "@/components/ui/icons"; | |
| 5 | +import { dietaryTagLabel, formatTry, mealSlotLabel } from "@/lib/meals"; | |
| 6 | +import { useT } from "@/stores/preferences-context"; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * One meal of a day: slot, the dishes as one quiet line, capacity and price. | |
| 10 | + * Booking totals live on the menu's detail page (one audit read per menu). | |
| 11 | + */ | |
| 12 | +export function MealMenuRow(props: { menu: MealMenu; locale: string }) { | |
| 13 | + const t = useT(); | |
| 14 | + const total = () => props.menu.dishes.reduce((sum, dish) => sum + dish.price_minor, 0); | |
| 15 | + const dishes = () => props.menu.dishes.map((dish) => dish.name).join(" · "); | |
| 16 | + const conflicts = () => [...new Set(props.menu.dishes.flatMap((dish) => dish.conflicts))]; | |
| 17 | + const capacity = () => (props.menu.capacity == null ? t("meals.unlimited") : String(props.menu.capacity)); | |
| 18 | + | |
| 19 | + return ( | |
| 20 | + <Link | |
| 21 | + to="/meals/$id" | |
| 22 | + params={{ id: props.menu.id }} | |
| 23 | + class="group grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-4 gap-y-1 px-4 py-3 transition-colors hover:bg-surface-tint focus-visible:bg-surface-tint focus-visible:outline-none sm:grid-cols-[9rem_minmax(0,1fr)_7rem_6rem_1rem]" | |
| 24 | + > | |
| 25 | + <span class="col-start-1 row-start-1 truncate font-medium text-text-strong sm:col-start-auto sm:row-start-auto">{mealSlotLabel(props.menu.slot, t)}</span> | |
| 26 | + <span class="col-span-2 col-start-1 row-start-2 flex min-w-0 items-center gap-1.5 text-sm text-muted-foreground sm:col-span-1 sm:col-start-auto sm:row-start-auto"> | |
| 27 | + <Show when={conflicts().length > 0}> | |
| 28 | + <span class="shrink-0 text-warning-text" title={`${t("meals.conflict")}: ${conflicts().map((tag) => dietaryTagLabel(tag, t)).join(", ")}`}> | |
| 29 | + <IconAlert class="h-4 w-4" /> | |
| 30 | + </span> | |
| 31 | + </Show> | |
| 32 | + <span class="truncate">{dishes() || t("meals.noDishes")}</span> | |
| 33 | + </span> | |
| 34 | + <span class="hidden text-right text-xs text-muted-foreground tabular-nums sm:block"> | |
| 35 | + {t("meals.capacity")} {capacity()} | |
| 36 | + </span> | |
| 37 | + <span class="col-start-2 row-start-1 text-right font-medium tabular-nums sm:col-start-auto sm:row-start-auto">{formatTry(total(), props.locale)}</span> | |
| 38 | + <IconChevronRight class="hidden h-4 w-4 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 sm:block" /> | |
| 39 | + </Link> | |
| 40 | + ); | |
| 41 | +} |
src/components/meals/meal-publish-panel.tsxadded+76 -0
| @@ -0,0 +1,76 @@ | ||
| 1 | +import { For, Show, createSignal } from "solid-js"; | |
| 2 | +import { formatApiError, type Limits, type MealSlot } from "@/api/client"; | |
| 3 | +import { Alert } from "@/components/ui/alert"; | |
| 4 | +import { Button } from "@/components/ui/button"; | |
| 5 | +import { DatePicker } from "@/components/ui/date-picker"; | |
| 6 | +import { ErrorAlert } from "@/components/ui/error-alert"; | |
| 7 | +import { Input } from "@/components/ui/input"; | |
| 8 | +import { Label } from "@/components/ui/label"; | |
| 9 | +import { Select } from "@/components/ui/select"; | |
| 10 | +import { SidePanel } from "@/components/ui/side-panel"; | |
| 11 | +import { inputDateToIso, isoDateToInput } from "@/lib/datetime-input"; | |
| 12 | +import { mealSlotLabel } from "@/lib/meals"; | |
| 13 | +import { useT } from "@/stores/preferences-context"; | |
| 14 | + | |
| 15 | +export type MealPublishInput = { date: string; slot: string; capacity: number | null }; | |
| 16 | + | |
| 17 | +/** Publish one menu (date + slot + optional capacity) from the list header. */ | |
| 18 | +export function MealPublishPanel(props: { | |
| 19 | + open: boolean; | |
| 20 | + onOpenChange: (open: boolean) => void; | |
| 21 | + initialDate: string; | |
| 22 | + slots: MealSlot[]; | |
| 23 | + limits?: Limits | null; | |
| 24 | + limitsError?: string; | |
| 25 | + onRetryLimits: () => void; | |
| 26 | + onPublish: (input: MealPublishInput) => Promise<void>; | |
| 27 | +}) { | |
| 28 | + const t = useT(); | |
| 29 | + const [date, setDate] = createSignal(props.initialDate); | |
| 30 | + const [picked, setSlot] = createSignal(""); | |
| 31 | + // Settings may land after mount: default to the school's first slot. | |
| 32 | + const slot = () => picked() || props.slots[0]?.name || ""; | |
| 33 | + const [capacity, setCapacity] = createSignal(""); | |
| 34 | + const [pending, setPending] = createSignal(false); | |
| 35 | + const [error, setError] = createSignal(""); | |
| 36 | + | |
| 37 | + const submit = async (event: SubmitEvent) => { | |
| 38 | + event.preventDefault(); | |
| 39 | + setPending(true); setError(""); | |
| 40 | + try { | |
| 41 | + await props.onPublish({ date: date(), slot: slot(), capacity: capacity() ? Number(capacity()) : null }); | |
| 42 | + setCapacity(""); | |
| 43 | + } catch (err) { | |
| 44 | + setError(formatApiError(err)); | |
| 45 | + } finally { | |
| 46 | + setPending(false); | |
| 47 | + } | |
| 48 | + }; | |
| 49 | + | |
| 50 | + return ( | |
| 51 | + <SidePanel open={props.open} onOpenChange={props.onOpenChange} guardUnsaved title={t("meals.publish")} description={t("meals.publishHelp")}> | |
| 52 | + <form class="space-y-4" onSubmit={submit}> | |
| 53 | + <Show when={props.limitsError}><ErrorAlert message={props.limitsError!} onRetry={props.onRetryLimits} /></Show> | |
| 54 | + <div class="space-y-1.5"> | |
| 55 | + <Label for="meal-date">{t("meals.date")}</Label> | |
| 56 | + <DatePicker id="meal-date" required placeholder={t("form.datePlaceholder")} value={isoDateToInput(date())} onChange={(value) => setDate(inputDateToIso(value))} /> | |
| 57 | + </div> | |
| 58 | + <div class="space-y-1.5"> | |
| 59 | + <Label for="meal-slot">{t("meals.slot")}</Label> | |
| 60 | + <Select id="meal-slot" required value={slot()} onChange={(e) => setSlot(e.currentTarget.value)}> | |
| 61 | + <For each={props.slots}>{(item) => <option value={item.name}>{mealSlotLabel(item.name, t)}</option>}</For> | |
| 62 | + </Select> | |
| 63 | + </div> | |
| 64 | + <div class="space-y-1.5"> | |
| 65 | + <Label for="meal-capacity">{t("meals.capacity")}</Label> | |
| 66 | + <Input id="meal-capacity" type="number" min={0} max={props.limits?.meal.max_menu_capacity} value={capacity()} onInput={(e) => setCapacity(e.currentTarget.value)} /> | |
| 67 | + </div> | |
| 68 | + <Show when={error()}><Alert variant="destructive">{error()}</Alert></Show> | |
| 69 | + <div class="flex gap-2 border-t border-border-hairline pt-4"> | |
| 70 | + <Button type="submit" disabled={pending()}>{t("common.create")}</Button> | |
| 71 | + <Button type="button" variant="outline" onClick={() => props.onOpenChange(false)}>{t("common.cancel")}</Button> | |
| 72 | + </div> | |
| 73 | + </form> | |
| 74 | + </SidePanel> | |
| 75 | + ); | |
| 76 | +} |
src/components/meals/meal-section-heading.tsxadded+16 -0
| @@ -0,0 +1,16 @@ | ||
| 1 | +import { Show } from "solid-js"; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Plain heading over a detail-page table. DataTable draws no title of its | |
| 5 | + * own, and a page with several tables needs to say which one is which. | |
| 6 | + */ | |
| 7 | +export function MealSectionHeading(props: { id: string; title: string; description?: string }) { | |
| 8 | + return ( | |
| 9 | + <div class="px-1"> | |
| 10 | + <h2 id={props.id} class="text-base font-semibold tracking-tight text-foreground">{props.title}</h2> | |
| 11 | + <Show when={props.description}> | |
| 12 | + <p class="mt-0.5 text-sm text-muted-foreground">{props.description}</p> | |
| 13 | + </Show> | |
| 14 | + </div> | |
| 15 | + ); | |
| 16 | +} |
src/components/meals/meal-service-table.tsxadded+143 -0
| @@ -0,0 +1,143 @@ | ||
| 1 | +import type { ColumnDef } from "@tanstack/solid-table"; | |
| 2 | +import { Show } from "solid-js"; | |
| 3 | +import type { MealBooking } from "@/api/client"; | |
| 4 | +import type { MealServiceEntry } from "@/components/meals/meal-service-table.types"; | |
| 5 | +import { Badge } from "@/components/ui/badge"; | |
| 6 | +import { Button } from "@/components/ui/button"; | |
| 7 | +import { MealSectionHeading } from "@/components/meals/meal-section-heading"; | |
| 8 | +import { DataTable } from "@/components/ui/data-table"; | |
| 9 | +import { IconCheck, IconPlus, IconTrash, IconX } from "@/components/ui/icons"; | |
| 10 | +import { TableRowActions } from "@/components/ui/table-row-actions"; | |
| 11 | +import { mealBookingStateLabel, mealServiceStatusLabel } from "@/lib/meals"; | |
| 12 | +import { personLabel } from "@/lib/person"; | |
| 13 | +import { useT } from "@/stores/preferences-context"; | |
| 14 | + | |
| 15 | +const ACTIONS_CLASS = "w-[110px] min-w-[110px] max-w-[110px] h-[45px] text-center whitespace-nowrap"; | |
| 16 | + | |
| 17 | +/** | |
| 18 | + * The serving desk's list: who booked (manager audit), who was served or | |
| 19 | + * missed, one-tap marks per row, walk-ins from the header. | |
| 20 | + */ | |
| 21 | +export function MealServiceTable(props: { | |
| 22 | + entries: MealServiceEntry[]; | |
| 23 | + canManage: boolean; | |
| 24 | + pending: boolean; | |
| 25 | + onMark: (studentId: string, status: "served" | "missed") => void; | |
| 26 | + onCancelBooking: (booking: MealBooking) => void; | |
| 27 | + onAddWalkIn: () => void; | |
| 28 | +}) { | |
| 29 | + const t = useT(); | |
| 30 | + const bookingCell = (entry: MealServiceEntry) => | |
| 31 | + entry.booking ? mealBookingStateLabel(entry.booking.status, t) : t("meals.walkIn"); | |
| 32 | + const columns = (): ColumnDef<MealServiceEntry>[] => [ | |
| 33 | + { | |
| 34 | + id: "student", | |
| 35 | + accessorFn: (row) => personLabel(row.student), | |
| 36 | + header: t("meals.student"), | |
| 37 | + meta: { cellClass: "max-w-0 truncate font-medium" }, | |
| 38 | + }, | |
| 39 | + { | |
| 40 | + id: "booking", | |
| 41 | + accessorFn: bookingCell, | |
| 42 | + header: t("meals.bookingStatus"), | |
| 43 | + meta: { cellClass: "whitespace-nowrap" }, | |
| 44 | + cell: (cell) => ( | |
| 45 | + <span class={cell.row.original.booking?.status === "cancelled" ? "text-muted-foreground line-through" : undefined}> | |
| 46 | + {bookingCell(cell.row.original)} | |
| 47 | + </span> | |
| 48 | + ), | |
| 49 | + }, | |
| 50 | + { | |
| 51 | + id: "service", | |
| 52 | + accessorFn: (row) => row.attendance?.status ?? "", | |
| 53 | + header: t("meals.serviceStatus"), | |
| 54 | + meta: { cellClass: "whitespace-nowrap" }, | |
| 55 | + cell: (cell) => { | |
| 56 | + const status = () => cell.row.original.attendance?.status; | |
| 57 | + return ( | |
| 58 | + <Show when={status()} fallback={<span class="text-muted-foreground">{t("meals.notMarked")}</span>}> | |
| 59 | + <Badge variant={status() === "served" ? "success" : status() === "missed" ? "warning" : "secondary"}> | |
| 60 | + {mealServiceStatusLabel(status()!, t)} | |
| 61 | + </Badge> | |
| 62 | + </Show> | |
| 63 | + ); | |
| 64 | + }, | |
| 65 | + }, | |
| 66 | + { | |
| 67 | + id: "mark", | |
| 68 | + header: t("meals.mark"), | |
| 69 | + enableSorting: false, | |
| 70 | + meta: { cellClass: "whitespace-nowrap" }, | |
| 71 | + cell: (cell) => { | |
| 72 | + const status = () => cell.row.original.attendance?.status; | |
| 73 | + return ( | |
| 74 | + <div class="flex gap-1.5"> | |
| 75 | + <Button | |
| 76 | + size="sm" | |
| 77 | + variant={status() === "served" ? "default" : "outline"} | |
| 78 | + class="rounded-lg" | |
| 79 | + disabled={props.pending} | |
| 80 | + aria-pressed={status() === "served"} | |
| 81 | + onClick={(event) => { event.stopPropagation(); props.onMark(cell.row.original.student.id, "served"); }} | |
| 82 | + > | |
| 83 | + <IconCheck class="h-3.5 w-3.5" /> | |
| 84 | + {t("meals.served")} | |
| 85 | + </Button> | |
| 86 | + <Button | |
| 87 | + size="sm" | |
| 88 | + variant="outline" | |
| 89 | + class={status() === "missed" ? "rounded-lg border-warning/60 bg-warning/10 text-warning-text" : "rounded-lg"} | |
| 90 | + disabled={props.pending} | |
| 91 | + aria-pressed={status() === "missed"} | |
| 92 | + onClick={(event) => { event.stopPropagation(); props.onMark(cell.row.original.student.id, "missed"); }} | |
| 93 | + > | |
| 94 | + <IconX class="h-3.5 w-3.5" /> | |
| 95 | + {t("meals.missed")} | |
| 96 | + </Button> | |
| 97 | + </div> | |
| 98 | + ); | |
| 99 | + }, | |
| 100 | + }, | |
| 101 | + ...(props.canManage | |
| 102 | + ? [{ | |
| 103 | + id: "actions", | |
| 104 | + header: t("common.actions"), | |
| 105 | + enableSorting: false, | |
| 106 | + meta: { headerClass: ACTIONS_CLASS, cellClass: ACTIONS_CLASS }, | |
| 107 | + cell: (cell) => ( | |
| 108 | + <Show when={cell.row.original.booking?.status === "booked"}> | |
| 109 | + <TableRowActions | |
| 110 | + label={t("common.actions")} | |
| 111 | + actions={[{ | |
| 112 | + label: t("meals.cancelBooking"), | |
| 113 | + icon: <IconTrash class="h-4 w-4" />, | |
| 114 | + destructive: true, | |
| 115 | + onSelect: () => props.onCancelBooking(cell.row.original.booking!), | |
| 116 | + }]} | |
| 117 | + /> | |
| 118 | + </Show> | |
| 119 | + ), | |
| 120 | + } satisfies ColumnDef<MealServiceEntry>] | |
| 121 | + : []), | |
| 122 | + ]; | |
| 123 | + return ( | |
| 124 | + <section class="space-y-3" aria-labelledby="meal-service-title"> | |
| 125 | + <MealSectionHeading id="meal-service-title" title={t("meals.service")} description={t("meals.serviceHelp")} /> | |
| 126 | + <DataTable | |
| 127 | + actions={ | |
| 128 | + <Button variant="outline" size="sm" class="rounded-lg" onClick={props.onAddWalkIn}> | |
| 129 | + <IconPlus class="h-4 w-4" /> | |
| 130 | + {t("meals.addWalkIn")} | |
| 131 | + </Button> | |
| 132 | + } | |
| 133 | + columns={columns()} | |
| 134 | + data={props.entries} | |
| 135 | + searchPredicate={(row, query) => personLabel(row.student).toLocaleLowerCase().includes(query.toLocaleLowerCase())} | |
| 136 | + filterHint={t("meals.student")} | |
| 137 | + pageSize={20} | |
| 138 | + emptyIllustration="meals" | |
| 139 | + empty={t("meals.noService")} | |
| 140 | + /> | |
| 141 | + </section> | |
| 142 | + ); | |
| 143 | +} |
src/components/meals/meal-service-table.types.tsadded+4 -0
| @@ -0,0 +1,4 @@ | ||
| 1 | +import type { MealAttendance, MealBooking, PersonRef } from "@/api/client"; | |
| 2 | + | |
| 3 | +/** One student on a menu's service list: their booking (managers only) and their service mark. */ | |
| 4 | +export type MealServiceEntry = { student: PersonRef; booking: MealBooking | null; attendance: MealAttendance | null }; |
src/components/meals/meal-student-record-panel.tsxadded+105 -0
| @@ -0,0 +1,105 @@ | ||
| 1 | +import { Show, createEffect, createSignal } from "solid-js"; | |
| 2 | +import type { DietaryProfile, Limits } from "@/api/client"; | |
| 3 | +import { MealTagCheckboxes } from "@/components/meals/meal-tag-checkboxes"; | |
| 4 | +import { Alert } from "@/components/ui/alert"; | |
| 5 | +import { Button } from "@/components/ui/button"; | |
| 6 | +import { Input } from "@/components/ui/input"; | |
| 7 | +import { Label } from "@/components/ui/label"; | |
| 8 | +import { SidePanel } from "@/components/ui/side-panel"; | |
| 9 | +import { Textarea } from "@/components/ui/textarea"; | |
| 10 | +import { UserSearchSelect } from "@/components/users/user-search-select"; | |
| 11 | +import { formatTry } from "@/lib/meals"; | |
| 12 | +import { useT } from "@/stores/preferences-context"; | |
| 13 | + | |
| 14 | +export type MealCreditInput = { amountMinor: number; method?: string; note?: string }; | |
| 15 | + | |
| 16 | +/** | |
| 17 | + * Manager tools for one student: their dietary profile, and for admins an | |
| 18 | + * append-only canteen credit. Lives in a panel so the menu page stays about | |
| 19 | + * the menu. | |
| 20 | + */ | |
| 21 | +export function MealStudentRecordPanel(props: { | |
| 22 | + open: boolean; | |
| 23 | + onOpenChange: (open: boolean) => void; | |
| 24 | + studentId: string; | |
| 25 | + onStudentChange: (id: string) => void; | |
| 26 | + profile?: DietaryProfile | null; | |
| 27 | + balanceMinor?: number; | |
| 28 | + dietaryTags: string[]; | |
| 29 | + limits?: Limits | null; | |
| 30 | + isAdmin: boolean; | |
| 31 | + moneyLocale: string; | |
| 32 | + pending: boolean; | |
| 33 | + error: string; | |
| 34 | + onSaveProfile: (tags: string[], note: string | null) => Promise<boolean>; | |
| 35 | + onRecordCredit: (input: MealCreditInput) => Promise<boolean>; | |
| 36 | +}) { | |
| 37 | + const t = useT(); | |
| 38 | + const [tags, setTags] = createSignal<string[]>([]); | |
| 39 | + const [note, setNote] = createSignal(""); | |
| 40 | + const [amount, setAmount] = createSignal(""); | |
| 41 | + const [method, setMethod] = createSignal(""); | |
| 42 | + const [creditNote, setCreditNote] = createSignal(""); | |
| 43 | + createEffect(() => { | |
| 44 | + const profile = props.profile; | |
| 45 | + if (profile) { setTags([...profile.tags]); setNote(profile.note ?? ""); } | |
| 46 | + }); | |
| 47 | + | |
| 48 | + const saveProfile = (event: SubmitEvent) => { | |
| 49 | + event.preventDefault(); | |
| 50 | + void props.onSaveProfile(tags(), note().trim() || null); | |
| 51 | + }; | |
| 52 | + const recordCredit = async (event: SubmitEvent) => { | |
| 53 | + event.preventDefault(); | |
| 54 | + const ok = await props.onRecordCredit({ | |
| 55 | + amountMinor: Math.round(Number(amount()) * 100), | |
| 56 | + method: method().trim() || undefined, | |
| 57 | + note: creditNote().trim() || undefined, | |
| 58 | + }); | |
| 59 | + if (ok) { setAmount(""); setMethod(""); setCreditNote(""); } | |
| 60 | + }; | |
| 61 | + | |
| 62 | + return ( | |
| 63 | + <SidePanel open={props.open} onOpenChange={props.onOpenChange} title={t("meals.studentRecord")} description={t("meals.studentRecordHelp")}> | |
| 64 | + <div class="space-y-5"> | |
| 65 | + <UserSearchSelect id="meal-record-user" role="student" value={props.studentId} onChange={props.onStudentChange} label={t("meals.student")} /> | |
| 66 | + <Show when={props.error}><Alert variant="destructive">{props.error}</Alert></Show> | |
| 67 | + <Show when={props.studentId} fallback={<p class="text-sm text-muted-foreground">{t("meals.selectStudentFirst")}</p>}> | |
| 68 | + <Show when={props.balanceMinor != null}> | |
| 69 | + <div class="flex items-baseline justify-between rounded-lg bg-surface-tint px-3 py-2"> | |
| 70 | + <span class="text-sm text-muted-foreground">{t("meals.balance")}</span> | |
| 71 | + <span class="font-semibold tabular-nums">{formatTry(props.balanceMinor!, props.moneyLocale)}</span> | |
| 72 | + </div> | |
| 73 | + </Show> | |
| 74 | + <form class="space-y-3" onSubmit={saveProfile}> | |
| 75 | + <h3 class="text-sm font-semibold text-text-strong">{t("meals.dietaryProfile")}</h3> | |
| 76 | + <MealTagCheckboxes tags={props.dietaryTags} selected={tags()} onChange={setTags} /> | |
| 77 | + <Textarea maxlength={props.limits?.meal.max_dietary_note_len} value={note()} placeholder={t("meals.dietaryNote")} aria-label={t("meals.dietaryNote")} onInput={(e) => setNote(e.currentTarget.value)} /> | |
| 78 | + <Button type="submit" size="sm" class="rounded-lg" disabled={props.pending}>{t("common.save")}</Button> | |
| 79 | + </form> | |
| 80 | + <Show when={props.isAdmin}> | |
| 81 | + <form class="space-y-3 border-t border-border-hairline pt-5" onSubmit={recordCredit}> | |
| 82 | + <div> | |
| 83 | + <h3 class="text-sm font-semibold text-text-strong">{t("meals.recordCredit")}</h3> | |
| 84 | + <p class="mt-0.5 text-xs text-muted-foreground">{t("meals.creditAppendOnly")}</p> | |
| 85 | + </div> | |
| 86 | + <div class="space-y-1.5"> | |
| 87 | + <Label for="meal-credit-amount">{t("meals.amountTry")}</Label> | |
| 88 | + <Input id="meal-credit-amount" type="number" min={0.01} step={0.01} value={amount()} onInput={(e) => setAmount(e.currentTarget.value)} /> | |
| 89 | + </div> | |
| 90 | + <div class="space-y-1.5"> | |
| 91 | + <Label for="meal-credit-method">{t("meals.method")}</Label> | |
| 92 | + <Input id="meal-credit-method" maxlength={props.limits?.meal.max_ledger_method_len} value={method()} onInput={(e) => setMethod(e.currentTarget.value)} /> | |
| 93 | + </div> | |
| 94 | + <div class="space-y-1.5"> | |
| 95 | + <Label for="meal-credit-note">{t("meals.note")}</Label> | |
| 96 | + <Textarea id="meal-credit-note" maxlength={props.limits?.meal.max_ledger_note_len} value={creditNote()} onInput={(e) => setCreditNote(e.currentTarget.value)} /> | |
| 97 | + </div> | |
| 98 | + <Button type="submit" size="sm" class="rounded-lg" disabled={props.pending}>{t("meals.recordCredit")}</Button> | |
| 99 | + </form> | |
| 100 | + </Show> | |
| 101 | + </Show> | |
| 102 | + </div> | |
| 103 | + </SidePanel> | |
| 104 | + ); | |
| 105 | +} |
src/components/meals/meal-tag-checkboxes.tsxadded+22 -0
| @@ -0,0 +1,22 @@ | ||
| 1 | +import { For } from "solid-js"; | |
| 2 | +import { dietaryTagLabel } from "@/lib/meals"; | |
| 3 | +import { useT } from "@/stores/preferences-context"; | |
| 4 | + | |
| 5 | +/** The school's dietary tags as toggles (dish tags and a student's profile). */ | |
| 6 | +export function MealTagCheckboxes(props: { tags: string[]; selected: string[]; onChange: (selected: string[]) => void }) { | |
| 7 | + const t = useT(); | |
| 8 | + const toggle = (tag: string) => | |
| 9 | + props.onChange(props.selected.includes(tag) ? props.selected.filter((item) => item !== tag) : [...props.selected, tag]); | |
| 10 | + return ( | |
| 11 | + <div class="flex flex-wrap gap-2"> | |
| 12 | + <For each={props.tags}> | |
| 13 | + {(tag) => ( | |
| 14 | + <label class="flex cursor-pointer items-center gap-2 rounded-lg border border-border-line px-3 py-1.5 text-sm has-[:checked]:border-primary/50 has-[:checked]:bg-primary/5"> | |
| 15 | + <input type="checkbox" checked={props.selected.includes(tag)} onChange={() => toggle(tag)} /> | |
| 16 | + {dietaryTagLabel(tag, t)} | |
| 17 | + </label> | |
| 18 | + )} | |
| 19 | + </For> | |
| 20 | + </div> | |
| 21 | + ); | |
| 22 | +} |
src/components/meals/meal-walk-in-panel.tsxadded+40 -0
| @@ -0,0 +1,40 @@ | ||
| 1 | +import { Show, createSignal } from "solid-js"; | |
| 2 | +import { Alert } from "@/components/ui/alert"; | |
| 3 | +import { Button } from "@/components/ui/button"; | |
| 4 | +import { SidePanel } from "@/components/ui/side-panel"; | |
| 5 | +import { UserSearchSelect } from "@/components/users/user-search-select"; | |
| 6 | +import { useT } from "@/stores/preferences-context"; | |
| 7 | + | |
| 8 | +/** Record a student who came without a booking as served. */ | |
| 9 | +export function MealWalkInPanel(props: { | |
| 10 | + open: boolean; | |
| 11 | + onOpenChange: (open: boolean) => void; | |
| 12 | + description: string; | |
| 13 | + pending: boolean; | |
| 14 | + error: string; | |
| 15 | + onSubmit: (studentId: string) => Promise<boolean>; | |
| 16 | +}) { | |
| 17 | + const t = useT(); | |
| 18 | + const [student, setStudent] = createSignal(""); | |
| 19 | + const submit = async (event: SubmitEvent) => { | |
| 20 | + event.preventDefault(); | |
| 21 | + if (!student()) return; | |
| 22 | + if (await props.onSubmit(student())) { | |
| 23 | + setStudent(""); | |
| 24 | + props.onOpenChange(false); | |
| 25 | + } | |
| 26 | + }; | |
| 27 | + return ( | |
| 28 | + <SidePanel open={props.open} onOpenChange={props.onOpenChange} title={t("meals.addWalkIn")} description={props.description}> | |
| 29 | + <form class="space-y-4" onSubmit={submit}> | |
| 30 | + <p class="text-sm text-muted-foreground">{t("meals.walkInHelp")}</p> | |
| 31 | + <UserSearchSelect id="meal-walkin" value={student()} onChange={setStudent} label={t("meals.student")} placeholder={t("form.selectStudent")} /> | |
| 32 | + <Show when={props.error}><Alert variant="destructive">{props.error}</Alert></Show> | |
| 33 | + <div class="flex gap-2 border-t border-border-hairline pt-4"> | |
| 34 | + <Button type="submit" disabled={!student() || props.pending}>{t("meals.served")}</Button> | |
| 35 | + <Button type="button" variant="outline" onClick={() => props.onOpenChange(false)}>{t("common.cancel")}</Button> | |
| 36 | + </div> | |
| 37 | + </form> | |
| 38 | + </SidePanel> | |
| 39 | + ); | |
| 40 | +} |
src/components/meals/meal-week-nav.tsxadded+51 -0
| @@ -0,0 +1,51 @@ | ||
| 1 | +import { For } from "solid-js"; | |
| 2 | +import type { MealSlot } from "@/api/client"; | |
| 3 | +import { Button } from "@/components/ui/button"; | |
| 4 | +import { DatePicker } from "@/components/ui/date-picker"; | |
| 5 | +import { IconChevronLeft, IconChevronRight } from "@/components/ui/icons"; | |
| 6 | +import { Select } from "@/components/ui/select"; | |
| 7 | +import { inputDateToIso } from "@/lib/datetime-input"; | |
| 8 | +import { addDaysIso, formatMealWeek, mealSlotLabel, weekStartIso } from "@/lib/meals"; | |
| 9 | +import { useT } from "@/stores/preferences-context"; | |
| 10 | + | |
| 11 | +/** Week stepper, a date jump and the slot filter — the list's whole toolbar. */ | |
| 12 | +export function MealWeekNav(props: { | |
| 13 | + weekStart: string; | |
| 14 | + thisWeek: string; | |
| 15 | + locale: string; | |
| 16 | + slot: string; | |
| 17 | + slots: MealSlot[]; | |
| 18 | + onWeekChange: (weekStart: string) => void; | |
| 19 | + onSlotChange: (slot: string) => void; | |
| 20 | +}) { | |
| 21 | + const t = useT(); | |
| 22 | + return ( | |
| 23 | + <div class="flex flex-wrap items-center gap-2"> | |
| 24 | + <div class="flex items-center gap-1"> | |
| 25 | + <Button variant="outline" size="icon" class="h-8 w-8 rounded-lg" aria-label={t("meals.prevWeek")} onClick={() => props.onWeekChange(addDaysIso(props.weekStart, -7))}> | |
| 26 | + <IconChevronLeft class="h-4 w-4" /> | |
| 27 | + </Button> | |
| 28 | + <Button variant="outline" size="icon" class="h-8 w-8 rounded-lg" aria-label={t("meals.nextWeek")} onClick={() => props.onWeekChange(addDaysIso(props.weekStart, 7))}> | |
| 29 | + <IconChevronRight class="h-4 w-4" /> | |
| 30 | + </Button> | |
| 31 | + </div> | |
| 32 | + <p class="min-w-0 text-sm font-medium text-text-strong tabular-nums" aria-live="polite">{formatMealWeek(props.weekStart, props.locale)}</p> | |
| 33 | + <Button variant="ghost" size="sm" class="h-8 rounded-lg text-[13px]" disabled={props.weekStart === props.thisWeek} onClick={() => props.onWeekChange(props.thisWeek)}> | |
| 34 | + {t("meals.thisWeek")} | |
| 35 | + </Button> | |
| 36 | + <div class="flex w-full flex-wrap items-center gap-2 sm:ml-auto sm:w-auto"> | |
| 37 | + <DatePicker | |
| 38 | + id="menus-week" | |
| 39 | + class="h-8 w-40" | |
| 40 | + placeholder={t("meals.goToDate")} | |
| 41 | + value="" | |
| 42 | + onChange={(value) => { const iso = inputDateToIso(value); if (iso) props.onWeekChange(weekStartIso(iso)); }} | |
| 43 | + /> | |
| 44 | + <Select id="menus-slot" aria-label={t("meals.slot")} wrapperClass="w-auto" class="h-8 rounded-lg text-[13px]" value={props.slot} onChange={(e) => props.onSlotChange(e.currentTarget.value)}> | |
| 45 | + <option value="all">{t("meals.slot")}: {t("common.all")}</option> | |
| 46 | + <For each={props.slots}>{(item) => <option value={item.name}>{mealSlotLabel(item.name, t)}</option>}</For> | |
| 47 | + </Select> | |
| 48 | + </div> | |
| 49 | + </div> | |
| 50 | + ); | |
| 51 | +} |
src/i18n/locales/en.tsmodified+27 -1
| @@ -2076,7 +2076,7 @@ export const en: Dict = { | ||
| 2076 | 2076 | "settings.colorPaletteSource": "Browse trending palettes", |
| 2077 | 2077 | "settings.defaultColor": "Use default colour", |
| 2078 | 2078 | "meals.title": "Cafeteria", |
| 2079 | - "meals.subtitle": "Browse menus by date, manage dietary requirements, and track meal accounts.", | |
| 2079 | + "meals.subtitle": "This week's menus. Pick a meal to book or record service.", | |
| 2080 | 2080 | "meals.publish": "Publish menu", |
| 2081 | 2081 | "meals.publishHelp": "One menu per date and meal slot.", |
| 2082 | 2082 | "meals.date": "Menu date", |
| @@ -2139,6 +2139,32 @@ export const en: Dict = { | ||
| 2139 | 2139 | "meals.editDish": "Edit dish", |
| 2140 | 2140 | "meals.dishName": "Dish name", |
| 2141 | 2141 | "meals.priceTry": "Price (TRY)", |
| 2142 | + "meals.thisWeek": "This week", | |
| 2143 | + "meals.prevWeek": "Previous week", | |
| 2144 | + "meals.nextWeek": "Next week", | |
| 2145 | + "meals.goToDate": "Go to date", | |
| 2146 | + "meals.today": "Today", | |
| 2147 | + "meals.emptyWeek": "No menus published for this week.", | |
| 2148 | + "meals.emptyWeekHint": "Switch to another week or clear the meal filter.", | |
| 2149 | + "meals.unlimited": "Unlimited", | |
| 2150 | + "meals.dishCount": "{count} dishes", | |
| 2151 | + "meals.reservedOf": "{count} / {capacity}", | |
| 2152 | + "meals.studentRecordHelp": "Pick a student to manage their dietary profile and meal account.", | |
| 2153 | + "meals.selectStudentFirst": "Pick a student to see their record.", | |
| 2154 | + "meals.serviceHelp": "Booked students and recorded service.", | |
| 2155 | + "meals.addWalkIn": "Add walk-in", | |
| 2156 | + "meals.walkInHelp": "Record a student who came without a booking as served.", | |
| 2157 | + "meals.noService": "No bookings or service records yet.", | |
| 2158 | + "meals.serviceStatus": "Service", | |
| 2159 | + "meals.mark": "Mark", | |
| 2160 | + "meals.bookingState.booked": "Booked", | |
| 2161 | + "meals.bookingState.cancelled": "Cancelled", | |
| 2162 | + "meals.kind": "Type", | |
| 2163 | + "meals.detail": "Details", | |
| 2164 | + "meals.when": "Date", | |
| 2165 | + "meals.amount": "Amount", | |
| 2166 | + "meals.status": "Status", | |
| 2167 | + "meals.noAttendance": "No meal attendance yet.", | |
| 2142 | 2168 | "nav.payments": "Payments & collection", |
| 2143 | 2169 | "nav.paymentStatement": "My Fees", |
| 2144 | 2170 | "nav.whiteboards": "Whiteboards", |
src/i18n/locales/tr.tsmodified+27 -1
| @@ -2072,7 +2072,7 @@ export const tr: Dict = { | ||
| 2072 | 2072 | "settings.colorPaletteSource": "Trend paletlere göz at", |
| 2073 | 2073 | "settings.defaultColor": "Varsayılan rengi kullan", |
| 2074 | 2074 | "meals.title": "Yemekhane", |
| 2075 | - "meals.subtitle": "Menüleri tarihe göre inceleyin, beslenme gereksinimlerini yönetin ve yemek hesaplarını takip edin.", | |
| 2075 | + "meals.subtitle": "Haftanın menüleri. Rezervasyon ve servis için bir öğün seçin.", | |
| 2076 | 2076 | "meals.publish": "Menü yayınla", |
| 2077 | 2077 | "meals.publishHelp": "Her tarih ve öğün için tek menü.", |
| 2078 | 2078 | "meals.date": "Menü tarihi", |
| @@ -2135,6 +2135,32 @@ export const tr: Dict = { | ||
| 2135 | 2135 | "meals.editDish": "Yemeği düzenle", |
| 2136 | 2136 | "meals.dishName": "Yemek adı", |
| 2137 | 2137 | "meals.priceTry": "Fiyat (TRY)", |
| 2138 | + "meals.thisWeek": "Bu hafta", | |
| 2139 | + "meals.prevWeek": "Önceki hafta", | |
| 2140 | + "meals.nextWeek": "Sonraki hafta", | |
| 2141 | + "meals.goToDate": "Tarihe git", | |
| 2142 | + "meals.today": "Bugün", | |
| 2143 | + "meals.emptyWeek": "Bu hafta için yayınlanmış menü yok.", | |
| 2144 | + "meals.emptyWeekHint": "Başka bir haftaya geçin veya öğün filtresini kaldırın.", | |
| 2145 | + "meals.unlimited": "Sınırsız", | |
| 2146 | + "meals.dishCount": "{count} yemek", | |
| 2147 | + "meals.reservedOf": "{count} / {capacity}", | |
| 2148 | + "meals.studentRecordHelp": "Öğrenci seçin; beslenme profilini ve yemek hesabını yönetin.", | |
| 2149 | + "meals.selectStudentFirst": "Kaydı görmek için bir öğrenci seçin.", | |
| 2150 | + "meals.serviceHelp": "Rezervasyonlu öğrenciler ve kaydedilen servis.", | |
| 2151 | + "meals.addWalkIn": "Rezervasyonsuz ekle", | |
| 2152 | + "meals.walkInHelp": "Rezervasyonu olmadan gelen öğrenciyi servis edildi olarak kaydedin.", | |
| 2153 | + "meals.noService": "Henüz rezervasyon veya servis kaydı yok.", | |
| 2154 | + "meals.serviceStatus": "Servis", | |
| 2155 | + "meals.mark": "İşaretle", | |
| 2156 | + "meals.bookingState.booked": "Rezerve", | |
| 2157 | + "meals.bookingState.cancelled": "İptal edildi", | |
| 2158 | + "meals.kind": "Tür", | |
| 2159 | + "meals.detail": "Açıklama", | |
| 2160 | + "meals.when": "Tarih", | |
| 2161 | + "meals.amount": "Tutar", | |
| 2162 | + "meals.status": "Durum", | |
| 2163 | + "meals.noAttendance": "Yemek katılımı kaydı yok.", | |
| 2138 | 2164 | "nav.payments": "Ödeme ve tahsilat", |
| 2139 | 2165 | "nav.paymentStatement": "Ücretlerim", |
| 2140 | 2166 | "nav.whiteboards": "Tahtalar", |
src/i18n/messages.tsmodified+26 -0
| @@ -2028,6 +2028,32 @@ export type MessageKey = | ||
| 2028 | 2028 | | "meals.editDish" |
| 2029 | 2029 | | "meals.dishName" |
| 2030 | 2030 | | "meals.priceTry" |
| 2031 | + | "meals.thisWeek" | |
| 2032 | + | "meals.prevWeek" | |
| 2033 | + | "meals.nextWeek" | |
| 2034 | + | "meals.goToDate" | |
| 2035 | + | "meals.today" | |
| 2036 | + | "meals.emptyWeek" | |
| 2037 | + | "meals.emptyWeekHint" | |
| 2038 | + | "meals.unlimited" | |
| 2039 | + | "meals.dishCount" | |
| 2040 | + | "meals.reservedOf" | |
| 2041 | + | "meals.studentRecordHelp" | |
| 2042 | + | "meals.selectStudentFirst" | |
| 2043 | + | "meals.serviceHelp" | |
| 2044 | + | "meals.addWalkIn" | |
| 2045 | + | "meals.walkInHelp" | |
| 2046 | + | "meals.noService" | |
| 2047 | + | "meals.serviceStatus" | |
| 2048 | + | "meals.mark" | |
| 2049 | + | "meals.bookingState.booked" | |
| 2050 | + | "meals.bookingState.cancelled" | |
| 2051 | + | "meals.kind" | |
| 2052 | + | "meals.detail" | |
| 2053 | + | "meals.when" | |
| 2054 | + | "meals.amount" | |
| 2055 | + | "meals.status" | |
| 2056 | + | "meals.noAttendance" | |
| 2031 | 2057 | | "nav.payments" |
| 2032 | 2058 | | "nav.paymentStatement" |
| 2033 | 2059 | | "nav.whiteboards" |
src/lib/meals.test.tsmodified+39 -1
| @@ -1,8 +1,46 @@ | ||
| 1 | 1 | import { describe, expect, it, test } from "vitest"; |
| 2 | 2 | import type { SchoolSettings } from "@/api/client"; |
| 3 | -import { dirtySettingsPatch, formatTry, mealCutoffAt, minuteToUtcTime, nextCourseWork, utcTimeToMinute } from "./meals"; | |
| 3 | +import { | |
| 4 | + addDaysIso, | |
| 5 | + dirtySettingsPatch, | |
| 6 | + formatMealDay, | |
| 7 | + formatTry, | |
| 8 | + groupMenusByDay, | |
| 9 | + localIsoDate, | |
| 10 | + mealCutoffAt, | |
| 11 | + minuteToUtcTime, | |
| 12 | + nextCourseWork, | |
| 13 | + utcTimeToMinute, | |
| 14 | + weekStartIso, | |
| 15 | +} from "./meals"; | |
| 4 | 16 | |
| 5 | 17 | describe("meal helpers", () => { |
| 18 | + it("walks calendar weeks from Monday", () => { | |
| 19 | + expect(weekStartIso("2026-09-25")).toBe("2026-09-21"); | |
| 20 | + expect(weekStartIso("2026-09-21")).toBe("2026-09-21"); | |
| 21 | + expect(weekStartIso("2026-09-27")).toBe("2026-09-21"); | |
| 22 | + expect(addDaysIso("2026-09-28", 7)).toBe("2026-10-05"); | |
| 23 | + expect(addDaysIso("2026-03-01", -1)).toBe("2026-02-28"); | |
| 24 | + expect(localIsoDate(new Date(2026, 0, 5, 23, 30))).toBe("2026-01-05"); | |
| 25 | + }); | |
| 26 | + | |
| 27 | + it("groups menus per day in the school's slot order", () => { | |
| 28 | + const menus = [ | |
| 29 | + { date: "2026-10-21", slot: "lunch" }, | |
| 30 | + { date: "2026-10-20", slot: "snack" }, | |
| 31 | + { date: "2026-10-21", slot: "breakfast" }, | |
| 32 | + { date: "2026-10-20", slot: "custom" }, | |
| 33 | + ]; | |
| 34 | + expect(groupMenusByDay(menus, ["breakfast", "lunch", "snack"])).toEqual([ | |
| 35 | + { date: "2026-10-20", menus: [{ date: "2026-10-20", slot: "snack" }, { date: "2026-10-20", slot: "custom" }] }, | |
| 36 | + { date: "2026-10-21", menus: [{ date: "2026-10-21", slot: "breakfast" }, { date: "2026-10-21", slot: "lunch" }] }, | |
| 37 | + ]); | |
| 38 | + }); | |
| 39 | + | |
| 40 | + it("formats a menu date without shifting it", () => { | |
| 41 | + expect(formatMealDay("2026-10-21", "en-US")).toBe("Wednesday, October 21"); | |
| 42 | + }); | |
| 43 | + | |
| 6 | 44 | it("formats minor units as TRY", () => { |
| 7 | 45 | expect(formatTry(4550, "tr-TR")).toContain("45,50"); |
| 8 | 46 | }); |
src/lib/meals.tsmodified+73 -0
| @@ -33,6 +33,34 @@ export function dietaryTagLabel(tag: string, t: T): string { | ||
| 33 | 33 | return lookup(DIETARY_TAG_LABELS, tag, t); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | +const BOOKING_STATE_LABELS: Record<string, MessageKey> = { | |
| 37 | + booked: "meals.bookingState.booked", | |
| 38 | + cancelled: "meals.bookingState.cancelled", | |
| 39 | +}; | |
| 40 | + | |
| 41 | +const SERVICE_STATUS_LABELS: Record<string, MessageKey> = { | |
| 42 | + served: "meals.served", | |
| 43 | + missed: "meals.missed", | |
| 44 | +}; | |
| 45 | + | |
| 46 | +const LEDGER_KIND_LABELS: Record<string, MessageKey> = { | |
| 47 | + charge: "meals.ledger.charge", | |
| 48 | + credit: "meals.ledger.credit", | |
| 49 | + reversal: "meals.ledger.reversal", | |
| 50 | +}; | |
| 51 | + | |
| 52 | +export function mealBookingStateLabel(status: string, t: T): string { | |
| 53 | + return lookup(BOOKING_STATE_LABELS, status, t); | |
| 54 | +} | |
| 55 | + | |
| 56 | +export function mealServiceStatusLabel(status: string, t: T): string { | |
| 57 | + return lookup(SERVICE_STATUS_LABELS, status, t); | |
| 58 | +} | |
| 59 | + | |
| 60 | +export function mealLedgerKindLabel(kind: string, t: T): string { | |
| 61 | + return lookup(LEDGER_KIND_LABELS, kind, t); | |
| 62 | +} | |
| 63 | + | |
| 36 | 64 | export function formatTry(minor: number, locale: string): string { |
| 37 | 65 | return new Intl.NumberFormat(locale, { style: "currency", currency: "TRY" }).format(minor / 100); |
| 38 | 66 | } |
| @@ -47,6 +75,51 @@ export function utcTimeToMinute(value: string): number | null { | ||
| 47 | 75 | return match ? Number(match[1]) * 60 + Number(match[2]) : null; |
| 48 | 76 | } |
| 49 | 77 | |
| 78 | +const DAY_MS = 86_400_000; | |
| 79 | +const isoToUtcMs = (iso: string) => Date.parse(`${iso}T00:00:00Z`); | |
| 80 | +const utcMsToIso = (ms: number) => new Date(ms).toISOString().slice(0, 10); | |
| 81 | + | |
| 82 | +/** The viewer's own calendar day as yyyy-mm-dd (menus are plain calendar dates). */ | |
| 83 | +export function localIsoDate(now: Date = new Date()): string { | |
| 84 | + const pad = (value: number) => String(value).padStart(2, "0"); | |
| 85 | + return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`; | |
| 86 | +} | |
| 87 | + | |
| 88 | +export function addDaysIso(iso: string, days: number): string { | |
| 89 | + return utcMsToIso(isoToUtcMs(iso) + days * DAY_MS); | |
| 90 | +} | |
| 91 | + | |
| 92 | +/** Monday of the week holding `iso`. */ | |
| 93 | +export function weekStartIso(iso: string): string { | |
| 94 | + const weekday = new Date(isoToUtcMs(iso)).getUTCDay(); | |
| 95 | + return addDaysIso(iso, -((weekday + 6) % 7)); | |
| 96 | +} | |
| 97 | + | |
| 98 | +/** Menus grouped per date (ascending), each day's slots in the school's slot order. */ | |
| 99 | +export function groupMenusByDay<M extends { date: string; slot: string }>(menus: M[], slotOrder: string[]): { date: string; menus: M[] }[] { | |
| 100 | + const rank = (slot: string) => { | |
| 101 | + const index = slotOrder.indexOf(slot); | |
| 102 | + return index === -1 ? slotOrder.length : index; | |
| 103 | + }; | |
| 104 | + const days = new Map<string, M[]>(); | |
| 105 | + for (const menu of menus) days.set(menu.date, [...(days.get(menu.date) ?? []), menu]); | |
| 106 | + return [...days.entries()] | |
| 107 | + .sort(([a], [b]) => a.localeCompare(b)) | |
| 108 | + .map(([date, items]) => ({ date, menus: [...items].sort((a, b) => rank(a.slot) - rank(b.slot) || a.slot.localeCompare(b.slot)) })); | |
| 109 | +} | |
| 110 | + | |
| 111 | +/** "Çarşamba, 21 Ekim" — a menu's calendar date, never shifted by the viewer's zone. */ | |
| 112 | +export function formatMealDay(iso: string, locale: string, withYear = false): string { | |
| 113 | + return new Intl.DateTimeFormat(locale, { weekday: "long", day: "numeric", month: "long", ...(withYear ? { year: "numeric" } : {}), timeZone: "UTC" }) | |
| 114 | + .format(new Date(isoToUtcMs(iso))); | |
| 115 | +} | |
| 116 | + | |
| 117 | +/** "22 – 28 Eylül 2026" for the Monday-to-Sunday week starting at `startIso`. */ | |
| 118 | +export function formatMealWeek(startIso: string, locale: string): string { | |
| 119 | + return new Intl.DateTimeFormat(locale, { day: "numeric", month: "long", year: "numeric", timeZone: "UTC" }) | |
| 120 | + .formatRange(new Date(isoToUtcMs(startIso)), new Date(isoToUtcMs(addDaysIso(startIso, 6)))); | |
| 121 | +} | |
| 122 | + | |
| 50 | 123 | export function mealCutoffAt(date: string, slot: MealSlot | undefined, minutes: number | null): number | null { |
| 51 | 124 | if (minutes == null) return null; |
| 52 | 125 | const servingMinute = slot?.serving_minute ?? 0; |
src/pages/meal-detail-page.tsxmodified+279 -164
| @@ -1,4 +1,4 @@ | ||
| 1 | -import { For, Show, Suspense, createEffect, createMemo, createSignal } from "solid-js"; | |
| 1 | +import { Show, Suspense, createEffect, createMemo, createSignal } from "solid-js"; | |
| 2 | 2 | import { createResource } from "@/lib/create-resource"; |
| 3 | 3 | import { useLocation, useNavigate, useParams } from "@tanstack/solid-router"; |
| 4 | 4 | import { getLimits } from "@/api/limits"; |
| @@ -23,11 +23,24 @@ import { | ||
| 23 | 23 | postMealBooking, |
| 24 | 24 | postMealCredit, |
| 25 | 25 | postMealDish, |
| 26 | + type MealDishBody, | |
| 26 | 27 | } from "@/api/meals"; |
| 27 | 28 | import { getMyStudents } from "@/api/parents"; |
| 28 | 29 | import { getSettings } from "@/api/settings"; |
| 29 | 30 | import { getTime } from "@/api/time"; |
| 30 | -import { formatApiError, type MealAttendance, type MealBooking, type MealDish, type PersonRef } from "@/api/client"; | |
| 31 | +import { formatApiError, type MealBooking, type MealDish } from "@/api/client"; | |
| 32 | +import { MealAccountCard } from "@/components/meals/meal-account-card"; | |
| 33 | +import { MealAttendanceTable } from "@/components/meals/meal-attendance-table"; | |
| 34 | +import { MealBookingCard } from "@/components/meals/meal-booking-card"; | |
| 35 | +import { MealDishList } from "@/components/meals/meal-dish-list"; | |
| 36 | +import { MealDishPanel } from "@/components/meals/meal-dish-panel"; | |
| 37 | +import { MealFact } from "@/components/meals/meal-fact"; | |
| 38 | +import { MealLedgerTable } from "@/components/meals/meal-ledger-table"; | |
| 39 | +import { MealMenuEditPanel } from "@/components/meals/meal-menu-edit-panel"; | |
| 40 | +import { MealServiceTable } from "@/components/meals/meal-service-table"; | |
| 41 | +import type { MealServiceEntry } from "@/components/meals/meal-service-table.types"; | |
| 42 | +import { MealStudentRecordPanel, type MealCreditInput } from "@/components/meals/meal-student-record-panel"; | |
| 43 | +import { MealWalkInPanel } from "@/components/meals/meal-walk-in-panel"; | |
| 31 | 44 | import { PageHeader } from "@/components/layout/page-header"; |
| 32 | 45 | import { Breadcrumbs } from "@/components/layout/breadcrumbs"; |
| 33 | 46 | import { RouteGuard } from "@/components/layout/route-guard"; |
| @@ -35,24 +48,16 @@ import { Alert } from "@/components/ui/alert"; | ||
| 35 | 48 | import { Badge } from "@/components/ui/badge"; |
| 36 | 49 | import { Button } from "@/components/ui/button"; |
| 37 | 50 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; |
| 38 | -import { EmptyState } from "@/components/ui/empty-state"; | |
| 39 | 51 | import { ErrorAlert } from "@/components/ui/error-alert"; |
| 40 | -import { IconAlert, IconEdit, IconPlus, IconTrash } from "@/components/ui/icons"; | |
| 41 | -import { Input } from "@/components/ui/input"; | |
| 42 | -import { Label } from "@/components/ui/label"; | |
| 52 | +import { IconEdit, IconTrash, IconUsers } from "@/components/ui/icons"; | |
| 43 | 53 | import { PageSpinner } from "@/components/ui/page-spinner"; |
| 44 | -import { SearchableSelect } from "@/components/ui/searchable-select"; | |
| 45 | -import { SidePanel } from "@/components/ui/side-panel"; | |
| 46 | -import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; | |
| 47 | -import { Textarea } from "@/components/ui/textarea"; | |
| 48 | -import { UserSearchSelect } from "@/components/users/user-search-select"; | |
| 54 | +import { TableRowActions } from "@/components/ui/table-row-actions"; | |
| 49 | 55 | import { formatDateTime } from "@/lib/format"; |
| 50 | -import { dietaryTagLabel, formatTry, mealCutoffAt, mealSlotLabel } from "@/lib/meals"; | |
| 56 | +import { formatMealDay, formatTry, mealCutoffAt, mealSlotLabel } from "@/lib/meals"; | |
| 51 | 57 | import { personLabel } from "@/lib/person"; |
| 52 | 58 | import { hasMinRole } from "@/lib/roles"; |
| 53 | 59 | import { useAuth } from "@/stores/auth-context"; |
| 54 | 60 | import { usePreferences, useT } from "@/stores/preferences-context"; |
| 55 | -import { TableRowActions } from "@/components/ui/table-row-actions"; | |
| 56 | 61 | |
| 57 | 62 | export default function MealDetailPage() { |
| 58 | 63 | return <RouteGuard><MealDetailContent /></RouteGuard>; |
| @@ -75,16 +80,15 @@ function MealDetailContent() { | ||
| 75 | 80 | // student, or manager+. Teachers are no longer allowed (backend 403s). |
| 76 | 81 | const canReadMoney = () => isStudent() || isParent() || canManage(); |
| 77 | 82 | const isAdmin = () => role() === "admin"; |
| 78 | - const moneyLocale = () => locale() === "tr" ? "tr-TR" : "en-US"; | |
| 83 | + const moneyLocale = () => (locale() === "tr" ? "tr-TR" : "en-US"); | |
| 79 | 84 | |
| 80 | 85 | const [menu, { refetch: refetchMenu }] = createResource(id, (menuId) => getMealMenuById(menuId)); |
| 81 | 86 | const [settings] = createResource(() => getSettings()); |
| 82 | 87 | const [limits, { refetch: refetchLimits }] = createResource(() => getLimits()); |
| 83 | 88 | const [serverTime] = createResource(() => getTime().catch(() => ({ now: Date.now() }))); |
| 84 | - const [children] = createResource(() => isParent() ? getMyStudents({ limit: 100 }) : null); | |
| 89 | + const [children] = createResource(() => (isParent() ? getMyStudents({ limit: 100 }) : null)); | |
| 85 | 90 | const [selectedStudent, setSelectedStudent] = createSignal(""); |
| 86 | 91 | const [lookupStudent, setLookupStudent] = createSignal(""); |
| 87 | - const [tab, setTab] = createSignal("menu"); | |
| 88 | 92 | const [error, setError] = createSignal(""); |
| 89 | 93 | const [success, setSuccess] = createSignal(""); |
| 90 | 94 | const [pending, setPending] = createSignal(false); |
| @@ -94,6 +98,11 @@ function MealDetailContent() { | ||
| 94 | 98 | const [cancelBooking, setCancelBooking] = createSignal<MealBooking | null>(null); |
| 95 | 99 | const [deleteMenuOpen, setDeleteMenuOpen] = createSignal(false); |
| 96 | 100 | const [deleteDish, setDeleteDish] = createSignal<MealDish | null>(null); |
| 101 | + const [showMenuEdit, setShowMenuEdit] = createSignal(false); | |
| 102 | + const [showDishForm, setShowDishForm] = createSignal(false); | |
| 103 | + const [editingDish, setEditingDish] = createSignal<MealDish | null>(null); | |
| 104 | + const [showWalkIn, setShowWalkIn] = createSignal(false); | |
| 105 | + const [showRecord, setShowRecord] = createSignal(false); | |
| 97 | 106 | |
| 98 | 107 | createEffect(() => { |
| 99 | 108 | if (isParent() && !selectedStudent() && children()?.items[0]) setSelectedStudent(children()!.items[0].id); |
| @@ -103,36 +112,33 @@ function MealDetailContent() { | ||
| 103 | 112 | const targetId = () => (isStudent() ? auth.user()!.id : isParent() ? selectedStudent() : lookupStudent()) || null; |
| 104 | 113 | const canBook = () => (isStudent() || isParent()) && !!targetId(); |
| 105 | 114 | |
| 106 | - const [bookings, { refetch: refetchBookings }] = createResource(() => canBook(), async (enabled) => enabled ? getMyMealBookings({ limit: 100 }) : null); | |
| 115 | + const [bookings, { refetch: refetchBookings }] = createResource(() => canBook(), async (enabled) => (enabled ? getMyMealBookings({ limit: 100 }) : null)); | |
| 107 | 116 | const activeBooking = createMemo(() => bookings()?.items.find((booking) => booking.menu_id === id() && booking.student.id === targetId() && booking.status === "booked") ?? null); |
| 108 | 117 | const [profile, { refetch: refetchProfile }] = createResource( |
| 109 | 118 | targetId, |
| 110 | - async (userId) => userId === auth.user()!.id ? getMyDietaryProfile() : getDietaryProfileByUserId(userId), | |
| 119 | + async (userId) => (userId === auth.user()!.id ? getMyDietaryProfile() : getDietaryProfileByUserId(userId)), | |
| 111 | 120 | ); |
| 112 | 121 | const [balance, { refetch: refetchBalance }] = createResource( |
| 113 | - () => canReadMoney() ? targetId() : null, | |
| 114 | - async (userId) => userId === auth.user()!.id ? getMyMealBalance() : getMealBalanceByUserId(userId), | |
| 122 | + () => (canReadMoney() ? targetId() : null), | |
| 123 | + async (userId) => (userId === auth.user()!.id ? getMyMealBalance() : getMealBalanceByUserId(userId)), | |
| 115 | 124 | ); |
| 116 | - const [ledger, { refetch: refetchLedger }] = createResource(() => canReadMoney() ? targetId() : null, (userId) => getMealLedgerByUserId(userId, { limit: 20 })); | |
| 125 | + const [ledger, { refetch: refetchLedger }] = createResource(() => (canReadMoney() ? targetId() : null), (userId) => getMealLedgerByUserId(userId, { limit: 20 })); | |
| 117 | 126 | const [attendance] = createResource(targetId, (userId) => getMealAttendanceByUserId(userId, { limit: 20 })); |
| 118 | 127 | // The backend does not expose a teacher-visible service-roster endpoint. |
| 119 | 128 | // Teachers can still see and amend recorded service; managers additionally |
| 120 | - // receive the supported booking audit and get the combined operational list. | |
| 129 | + // receive the booking audit (every booking with its status), merged into | |
| 130 | + // the same service list. | |
| 121 | 131 | const [serviceAttendance, { refetch: refetchServiceAttendance }] = createResource( |
| 122 | - () => canServe() ? id() : null, | |
| 132 | + () => (canServe() ? id() : null), | |
| 123 | 133 | (menuId) => getMealMenuAttendance(menuId, { limit: 100 }), |
| 124 | 134 | ); |
| 125 | 135 | const [serviceBookings, { refetch: refetchServiceBookings }] = createResource( |
| 126 | - () => canManage() ? id() : null, | |
| 127 | - (menuId) => getMealMenuBookings(menuId, { limit: 100 }), | |
| 128 | - ); | |
| 129 | - const [audit] = createResource( | |
| 130 | - () => canManage() ? id() : null, | |
| 136 | + () => (canManage() ? id() : null), | |
| 131 | 137 | (menuId) => getMealMenuBookings(menuId, { limit: 100 }), |
| 132 | 138 | ); |
| 133 | 139 | |
| 134 | 140 | const serviceEntries = createMemo(() => { |
| 135 | - const entries = new Map<string, { student: PersonRef; booking: MealBooking | null; attendance: MealAttendance | null }>(); | |
| 141 | + const entries = new Map<string, MealServiceEntry>(); | |
| 136 | 142 | for (const booking of serviceBookings()?.items ?? []) entries.set(booking.student.id, { student: booking.student, booking, attendance: null }); |
| 137 | 143 | for (const attendanceRow of serviceAttendance()?.items ?? []) { |
| 138 | 144 | const existing = entries.get(attendanceRow.student.id); |
| @@ -141,165 +147,274 @@ function MealDetailContent() { | ||
| 141 | 147 | return [...entries.values()]; |
| 142 | 148 | }); |
| 143 | 149 | const refetchService = () => Promise.all([refetchServiceAttendance(), refetchServiceBookings()]); |
| 150 | + // Confirmed bookings, only when the audit page holds every booking (a | |
| 151 | + // truncated page would undercount). | |
| 152 | + const bookedCount = () => { | |
| 153 | + const page = serviceBookings(); | |
| 154 | + if (!page || page.items.length < page.total) return null; | |
| 155 | + return page.items.filter((booking) => booking.status === "booked").length; | |
| 156 | + }; | |
| 144 | 157 | |
| 145 | 158 | const total = () => menu()?.dishes.reduce((sum, dish) => sum + dish.price_minor, 0) ?? 0; |
| 146 | - const conflicts = () => [...new Set(menu()?.dishes.flatMap((dish) => dish.conflicts) ?? [])]; | |
| 147 | 159 | const slot = () => settings()?.meal_slots.find((item) => item.name === menu()?.slot); |
| 148 | - const cutoff = () => menu() ? mealCutoffAt(menu()!.date, slot(), settings()?.meal_cancel_cutoff_minutes ?? null) : null; | |
| 160 | + const cutoff = () => (menu() ? mealCutoffAt(menu()!.date, slot(), settings()?.meal_cancel_cutoff_minutes ?? null) : null); | |
| 149 | 161 | const cutoffClosed = () => cutoff() != null && (serverTime()?.now ?? Date.now()) >= cutoff()!; |
| 162 | + const capacityLabel = () => (menu()?.capacity == null ? t("meals.unlimited") : String(menu()!.capacity)); | |
| 150 | 163 | |
| 151 | - const [capacity, setCapacity] = createSignal(""); | |
| 152 | - const [showMenuEdit, setShowMenuEdit] = createSignal(false); | |
| 153 | - const [showDishForm, setShowDishForm] = createSignal(false); | |
| 154 | - const [editingDish, setEditingDish] = createSignal<MealDish | null>(null); | |
| 155 | - const [dishName, setDishName] = createSignal(""); | |
| 156 | - const [dishDescription, setDishDescription] = createSignal(""); | |
| 157 | - const [dishPrice, setDishPrice] = createSignal(""); | |
| 158 | - const [dishTags, setDishTags] = createSignal<string[]>([]); | |
| 159 | - const [profileTags, setProfileTags] = createSignal<string[]>([]); | |
| 160 | - const [profileNote, setProfileNote] = createSignal(""); | |
| 161 | - const [creditAmount, setCreditAmount] = createSignal(""); | |
| 162 | - const [creditMethod, setCreditMethod] = createSignal(""); | |
| 163 | - const [creditNote, setCreditNote] = createSignal(""); | |
| 164 | - const [walkIn, setWalkIn] = createSignal(""); | |
| 165 | - | |
| 166 | - createEffect(() => { | |
| 167 | - if (profile()) { setProfileTags([...profile()!.tags]); setProfileNote(profile()!.note ?? ""); } | |
| 168 | - }); | |
| 169 | - const run = async (work: () => Promise<void>, message = t("common.saved")) => { | |
| 164 | + const run = async (work: () => Promise<void>, message = t("common.saved")): Promise<boolean> => { | |
| 170 | 165 | setPending(true); setError(""); setSuccess(""); |
| 171 | - try { await work(); setSuccess(message); } | |
| 172 | - catch (err) { setError(formatApiError(err)); } | |
| 166 | + try { await work(); setSuccess(message); return true; } | |
| 167 | + catch (err) { setError(formatApiError(err)); return false; } | |
| 173 | 168 | finally { setPending(false); } |
| 174 | 169 | }; |
| 170 | + const confirmRun = async (work: () => Promise<void>, message?: string) => { await run(work, message); }; | |
| 175 | 171 | const openDish = (dish?: MealDish) => { |
| 172 | + setError(""); | |
| 176 | 173 | setEditingDish(dish ?? null); |
| 177 | - setDishName(dish?.name ?? ""); setDishDescription(dish?.description ?? ""); | |
| 178 | - setDishPrice(dish ? String(dish.price_minor / 100) : ""); setDishTags(dish?.tags ?? []); | |
| 179 | 174 | setShowDishForm(true); |
| 180 | 175 | }; |
| 181 | - const toggleTag = (tag: string, selected: string[], set: (value: string[]) => void) => | |
| 182 | - set(selected.includes(tag) ? selected.filter((item) => item !== tag) : [...selected, tag]); | |
| 176 | + const refreshAccount = () => Promise.all([refetchBookings(), refetchBalance(), refetchLedger()]); | |
| 177 | + const book = () => run(async () => { | |
| 178 | + await postMealBooking(id(), isParent() ? targetId() ?? undefined : undefined); | |
| 179 | + await refreshAccount(); | |
| 180 | + }, t("meals.booked")); | |
| 181 | + const mark = (studentId: string, status: "served" | "missed") => run(async () => { | |
| 182 | + await postMealAttendance(id(), studentId, status); | |
| 183 | + await refetchService(); | |
| 184 | + }); | |
| 185 | + const saveDish = (body: MealDishBody) => run(async () => { | |
| 186 | + const dish = editingDish(); | |
| 187 | + if (dish) await patchMealDishById(dish.id, body); | |
| 188 | + else await postMealDish(id(), body); | |
| 189 | + await refetchMenu(); | |
| 190 | + }); | |
| 191 | + const saveProfile = (tags: string[], note: string | null) => run(async () => { | |
| 192 | + await patchDietaryProfileByUserId(lookupStudent(), { tags, note }); | |
| 193 | + await refetchProfile(); | |
| 194 | + }); | |
| 195 | + const recordCredit = (input: MealCreditInput) => run(async () => { | |
| 196 | + await postMealCredit({ student_id: lookupStudent(), amount_minor: input.amountMinor, method: input.method, note: input.note }); | |
| 197 | + await Promise.all([refetchBalance(), refetchLedger()]); | |
| 198 | + }, t("meals.creditRecorded")); | |
| 183 | 199 | |
| 184 | 200 | return ( |
| 185 | 201 | <Suspense fallback={<PageSpinner />}> |
| 186 | - <Show when={menu()?.id === id() ? menu() : undefined} fallback={<Show when={menu.error} fallback={<PageSpinner />}><ErrorAlert message={formatApiError(menu.error)} onRetry={() => void refetchMenu()} /></Show>}> | |
| 187 | - {(current) => ( | |
| 188 | - <div class="space-y-5"> | |
| 189 | - <div class="space-y-2"> | |
| 190 | - <Breadcrumbs items={[{ label: t("meals.title"), to: "/meals" }, { label: `${current().date} · ${mealSlotLabel(current().slot, t)}` }]} /> | |
| 191 | - <PageHeader | |
| 192 | - title={t("meals.menu")} | |
| 193 | - description={t("meals.detailHelp")} | |
| 194 | - actions={canManage() ? <div class="detail-action-group"><Button variant="outline" size="sm" onClick={() => { setCapacity(current().capacity == null ? "" : String(current().capacity)); setShowMenuEdit(true); }}><IconEdit class="h-4 w-4" />{t("common.edit")}</Button><TableRowActions label={t("common.actions")} actions={[{ label: t("common.delete"), icon: <IconTrash class="h-4 w-4" />, destructive: true, onSelect: () => setDeleteMenuOpen(true) }]} /></div> : undefined} | |
| 195 | - /> | |
| 196 | - </div> | |
| 197 | - <Show when={limits.error}><ErrorAlert message={formatApiError(limits.error)} onRetry={() => void refetchLimits()} /></Show> | |
| 198 | - <Show when={error()}><Alert variant="destructive">{error()}</Alert></Show> | |
| 199 | - <Show when={success()}><Alert variant="success">{success()}</Alert></Show> | |
| 200 | - | |
| 201 | - <div class="grid gap-3 sm:grid-cols-2 lg:grid-cols-4"> | |
| 202 | - <div class="detail-metric-card"><p class="text-xs uppercase text-muted-foreground">{t("meals.total")}</p><p class="mt-1 font-semibold">{formatTry(total(), moneyLocale())}</p></div> | |
| 203 | - <div class="detail-metric-card"><p class="text-xs uppercase text-muted-foreground">{t("meals.capacity")}</p><p class="mt-1 font-semibold">{current().capacity ?? "∞"}</p></div> | |
| 204 | - <div class="detail-metric-card"><p class="text-xs uppercase text-muted-foreground">{t("meals.cutoff")}</p><p class="mt-1 font-semibold">{cutoff() == null ? t("meals.noCutoff") : formatDateTime(cutoff(), locale())}</p></div> | |
| 205 | - <div class="detail-metric-card"><p class="text-xs uppercase text-muted-foreground">{t("meals.bookingStatus")}</p><p class="mt-1 font-semibold">{cutoffClosed() ? t("meals.closed") : t("meals.open")}</p></div> | |
| 206 | - </div> | |
| 207 | - | |
| 208 | - <Show when={conflicts().length > 0}> | |
| 209 | - <Alert class="border-warning/50 bg-warning/10 text-warning-text"><span class="flex gap-2"><IconAlert class="mt-0.5 h-4 w-4 shrink-0" /><span>{t("meals.conflict")}: {conflicts().join(", ")}</span></span></Alert> | |
| 210 | - </Show> | |
| 211 | - | |
| 212 | - <Show when={isParent()}> | |
| 213 | - <div class="data-shell max-w-md p-4"><Label for="meal-child">{t("meals.child")}</Label><SearchableSelect id="meal-child" value={selectedStudent()} onChange={setSelectedStudent} options={(children()?.items ?? []).map((child) => ({ value: child.id, label: personLabel(child) }))} /></div> | |
| 214 | - </Show> | |
| 202 | + <Show | |
| 203 | + when={menu()?.id === id() ? menu() : undefined} | |
| 204 | + fallback={<Show when={menu.error} fallback={<PageSpinner />}><ErrorAlert message={formatApiError(menu.error)} onRetry={() => void refetchMenu()} /></Show>} | |
| 205 | + > | |
| 206 | + {(current) => { | |
| 207 | + const heading = () => `${formatMealDay(current().date, moneyLocale())} · ${mealSlotLabel(current().slot, t)}`; | |
| 208 | + return ( | |
| 209 | + <div class="space-y-5"> | |
| 210 | + <section class="rounded-xl border border-border-line bg-surface-base px-4 py-3 shadow-xs sm:px-5"> | |
| 211 | + <Breadcrumbs items={[{ label: t("meals.title"), to: "/meals" }, { label: heading() }]} /> | |
| 212 | + <PageHeader | |
| 213 | + title={mealSlotLabel(current().slot, t)} | |
| 214 | + description={formatMealDay(current().date, moneyLocale(), true)} | |
| 215 | + actions={ | |
| 216 | + canManage() ? ( | |
| 217 | + <div class="detail-action-group"> | |
| 218 | + <Button variant="outline" size="sm" class="flex-1 rounded-lg sm:flex-none" onClick={() => { setError(""); setShowRecord(true); }}> | |
| 219 | + <IconUsers class="h-4 w-4" /> | |
| 220 | + {t("meals.studentRecord")} | |
| 221 | + </Button> | |
| 222 | + <Button variant="outline" size="sm" class="flex-1 rounded-lg sm:flex-none" onClick={() => { setError(""); setShowMenuEdit(true); }}> | |
| 223 | + <IconEdit class="h-4 w-4" /> | |
| 224 | + {t("common.edit")} | |
| 225 | + </Button> | |
| 226 | + <TableRowActions | |
| 227 | + label={t("common.actions")} | |
| 228 | + actions={[{ label: t("meals.deleteMenu"), icon: <IconTrash class="h-4 w-4" />, destructive: true, onSelect: () => setDeleteMenuOpen(true) }]} | |
| 229 | + /> | |
| 230 | + </div> | |
| 231 | + ) : undefined | |
| 232 | + } | |
| 233 | + /> | |
| 234 | + <dl class="mt-1 grid grid-cols-2 gap-x-6 gap-y-3 border-t border-border-hairline pt-3 sm:flex sm:flex-wrap sm:gap-x-10"> | |
| 235 | + <MealFact label={t("meals.total")}>{formatTry(total(), moneyLocale())}</MealFact> | |
| 236 | + <MealFact label={bookedCount() != null ? `${t("meals.reservations")} / ${t("meals.capacity")}` : t("meals.capacity")}> | |
| 237 | + <Show when={bookedCount() != null} fallback={capacityLabel()}> | |
| 238 | + {t("meals.reservedOf", { count: bookedCount()!, capacity: capacityLabel() })} | |
| 239 | + </Show> | |
| 240 | + </MealFact> | |
| 241 | + <MealFact label={t("meals.cutoff")}>{cutoff() == null ? t("meals.noCutoff") : formatDateTime(cutoff(), locale())}</MealFact> | |
| 242 | + <MealFact label={t("meals.bookingStatus")}> | |
| 243 | + <Badge variant={cutoffClosed() ? "secondary" : "success"}>{cutoffClosed() ? t("meals.closed") : t("meals.open")}</Badge> | |
| 244 | + </MealFact> | |
| 245 | + </dl> | |
| 246 | + </section> | |
| 215 | 247 | |
| 216 | - <Tabs value={tab()} onChange={setTab}> | |
| 217 | - <TabsList> | |
| 218 | - <TabsTrigger value="menu">{t("meals.menu")}</TabsTrigger> | |
| 219 | - <Show when={canBook()}><TabsTrigger value="account">{t("meals.myAccount")}</TabsTrigger></Show> | |
| 220 | - <Show when={canServe()}><TabsTrigger value="service">{t("meals.service")}</TabsTrigger></Show> | |
| 221 | - <Show when={canManage()}><TabsTrigger value="manage">{t("meals.manage")}</TabsTrigger></Show> | |
| 222 | - </TabsList> | |
| 248 | + <Show when={limits.error}><ErrorAlert message={formatApiError(limits.error)} onRetry={() => void refetchLimits()} /></Show> | |
| 249 | + <Show when={error()}><Alert variant="destructive">{error()}</Alert></Show> | |
| 250 | + <Show when={success()}><Alert variant="success">{success()}</Alert></Show> | |
| 223 | 251 | |
| 224 | - <TabsContent value="menu" class="space-y-4"> | |
| 225 | - <div class="grid gap-3 sm:grid-cols-2 lg:grid-cols-3"> | |
| 226 | - <For each={current().dishes}>{(dish) => ( | |
| 227 | - <article class="rounded-xl border border-border-line bg-surface-base p-4"> | |
| 228 | - <div class="flex justify-between gap-3"><h2 class="font-semibold text-text-strong">{dish.name}</h2><span class="font-semibold">{formatTry(dish.price_minor, moneyLocale())}</span></div> | |
| 229 | - <p class="mt-2 text-sm text-text-subtle">{dish.description || "—"}</p> | |
| 230 | - <div class="mt-3 flex flex-wrap gap-1"><For each={dish.tags}>{(tag) => <Badge variant="outline" class={dish.conflicts.includes(tag) ? "border-warning/50 bg-warning/10 text-warning-text" : ""}>{dish.conflicts.includes(tag) ? `⚠ ${dietaryTagLabel(tag, t)}` : dietaryTagLabel(tag, t)}</Badge>}</For></div> | |
| 231 | - <Show when={canManage()}><div class="mt-3 flex gap-2 border-t border-border-hairline pt-3"><Button variant="outline" size="sm" onClick={() => openDish(dish)}>{t("common.edit")}</Button><Button variant="ghost" size="sm" class="text-destructive-text" onClick={() => setDeleteDish(dish)}>{t("common.delete")}</Button></div></Show> | |
| 232 | - </article> | |
| 233 | - )}</For> | |
| 234 | - </div> | |
| 235 | - <Show when={current().dishes.length === 0}><EmptyState kind="meals" title={t("meals.noDishes")} /></Show> | |
| 236 | - <Show when={canBook()}> | |
| 237 | - <div class="data-shell flex flex-wrap items-center justify-between gap-3 p-4"> | |
| 238 | - <div><p class="font-semibold">{activeBooking() ? t("meals.booked") : t("meals.notBooked")}</p><p class="text-sm text-muted-foreground">{cutoffClosed() ? t("meals.cutoffPassed") : t("meals.bookingHelp")}</p></div> | |
| 239 | - <Show when={activeBooking()} fallback={<Button disabled={pending() || cutoffClosed()} onClick={() => void run(async () => { await postMealBooking(id(), isParent() ? targetId() ?? undefined : undefined); await Promise.all([refetchBookings(), refetchBalance(), refetchLedger()]); }, t("meals.booked"))}>{t("meals.book")}</Button>}><Button variant="destructive" disabled={pending() || cutoffClosed()} onClick={() => setCancelOpen(true)}>{t("meals.cancelBooking")}</Button></Show> | |
| 240 | - </div> | |
| 252 | + <div class={isStudent() || isParent() ? "grid gap-5 lg:grid-cols-[minmax(0,1fr)_20rem] lg:items-start" : undefined}> | |
| 253 | + <MealDishList | |
| 254 | + dishes={current().dishes} | |
| 255 | + moneyLocale={moneyLocale()} | |
| 256 | + canManage={canManage()} | |
| 257 | + onAdd={() => openDish()} | |
| 258 | + onEdit={openDish} | |
| 259 | + onDelete={setDeleteDish} | |
| 260 | + /> | |
| 261 | + <Show when={isStudent() || isParent()}> | |
| 262 | + <aside class="space-y-5"> | |
| 263 | + <MealBookingCard | |
| 264 | + isParent={isParent()} | |
| 265 | + children={children()?.items ?? []} | |
| 266 | + selectedChild={selectedStudent()} | |
| 267 | + onSelectChild={setSelectedStudent} | |
| 268 | + canBook={canBook()} | |
| 269 | + booked={!!activeBooking()} | |
| 270 | + cutoffClosed={cutoffClosed()} | |
| 271 | + pending={pending()} | |
| 272 | + onBook={() => void book()} | |
| 273 | + onCancel={() => setCancelOpen(true)} | |
| 274 | + /> | |
| 275 | + <Show when={canBook()}> | |
| 276 | + <MealAccountCard | |
| 277 | + showBalance={canReadMoney()} | |
| 278 | + balanceMinor={balance()?.balance_minor} | |
| 279 | + profile={profile()} | |
| 280 | + moneyLocale={moneyLocale()} | |
| 281 | + /> | |
| 282 | + </Show> | |
| 283 | + </aside> | |
| 241 | 284 | </Show> |
| 242 | - </TabsContent> | |
| 243 | - | |
| 244 | - <TabsContent value="account" class="space-y-4"> | |
| 245 | - <div class="grid gap-4 lg:grid-cols-2"> | |
| 246 | - <section class="data-shell p-4"><h2 class="font-semibold text-text-strong">{t("meals.dietaryProfile")}</h2><div class="mt-3 flex flex-wrap gap-1.5"><For each={profile()?.tags ?? []}>{(tag) => <Badge variant="outline" class="border-warning/50 bg-warning/10 text-warning-text">⚠ {dietaryTagLabel(tag, t)}</Badge>}</For></div><p class="mt-3 text-sm text-text-subtle">{profile()?.note || t("meals.noDietaryNotes")}</p></section> | |
| 247 | - <Show when={canReadMoney()}><section class="data-shell p-4"><h2 class="font-semibold text-text-strong">{t("meals.balance")}</h2><p class="mt-3 text-2xl font-semibold tabular-nums">{formatTry(balance()?.balance_minor ?? 0, moneyLocale())}</p></section></Show> | |
| 248 | - </div> | |
| 249 | - <Show when={canReadMoney()}><section class="data-shell p-4"><h2 class="font-semibold text-text-strong">{t("meals.ledger")}</h2><div class="mt-3 divide-y divide-border-hairline"><For each={ledger()?.items ?? []}>{(line) => <div class="flex justify-between gap-3 py-3 text-sm"><div><p class="font-medium">{t(`meals.ledger.${line.kind}` as never)}</p><p class="text-xs text-text-subtle">{line.note || line.method || "—"} · {formatDateTime(line.created_at, locale())}</p></div><span class="font-semibold tabular-nums">{line.kind === "charge" ? "−" : "+"}{formatTry(line.amount_minor, moneyLocale())}</span></div>}</For></div><Show when={(ledger()?.items.length ?? 0) === 0}><p class="mt-3 text-sm text-text-subtle">{t("meals.noLedger")}</p></Show></section></Show> | |
| 250 | - <section class="data-shell p-4"><h2 class="font-semibold text-text-strong">{t("meals.attendance")}</h2><div class="mt-3 divide-y divide-border-hairline"><For each={attendance()?.items ?? []}>{(row) => <div class="flex justify-between gap-3 py-3 text-sm"><span>{row.status}</span><span class="text-text-subtle">{formatDateTime(row.marked_at, locale())}</span></div>}</For></div></section> | |
| 251 | - </TabsContent> | |
| 285 | + </div> | |
| 252 | 286 | |
| 253 | - <TabsContent value="service" class="space-y-4"> | |
| 254 | - <div class="data-shell p-4"> | |
| 255 | - <h2 class="font-semibold text-text-strong">{t("meals.walkIn")}</h2> | |
| 256 | - <div class="mt-3 flex flex-col gap-2 sm:flex-row sm:items-end"><div class="min-w-0 flex-1"><UserSearchSelect id="meal-walkin" value={walkIn()} onChange={setWalkIn} placeholder={t("form.selectStudent")} /></div><Button disabled={!walkIn() || pending()} onClick={() => void run(async () => { await postMealAttendance(id(), walkIn(), "served"); setWalkIn(""); await refetchService(); })}>{t("meals.served")}</Button></div> | |
| 257 | - </div> | |
| 258 | - <Show when={serviceAttendance.error || serviceBookings.error}><ErrorAlert message={formatApiError(serviceAttendance.error || serviceBookings.error)} onRetry={() => void refetchService()} /></Show> | |
| 259 | - <div class="space-y-2"> | |
| 260 | - <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-text-subtle">{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-text" onClick={() => setCancelBooking(entry.booking)}>{t("meals.cancelBooking")}</Button></Show></div></div>}</For> | |
| 287 | + <Show when={canBook()}> | |
| 288 | + <div class="grid gap-5 xl:grid-cols-[minmax(0,3fr)_minmax(0,2fr)]"> | |
| 289 | + <Show when={canReadMoney()}> | |
| 290 | + <MealLedgerTable items={ledger()?.items ?? []} locale={locale()} moneyLocale={moneyLocale()} /> | |
| 291 | + </Show> | |
| 292 | + <MealAttendanceTable items={attendance()?.items ?? []} locale={locale()} /> | |
| 261 | 293 | </div> |
| 262 | - </TabsContent> | |
| 294 | + </Show> | |
| 263 | 295 | |
| 264 | - <TabsContent value="manage" class="space-y-5"> | |
| 265 | - <div class="flex justify-end"><Button size="sm" class="rounded-lg" onClick={() => openDish()}><IconPlus class="h-4 w-4" />{t("meals.addDish")}</Button></div> | |
| 266 | - <section class="data-shell space-y-4 p-4"> | |
| 267 | - <h2 class="font-semibold text-text-strong">{t("meals.studentRecord")}</h2> | |
| 268 | - <UserSearchSelect id="meal-record-user" role="student" value={lookupStudent()} onChange={setLookupStudent} label={t("meals.student")} /> | |
| 269 | - <Show when={lookupStudent()}> | |
| 270 | - <div class="space-y-3"> | |
| 271 | - <div class="flex flex-wrap gap-2"><For each={settings()?.dietary_tags ?? []}>{(tag) => <label class="flex items-center gap-2 rounded-lg border border-border-line px-3 py-2 text-sm"><input type="checkbox" checked={profileTags().includes(tag)} onChange={() => toggleTag(tag, profileTags(), setProfileTags)} />{dietaryTagLabel(tag, t)}</label>}</For></div> | |
| 272 | - <Textarea maxlength={limits()?.meal.max_dietary_note_len} value={profileNote()} placeholder={t("meals.dietaryNote")} onInput={(e) => setProfileNote(e.currentTarget.value)} /> | |
| 273 | - <Button disabled={pending()} onClick={() => void run(async () => { await patchDietaryProfileByUserId(lookupStudent(), { tags: profileTags(), note: profileNote().trim() || null }); await refetchProfile(); })}>{t("common.save")}</Button> | |
| 274 | - </div> | |
| 275 | - </Show> | |
| 276 | - </section> | |
| 277 | - <section class="data-shell p-4"><h2 class="font-semibold text-text-strong">{t("meals.bookingAudit")}</h2><div class="mt-3 divide-y divide-border-hairline"><For each={audit()?.items ?? []}>{(booking) => <div class="flex justify-between gap-3 py-3 text-sm"><span>{personLabel(booking.student)}</span><Badge variant={booking.status === "booked" ? "default" : "secondary"}>{booking.status}</Badge></div>}</For></div></section> | |
| 278 | - <Show when={isAdmin()}> | |
| 279 | - <section class="data-shell space-y-3 p-4"><h2 class="font-semibold text-text-strong">{t("meals.recordCredit")}</h2><p class="text-sm text-text-subtle">{t("meals.creditAppendOnly")}</p><Input type="number" min={0.01} step={0.01} value={creditAmount()} placeholder={t("meals.amountTry")} onInput={(e) => setCreditAmount(e.currentTarget.value)} /><Input maxlength={limits()?.meal.max_ledger_method_len} value={creditMethod()} placeholder={t("meals.method")} onInput={(e) => setCreditMethod(e.currentTarget.value)} /><Textarea maxlength={limits()?.meal.max_ledger_note_len} value={creditNote()} placeholder={t("meals.note")} onInput={(e) => setCreditNote(e.currentTarget.value)} /><Button disabled={!lookupStudent() || pending()} onClick={() => void run(async () => { await postMealCredit({ student_id: lookupStudent(), amount_minor: Math.round(Number(creditAmount()) * 100), method: creditMethod().trim() || undefined, note: creditNote().trim() || undefined }); setCreditAmount(""); setCreditMethod(""); setCreditNote(""); await Promise.all([refetchBalance(), refetchLedger()]); }, t("meals.creditRecorded"))}>{t("meals.recordCredit")}</Button></section> | |
| 296 | + <Show when={canServe()}> | |
| 297 | + <Show when={serviceAttendance.error || serviceBookings.error}> | |
| 298 | + <ErrorAlert message={formatApiError(serviceAttendance.error || serviceBookings.error)} onRetry={() => void refetchService()} /> | |
| 280 | 299 | </Show> |
| 281 | - </TabsContent> | |
| 282 | - </Tabs> | |
| 300 | + <MealServiceTable | |
| 301 | + entries={serviceEntries()} | |
| 302 | + canManage={canManage()} | |
| 303 | + pending={pending()} | |
| 304 | + onMark={(studentId, status) => void mark(studentId, status)} | |
| 305 | + onCancelBooking={setCancelBooking} | |
| 306 | + onAddWalkIn={() => { setError(""); setShowWalkIn(true); }} | |
| 307 | + /> | |
| 308 | + </Show> | |
| 283 | 309 | |
| 284 | - <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"))} /> | |
| 285 | - <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"))} /> | |
| 286 | - <ConfirmDialog open={deleteMenuOpen()} onOpenChange={setDeleteMenuOpen} title={t("meals.deleteMenu")} variant="destructive" summary={`${current().date} · ${mealSlotLabel(current().slot, t)}`} onConfirm={() => run(async () => { await deleteMealMenuById(id()); void navigate({ to: "/meals" }); }, t("common.deleted"))} /> | |
| 287 | - <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"))} /> | |
| 310 | + <ConfirmDialog | |
| 311 | + open={cancelOpen()} | |
| 312 | + onOpenChange={setCancelOpen} | |
| 313 | + title={t("meals.cancelBooking")} | |
| 314 | + variant="destructive" | |
| 315 | + summary={t("meals.cancelSummary")} | |
| 316 | + onConfirm={() => confirmRun(async () => { | |
| 317 | + const booking = activeBooking(); | |
| 318 | + if (!booking) return; | |
| 319 | + await deleteMealBookingById(booking.id); | |
| 320 | + await refreshAccount(); | |
| 321 | + }, t("meals.cancelled"))} | |
| 322 | + /> | |
| 323 | + <ConfirmDialog | |
| 324 | + open={cancelBooking() !== null} | |
| 325 | + onOpenChange={(open) => !open && setCancelBooking(null)} | |
| 326 | + title={t("meals.cancelBooking")} | |
| 327 | + variant="destructive" | |
| 328 | + summary={cancelBooking() ? `${t("meals.cancelSummary")} · ${personLabel(cancelBooking()!.student)}` : ""} | |
| 329 | + onConfirm={() => confirmRun(async () => { | |
| 330 | + const booking = cancelBooking(); | |
| 331 | + if (!booking) return; | |
| 332 | + await deleteMealBookingById(booking.id); | |
| 333 | + setCancelBooking(null); | |
| 334 | + await refetchService(); | |
| 335 | + }, t("meals.cancelled"))} | |
| 336 | + /> | |
| 337 | + <ConfirmDialog | |
| 338 | + open={deleteMenuOpen()} | |
| 339 | + onOpenChange={setDeleteMenuOpen} | |
| 340 | + title={t("meals.deleteMenu")} | |
| 341 | + variant="destructive" | |
| 342 | + summary={heading()} | |
| 343 | + onConfirm={() => confirmRun(async () => { | |
| 344 | + await deleteMealMenuById(id()); | |
| 345 | + void navigate({ to: "/meals" }); | |
| 346 | + }, t("common.deleted"))} | |
| 347 | + /> | |
| 348 | + <ConfirmDialog | |
| 349 | + open={deleteDish() !== null} | |
| 350 | + onOpenChange={(open) => !open && setDeleteDish(null)} | |
| 351 | + title={t("meals.deleteDish")} | |
| 352 | + variant="destructive" | |
| 353 | + summary={deleteDish()?.name ?? ""} | |
| 354 | + onConfirm={() => confirmRun(async () => { | |
| 355 | + const dish = deleteDish(); | |
| 356 | + if (!dish) return; | |
| 357 | + await deleteMealDishById(dish.id); | |
| 358 | + setDeleteDish(null); | |
| 359 | + await refetchMenu(); | |
| 360 | + }, t("common.deleted"))} | |
| 361 | + /> | |
| 288 | 362 | |
| 289 | - <SidePanel guardUnsaved open={showMenuEdit()} onOpenChange={setShowMenuEdit} title={t("meals.editMenu")} description={`${current().date} · ${mealSlotLabel(current().slot, t)}`}> | |
| 290 | - <form class="space-y-4" onSubmit={(e) => { e.preventDefault(); void run(async () => { await patchMealMenuById(id(), { capacity: capacity() ? Number(capacity()) : null }); setShowMenuEdit(false); await refetchMenu(); }); }}><div class="space-y-1.5"><Label for="menu-capacity">{t("meals.capacity")}</Label><Input id="menu-capacity" type="number" min={0} max={limits()?.meal.max_menu_capacity} value={capacity()} onInput={(e) => setCapacity(e.currentTarget.value)} /></div><Button type="submit" disabled={pending()}>{t("common.save")}</Button></form> | |
| 291 | - </SidePanel> | |
| 292 | - <SidePanel guardUnsaved open={showDishForm()} onOpenChange={setShowDishForm} title={editingDish() ? t("meals.editDish") : t("meals.addDish")} description={`${current().date} · ${mealSlotLabel(current().slot, t)}`}> | |
| 293 | - <form class="space-y-4" onSubmit={(e) => { e.preventDefault(); void run(async () => { const body = { name: dishName().trim(), description: dishDescription().trim() || null, price_minor: Math.round(Number(dishPrice()) * 100), tags: dishTags() }; if (editingDish()) await patchMealDishById(editingDish()!.id, body); else await postMealDish(id(), body); setShowDishForm(false); await refetchMenu(); }); }}> | |
| 294 | - <div class="space-y-1.5"><Label for="dish-name">{t("meals.dishName")}</Label><Input id="dish-name" required maxlength={limits()?.meal.max_dish_name_len} value={dishName()} onInput={(e) => setDishName(e.currentTarget.value)} /></div> | |
| 295 | - <div class="space-y-1.5"><Label for="dish-description">{t("form.description")}</Label><Textarea id="dish-description" maxlength={limits()?.meal.max_dish_description_len} value={dishDescription()} onInput={(e) => setDishDescription(e.currentTarget.value)} /></div> | |
| 296 | - <div class="space-y-1.5"><Label for="dish-price">{t("meals.priceTry")}</Label><Input id="dish-price" required type="number" min={0} step={0.01} value={dishPrice()} onInput={(e) => setDishPrice(e.currentTarget.value)} /></div> | |
| 297 | - <div class="flex flex-wrap gap-2"><For each={settings()?.dietary_tags ?? []}>{(tag) => <label class="flex items-center gap-2 rounded-lg border border-border-line px-3 py-2 text-sm"><input type="checkbox" checked={dishTags().includes(tag)} onChange={() => toggleTag(tag, dishTags(), setDishTags)} />{dietaryTagLabel(tag, t)}</label>}</For></div> | |
| 298 | - <Button type="submit" disabled={pending()}>{t("common.save")}</Button> | |
| 299 | - </form> | |
| 300 | - </SidePanel> | |
| 301 | - </div> | |
| 302 | - )} | |
| 363 | + <MealMenuEditPanel | |
| 364 | + open={showMenuEdit()} | |
| 365 | + onOpenChange={setShowMenuEdit} | |
| 366 | + description={heading()} | |
| 367 | + capacity={current().capacity} | |
| 368 | + maxCapacity={limits()?.meal.max_menu_capacity} | |
| 369 | + pending={pending()} | |
| 370 | + error={error()} | |
| 371 | + onSave={(capacity) => run(async () => { | |
| 372 | + await patchMealMenuById(id(), { capacity }); | |
| 373 | + await refetchMenu(); | |
| 374 | + })} | |
| 375 | + /> | |
| 376 | + <MealDishPanel | |
| 377 | + open={showDishForm()} | |
| 378 | + onOpenChange={setShowDishForm} | |
| 379 | + dish={editingDish()} | |
| 380 | + description={heading()} | |
| 381 | + dietaryTags={settings()?.dietary_tags ?? []} | |
| 382 | + limits={limits()} | |
| 383 | + pending={pending()} | |
| 384 | + error={error()} | |
| 385 | + onSave={saveDish} | |
| 386 | + /> | |
| 387 | + <Show when={canServe()}> | |
| 388 | + <MealWalkInPanel | |
| 389 | + open={showWalkIn()} | |
| 390 | + onOpenChange={setShowWalkIn} | |
| 391 | + description={heading()} | |
| 392 | + pending={pending()} | |
| 393 | + error={error()} | |
| 394 | + onSubmit={(studentId) => mark(studentId, "served")} | |
| 395 | + /> | |
| 396 | + </Show> | |
| 397 | + <Show when={canManage()}> | |
| 398 | + <MealStudentRecordPanel | |
| 399 | + open={showRecord()} | |
| 400 | + onOpenChange={setShowRecord} | |
| 401 | + studentId={lookupStudent()} | |
| 402 | + onStudentChange={setLookupStudent} | |
| 403 | + profile={lookupStudent() ? profile() : null} | |
| 404 | + balanceMinor={lookupStudent() ? balance()?.balance_minor : undefined} | |
| 405 | + dietaryTags={settings()?.dietary_tags ?? []} | |
| 406 | + limits={limits()} | |
| 407 | + isAdmin={isAdmin()} | |
| 408 | + moneyLocale={moneyLocale()} | |
| 409 | + pending={pending()} | |
| 410 | + error={error()} | |
| 411 | + onSaveProfile={saveProfile} | |
| 412 | + onRecordCredit={recordCredit} | |
| 413 | + /> | |
| 414 | + </Show> | |
| 415 | + </div> | |
| 416 | + ); | |
| 417 | + }} | |
| 303 | 418 | </Show> |
| 304 | 419 | </Suspense> |
| 305 | 420 | ); |
src/pages/meals-page.tsxmodified+71 -77
| @@ -1,12 +1,12 @@ | ||
| 1 | -import { For, Show, Suspense, createEffect, createMemo, createSignal, on } from "solid-js"; | |
| 2 | -import { createResponsivePageSize } from "@/lib/create-page-size"; | |
| 1 | +import { For, Show, Suspense, createMemo, createSignal } from "solid-js"; | |
| 3 | 2 | import { createResource } from "@/lib/create-resource"; |
| 4 | 3 | import { getLimits } from "@/api/limits"; |
| 5 | -import { getMealMenuBookings, getMealMenus, postMealMenu } from "@/api/meals"; | |
| 4 | +import { getMealMenus, postMealMenu } from "@/api/meals"; | |
| 6 | 5 | import { getSettings } from "@/api/settings"; |
| 7 | 6 | import { formatApiError } from "@/api/client"; |
| 8 | -import { MealMenuCard } from "@/components/meals/meal-menu-card"; | |
| 9 | -import { DatePicker } from "@/components/ui/date-picker"; | |
| 7 | +import { MealDayGroup } from "@/components/meals/meal-day-group"; | |
| 8 | +import { MealPublishPanel, type MealPublishInput } from "@/components/meals/meal-publish-panel"; | |
| 9 | +import { MealWeekNav } from "@/components/meals/meal-week-nav"; | |
| 10 | 10 | import { DataSection } from "@/components/ui/data-section"; |
| 11 | 11 | import { RouteGuard } from "@/components/layout/route-guard"; |
| 12 | 12 | import { Alert } from "@/components/ui/alert"; |
| @@ -14,21 +14,16 @@ import { Button } from "@/components/ui/button"; | ||
| 14 | 14 | import { EmptyState } from "@/components/ui/empty-state"; |
| 15 | 15 | import { ErrorAlert } from "@/components/ui/error-alert"; |
| 16 | 16 | import { IconPlus } from "@/components/ui/icons"; |
| 17 | -import { Input } from "@/components/ui/input"; | |
| 18 | -import { Label } from "@/components/ui/label"; | |
| 19 | 17 | import { PageSpinner } from "@/components/ui/page-spinner"; |
| 20 | -import { TablePagination } from "@/components/ui/table-pagination"; | |
| 21 | -import { Select } from "@/components/ui/select"; | |
| 22 | -import { SidePanel } from "@/components/ui/side-panel"; | |
| 23 | -import { inputDateToIso, isoDateToInput } from "@/lib/datetime-input"; | |
| 24 | 18 | import { createFlash } from "@/lib/flash"; |
| 25 | -import { mealSlotLabel } from "@/lib/meals"; | |
| 19 | +import { addDaysIso, groupMenusByDay, localIsoDate, weekStartIso } from "@/lib/meals"; | |
| 26 | 20 | import { hasMinRole } from "@/lib/roles"; |
| 27 | 21 | import { useAuth } from "@/stores/auth-context"; |
| 28 | 22 | import { usePreferences, useT } from "@/stores/preferences-context"; |
| 29 | 23 | |
| 30 | -const PAGE_SIZE = 10; | |
| 31 | -const today = () => new Date().toISOString().slice(0, 10); | |
| 24 | +// A school publishes at most a few slots a day, so one Monday–Sunday week is | |
| 25 | +// a small, bounded list: fetch it whole and group it by day on the client. | |
| 26 | +const WEEK_LIMIT = 100; | |
| 32 | 27 | |
| 33 | 28 | export default function MealsPage() { |
| 34 | 29 | return <RouteGuard><MealsContent /></RouteGuard>; |
| @@ -38,84 +33,83 @@ function MealsContent() { | ||
| 38 | 33 | const auth = useAuth(); |
| 39 | 34 | const t = useT(); |
| 40 | 35 | const { locale } = usePreferences(); |
| 36 | + const intlLocale = () => (locale() === "tr" ? "tr-TR" : "en-US"); | |
| 41 | 37 | const canManage = () => hasMinRole(auth.user()?.role, "manager"); |
| 42 | - const [page, setPage] = createSignal(0); | |
| 43 | - const pageSize = createResponsivePageSize(PAGE_SIZE); | |
| 44 | - createEffect(on(pageSize, () => setPage(0), { defer: true })); | |
| 45 | - const [from, setFrom] = createSignal(today()); | |
| 38 | + const today = localIsoDate(); | |
| 39 | + const thisWeek = weekStartIso(today); | |
| 40 | + const [weekStart, setWeekStart] = createSignal(thisWeek); | |
| 46 | 41 | const [slot, setSlot] = createSignal("all"); |
| 47 | 42 | const [showCreate, setShowCreate] = createSignal(false); |
| 48 | - const [date, setDate] = createSignal(today()); | |
| 49 | - const [newSlot, setNewSlot] = createSignal(""); | |
| 50 | - const [capacity, setCapacity] = createSignal(""); | |
| 51 | - const [pending, setPending] = createSignal(false); | |
| 52 | - const [error, setError] = createSignal(""); | |
| 53 | 43 | const [flash, setFlash] = createFlash(); |
| 54 | 44 | const [settings] = createResource(() => getSettings()); |
| 55 | - const [limits, { refetch: refetchLimits }] = createResource(() => canManage() ? getLimits() : null); | |
| 56 | - const [menus, { refetch }] = createResource( | |
| 57 | - () => [from(), page(), pageSize()] as const, | |
| 58 | - async ([start, index, size]) => getMealMenus({ from: start || undefined, limit: size, offset: index * size }), | |
| 45 | + const [limits, { refetch: refetchLimits }] = createResource(() => (canManage() ? getLimits() : null)); | |
| 46 | + const [menus, { refetch }] = createResource(weekStart, (start) => | |
| 47 | + // `to` is a day past Sunday so the week is whole whether the API reads it | |
| 48 | + // inclusively or not; the filter below trims anything past Sunday. | |
| 49 | + getMealMenus({ from: start, to: addDaysIso(start, 7), limit: WEEK_LIMIT, offset: 0 }), | |
| 59 | 50 | ); |
| 60 | - const visible = createMemo(() => slot() === "all" ? menus()?.items ?? [] : (menus()?.items ?? []).filter((menu) => menu.slot === slot())); | |
| 61 | - const totalPages = createMemo(() => Math.max(1, Math.ceil((menus()?.total ?? 0) / pageSize()))); | |
| 62 | 51 | |
| 63 | - // Real occupancy = confirmed bookings / capacity, both true fields — not the | |
| 64 | - // fabricated İyi/Takipte/Risk badge Figma shows. `getMealMenuBookings` is | |
| 65 | - // the same manager-only booking-audit read already used on the detail page, | |
| 66 | - // so this only runs for managers and only for the menus on screen. | |
| 67 | - const [reservationCounts] = createResource( | |
| 68 | - () => canManage() ? visible().map((menu) => menu.id) : null, | |
| 69 | - async (ids) => { | |
| 70 | - const entries = await Promise.all( | |
| 71 | - ids.map(async (id) => { | |
| 72 | - try { | |
| 73 | - return [id, (await getMealMenuBookings(id, { limit: 1 })).total] as const; | |
| 74 | - } catch { | |
| 75 | - return [id, null] as const; | |
| 76 | - } | |
| 77 | - }), | |
| 78 | - ); | |
| 79 | - return new Map(entries); | |
| 80 | - }, | |
| 81 | - ); | |
| 52 | + const slots = () => settings()?.meal_slots ?? []; | |
| 53 | + const days = createMemo(() => { | |
| 54 | + const end = addDaysIso(weekStart(), 6); | |
| 55 | + const items = (menus()?.items ?? []).filter( | |
| 56 | + (menu) => menu.date >= weekStart() && menu.date <= end && (slot() === "all" || menu.slot === slot()), | |
| 57 | + ); | |
| 58 | + return groupMenusByDay(items, slots().map((item) => item.name)); | |
| 59 | + }); | |
| 82 | 60 | |
| 83 | - const publish = async (event: SubmitEvent) => { | |
| 84 | - event.preventDefault(); | |
| 85 | - setPending(true); setError(""); | |
| 86 | - try { | |
| 87 | - await postMealMenu({ date: date(), slot: newSlot(), capacity: capacity() ? Number(capacity()) : null }); | |
| 88 | - setShowCreate(false); setCapacity(""); await refetch(); setFlash(t("common.created")); | |
| 89 | - } catch (err) { | |
| 90 | - setError(formatApiError(err)); | |
| 91 | - } finally { | |
| 92 | - setPending(false); | |
| 93 | - } | |
| 61 | + const publish = async (input: MealPublishInput) => { | |
| 62 | + await postMealMenu(input); | |
| 63 | + setShowCreate(false); | |
| 64 | + await refetch(); | |
| 65 | + setFlash(t("common.created")); | |
| 94 | 66 | }; |
| 95 | 67 | |
| 96 | 68 | return ( |
| 97 | 69 | <div class="space-y-5"> |
| 98 | - <SidePanel open={showCreate()} onOpenChange={setShowCreate} guardUnsaved title={t("meals.publish")} description={t("meals.publishHelp")}> | |
| 99 | - <form class="space-y-4" onSubmit={publish}> | |
| 100 | - <Show when={limits.error}><ErrorAlert message={formatApiError(limits.error)} onRetry={() => void refetchLimits()} /></Show> | |
| 101 | - <div class="space-y-1.5"><Label for="meal-date">{t("meals.date")}</Label><DatePicker id="meal-date" required placeholder={t("form.datePlaceholder")} value={isoDateToInput(date())} onChange={(value) => setDate(inputDateToIso(value))} /></div> | |
| 102 | - <div class="space-y-1.5"><Label for="meal-slot">{t("meals.slot")}</Label><Select id="meal-slot" required value={newSlot()} onChange={(e) => setNewSlot(e.currentTarget.value)}><For each={settings()?.meal_slots ?? []}>{(item) => <option value={item.name}>{mealSlotLabel(item.name, t)}</option>}</For></Select></div> | |
| 103 | - <div class="space-y-1.5"><Label for="meal-capacity">{t("meals.capacity")}</Label><Input id="meal-capacity" type="number" min={0} max={limits()?.meal.max_menu_capacity} value={capacity()} onInput={(e) => setCapacity(e.currentTarget.value)} /></div> | |
| 104 | - <Show when={error()}><Alert variant="destructive">{error()}</Alert></Show> | |
| 105 | - <div class="flex gap-2 border-t border-border-hairline pt-4"><Button type="submit" disabled={pending()}>{t("common.create")}</Button><Button type="button" variant="outline" onClick={() => setShowCreate(false)}>{t("common.cancel")}</Button></div> | |
| 106 | - </form> | |
| 107 | - </SidePanel> | |
| 70 | + <MealPublishPanel | |
| 71 | + open={showCreate()} | |
| 72 | + onOpenChange={setShowCreate} | |
| 73 | + initialDate={today} | |
| 74 | + slots={slots()} | |
| 75 | + limits={limits()} | |
| 76 | + limitsError={limits.error ? formatApiError(limits.error) : undefined} | |
| 77 | + onRetryLimits={() => void refetchLimits()} | |
| 78 | + onPublish={publish} | |
| 79 | + /> | |
| 108 | 80 | <Show when={flash()}><Alert variant="success">{flash()}</Alert></Show> |
| 109 | - <DataSection title={t("meals.title")} description={t("meals.subtitle")} actions={<Show when={canManage()}><Button size="sm" class="min-w-[7.5rem] rounded-lg" onClick={() => { setNewSlot(settings()?.meal_slots[0]?.name ?? ""); setShowCreate(true); }}><IconPlus class="h-4 w-4" />{t("meals.publish")}</Button></Show>}> | |
| 110 | - <div class="flex flex-wrap items-center gap-2"> | |
| 111 | - <DatePicker id="menus-from" class="h-8 w-44" placeholder={t("meals.from")} value={isoDateToInput(from())} onChange={(value) => { const iso = inputDateToIso(value); if (iso) { setFrom(iso); setPage(0); } }} /> | |
| 112 | - <Select id="menus-slot" aria-label={t("meals.slot")} wrapperClass="w-auto" class="h-8 rounded-lg text-[13px]" value={slot()} onChange={(e) => setSlot(e.currentTarget.value)}><option value="all">{t("meals.slot")}: {t("common.all")}</option><For each={settings()?.meal_slots ?? []}>{(item) => <option value={item.name}>{mealSlotLabel(item.name, t)}</option>}</For></Select> | |
| 113 | - </div> | |
| 81 | + <DataSection | |
| 82 | + title={t("meals.title")} | |
| 83 | + description={t("meals.subtitle")} | |
| 84 | + actions={ | |
| 85 | + <Show when={canManage()}> | |
| 86 | + <Button size="sm" class="min-w-[7.5rem] rounded-lg" onClick={() => setShowCreate(true)}> | |
| 87 | + <IconPlus class="h-4 w-4" /> | |
| 88 | + {t("meals.publish")} | |
| 89 | + </Button> | |
| 90 | + </Show> | |
| 91 | + } | |
| 92 | + > | |
| 93 | + <MealWeekNav | |
| 94 | + weekStart={weekStart()} | |
| 95 | + thisWeek={thisWeek} | |
| 96 | + locale={intlLocale()} | |
| 97 | + slot={slot()} | |
| 98 | + slots={slots()} | |
| 99 | + onWeekChange={setWeekStart} | |
| 100 | + onSlotChange={setSlot} | |
| 101 | + /> | |
| 114 | 102 | <Suspense fallback={<PageSpinner />}> |
| 115 | 103 | <Show when={menus.error}><ErrorAlert message={formatApiError(menus.error)} onRetry={() => void refetch()} /></Show> |
| 116 | - <Show when={visible().length > 0} fallback={<EmptyState kind="meals" title={t("meals.empty")} />}> | |
| 117 | - <div class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4"><For each={visible()}>{(menu) => <MealMenuCard menu={menu} locale={locale() === "tr" ? "tr-TR" : "en-US"} labels={{ dishes: t("meals.dishes"), capacity: t("meals.capacity"), conflict: t("meals.conflict"), reservations: t("meals.reservations") }} reservationCount={reservationCounts()?.get(menu.id) ?? undefined} />}</For></div> | |
| 118 | - <TablePagination pageIndex={page()} pageCount={totalPages()} onPageChange={setPage} /> | |
| 104 | + <Show | |
| 105 | + when={days().length > 0} | |
| 106 | + fallback={<Show when={!menus.error}><EmptyState kind="meals" title={t("meals.emptyWeek")} description={t("meals.emptyWeekHint")} /></Show>} | |
| 107 | + > | |
| 108 | + <div class="space-y-5" aria-busy={menus.loading}> | |
| 109 | + <For each={days()}> | |
| 110 | + {(day) => <MealDayGroup date={day.date} menus={day.menus} locale={intlLocale()} isToday={day.date === today} />} | |
| 111 | + </For> | |
| 112 | + </div> | |
| 119 | 113 | </Show> |
| 120 | 114 | </Suspense> |
| 121 | 115 | </DataSection> |