hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | import { createMemo, type JSX } from "solid-js"; |
| 2 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 3 | import type { WeeklySlot } from "@/api/client"; |
| 4 | import { DataTable } from "@/components/ui/data-table"; |
| 5 | import { IconTrash } from "@/components/ui/icons"; |
| 6 | import { TableRowActions } from "@/components/ui/table-row-actions"; |
| 7 | import { minutesToHHmm, sortSlots, weekdayLabel } from "@/lib/weekly-plan"; |
| 8 | import { usePreferences, useT } from "@/stores/preferences-context"; |
| 9 | |
| 10 | /** |
| 11 | * A weekly plan's slots, weekday first; removable when `onRemove` is given. |
| 12 | * `actions` (add slot, generate, reset) sit in the table's toolbar card beside |
| 13 | * "Sütunlar", not in a header row above it. |
| 14 | */ |
| 15 | export function WeeklyPlanTable(props: { slots: WeeklySlot[]; onRemove?: (slot: WeeklySlot) => void; empty?: string; actions?: JSX.Element }) { |
| 16 | const t = useT(); |
| 17 | const { locale } = usePreferences(); |
| 18 | const rows = createMemo(() => sortSlots(props.slots)); |
| 19 | const columns = createMemo<ColumnDef<WeeklySlot>[]>(() => [ |
| 20 | { |
| 21 | id: "weekday", |
| 22 | accessorFn: (row) => row.weekday, |
| 23 | header: t("weeklyPlan.weekday"), |
| 24 | meta: { cellClass: "font-medium whitespace-nowrap" }, |
| 25 | cell: (cell) => weekdayLabel(cell.row.original.weekday, locale()), |
| 26 | }, |
| 27 | { |
| 28 | id: "time", |
| 29 | accessorFn: (row) => row.starts_at, |
| 30 | header: t("weeklyPlan.time"), |
| 31 | meta: { cellClass: "tabular-nums whitespace-nowrap" }, |
| 32 | cell: (cell) => `${minutesToHHmm(cell.row.original.starts_at)}–${minutesToHHmm(cell.row.original.ends_at)}`, |
| 33 | }, |
| 34 | { |
| 35 | id: "topic", |
| 36 | accessorFn: (row) => row.topic ?? "", |
| 37 | header: t("weeklyPlan.topic"), |
| 38 | meta: { cellClass: "text-muted-foreground" }, |
| 39 | cell: (cell) => cell.row.original.topic || "—", |
| 40 | }, |
| 41 | ...(props.onRemove |
| 42 | ? [ |
| 43 | { |
| 44 | id: "actions", |
| 45 | header: t("common.actions"), |
| 46 | meta: { headerClass: "w-[110px] min-w-[110px] max-w-[110px] h-[45px] text-center whitespace-nowrap", cellClass: "text-center" }, |
| 47 | cell: (cell) => ( |
| 48 | <TableRowActions |
| 49 | label={t("common.actions")} |
| 50 | actions={[{ label: t("weeklyPlan.removeSlot"), icon: <IconTrash class="h-4 w-4" />, destructive: true, onSelect: () => props.onRemove?.(cell.row.original) }]} |
| 51 | /> |
| 52 | ), |
| 53 | } satisfies ColumnDef<WeeklySlot>, |
| 54 | ] |
| 55 | : []), |
| 56 | ]); |
| 57 | return <DataTable columns={columns()} data={rows()} empty={props.empty ?? t("weeklyPlan.empty")} actions={props.actions} />; |
| 58 | } |