import { useState, useEffect } from "react"; import { useParams, useNavigate } from "react-router-dom"; import api from "../api/client"; import { useAuth } from "../auth/AuthContext"; import ConfirmDialog from "../components/ConfirmDialog"; const categoryStyle = (cat) => { switch (cat) { case "issue": return { backgroundColor: "var(--danger-bg)", color: "var(--danger-text)" }; case "maintenance": return { backgroundColor: "var(--warning-bg, rgba(245,158,11,0.15))", color: "var(--warning-text, #f59e0b)" }; case "installation": return { backgroundColor: "var(--success-bg)", color: "var(--success-text)" }; default: return { backgroundColor: "var(--bg-card-hover)", color: "var(--text-muted)" }; } }; function Field({ label, children }) { return (
{label}
{children || "-"}
); } export default function NoteDetail() { const { id } = useParams(); const navigate = useNavigate(); const { hasPermission } = useAuth(); const canEdit = hasPermission("equipment", "edit"); const [note, setNote] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(""); const [showDelete, setShowDelete] = useState(false); useEffect(() => { loadNote(); }, [id]); const loadNote = async () => { setLoading(true); try { const data = await api.get(`/equipment/notes/${id}`); setNote(data); } catch (err) { setError(err.message); } finally { setLoading(false); } }; const handleDelete = async () => { try { await api.delete(`/equipment/notes/${id}`); navigate("/equipment/notes"); } catch (err) { setError(err.message); setShowDelete(false); } }; if (loading) { return (
Loading...
); } if (error && !note) { return (
{error}
); } if (!note) return null; return (

{note.title || "Untitled Note"}

{note.category || "general"}
{canEdit && (
)}
{error && (
{error}
)}
{/* Left Column */}
{/* Note Content */}

Content

{note.content || "No content."}
{/* Timestamps */}

Details

{note.category || "general"} {note.created_by} {note.id} {note.created_at} {note.updated_at}
{/* Right Column */}
{/* Linked Device */}

Linked Device

{note.device_id ? (

{note.device_name || "Unnamed Device"}

{note.device_id}

) : (

No device linked.

)}
{/* Linked User */}

Linked User

{note.user_id ? (

{note.user_name || "Unnamed User"}

{note.user_id}

) : (

No user linked.

)}
setShowDelete(false)} />
); }