122 lines
4.6 KiB
TypeScript
122 lines
4.6 KiB
TypeScript
import { Link, useForm } from '@inertiajs/react';
|
|
import { Frame, card, button } from '@/pages/investment/shared';
|
|
import type { Criterion } from './shared';
|
|
type Reference = {
|
|
code: string;
|
|
hash: string;
|
|
edition: string;
|
|
provenance: { url: string; checked_on: string; reference: string }[];
|
|
draft: {
|
|
title: string;
|
|
summary: string;
|
|
manager_name: string;
|
|
coverage_text: string;
|
|
sectors_text: string;
|
|
criteria: Criterion[];
|
|
windows: {
|
|
code: string;
|
|
title: string;
|
|
end_on?: string;
|
|
coverage_text: string;
|
|
criteria: Criterion[];
|
|
}[];
|
|
};
|
|
};
|
|
function Criteria({ items }: { items: Criterion[] }) {
|
|
return (
|
|
<ul>
|
|
{items.map((item) => (
|
|
<li key={item.code} className="my-3">
|
|
<strong>{item.question}</strong>
|
|
<p>{item.explanation}</p>
|
|
<p>
|
|
Resposta indicada:{' '}
|
|
{item.expected === 'yes' ? 'Sim' : 'Não'};{' '}
|
|
{item.applies_to === 'individual'
|
|
? 'pessoas singulares'
|
|
: item.applies_to === 'entity'
|
|
? 'entidades'
|
|
: 'todos os candidatos'}
|
|
. Fonte: {item.source_reference}.
|
|
</p>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
);
|
|
}
|
|
export default function ReferencePage({ reference }: { reference: Reference }) {
|
|
const form = useForm({ hash: reference.hash });
|
|
return (
|
|
<Frame title="Preparar referência de fundo">
|
|
<Link className="underline" href="/management/fundos">
|
|
Voltar à gestão
|
|
</Link>
|
|
<section className={card}>
|
|
<h2 className="text-xl font-semibold">
|
|
{reference.draft.title}
|
|
</h2>
|
|
<p>{reference.draft.summary}</p>
|
|
<p>Gestão: {reference.draft.manager_name}</p>
|
|
<p>{reference.draft.coverage_text}</p>
|
|
<p>{reference.draft.sectors_text}</p>
|
|
<Criteria items={reference.draft.criteria} />
|
|
</section>
|
|
<section className={card}>
|
|
<h2>Chamadas documentadas</h2>
|
|
{reference.draft.windows.map((window) => (
|
|
<article key={window.code}>
|
|
<h3 className="font-semibold">{window.title}</h3>
|
|
{window.end_on && (
|
|
<p>
|
|
Prazo indicado na fonte: {window.end_on}.
|
|
Consulte o estado calculado na ficha; esta data
|
|
não é renovada automaticamente.
|
|
</p>
|
|
)}
|
|
<p>{window.coverage_text}</p>
|
|
<Criteria items={window.criteria} />
|
|
</article>
|
|
))}
|
|
</section>
|
|
<section className={card}>
|
|
<h2>Fontes e edições utilizadas</h2>
|
|
{reference.provenance.map((source) => (
|
|
<p key={source.url}>
|
|
<a
|
|
className="underline"
|
|
href={source.url}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
>
|
|
{source.reference}
|
|
</a>{' '}
|
|
— consultada em {source.checked_on}
|
|
</p>
|
|
))}
|
|
</section>
|
|
<form
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
form.post(
|
|
`/management/fundos/referencias/${reference.code}/preparar`,
|
|
);
|
|
}}
|
|
>
|
|
<p>
|
|
Prepara um rascunho para edição. A publicação é feita
|
|
posteriormente no editor. Se a ficha já existir, será aberta
|
|
sem substituir o seu conteúdo.
|
|
</p>
|
|
{Object.values(form.errors).map((error, index) => (
|
|
<p role="alert" key={index}>
|
|
{error}
|
|
</p>
|
|
))}
|
|
<button className={button} disabled={form.processing}>
|
|
Preparar ou abrir ficha existente
|
|
</button>
|
|
</form>
|
|
</Frame>
|
|
);
|
|
}
|