import React, { useState, useEffect } from "react"; import { useParams, useNavigate } from "react-router"; import { toast } from "react-toastify"; import { getWorkOrderById } from "../api"; import "./WorkOrderViewPage.css"; export default function WorkOrderViewPage() { const { id } = useParams(); const navigate = useNavigate(); const [wo, setWo] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { const load = async () => { try { const data = await getWorkOrderById(id); setWo(data); } catch (err) { toast.error("Failed to load work order"); } finally { setLoading(false); } }; load(); }, [id]); if (loading) return
Loading...
; if (!wo) return
Work order not found.
; const statusClass = (wo.status || "").toLowerCase().replace(/\s+/g, "-"); return (
  1. { e.preventDefault(); navigate("/workorders"); }}> Work Orders
  2. {wo.workOrderNumber}

{wo.title}

{wo.status}

Details

WO # {wo.workOrderNumber}
Priority {wo.priority || "—"}
Location {wo.location || "—"}
Assigned To {wo.assignedTo || "—"}
Created {wo.createdDate || "—"}
Due Date {wo.dueDate || "—"}
PO {wo.po || "—"}
TT {wo.tt || "—"}

Description

{wo.description || "No description provided."}

{wo.comments && wo.comments.length > 0 && (

Activity ({wo.comments.length})

{wo.comments.map((c) => (
{c.userName || c.commenter || "System"} {c.createdDate ? new Date(c.createdDate).toLocaleString() : ""}
{c.commenttext}
))}
)}
); }