| 1 | "use client"; |
| 2 | import { useEffect, useState } from "react"; |
| 3 | import Link from "next/link"; |
| 4 | import { api, Investigation } from "@/lib/api"; |
| 5 | |
| 6 | export default function Investigations() { |
| 7 | const [invs, setInvs] = useState<Investigation[]>([]); |
| 8 | const [err, setErr] = useState<string | null>(null); |
| 9 | |
| 10 | useEffect(() => { |
| 11 | api.investigations().then(setInvs) |
| 12 | .catch((e) => setErr(e.status === 401 ? "Sign in to view investigations." : String(e))); |
| 13 | }, []); |
| 14 | |
| 15 | return ( |
| 16 | <div> |
| 17 | <h1>Investigations</h1> |
| 18 | {err && <div className="badge danger">{err}</div>} |
| 19 | <div className="card" style={{ marginTop: 12 }}> |
| 20 | <table> |
| 21 | <thead><tr><th>Title</th><th>Status</th><th>Priority</th><th>Created</th></tr></thead> |
| 22 | <tbody> |
| 23 | {invs.map((i) => ( |
| 24 | <tr key={i.id}> |
| 25 | <td><Link href={`/investigations/${i.id}`}>{i.title}</Link></td> |
| 26 | <td><span className="badge">{i.status}</span></td> |
| 27 | <td>{i.priority}</td> |
| 28 | <td className="muted">{new Date(i.created_at).toLocaleDateString()}</td> |
| 29 | </tr> |
| 30 | ))} |
| 31 | {!invs.length && !err && <tr><td colSpan={4} className="muted">No investigations.</td></tr>} |
| 32 | </tbody> |
| 33 | </table> |
| 34 | </div> |
| 35 | </div> |
| 36 | ); |
| 37 | } |