138 lines
4.6 KiB
TypeScript
138 lines
4.6 KiB
TypeScript
import { Link } from '@inertiajs/react';
|
|
|
|
export type PublicDocument = {
|
|
id: number;
|
|
title: string;
|
|
description: string | null;
|
|
issuer: string | null;
|
|
document_number: string | null;
|
|
document_date: string | null;
|
|
applicable_from: string | null;
|
|
applicable_until: string | null;
|
|
source_url: string | null;
|
|
source_confirmation: string;
|
|
usage_notice: string | null;
|
|
view_url: string | null;
|
|
download_url: string;
|
|
context_actions: { href: string; label: string }[];
|
|
};
|
|
|
|
export function PublicDocumentContent({
|
|
resource: r,
|
|
detail = false,
|
|
back = '/documentos',
|
|
}: {
|
|
resource: PublicDocument;
|
|
detail?: boolean;
|
|
back?: string;
|
|
}) {
|
|
return (
|
|
<>
|
|
{detail ? (
|
|
<h1 className="text-3xl font-bold break-words">{r.title}</h1>
|
|
) : (
|
|
<h2 className="text-xl font-bold break-words">{r.title}</h2>
|
|
)}
|
|
{r.description && (
|
|
<p className="whitespace-pre-line">{r.description}</p>
|
|
)}
|
|
<dl className="grid gap-3 text-sm sm:grid-cols-2">
|
|
<div>
|
|
<dt className="font-semibold">Entidade emissora / autor</dt>
|
|
<dd>{r.issuer ?? 'Não indicada'}</dd>
|
|
</div>
|
|
{r.document_number && (
|
|
<div>
|
|
<dt className="font-semibold">Número</dt>
|
|
<dd>{r.document_number}</dd>
|
|
</div>
|
|
)}
|
|
{r.document_date && (
|
|
<div>
|
|
<dt className="font-semibold">Data do documento</dt>
|
|
<dd>{r.document_date}</dd>
|
|
</div>
|
|
)}
|
|
{r.applicable_from && (
|
|
<div>
|
|
<dt className="font-semibold">
|
|
Data de início indicada no registo
|
|
</dt>
|
|
<dd>{r.applicable_from}</dd>
|
|
</div>
|
|
)}
|
|
{r.applicable_until && (
|
|
<div>
|
|
<dt className="font-semibold">
|
|
Data final indicada no registo
|
|
</dt>
|
|
<dd>{r.applicable_until}</dd>
|
|
</div>
|
|
)}
|
|
<div>
|
|
<dt className="font-semibold">Fonte</dt>
|
|
<dd>
|
|
{r.source_confirmation === 'official_confirmed'
|
|
? 'Fonte oficial'
|
|
: r.source_url
|
|
? 'Fonte identificada'
|
|
: 'Não indicada'}
|
|
</dd>
|
|
</div>
|
|
</dl>
|
|
{r.usage_notice && (
|
|
<p
|
|
role="note"
|
|
className="rounded border border-amber-200 bg-amber-50 p-3 text-sm"
|
|
>
|
|
{r.usage_notice}
|
|
</p>
|
|
)}
|
|
<div className="flex flex-wrap gap-4 pt-2">
|
|
{!detail && (
|
|
<Link
|
|
className="underline"
|
|
href={`/documentos/${r.id}?${new URLSearchParams({ back }).toString()}`}
|
|
>
|
|
Consultar ficha
|
|
</Link>
|
|
)}
|
|
{r.view_url && (
|
|
<a
|
|
className="underline"
|
|
href={r.view_url}
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
>
|
|
Consultar ficheiro
|
|
</a>
|
|
)}
|
|
<a className="underline" href={r.download_url}>
|
|
Descarregar documento
|
|
</a>
|
|
{r.source_url && (
|
|
<a
|
|
className="underline"
|
|
href={r.source_url}
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
>
|
|
{r.source_confirmation === 'official_confirmed'
|
|
? 'Abrir fonte oficial'
|
|
: 'Abrir fonte'}
|
|
</a>
|
|
)}
|
|
{r.context_actions.map((action) => (
|
|
<Link
|
|
key={action.href}
|
|
className="underline"
|
|
href={action.href}
|
|
>
|
|
{action.label}
|
|
</Link>
|
|
))}
|
|
</div>
|
|
</>
|
|
);
|
|
}
|