From a05f0f1665281ca08845ab5afeaee885305b4db2 Mon Sep 17 00:00:00 2001 From: BOHA Date: Sat, 6 Jun 2026 23:47:59 +0200 Subject: [PATCH] feat(mui): migrate Trips History (Moje historie) onto MUI kit Co-Authored-By: Claude Opus 4.8 (1M context) --- src/admin/pages/TripsHistory.tsx | 405 ++++++++++++++++--------------- 1 file changed, 211 insertions(+), 194 deletions(-) diff --git a/src/admin/pages/TripsHistory.tsx b/src/admin/pages/TripsHistory.tsx index 35ecced..62d41f8 100644 --- a/src/admin/pages/TripsHistory.tsx +++ b/src/admin/pages/TripsHistory.tsx @@ -1,19 +1,26 @@ import { useState } from "react"; import { useQuery } from "@tanstack/react-query"; -import { useAlert } from "../context/AlertContext"; -import { useAuth } from "../context/AuthContext"; import { motion } from "framer-motion"; -import AdminDatePicker from "../components/AdminDatePicker"; +import Box from "@mui/material/Box"; +import { useAuth } from "../context/AuthContext"; import Forbidden from "../components/Forbidden"; import { formatDate } from "../utils/attendanceHelpers"; import { formatKm } from "../utils/formatters"; -import FormField from "../components/FormField"; +import { tripHistoryOptions, tripVehiclesOptions } from "../lib/queries/trips"; import { - tripHistoryOptions, - tripVehiclesOptions, - type BackendTrip, - type TripVehicle, -} from "../lib/queries/trips"; + Card, + DataTable, + Field, + Select, + MonthField, + StatusChip, + PageHeader, + FilterBar, + EmptyState, + LoadingState, + StatCard, + type DataColumn, +} from "../ui"; interface Trip { id: number; @@ -29,8 +36,56 @@ interface Trip { notes?: string; } +const TripsIcon = ( + + + + + +); +const TotalIcon = ( + + + +); +const BusinessIcon = ( + + + + + + + +); + export default function TripsHistory() { - const alert = useAlert(); const { user, hasPermission } = useAuth(); const [month, setMonth] = useState(() => { const now = new Date(); @@ -48,7 +103,7 @@ export default function TripsHistory() { userId: user?.id, }), ); - const trips = (tripsData ?? []).map((t) => ({ + const trips: Trip[] = (tripsData ?? []).map((t) => ({ id: t.id, trip_date: t.trip_date, spz: t.vehicles?.spz ?? "", @@ -81,222 +136,184 @@ export default function TripsHistory() { return date.toLocaleDateString("cs-CZ", { month: "long", year: "numeric" }); }; + const columns: DataColumn[] = [ + { + key: "trip_date", + header: "Datum", + width: "11%", + mono: true, + render: (trip) => formatDate(trip.trip_date), + }, + { + key: "vehicle", + header: "Vozidlo", + width: "10%", + render: (trip) => , + }, + { + key: "driver", + header: "Řidič", + width: "14%", + render: (trip) => ( + + {trip.driver_name} + + ), + }, + { + key: "route", + header: "Trasa", + width: "18%", + render: (trip) => ( + + {trip.route_from} → {trip.route_to} + + ), + }, + { + key: "km", + header: "Stav km", + width: "13%", + mono: true, + render: (trip) => ( + + {formatKm(trip.start_km)} - {formatKm(trip.end_km)} + + ), + }, + { + key: "distance", + header: "Vzdálenost", + width: "10%", + mono: true, + bold: true, + render: (trip) => `${formatKm(trip.distance)} km`, + }, + { + key: "type", + header: "Typ", + width: "10%", + render: (trip) => ( + + ), + }, + { + key: "notes", + header: "Poznámka", + width: "14%", + render: (trip) => ( + + {trip.notes || "—"} + + ), + }, + ]; + return ( -
+ -
-

Historie jízd

-

{getMonthName(month)}

-
+
{/* Filters */} -
-
- - setMonth(val)} - /> - - - setVehicleId(e.target.value)} - className="admin-form-select" - > - - {vehicles.map((v) => ( - - ))} - - -
-
+ onChange={(value) => setVehicleId(value)} + options={[ + { value: "", label: "Všechna vozidla" }, + ...vehicles.map((v) => ({ + value: String(v.id), + label: `${v.spz} - ${v.name}`, + })), + ]} + /> + +
+ -
-
- - - - - -
-
- {totals.count} - Počet jízd -
-
-
-
- - - -
-
- - {formatKm(totals.total)} km - - Celkem naježděno -
-
-
-
- - - - - - - -
-
- - {formatKm(totals.business)} km - - Služební km -
-
+ + + + +
{/* Trips Table */} -
+ {isPending ? ( -
-
-
+ ) : ( - <> - {trips.length === 0 && ( -
-

Žádné záznamy jízd pro vybrané období.

-
- )} - {trips.length > 0 && ( -
- - - - - - - - - - - - - - - {trips.map((trip) => ( - - - - - - - - - - - ))} - -
DatumVozidloŘidičTrasaStav kmVzdálenostTypPoznámka
- {formatDate(trip.trip_date)} - - {trip.spz} - - {trip.driver_name} - - - {trip.route_from} → {trip.route_to} - - - - {formatKm(trip.start_km)} -{" "} - {formatKm(trip.end_km)} - - - {formatKm(trip.distance)} km - - - {trip.is_business ? "Služební" : "Soukromá"} - - - {trip.notes || "—"} -
-
- )} - + + columns={columns} + rows={trips} + rowKey={(trip) => trip.id} + empty={ + + } + /> )} -
+
-
+ ); }