import React, { useEffect, useState } from 'react' import { useParams, Link } from 'react-router-dom' interface File { id: string name: string description?: string body?: string contract_id?: string version: number created_at: string } export function FileDetail() { const { contractId, fileId } = useParams<{ contractId: string; fileId: string }>() const [file, setFile] = useState(null) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) useEffect(() => { async function fetchFile() { if (!fileId) return try { setLoading(true) const response = await fetch(`/api/v1/files/${fileId}`) if (!response.ok) { throw new Error(`Failed to fetch file: ${response.statusText}`) } const data = await response.json() setFile(data) } catch (err) { setError(err instanceof Error ? err.message : 'Unknown error') } finally { setLoading(false) } } fetchFile() }, [fileId]) if (loading) { return (
Loading file...
) } if (error) { return (
Error: {error}
Back to Contract
) } if (!file) { return (
File not found
Back to Contract
) } return (
Back to Contract

{file.name}

{file.description && (

{file.description}

)}
Version: {file.version} Created: {new Date(file.created_at).toLocaleString()}
{file.body ? (
{file.body}
) : (

No content

)}
) }