import { useEffect, useState } from "react"; import { Link, useParams } from "react-router-dom"; import { useTranslation } from "react-i18next"; import { api } from "../api/client"; import type { VehicleDetail as VehicleDetailData } from "../api/types"; import { useLocaleFormat } from "../i18n/format"; import { SeverityBadge, StatusBadge } from "../components/Badge"; import { Icon } from "../components/Icons"; import { ErrorState, LoadingState, PageHeader } from "../components/PageChrome"; const TABS = ["overview", "bookings", "inspections", "maintenance", "quality"] as const; type Tab = (typeof TABS)[number]; export function VehicleDetail() { const { t } = useTranslation(["fleet", "bookings", "quality"]); const { formatNumber, formatShortDate } = useLocaleFormat(); const { publicRef } = useParams<{ publicRef: string }>(); const [vehicle, setVehicle] = useState(null); const [error, setError] = useState(null); const [tab, setTab] = useState("overview"); useEffect(() => { if (!publicRef) return; setVehicle(null); setError(null); api .get(`/api/v1/vehicles/${publicRef}`) .then(setVehicle) .catch(() => setError(t("detail.notFound"))); }, [publicRef]); if (error) return ; if (!vehicle) return ; return (
{t("detail.backLink")} {vehicle.attention && {t("detail.needsAttention")}}
} />
{TABS.map((tb) => ( ))}
{tab === "overview" && (
{t("detail.overview.registration")}
{vehicle.registration_number}
{t("detail.overview.modelYear")}
{vehicle.model_year}
{t("detail.overview.location")}
{vehicle.location}
{t("detail.overview.odometer")}
{formatNumber(vehicle.odometer_km)} km
{t("detail.overview.nextService")}
{formatNumber(vehicle.next_service_km)} km
{t("detail.overview.active")}
{vehicle.active ? t("detail.yes") : t("detail.no")}
)} {tab === "bookings" && (
    {vehicle.bookings.length === 0 &&
  • {t("detail.noBookings")}
  • } {vehicle.bookings.map((b) => (
  • {b.public_ref} {formatShortDate(b.starts_at)} → {formatShortDate(b.ends_at)}
  • ))}
)} {tab === "inspections" && (
    {vehicle.inspections.length === 0 &&
  • {t("detail.noInspections")}
  • } {vehicle.inspections.map((i) => (
  • {t(`fleet:detail.inspectionTypes.${i.type}`, { defaultValue: i.type })} {formatNumber(i.odometer_km)} km {t("detail.fuel", { percent: i.fuel_level_percent })} {i.damage_reported && {t("detail.damage")}} {i.technical_warning && {t("detail.technicalWarning")}}
  • ))}
)} {tab === "maintenance" && (
    {vehicle.maintenance.length === 0 &&
  • {t("detail.noMaintenance")}
  • } {vehicle.maintenance.map((m) => (
  • {t(`fleet:detail.maintenanceCategories.${m.category}`, { defaultValue: m.category })} {m.summary}
  • ))}
)} {tab === "quality" && (
    {vehicle.quality_issues.length === 0 &&
  • {t("detail.noQualityIssues")}
  • } {vehicle.quality_issues.map((q) => (
  • {q.public_ref} {t(`quality:ruleTypes.${q.rule_type}`, { defaultValue: q.rule_type.replace(/_/g, " ") })}
  • ))}
)} ); }