"use client"; import { useEffect, useState } from "react"; import { useParams, useRouter } from "next/navigation"; import { Spinner, EmptyState, Badge, PageHeader } from "@/src/Components/UI"; import { tripService } from "@/src/services/trip.service"; import { getStoredToken } from "@/src/lib/auth"; import type { Trip } from "@/src/types/trip"; import { TRIP_STATUS_MAP } from "@/src/types/trip"; function fmtDateTime(iso?: string | null): string { if (!iso) return "—"; return new Date(iso).toLocaleString("ar-SA", { dateStyle: "medium", timeStyle: "short" }); } export default function ArchivedTripDetailPage() { const params = useParams(); const router = useRouter(); const tripId = params?.tripId as string; const [trip, setTrip] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { if (!tripId) return; let cancelled = false; (async () => { setLoading(true); setError(null); try { const token = getStoredToken(); // Archived trips must go through the archived endpoint — // the normal /trip/:id endpoint won't return soft-deleted trips. const res = await tripService.getArchivedById(tripId, token); if (!cancelled) setTrip((res as unknown as { data: Trip }).data); } catch { if (!cancelled) setError("لم يتم العثور على هذه الرحلة في الأرشيف."); } finally { if (!cancelled) setLoading(false); } })(); return () => { cancelled = true; }; }, [tripId]); if (loading) { return (
جارٍ التحميل…
); } // Edge case: invalid/missing/unreachable trip ID if (error || !trip) { return ( router.push("/dashboard/trips")} className="text-sm font-semibold text-[var(--color-brand-600)] underline" > العودة إلى قائمة الرحلات } /> ); } const statusConfig = TRIP_STATUS_MAP[trip.status]; return (
} />
وقت البدء
{fmtDateTime(trip.startTime)}
وقت الانتهاء
{fmtDateTime(trip.endTime)}
تاريخ الأرشفة
{fmtDateTime(trip.deletedAt)}
{trip.driver && (
السائق
{trip.driver.name}
)}
); }