feat(mui): migrate Trips (Kniha jízd) onto MUI kit
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,14 +1,12 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { Link as RouterLink } from "react-router-dom";
|
||||||
|
import { motion } from "framer-motion";
|
||||||
|
import Box from "@mui/material/Box";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
import IconButton from "@mui/material/IconButton";
|
||||||
import { useAlert } from "../context/AlertContext";
|
import { useAlert } from "../context/AlertContext";
|
||||||
import { useAuth } from "../context/AuthContext";
|
import { useAuth } from "../context/AuthContext";
|
||||||
import { Link } from "react-router-dom";
|
|
||||||
import { motion } from "framer-motion";
|
|
||||||
|
|
||||||
import AdminDatePicker from "../components/AdminDatePicker";
|
|
||||||
import ConfirmModal from "../components/ConfirmModal";
|
|
||||||
import FormModal from "../components/FormModal";
|
|
||||||
import FormField from "../components/FormField";
|
|
||||||
import Forbidden from "../components/Forbidden";
|
import Forbidden from "../components/Forbidden";
|
||||||
import { formatDate } from "../utils/attendanceHelpers";
|
import { formatDate } from "../utils/attendanceHelpers";
|
||||||
import { formatKm, todayLocalStr } from "../utils/formatters";
|
import { formatKm, todayLocalStr } from "../utils/formatters";
|
||||||
@@ -17,9 +15,24 @@ import {
|
|||||||
tripListOptions,
|
tripListOptions,
|
||||||
tripVehiclesOptions,
|
tripVehiclesOptions,
|
||||||
type BackendTrip,
|
type BackendTrip,
|
||||||
type TripVehicle,
|
|
||||||
} from "../lib/queries/trips";
|
} from "../lib/queries/trips";
|
||||||
import { useApiMutation } from "../lib/queries/mutations";
|
import { useApiMutation } from "../lib/queries/mutations";
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Card,
|
||||||
|
DataTable,
|
||||||
|
Modal,
|
||||||
|
ConfirmDialog,
|
||||||
|
Field,
|
||||||
|
TextField,
|
||||||
|
Select,
|
||||||
|
DateField,
|
||||||
|
StatusChip,
|
||||||
|
LoadingState,
|
||||||
|
StatCard,
|
||||||
|
type DataColumn,
|
||||||
|
} from "../ui";
|
||||||
|
|
||||||
const API_BASE = "/api/admin";
|
const API_BASE = "/api/admin";
|
||||||
|
|
||||||
interface TripForm {
|
interface TripForm {
|
||||||
@@ -33,6 +46,114 @@ interface TripForm {
|
|||||||
notes: string;
|
notes: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PlusIcon = (
|
||||||
|
<svg
|
||||||
|
width="20"
|
||||||
|
height="20"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth="2"
|
||||||
|
>
|
||||||
|
<line x1="12" y1="5" x2="12" y2="19" />
|
||||||
|
<line x1="5" y1="12" x2="19" y2="12" />
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
const EditIcon = (
|
||||||
|
<svg
|
||||||
|
width="18"
|
||||||
|
height="18"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth="2"
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
>
|
||||||
|
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7" />
|
||||||
|
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z" />
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
const DeleteIcon = (
|
||||||
|
<svg
|
||||||
|
width="18"
|
||||||
|
height="18"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth="2"
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
>
|
||||||
|
<polyline points="3 6 5 6 21 6" />
|
||||||
|
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
|
||||||
|
const TripsIcon = (
|
||||||
|
<svg
|
||||||
|
width="22"
|
||||||
|
height="22"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth="2"
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
>
|
||||||
|
<line x1="12" y1="20" x2="12" y2="10" />
|
||||||
|
<line x1="18" y1="20" x2="18" y2="4" />
|
||||||
|
<line x1="6" y1="20" x2="6" y2="16" />
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
const TotalIcon = (
|
||||||
|
<svg
|
||||||
|
width="22"
|
||||||
|
height="22"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth="2"
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
>
|
||||||
|
<path d="M22 12h-4l-3 9L9 3l-3 9H2" />
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
const BusinessIcon = (
|
||||||
|
<svg
|
||||||
|
width="22"
|
||||||
|
height="22"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth="2"
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
>
|
||||||
|
<rect x="1" y="3" width="15" height="13" rx="2" ry="2" />
|
||||||
|
<path d="M16 8h2a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-1" />
|
||||||
|
<circle cx="5.5" cy="18" r="2" />
|
||||||
|
<circle cx="18.5" cy="18" r="2" />
|
||||||
|
<path d="M8 18h8" />
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
const PrivateIcon = (
|
||||||
|
<svg
|
||||||
|
width="22"
|
||||||
|
height="22"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth="2"
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
>
|
||||||
|
<path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z" />
|
||||||
|
<polyline points="9 22 9 12 15 12 15 22" />
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
|
||||||
export default function Trips() {
|
export default function Trips() {
|
||||||
const alert = useAlert();
|
const alert = useAlert();
|
||||||
const { hasPermission } = useAuth();
|
const { hasPermission } = useAuth();
|
||||||
@@ -197,11 +318,7 @@ export default function Trips() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (tripsLoading) {
|
if (tripsLoading) {
|
||||||
return (
|
return <LoadingState />;
|
||||||
<div className="admin-loading">
|
|
||||||
<div className="admin-spinner" />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const totals = trips.reduce(
|
const totals = trips.reduce(
|
||||||
@@ -216,440 +333,359 @@ export default function Trips() {
|
|||||||
{ total: 0, business: 0, private: 0, count: 0 },
|
{ total: 0, business: 0, private: 0, count: 0 },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const recentTrips = trips.slice(0, 10);
|
||||||
|
|
||||||
|
const columns: DataColumn<BackendTrip>[] = [
|
||||||
|
{
|
||||||
|
key: "trip_date",
|
||||||
|
header: "Datum",
|
||||||
|
width: "12%",
|
||||||
|
mono: true,
|
||||||
|
render: (trip) => formatDate(trip.trip_date),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "vehicle",
|
||||||
|
header: "Vozidlo",
|
||||||
|
width: "12%",
|
||||||
|
render: (trip) => (
|
||||||
|
<StatusChip label={trip.vehicles?.spz ?? ""} color="default" />
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "driver",
|
||||||
|
header: "Řidič",
|
||||||
|
width: "16%",
|
||||||
|
render: (trip) =>
|
||||||
|
trip.users ? `${trip.users.first_name} ${trip.users.last_name}` : "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "route",
|
||||||
|
header: "Trasa",
|
||||||
|
width: "22%",
|
||||||
|
render: (trip) => (
|
||||||
|
<Box component="span" sx={{ whiteSpace: "nowrap" }}>
|
||||||
|
{trip.route_from} → {trip.route_to}
|
||||||
|
</Box>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "distance",
|
||||||
|
header: "Vzdálenost",
|
||||||
|
width: "12%",
|
||||||
|
mono: true,
|
||||||
|
bold: true,
|
||||||
|
render: (trip) =>
|
||||||
|
`${formatKm(trip.distance ?? trip.end_km - trip.start_km)} km`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "type",
|
||||||
|
header: "Typ",
|
||||||
|
width: "12%",
|
||||||
|
render: (trip) => (
|
||||||
|
<StatusChip
|
||||||
|
label={trip.is_business ? "Služební" : "Soukromá"}
|
||||||
|
color={trip.is_business ? "success" : "warning"}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "actions",
|
||||||
|
header: "Akce",
|
||||||
|
width: "10%",
|
||||||
|
align: "right",
|
||||||
|
render: (trip) => (
|
||||||
|
<Box sx={{ display: "flex", gap: 0.5, justifyContent: "flex-end" }}>
|
||||||
|
<IconButton
|
||||||
|
size="small"
|
||||||
|
onClick={() => openEditModal(trip)}
|
||||||
|
aria-label="Upravit"
|
||||||
|
title="Upravit"
|
||||||
|
>
|
||||||
|
{EditIcon}
|
||||||
|
</IconButton>
|
||||||
|
<IconButton
|
||||||
|
size="small"
|
||||||
|
color="error"
|
||||||
|
onClick={() => setDeleteConfirm({ show: true, tripId: trip.id })}
|
||||||
|
aria-label="Smazat"
|
||||||
|
title="Smazat"
|
||||||
|
>
|
||||||
|
{DeleteIcon}
|
||||||
|
</IconButton>
|
||||||
|
</Box>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<Box>
|
||||||
<motion.div
|
<motion.div
|
||||||
className="admin-page-header"
|
|
||||||
initial={{ opacity: 0, y: 12 }}
|
initial={{ opacity: 0, y: 12 }}
|
||||||
animate={{ opacity: 1, y: 0 }}
|
animate={{ opacity: 1, y: 0 }}
|
||||||
transition={{ duration: 0.25 }}
|
transition={{ duration: 0.25 }}
|
||||||
>
|
>
|
||||||
<div>
|
<Box
|
||||||
<h1 className="admin-page-title">Kniha jízd</h1>
|
sx={{
|
||||||
<p className="admin-page-subtitle">
|
display: "flex",
|
||||||
{new Date().toLocaleDateString("cs-CZ", {
|
alignItems: "flex-start",
|
||||||
month: "long",
|
justifyContent: "space-between",
|
||||||
year: "numeric",
|
flexWrap: "wrap",
|
||||||
})}
|
gap: 2,
|
||||||
</p>
|
mb: 3,
|
||||||
</div>
|
}}
|
||||||
<div className="admin-page-actions">
|
>
|
||||||
<button
|
<Box>
|
||||||
onClick={openCreateModal}
|
<Typography variant="h4">Kniha jízd</Typography>
|
||||||
className="admin-btn admin-btn-primary"
|
<Typography variant="body2" color="text.secondary" sx={{ mt: 0.5 }}>
|
||||||
>
|
{new Date().toLocaleDateString("cs-CZ", {
|
||||||
<svg
|
month: "long",
|
||||||
width="20"
|
year: "numeric",
|
||||||
height="20"
|
})}
|
||||||
viewBox="0 0 24 24"
|
</Typography>
|
||||||
fill="none"
|
</Box>
|
||||||
stroke="currentColor"
|
<Button startIcon={PlusIcon} onClick={openCreateModal}>
|
||||||
strokeWidth="2"
|
|
||||||
>
|
|
||||||
<line x1="12" y1="5" x2="12" y2="19" />
|
|
||||||
<line x1="5" y1="12" x2="19" y2="12" />
|
|
||||||
</svg>
|
|
||||||
Přidat jízdu
|
Přidat jízdu
|
||||||
</button>
|
</Button>
|
||||||
</div>
|
</Box>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
|
|
||||||
{/* Stats Cards */}
|
{/* Stats Cards */}
|
||||||
<motion.div
|
<motion.div
|
||||||
className="admin-grid admin-grid-4"
|
|
||||||
initial={{ opacity: 0, y: 12 }}
|
initial={{ opacity: 0, y: 12 }}
|
||||||
animate={{ opacity: 1, y: 0 }}
|
animate={{ opacity: 1, y: 0 }}
|
||||||
transition={{ duration: 0.25, delay: 0.06 }}
|
transition={{ duration: 0.25, delay: 0.06 }}
|
||||||
>
|
>
|
||||||
<div className="admin-stat-card info">
|
<Box
|
||||||
<div className="admin-stat-icon info">
|
sx={{
|
||||||
<svg
|
display: "grid",
|
||||||
width="22"
|
gridTemplateColumns: {
|
||||||
height="22"
|
xs: "1fr",
|
||||||
viewBox="0 0 24 24"
|
sm: "1fr 1fr",
|
||||||
fill="none"
|
lg: "repeat(4, 1fr)",
|
||||||
stroke="currentColor"
|
},
|
||||||
strokeWidth="2"
|
gap: 2,
|
||||||
strokeLinecap="round"
|
}}
|
||||||
strokeLinejoin="round"
|
>
|
||||||
>
|
<StatCard
|
||||||
<line x1="12" y1="20" x2="12" y2="10" />
|
label="Počet jízd"
|
||||||
<line x1="18" y1="20" x2="18" y2="4" />
|
value={totals.count}
|
||||||
<line x1="6" y1="20" x2="6" y2="16" />
|
icon={TripsIcon}
|
||||||
</svg>
|
color="info"
|
||||||
</div>
|
/>
|
||||||
<div className="admin-stat-content">
|
<StatCard
|
||||||
<span className="admin-stat-value">{totals.count}</span>
|
label="Celkem naježděno"
|
||||||
<span className="admin-stat-label">Počet jízd</span>
|
value={`${formatKm(totals.total)} km`}
|
||||||
</div>
|
icon={TotalIcon}
|
||||||
</div>
|
color="default"
|
||||||
|
/>
|
||||||
<div className="admin-stat-card">
|
<StatCard
|
||||||
<div className="admin-stat-icon">
|
label="Služební"
|
||||||
<svg
|
value={`${formatKm(totals.business)} km`}
|
||||||
width="22"
|
icon={BusinessIcon}
|
||||||
height="22"
|
color="success"
|
||||||
viewBox="0 0 24 24"
|
/>
|
||||||
fill="none"
|
<StatCard
|
||||||
stroke="currentColor"
|
label="Soukromé"
|
||||||
strokeWidth="2"
|
value={`${formatKm(totals.private)} km`}
|
||||||
strokeLinecap="round"
|
icon={PrivateIcon}
|
||||||
strokeLinejoin="round"
|
color="warning"
|
||||||
>
|
/>
|
||||||
<path d="M22 12h-4l-3 9L9 3l-3 9H2" />
|
</Box>
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
<div className="admin-stat-content">
|
|
||||||
<span className="admin-stat-value">
|
|
||||||
{formatKm(totals.total)} km
|
|
||||||
</span>
|
|
||||||
<span className="admin-stat-label">Celkem naježděno</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="admin-stat-card success">
|
|
||||||
<div className="admin-stat-icon success">
|
|
||||||
<svg
|
|
||||||
width="22"
|
|
||||||
height="22"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
fill="none"
|
|
||||||
stroke="currentColor"
|
|
||||||
strokeWidth="2"
|
|
||||||
strokeLinecap="round"
|
|
||||||
strokeLinejoin="round"
|
|
||||||
>
|
|
||||||
<rect x="1" y="3" width="15" height="13" rx="2" ry="2" />
|
|
||||||
<path d="M16 8h2a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-1" />
|
|
||||||
<circle cx="5.5" cy="18" r="2" />
|
|
||||||
<circle cx="18.5" cy="18" r="2" />
|
|
||||||
<path d="M8 18h8" />
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
<div className="admin-stat-content">
|
|
||||||
<span className="admin-stat-value">
|
|
||||||
{formatKm(totals.business)} km
|
|
||||||
</span>
|
|
||||||
<span className="admin-stat-label">Služební</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="admin-stat-card warning">
|
|
||||||
<div className="admin-stat-icon warning">
|
|
||||||
<svg
|
|
||||||
width="22"
|
|
||||||
height="22"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
fill="none"
|
|
||||||
stroke="currentColor"
|
|
||||||
strokeWidth="2"
|
|
||||||
strokeLinecap="round"
|
|
||||||
strokeLinejoin="round"
|
|
||||||
>
|
|
||||||
<path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z" />
|
|
||||||
<polyline points="9 22 9 12 15 12 15 22" />
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
<div className="admin-stat-content">
|
|
||||||
<span className="admin-stat-value">
|
|
||||||
{formatKm(totals.private)} km
|
|
||||||
</span>
|
|
||||||
<span className="admin-stat-label">Soukromé</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</motion.div>
|
</motion.div>
|
||||||
|
|
||||||
{/* Recent Trips */}
|
{/* Recent Trips */}
|
||||||
<motion.div
|
<motion.div
|
||||||
className="admin-card mt-6"
|
|
||||||
initial={{ opacity: 0, y: 12 }}
|
initial={{ opacity: 0, y: 12 }}
|
||||||
animate={{ opacity: 1, y: 0 }}
|
animate={{ opacity: 1, y: 0 }}
|
||||||
transition={{ duration: 0.25, delay: 0.12 }}
|
transition={{ duration: 0.25, delay: 0.12 }}
|
||||||
>
|
>
|
||||||
<div className="admin-card-header flex-between">
|
<Card sx={{ mt: 3 }}>
|
||||||
<h2 className="admin-card-title">Poslední jízdy</h2>
|
<Box
|
||||||
<Link
|
sx={{
|
||||||
to="/trips/history"
|
display: "flex",
|
||||||
className="admin-btn admin-btn-secondary admin-btn-sm"
|
alignItems: "center",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
mb: 2,
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
Zobrazit historii
|
<Typography variant="h6">Poslední jízdy</Typography>
|
||||||
</Link>
|
<Button
|
||||||
</div>
|
component={RouterLink}
|
||||||
<div className="admin-card-body">
|
to="/trips/history"
|
||||||
{trips.length === 0 ? (
|
variant="outlined"
|
||||||
<div className="admin-empty-state">
|
color="inherit"
|
||||||
<div className="admin-empty-icon">
|
size="small"
|
||||||
<svg
|
>
|
||||||
width="28"
|
Zobrazit historii
|
||||||
height="28"
|
</Button>
|
||||||
viewBox="0 0 24 24"
|
</Box>
|
||||||
fill="none"
|
<DataTable<BackendTrip>
|
||||||
stroke="currentColor"
|
columns={columns}
|
||||||
strokeWidth="1.5"
|
rows={recentTrips}
|
||||||
strokeLinecap="round"
|
rowKey={(trip) => trip.id}
|
||||||
strokeLinejoin="round"
|
empty={
|
||||||
>
|
<Box sx={{ textAlign: "center", py: 6 }}>
|
||||||
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" />
|
<Typography color="text.secondary" gutterBottom>
|
||||||
<polyline points="14 2 14 8 20 8" />
|
Zatím nemáte žádné záznamy jízd.
|
||||||
<line x1="16" y1="13" x2="8" y2="13" />
|
</Typography>
|
||||||
<line x1="16" y1="17" x2="8" y2="17" />
|
<Button startIcon={PlusIcon} onClick={openCreateModal}>
|
||||||
</svg>
|
Přidat první jízdu
|
||||||
</div>
|
</Button>
|
||||||
<p>Zatím nemáte žádné záznamy jízd.</p>
|
</Box>
|
||||||
<button
|
}
|
||||||
onClick={openCreateModal}
|
/>
|
||||||
className="admin-btn admin-btn-primary"
|
</Card>
|
||||||
>
|
|
||||||
Přidat první jízdu
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div className="admin-table-responsive">
|
|
||||||
<table className="admin-table">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Datum</th>
|
|
||||||
<th>Vozidlo</th>
|
|
||||||
<th>Řidič</th>
|
|
||||||
<th>Trasa</th>
|
|
||||||
<th>Vzdálenost</th>
|
|
||||||
<th>Typ</th>
|
|
||||||
<th>Akce</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{trips.slice(0, 10).map((trip) => (
|
|
||||||
<tr key={trip.id}>
|
|
||||||
<td className="admin-mono">
|
|
||||||
{formatDate(trip.trip_date)}
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<span className="admin-badge">
|
|
||||||
{trip.vehicles?.spz ?? ""}
|
|
||||||
</span>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
{trip.users
|
|
||||||
? `${trip.users.first_name} ${trip.users.last_name}`
|
|
||||||
: ""}
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<span style={{ whiteSpace: "nowrap" }}>
|
|
||||||
{trip.route_from} → {trip.route_to}
|
|
||||||
</span>
|
|
||||||
</td>
|
|
||||||
<td className="admin-mono">
|
|
||||||
<strong>
|
|
||||||
{formatKm(
|
|
||||||
trip.distance ?? trip.end_km - trip.start_km,
|
|
||||||
)}{" "}
|
|
||||||
km
|
|
||||||
</strong>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<span
|
|
||||||
className={`admin-badge ${trip.is_business ? "admin-badge-success" : "admin-badge-warning"}`}
|
|
||||||
>
|
|
||||||
{trip.is_business ? "Služební" : "Soukromá"}
|
|
||||||
</span>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<div className="admin-table-actions">
|
|
||||||
<button
|
|
||||||
onClick={() => openEditModal(trip)}
|
|
||||||
className="admin-btn-icon"
|
|
||||||
title="Upravit"
|
|
||||||
aria-label="Upravit"
|
|
||||||
>
|
|
||||||
<svg
|
|
||||||
width="18"
|
|
||||||
height="18"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
fill="none"
|
|
||||||
stroke="currentColor"
|
|
||||||
strokeWidth="2"
|
|
||||||
strokeLinecap="round"
|
|
||||||
strokeLinejoin="round"
|
|
||||||
>
|
|
||||||
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7" />
|
|
||||||
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z" />
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
onClick={() =>
|
|
||||||
setDeleteConfirm({ show: true, tripId: trip.id })
|
|
||||||
}
|
|
||||||
className="admin-btn-icon danger"
|
|
||||||
title="Smazat"
|
|
||||||
aria-label="Smazat"
|
|
||||||
>
|
|
||||||
<svg
|
|
||||||
width="18"
|
|
||||||
height="18"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
fill="none"
|
|
||||||
stroke="currentColor"
|
|
||||||
strokeWidth="2"
|
|
||||||
strokeLinecap="round"
|
|
||||||
strokeLinejoin="round"
|
|
||||||
>
|
|
||||||
<polyline points="3 6 5 6 21 6" />
|
|
||||||
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
))}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</motion.div>
|
</motion.div>
|
||||||
|
|
||||||
{/* Add/Edit Modal */}
|
{/* Add/Edit Modal */}
|
||||||
<FormModal
|
<Modal
|
||||||
isOpen={showModal}
|
isOpen={showModal}
|
||||||
onClose={() => setShowModal(false)}
|
onClose={() => setShowModal(false)}
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
title={editingTrip ? "Upravit jízdu" : "Přidat jízdu"}
|
title={editingTrip ? "Upravit jízdu" : "Přidat jízdu"}
|
||||||
loading={submitMutation.isPending}
|
loading={submitMutation.isPending}
|
||||||
size="lg"
|
maxWidth="md"
|
||||||
>
|
>
|
||||||
<div className="admin-form">
|
<Box
|
||||||
<div className="admin-form-row">
|
sx={{
|
||||||
<FormField label="Vozidlo" error={errors.vehicle_id} required>
|
display: "grid",
|
||||||
<select
|
gridTemplateColumns: { xs: "1fr", sm: "1fr 1fr" },
|
||||||
value={form.vehicle_id}
|
gap: 2,
|
||||||
onChange={(e) => {
|
}}
|
||||||
handleVehicleChange(e.target.value);
|
>
|
||||||
setErrors((prev) => ({ ...prev, vehicle_id: "" }));
|
<Field label="Vozidlo" required error={errors.vehicle_id}>
|
||||||
}}
|
<Select
|
||||||
className="admin-form-select"
|
value={form.vehicle_id}
|
||||||
>
|
onChange={(value) => {
|
||||||
<option value="">Vyberte vozidlo</option>
|
handleVehicleChange(value);
|
||||||
{vehicles.map((v) => (
|
setErrors((prev) => ({ ...prev, vehicle_id: "" }));
|
||||||
<option key={v.id} value={v.id}>
|
}}
|
||||||
{v.spz} - {v.name}
|
error={!!errors.vehicle_id}
|
||||||
</option>
|
options={[
|
||||||
))}
|
{ value: "", label: "Vyberte vozidlo" },
|
||||||
</select>
|
...vehicles.map((v) => ({
|
||||||
</FormField>
|
value: String(v.id),
|
||||||
|
label: `${v.spz} - ${v.name}`,
|
||||||
<FormField label="Datum jízdy" error={errors.trip_date} required>
|
})),
|
||||||
<AdminDatePicker
|
]}
|
||||||
mode="date"
|
|
||||||
value={form.trip_date}
|
|
||||||
onChange={(val: string) => {
|
|
||||||
setForm({ ...form, trip_date: val });
|
|
||||||
setErrors((prev) => ({ ...prev, trip_date: "" }));
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</FormField>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="admin-form-row admin-form-row-3">
|
|
||||||
<FormField
|
|
||||||
label="Počáteční stav km"
|
|
||||||
error={errors.start_km}
|
|
||||||
required
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="number"
|
|
||||||
inputMode="numeric"
|
|
||||||
value={form.start_km}
|
|
||||||
onChange={(e) => {
|
|
||||||
setForm({ ...form, start_km: e.target.value });
|
|
||||||
setErrors((prev) => ({ ...prev, start_km: "" }));
|
|
||||||
}}
|
|
||||||
className="admin-form-input"
|
|
||||||
min="0"
|
|
||||||
/>
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label="Konečný stav km" error={errors.end_km} required>
|
|
||||||
<input
|
|
||||||
type="number"
|
|
||||||
inputMode="numeric"
|
|
||||||
value={form.end_km}
|
|
||||||
onChange={(e) => {
|
|
||||||
setForm({ ...form, end_km: e.target.value });
|
|
||||||
setErrors((prev) => ({ ...prev, end_km: "" }));
|
|
||||||
}}
|
|
||||||
className="admin-form-input"
|
|
||||||
min="0"
|
|
||||||
/>
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label="Vzdálenost">
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
value={`${formatKm(calculateDistance())} km`}
|
|
||||||
className="admin-form-input"
|
|
||||||
readOnly
|
|
||||||
disabled
|
|
||||||
/>
|
|
||||||
</FormField>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="admin-form-row">
|
|
||||||
<FormField label="Místo odjezdu" error={errors.route_from} required>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
value={form.route_from}
|
|
||||||
onChange={(e) => {
|
|
||||||
setForm({ ...form, route_from: e.target.value });
|
|
||||||
setErrors((prev) => ({ ...prev, route_from: "" }));
|
|
||||||
}}
|
|
||||||
className="admin-form-input"
|
|
||||||
placeholder="Např. Praha"
|
|
||||||
/>
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label="Místo příjezdu" error={errors.route_to} required>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
value={form.route_to}
|
|
||||||
onChange={(e) => {
|
|
||||||
setForm({ ...form, route_to: e.target.value });
|
|
||||||
setErrors((prev) => ({ ...prev, route_to: "" }));
|
|
||||||
}}
|
|
||||||
className="admin-form-input"
|
|
||||||
placeholder="Např. Brno"
|
|
||||||
/>
|
|
||||||
</FormField>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<FormField label="Typ jízdy">
|
|
||||||
<select
|
|
||||||
value={form.is_business}
|
|
||||||
onChange={(e) =>
|
|
||||||
setForm({
|
|
||||||
...form,
|
|
||||||
is_business: parseInt(e.target.value),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
className="admin-form-select"
|
|
||||||
>
|
|
||||||
<option value={1}>Služební</option>
|
|
||||||
<option value={0}>Soukromá</option>
|
|
||||||
</select>
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label="Poznámky">
|
|
||||||
<textarea
|
|
||||||
value={form.notes}
|
|
||||||
onChange={(e) => setForm({ ...form, notes: e.target.value })}
|
|
||||||
className="admin-form-textarea"
|
|
||||||
rows={2}
|
|
||||||
placeholder="Volitelné poznámky..."
|
|
||||||
/>
|
/>
|
||||||
</FormField>
|
</Field>
|
||||||
</div>
|
|
||||||
</FormModal>
|
|
||||||
|
|
||||||
<ConfirmModal
|
<Field label="Datum jízdy" required error={errors.trip_date}>
|
||||||
|
<DateField
|
||||||
|
value={form.trip_date}
|
||||||
|
onChange={(val) => {
|
||||||
|
setForm({ ...form, trip_date: val });
|
||||||
|
setErrors((prev) => ({ ...prev, trip_date: "" }));
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: "grid",
|
||||||
|
gridTemplateColumns: { xs: "1fr", sm: "1fr 1fr 1fr" },
|
||||||
|
gap: 2,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Field label="Počáteční stav km" required error={errors.start_km}>
|
||||||
|
<TextField
|
||||||
|
type="number"
|
||||||
|
inputMode="numeric"
|
||||||
|
value={form.start_km}
|
||||||
|
error={!!errors.start_km}
|
||||||
|
onChange={(e) => {
|
||||||
|
setForm({ ...form, start_km: e.target.value });
|
||||||
|
setErrors((prev) => ({ ...prev, start_km: "" }));
|
||||||
|
}}
|
||||||
|
slotProps={{ htmlInput: { min: 0 } }}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
|
||||||
|
<Field label="Konečný stav km" required error={errors.end_km}>
|
||||||
|
<TextField
|
||||||
|
type="number"
|
||||||
|
inputMode="numeric"
|
||||||
|
value={form.end_km}
|
||||||
|
error={!!errors.end_km}
|
||||||
|
onChange={(e) => {
|
||||||
|
setForm({ ...form, end_km: e.target.value });
|
||||||
|
setErrors((prev) => ({ ...prev, end_km: "" }));
|
||||||
|
}}
|
||||||
|
slotProps={{ htmlInput: { min: 0 } }}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
|
||||||
|
<Field label="Vzdálenost">
|
||||||
|
<TextField
|
||||||
|
type="text"
|
||||||
|
value={`${formatKm(calculateDistance())} km`}
|
||||||
|
disabled
|
||||||
|
slotProps={{ htmlInput: { readOnly: true } }}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: "grid",
|
||||||
|
gridTemplateColumns: { xs: "1fr", sm: "1fr 1fr" },
|
||||||
|
gap: 2,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Field label="Místo odjezdu" required error={errors.route_from}>
|
||||||
|
<TextField
|
||||||
|
type="text"
|
||||||
|
value={form.route_from}
|
||||||
|
error={!!errors.route_from}
|
||||||
|
onChange={(e) => {
|
||||||
|
setForm({ ...form, route_from: e.target.value });
|
||||||
|
setErrors((prev) => ({ ...prev, route_from: "" }));
|
||||||
|
}}
|
||||||
|
placeholder="Např. Praha"
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
|
||||||
|
<Field label="Místo příjezdu" required error={errors.route_to}>
|
||||||
|
<TextField
|
||||||
|
type="text"
|
||||||
|
value={form.route_to}
|
||||||
|
error={!!errors.route_to}
|
||||||
|
onChange={(e) => {
|
||||||
|
setForm({ ...form, route_to: e.target.value });
|
||||||
|
setErrors((prev) => ({ ...prev, route_to: "" }));
|
||||||
|
}}
|
||||||
|
placeholder="Např. Brno"
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Field label="Typ jízdy">
|
||||||
|
<Select
|
||||||
|
value={String(form.is_business)}
|
||||||
|
onChange={(value) =>
|
||||||
|
setForm({ ...form, is_business: parseInt(value) })
|
||||||
|
}
|
||||||
|
options={[
|
||||||
|
{ value: "1", label: "Služební" },
|
||||||
|
{ value: "0", label: "Soukromá" },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
|
||||||
|
<Field label="Poznámky">
|
||||||
|
<TextField
|
||||||
|
multiline
|
||||||
|
minRows={2}
|
||||||
|
value={form.notes}
|
||||||
|
onChange={(e) => setForm({ ...form, notes: e.target.value })}
|
||||||
|
placeholder="Volitelné poznámky..."
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
|
<ConfirmDialog
|
||||||
isOpen={deleteConfirm.show}
|
isOpen={deleteConfirm.show}
|
||||||
onClose={() => setDeleteConfirm({ show: false, tripId: null })}
|
onClose={() => setDeleteConfirm({ show: false, tripId: null })}
|
||||||
onConfirm={() => handleDelete(deleteConfirm.tripId!)}
|
onConfirm={() => handleDelete(deleteConfirm.tripId!)}
|
||||||
@@ -657,9 +693,9 @@ export default function Trips() {
|
|||||||
message="Opravdu chcete smazat tento záznam?"
|
message="Opravdu chcete smazat tento záznam?"
|
||||||
confirmText="Smazat"
|
confirmText="Smazat"
|
||||||
cancelText="Zrušit"
|
cancelText="Zrušit"
|
||||||
type="danger"
|
confirmVariant="danger"
|
||||||
loading={deleteMutation.isPending}
|
loading={deleteMutation.isPending}
|
||||||
/>
|
/>
|
||||||
</div>
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user