diff --git a/src/components/meals/meal-account-card.tsx b/src/components/meals/meal-account-card.tsx new file mode 100644 index 0000000..d5f078e --- /dev/null +++ b/src/components/meals/meal-account-card.tsx @@ -0,0 +1,36 @@ +import { For, Show } from "solid-js"; +import type { DietaryProfile } from "@/api/client"; +import { Badge } from "@/components/ui/badge"; +import { dietaryTagLabel, formatTry } from "@/lib/meals"; +import { useT } from "@/stores/preferences-context"; + +/** Balance (when the viewer may read money) and the dietary profile, side by side in one card. */ +export function MealAccountCard(props: { + showBalance: boolean; + balanceMinor?: number; + profile?: DietaryProfile | null; + moneyLocale: string; +}) { + const t = useT(); + return ( +
+ +
+

{t("meals.balance")}

+

+ {props.balanceMinor == null ? "—" : formatTry(props.balanceMinor, props.moneyLocale)} +

+
+
+
+

{t("meals.dietaryProfile")}

+ 0}> +
+ {(tag) => {dietaryTagLabel(tag, t)}} +
+
+

{props.profile?.note || t("meals.noDietaryNotes")}

+
+
+ ); +} diff --git a/src/components/meals/meal-attendance-table.tsx b/src/components/meals/meal-attendance-table.tsx new file mode 100644 index 0000000..9417eb2 --- /dev/null +++ b/src/components/meals/meal-attendance-table.tsx @@ -0,0 +1,40 @@ +import type { ColumnDef } from "@tanstack/solid-table"; +import type { MealAttendance } from "@/api/client"; +import type { Locale } from "@/i18n/messages"; +import { MealSectionHeading } from "@/components/meals/meal-section-heading"; +import { DataTable } from "@/components/ui/data-table"; +import { formatDateTime } from "@/lib/format"; +import { mealServiceStatusLabel } from "@/lib/meals"; +import { useT } from "@/stores/preferences-context"; + +/** The student's recent meal service marks (served / missed) across menus. */ +export function MealAttendanceTable(props: { items: MealAttendance[]; locale: Locale }) { + const t = useT(); + const columns: ColumnDef[] = [ + { + id: "status", + accessorFn: (row) => mealServiceStatusLabel(row.status, t), + header: t("meals.status"), + meta: { cellClass: "whitespace-nowrap font-medium" }, + }, + { + id: "when", + accessorFn: (row) => row.marked_at, + header: t("meals.when"), + meta: { cellClass: "whitespace-nowrap" }, + cell: (cell) => formatDateTime(cell.row.original.marked_at, props.locale), + }, + ]; + return ( +
+ + +
+ ); +} diff --git a/src/components/meals/meal-booking-card.tsx b/src/components/meals/meal-booking-card.tsx new file mode 100644 index 0000000..817f089 --- /dev/null +++ b/src/components/meals/meal-booking-card.tsx @@ -0,0 +1,59 @@ +import { Show } from "solid-js"; +import type { PersonRef } from "@/api/client"; +import { Badge } from "@/components/ui/badge"; +import { Button } from "@/components/ui/button"; +import { Label } from "@/components/ui/label"; +import { SearchableSelect } from "@/components/ui/searchable-select"; +import { personLabel } from "@/lib/person"; +import { useT } from "@/stores/preferences-context"; + +/** + * The student/parent's main task on a menu: am I booked, and the one button + * that books or cancels. A parent picks which child first. + */ +export function MealBookingCard(props: { + isParent: boolean; + children: PersonRef[]; + selectedChild: string; + onSelectChild: (id: string) => void; + canBook: boolean; + booked: boolean; + cutoffClosed: boolean; + pending: boolean; + onBook: () => void; + onCancel: () => void; +}) { + const t = useT(); + return ( +
+
+

{t("meals.bookingStatus")}

+ + {props.booked ? t("meals.booked") : t("meals.notBooked")} + +
+ +
+ + ({ value: child.id, label: personLabel(child) }))} + /> +
+
+ +

{props.cutoffClosed ? t("meals.cutoffPassed") : t("meals.bookingHelp")}

