diff --git a/frontend/app/(dashboard)/assets/[id]/page.tsx b/frontend/app/(dashboard)/assets/[id]/page.tsx index 4890b274..ed1f5d15 100644 --- a/frontend/app/(dashboard)/assets/[id]/page.tsx +++ b/frontend/app/(dashboard)/assets/[id]/page.tsx @@ -1 +1,740 @@ +// frontend/app/(dashboard)/assets/[id]/page.tsx +"use client"; + +import { useState } from "react"; +import { useParams, useRouter } from "next/navigation"; +import { + ArrowLeft, + Clock, + FileText, + Hash, + Wrench, + FolderOpen, + StickyNote, + Pencil, + ArrowRightLeft, + RefreshCw, + CheckCircle, + Upload, + Plus, + Trash2, +} from "lucide-react"; +import { format } from "date-fns"; +import { Button } from "@/components/ui/button"; +import { StatusBadge } from "@/components/assets/status-badge"; +import { ConditionBadge } from "@/components/assets/condition-badge"; +import { ConfirmDialog } from "@/components/ui/confirm-dialog"; +import { AssetQRCode } from "@/opsce/features/assets/AssetQRCode"; +import { AssetHistoryTimeline } from "@/opsce/features/assets/AssetHistoryTimeline"; +import { DeleteAssetDialog } from "@/opsce/features/assets/DeleteAssetDialog"; +import { DownloadAssetReportButton } from "@/opsce/features/assets/DownloadAssetReportButton"; +import { + useAsset, + useAssetDocuments, + useMaintenanceRecords, + useAssetNotes, + useDeleteAsset, + useUploadDocument, + useDeleteDocument, + useCreateMaintenanceRecord, + useUpdateMaintenanceStatus, + useCreateNote, + useDeleteNote, +} from "@/lib/query/hooks/useAsset"; +import type { MaintenanceType } from "@/lib/query/types/asset"; + +type Tab = "overview" | "history" | "maintenance" | "documents" | "notes"; + +// ── Skeleton ──────────────────────────────────────────────────────────────── +function Skeleton({ className }: { className?: string }) { + return ( +
+ ); +} + +// ── DetailRow ──────────────────────────────────────────────────────────────── +function DetailRow({ + label, + value, + fallback = "—", +}: { + label: string; + value?: string | null; + fallback?: string; +}) { + return ( +
+
{label}
+
{value || fallback}
+
+ ); +} + +// ── MaintenanceStatusBadge ─────────────────────────────────────────────────── +const maintenanceStatusColors: Record = { + SCHEDULED: "bg-blue-100 text-blue-700", + IN_PROGRESS: "bg-yellow-100 text-yellow-700", + COMPLETED: "bg-green-100 text-green-700", + CANCELLED: "bg-gray-100 text-gray-500", +}; + +function MaintenanceStatusBadge({ status }: { status: string }) { + const cls = maintenanceStatusColors[status] ?? "bg-gray-100 text-gray-500"; + return ( + + {status.replace(/_/g, " ")} + + ); +} + +// ── ScheduleMaintenanceModal ───────────────────────────────────────────────── +function ScheduleMaintenanceModal({ + assetId, + onClose, +}: { + assetId: string; + onClose: () => void; +}) { + const [form, setForm] = useState({ + type: "PREVENTIVE" as MaintenanceType, + description: "", + scheduledDate: "", + notes: "", + }); + const { mutate, isPending } = useCreateMaintenanceRecord(assetId, { + onSuccess: onClose, + }); + + return ( +
+
+
+

+ Schedule Maintenance +

+
+
+ + +
+
+ + setForm({ ...form, description: e.target.value })} + /> +
+
+ + setForm({ ...form, scheduledDate: e.target.value })} + /> +
+
+ +