+ {t("meals.book")}} + > + + +
+
+ ); +} diff --git a/src/components/meals/meal-day-group.tsx b/src/components/meals/meal-day-group.tsx new file mode 100644 index 0000000..6e6aad4 --- /dev/null +++ b/src/components/meals/meal-day-group.tsx @@ -0,0 +1,29 @@ +import { For, Show } from "solid-js"; +import type { MealMenu } from "@/api/client"; +import { Badge } from "@/components/ui/badge"; +import { MealMenuRow } from "@/components/meals/meal-menu-row"; +import { formatMealDay } from "@/lib/meals"; +import { useT } from "@/stores/preferences-context"; + +/** A day heading and its meals in one hairline list — no card per meal. */ +export function MealDayGroup(props: { + date: string; + menus: MealMenu[]; + locale: string; + isToday: boolean; +}) { + const t = useT(); + return ( +
+

+ {formatMealDay(props.date, props.locale)} + {t("meals.today")} +

+
+ + {(menu) => } + +
+
+ ); +} diff --git a/src/components/meals/meal-dish-list.tsx b/src/components/meals/meal-dish-list.tsx new file mode 100644 index 0000000..b3747d6 --- /dev/null +++ b/src/components/meals/meal-dish-list.tsx @@ -0,0 +1,63 @@ +import { For, Show } from "solid-js"; +import type { MealDish } from "@/api/client"; +import { MealDishRow } from "@/components/meals/meal-dish-row"; +import { Button } from "@/components/ui/button"; +import { EmptyInline } from "@/components/ui/empty-inline"; +import { IconAlert, IconPlus } from "@/components/ui/icons"; +import { dietaryTagLabel, formatTry } from "@/lib/meals"; +import { useT } from "@/stores/preferences-context"; + +/** The menu itself: every dish on one hairline list, the total at the foot. */ +export function MealDishList(props: { + dishes: MealDish[]; + moneyLocale: string; + canManage: boolean; + onAdd: () => void; + onEdit: (dish: MealDish) => void; + onDelete: (dish: MealDish) => void; +}) { + const t = useT(); + const total = () => props.dishes.reduce((sum, dish) => sum + dish.price_minor, 0); + const conflicts = () => [...new Set(props.dishes.flatMap((dish) => dish.conflicts))]; + return ( +
+
+
+

{t("meals.menu")}

+

{t("meals.dishCount", { count: props.dishes.length })}

+
+ + + +
+ 0}> +

+ + {t("meals.conflict")}: {conflicts().map((tag) => dietaryTagLabel(tag, t)).join(", ")} +

+
+ 0} fallback={}> +
    + + {(dish) => ( + props.onEdit(dish)} + onDelete={() => props.onDelete(dish)} + /> + )} + +
+
+ {t("meals.total")} + {formatTry(total(), props.moneyLocale)} +
+
+
+ ); +} diff --git a/src/components/meals/meal-dish-panel.tsx b/src/components/meals/meal-dish-panel.tsx new file mode 100644 index 0000000..28ddb7d --- /dev/null +++ b/src/components/meals/meal-dish-panel.tsx @@ -0,0 +1,64 @@ +import { Show, createEffect, createSignal, on } from "solid-js"; +import type { Limits, MealDish } from "@/api/client"; +import type { MealDishBody } from "@/api/meals"; +import { MealTagCheckboxes } from "@/components/meals/meal-tag-checkboxes"; +import { Alert } from "@/components/ui/alert"; +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { SidePanel } from "@/components/ui/side-panel"; +import { Textarea } from "@/components/ui/textarea"; +import { useT } from "@/stores/preferences-context"; + +/** Add a dish, or edit one (`dish` set). Prices are typed in TRY, sent in minor units. */ +export function MealDishPanel(props: { + open: boolean; + onOpenChange: (open: boolean) => void; + dish: MealDish | null; + description: string; + dietaryTags: string[]; + limits?: Limits | null; + pending: boolean; + error: string; + onSave: (body: MealDishBody) => Promise; +}) { + const t = useT(); + const [name, setName] = createSignal(""); + const [text, setText] = createSignal(""); + const [price, setPrice] = createSignal(""); + const [tags, setTags] = createSignal([]); + createEffect(on(() => [props.open, props.dish] as const, ([open, dish]) => { + if (!open) return; + setName(dish?.name ?? ""); setText(dish?.description ?? ""); + setPrice(dish ? String(dish.price_minor / 100) : ""); setTags(dish?.tags ?? []); + })); + const submit = async (event: SubmitEvent) => { + event.preventDefault(); + const body = { name: name().trim(), description: text().trim() || null, price_minor: Math.round(Number(price()) * 100), tags: tags() }; + if (await props.onSave(body)) props.onOpenChange(false); + }; + return ( + +
+
+ + setName(e.currentTarget.value)} /> +
+
+ +