commit16
This commit is contained in:
@@ -0,0 +1,943 @@
|
||||
import { Link, router, useForm } from '@inertiajs/react';
|
||||
import { useState } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { portalRequest, PortalApiError } from '@/lib/portal-api';
|
||||
import { Frame, card, button, input } from '@/pages/investment/shared';
|
||||
import type { Criterion } from './shared';
|
||||
|
||||
type Choice = { id: string | number; name?: string; title?: string };
|
||||
type WindowDraft = {
|
||||
code: string;
|
||||
title: string;
|
||||
mode: string;
|
||||
start_on: string;
|
||||
end_on: string;
|
||||
coverage: string;
|
||||
coverage_text: string;
|
||||
territory_ids: string[];
|
||||
source_url: string;
|
||||
source_reference: string;
|
||||
checked_on: string;
|
||||
application_url: string;
|
||||
criteria: Criterion[];
|
||||
};
|
||||
type Draft = {
|
||||
title: string;
|
||||
kind: string;
|
||||
summary: string;
|
||||
manager_name: string;
|
||||
manager_organization_id: string;
|
||||
source_url: string;
|
||||
source_reference: string;
|
||||
source_checked_on: string;
|
||||
source_published_on: string;
|
||||
source_status: string;
|
||||
coverage: string;
|
||||
coverage_text: string;
|
||||
territory_ids: string[];
|
||||
sectors_scope: string;
|
||||
sectors_text: string;
|
||||
sector_ids: number[];
|
||||
resource_ids: number[];
|
||||
criteria: Criterion[];
|
||||
windows: WindowDraft[];
|
||||
};
|
||||
type RecordData = {
|
||||
id: string;
|
||||
code: string;
|
||||
version: number;
|
||||
draft: Draft;
|
||||
published: boolean;
|
||||
};
|
||||
type Plan = { version: number; hash: string; payload: Draft };
|
||||
const empty: Draft = {
|
||||
title: '',
|
||||
kind: 'fund',
|
||||
summary: '',
|
||||
manager_name: '',
|
||||
manager_organization_id: '',
|
||||
source_url: '',
|
||||
source_reference: '',
|
||||
source_checked_on: '',
|
||||
source_published_on: '',
|
||||
source_status: 'unknown',
|
||||
coverage: 'unknown',
|
||||
coverage_text: '',
|
||||
territory_ids: [],
|
||||
sectors_scope: 'unknown',
|
||||
sectors_text: '',
|
||||
sector_ids: [],
|
||||
resource_ids: [],
|
||||
criteria: [],
|
||||
windows: [],
|
||||
};
|
||||
const newCode = () => crypto.randomUUID();
|
||||
function Field({ label, children }: { label: string; children: ReactNode }) {
|
||||
return (
|
||||
<label className="my-3 block">
|
||||
<span className="block font-medium">{label}</span>
|
||||
{children}
|
||||
</label>
|
||||
);
|
||||
}
|
||||
function Multi({
|
||||
label,
|
||||
options,
|
||||
values,
|
||||
onChange,
|
||||
}: {
|
||||
label: string;
|
||||
options: Choice[];
|
||||
values: (string | number)[];
|
||||
onChange: (ids: string[]) => void;
|
||||
}) {
|
||||
return (
|
||||
<Field label={label}>
|
||||
<select
|
||||
className={input}
|
||||
multiple
|
||||
value={values.map(String)}
|
||||
onChange={(e) =>
|
||||
onChange(
|
||||
Array.from(
|
||||
e.target.selectedOptions,
|
||||
(option) => option.value,
|
||||
),
|
||||
)
|
||||
}
|
||||
>
|
||||
{options.map((option) => (
|
||||
<option key={option.id} value={option.id}>
|
||||
{option.name ?? option.title}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<span className="text-sm">Pode seleccionar mais de uma opção.</span>
|
||||
</Field>
|
||||
);
|
||||
}
|
||||
function Criteria({
|
||||
value,
|
||||
onChange,
|
||||
}: {
|
||||
value: Criterion[];
|
||||
onChange: (criteria: Criterion[]) => void;
|
||||
}) {
|
||||
const update = (index: number, patch: Partial<Criterion>) =>
|
||||
onChange(
|
||||
value.map((item, i) =>
|
||||
i === index ? { ...item, ...patch } : item,
|
||||
),
|
||||
);
|
||||
return (
|
||||
<section>
|
||||
<h3 className="font-semibold">Critérios documentados</h3>
|
||||
{value.map((item, index) => (
|
||||
<fieldset className={card} key={item.code}>
|
||||
<legend>Critério {index + 1}</legend>
|
||||
<Field label="Pergunta">
|
||||
<input
|
||||
className={input}
|
||||
value={item.question ?? ''}
|
||||
maxLength={500}
|
||||
onChange={(e) =>
|
||||
update(index, { question: e.target.value })
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Aplica-se a">
|
||||
<select
|
||||
className={input}
|
||||
value={item.applies_to}
|
||||
onChange={(e) =>
|
||||
update(index, {
|
||||
applies_to: e.target
|
||||
.value as Criterion['applies_to'],
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="all">Todos os candidatos</option>
|
||||
<option value="individual">
|
||||
Pessoas singulares
|
||||
</option>
|
||||
<option value="entity">Entidades</option>
|
||||
</select>
|
||||
</Field>
|
||||
<Field label="Resposta exigida pela fonte">
|
||||
<select
|
||||
className={input}
|
||||
value={item.expected}
|
||||
onChange={(e) =>
|
||||
update(index, {
|
||||
expected: e.target.value as 'yes' | 'no',
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="yes">Sim</option>
|
||||
<option value="no">Não</option>
|
||||
</select>
|
||||
</Field>
|
||||
<Field label="Explicação da condição">
|
||||
<textarea
|
||||
className={input}
|
||||
value={item.explanation ?? ''}
|
||||
maxLength={2000}
|
||||
onChange={(e) =>
|
||||
update(index, { explanation: e.target.value })
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Referência exacta na fonte">
|
||||
<input
|
||||
className={input}
|
||||
value={item.source_reference ?? ''}
|
||||
maxLength={1500}
|
||||
onChange={(e) =>
|
||||
update(index, {
|
||||
source_reference: e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<button
|
||||
type="button"
|
||||
className="underline"
|
||||
onClick={() =>
|
||||
onChange(value.filter((_, i) => i !== index))
|
||||
}
|
||||
>
|
||||
Remover critério
|
||||
</button>
|
||||
</fieldset>
|
||||
))}
|
||||
<button
|
||||
type="button"
|
||||
className="underline"
|
||||
disabled={value.length >= 30}
|
||||
onClick={() =>
|
||||
onChange([
|
||||
...value,
|
||||
{
|
||||
code: newCode(),
|
||||
question: '',
|
||||
applies_to: 'all',
|
||||
expected: 'yes',
|
||||
source_reference: '',
|
||||
explanation: '',
|
||||
},
|
||||
])
|
||||
}
|
||||
>
|
||||
Acrescentar critério
|
||||
</button>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
function Editor({
|
||||
record,
|
||||
references,
|
||||
kinds,
|
||||
windowModes,
|
||||
history,
|
||||
}: {
|
||||
record: RecordData | null;
|
||||
references: Record<
|
||||
'organizations' | 'sectors' | 'territories' | 'documents',
|
||||
Choice[]
|
||||
>;
|
||||
kinds: Record<string, string>;
|
||||
windowModes: Record<string, string>;
|
||||
history: { version: number; reason: string; published_at: string }[];
|
||||
}) {
|
||||
const form = useForm({
|
||||
version: record?.version ?? 0,
|
||||
code: record?.code ?? newCode(),
|
||||
reason: '',
|
||||
draft: { ...empty, ...record?.draft },
|
||||
});
|
||||
const [plan, setPlan] = useState<Plan | null>(null);
|
||||
const [error, setError] = useState('');
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [confirmed, setConfirmed] = useState(false);
|
||||
const draft = form.data.draft;
|
||||
function change(patch: Partial<Draft>) {
|
||||
form.setData('draft', { ...draft, ...patch });
|
||||
setPlan(null);
|
||||
setConfirmed(false);
|
||||
}
|
||||
function text(
|
||||
key: {
|
||||
[K in keyof Draft]: Draft[K] extends string ? K : never;
|
||||
}[keyof Draft],
|
||||
label: string,
|
||||
type = 'text',
|
||||
) {
|
||||
return (
|
||||
<Field label={label}>
|
||||
<input
|
||||
type={type}
|
||||
className={input}
|
||||
value={draft[key] ?? ''}
|
||||
onChange={(e) => change({ [key]: e.target.value })}
|
||||
/>
|
||||
</Field>
|
||||
);
|
||||
}
|
||||
function windowChange(index: number, patch: Partial<WindowDraft>) {
|
||||
change({
|
||||
windows: draft.windows.map((item, i) =>
|
||||
i === index ? { ...item, ...patch } : item,
|
||||
),
|
||||
});
|
||||
}
|
||||
async function preview() {
|
||||
if (
|
||||
!record ||
|
||||
JSON.stringify(draft) !==
|
||||
JSON.stringify({ ...empty, ...record?.draft })
|
||||
) {
|
||||
setError('Guarde o rascunho antes de conferir a prévia.');
|
||||
return;
|
||||
}
|
||||
setBusy(true);
|
||||
setError('');
|
||||
setPlan(null);
|
||||
setConfirmed(false);
|
||||
try {
|
||||
setPlan(
|
||||
await portalRequest<Plan>(
|
||||
`/management/fundos/${record.id}/previa`,
|
||||
{ method: 'POST' },
|
||||
),
|
||||
);
|
||||
} catch (failure) {
|
||||
setError(
|
||||
failure instanceof PortalApiError
|
||||
? Object.values(failure.errors).flat().join(' ') ||
|
||||
failure.message
|
||||
: 'Não foi possível preparar a prévia.',
|
||||
);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
return (
|
||||
<Frame
|
||||
title={
|
||||
record ? 'Editar fundo ou programa' : 'Novo fundo ou programa'
|
||||
}
|
||||
>
|
||||
<Link className="underline" href="/management/fundos">
|
||||
Voltar à gestão
|
||||
</Link>
|
||||
<p>
|
||||
Guarde as condições efectivamente documentadas. Uma chamada
|
||||
local ou encerrada não altera, por si, a cobertura ou existência
|
||||
do programa.
|
||||
</p>
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
const url =
|
||||
'/management/fundos' + (record ? `/${record.id}` : '');
|
||||
if (record) form.put(url);
|
||||
else form.post(url);
|
||||
}}
|
||||
>
|
||||
<section className={card}>
|
||||
{text('title', 'Nome do programa')}
|
||||
<Field label="Tipo">
|
||||
<select
|
||||
className={input}
|
||||
value={draft.kind}
|
||||
onChange={(e) => change({ kind: e.target.value })}
|
||||
>
|
||||
{Object.entries(kinds).map(([key, label]) => (
|
||||
<option key={key} value={key}>
|
||||
{label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Field>
|
||||
<Field label="Resumo">
|
||||
<textarea
|
||||
className={input}
|
||||
value={draft.summary ?? ''}
|
||||
maxLength={4000}
|
||||
onChange={(e) =>
|
||||
change({ summary: e.target.value })
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Entidade gestora do cadastro">
|
||||
<select
|
||||
className={input}
|
||||
value={draft.manager_organization_id ?? ''}
|
||||
onChange={(e) =>
|
||||
change({
|
||||
manager_organization_id: e.target.value,
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="">Identificar pela fonte</option>
|
||||
{references.organizations.map((item) => (
|
||||
<option key={item.id} value={item.id}>
|
||||
{item.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Field>
|
||||
{!draft.manager_organization_id &&
|
||||
text('manager_name', 'Gestor indicado pela fonte')}
|
||||
{text('source_url', 'Endereço da fonte', 'url')}
|
||||
{text('source_reference', 'Documento, edição e referência')}
|
||||
{text(
|
||||
'source_checked_on',
|
||||
'Data de consulta da fonte',
|
||||
'date',
|
||||
)}
|
||||
{text(
|
||||
'source_published_on',
|
||||
'Data de publicação da fonte, se conhecida',
|
||||
'date',
|
||||
)}
|
||||
<Field label="Situação da fonte">
|
||||
<select
|
||||
className={input}
|
||||
value={draft.source_status}
|
||||
onChange={(e) =>
|
||||
change({ source_status: e.target.value })
|
||||
}
|
||||
>
|
||||
<option value="unknown">Por identificar</option>
|
||||
<option value="identified">
|
||||
Fonte efectiva identificada
|
||||
</option>
|
||||
<option value="example">
|
||||
Conteúdo explicitamente demonstrativo
|
||||
</option>
|
||||
</select>
|
||||
</Field>
|
||||
</section>
|
||||
<section className={card}>
|
||||
<Field label="Cobertura do programa">
|
||||
<select
|
||||
className={input}
|
||||
value={draft.coverage}
|
||||
onChange={(e) =>
|
||||
change({
|
||||
coverage: e.target.value,
|
||||
territory_ids: [],
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="unknown">Por determinar</option>
|
||||
<option value="national">Nacional</option>
|
||||
<option value="territorial">Territorial</option>
|
||||
</select>
|
||||
</Field>
|
||||
{draft.coverage === 'territorial' && (
|
||||
<Multi
|
||||
label="Locais abrangidos"
|
||||
options={references.territories}
|
||||
values={draft.territory_ids}
|
||||
onChange={(territory_ids) =>
|
||||
change({ territory_ids })
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{text('coverage_text', 'Explicação da cobertura')}
|
||||
<Field label="Sectores abrangidos">
|
||||
<select
|
||||
className={input}
|
||||
value={draft.sectors_scope}
|
||||
onChange={(e) =>
|
||||
change({
|
||||
sectors_scope: e.target.value,
|
||||
sector_ids: [],
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="unknown">Por determinar</option>
|
||||
<option value="all">Todos, segundo a fonte</option>
|
||||
<option value="selected">
|
||||
Sectores documentados
|
||||
</option>
|
||||
</select>
|
||||
</Field>
|
||||
{draft.sectors_scope === 'selected' && (
|
||||
<Multi
|
||||
label="Seleccionar sectores"
|
||||
options={references.sectors}
|
||||
values={draft.sector_ids}
|
||||
onChange={(ids) =>
|
||||
change({ sector_ids: ids.map(Number) })
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{text('sectors_text', 'Explicação do âmbito sectorial')}
|
||||
<Multi
|
||||
label="Documentos da biblioteca"
|
||||
options={references.documents}
|
||||
values={draft.resource_ids}
|
||||
onChange={(ids) =>
|
||||
change({ resource_ids: ids.map(Number) })
|
||||
}
|
||||
/>
|
||||
<Criteria
|
||||
value={draft.criteria}
|
||||
onChange={(criteria) => change({ criteria })}
|
||||
/>
|
||||
</section>
|
||||
<section className={card}>
|
||||
<h2 className="text-xl font-semibold">
|
||||
Janelas de candidatura
|
||||
</h2>
|
||||
{draft.windows.map((window, index) => (
|
||||
<fieldset key={window.code} className={card}>
|
||||
<legend>Janela {index + 1}</legend>
|
||||
{(
|
||||
[
|
||||
'title',
|
||||
'source_url',
|
||||
'source_reference',
|
||||
'checked_on',
|
||||
'application_url',
|
||||
'coverage_text',
|
||||
] as const
|
||||
).map((key) => (
|
||||
<Field
|
||||
key={key}
|
||||
label={
|
||||
{
|
||||
title: 'Nome da chamada',
|
||||
source_url: 'Endereço da fonte',
|
||||
source_reference:
|
||||
'Referência na fonte',
|
||||
checked_on: 'Data de consulta',
|
||||
application_url:
|
||||
'Canal de candidatura, se documentado',
|
||||
coverage_text:
|
||||
'Explicação da cobertura desta chamada',
|
||||
}[key]
|
||||
}
|
||||
>
|
||||
<input
|
||||
className={input}
|
||||
type={
|
||||
key === 'checked_on'
|
||||
? 'date'
|
||||
: key.endsWith('url')
|
||||
? 'url'
|
||||
: 'text'
|
||||
}
|
||||
value={window[key] ?? ''}
|
||||
onChange={(e) =>
|
||||
windowChange(index, {
|
||||
[key]: e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
))}
|
||||
<Field label="Estado documentado">
|
||||
<select
|
||||
className={input}
|
||||
value={window.mode}
|
||||
onChange={(e) =>
|
||||
windowChange(index, {
|
||||
mode: e.target.value,
|
||||
...(['rolling', 'unknown'].includes(
|
||||
e.target.value,
|
||||
)
|
||||
? { start_on: '', end_on: '' }
|
||||
: {}),
|
||||
})
|
||||
}
|
||||
>
|
||||
{Object.entries(windowModes).map(
|
||||
([key, label]) => (
|
||||
<option key={key} value={key}>
|
||||
{label}
|
||||
</option>
|
||||
),
|
||||
)}
|
||||
</select>
|
||||
</Field>
|
||||
{['dated', 'closed'].includes(window.mode) && (
|
||||
<>
|
||||
{(['start_on', 'end_on'] as const).map(
|
||||
(key) => (
|
||||
<Field
|
||||
key={key}
|
||||
label={
|
||||
key === 'start_on'
|
||||
? 'Data de abertura'
|
||||
: 'Data-limite'
|
||||
}
|
||||
>
|
||||
<input
|
||||
className={input}
|
||||
type="date"
|
||||
value={window[key] ?? ''}
|
||||
onChange={(e) =>
|
||||
windowChange(index, {
|
||||
[key]: e.target
|
||||
.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
),
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
<Field label="Cobertura da chamada">
|
||||
<select
|
||||
className={input}
|
||||
value={window.coverage}
|
||||
onChange={(e) =>
|
||||
windowChange(index, {
|
||||
coverage: e.target.value,
|
||||
territory_ids: [],
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="programme">
|
||||
A mesma do programa
|
||||
</option>
|
||||
<option value="unknown">
|
||||
Por determinar
|
||||
</option>
|
||||
<option value="national">Nacional</option>
|
||||
<option value="territorial">
|
||||
Territorial
|
||||
</option>
|
||||
</select>
|
||||
</Field>
|
||||
{window.coverage === 'territorial' && (
|
||||
<Multi
|
||||
label="Locais da chamada"
|
||||
options={references.territories}
|
||||
values={window.territory_ids ?? []}
|
||||
onChange={(territory_ids) =>
|
||||
windowChange(index, { territory_ids })
|
||||
}
|
||||
/>
|
||||
)}
|
||||
<Criteria
|
||||
value={window.criteria ?? []}
|
||||
onChange={(criteria) =>
|
||||
windowChange(index, { criteria })
|
||||
}
|
||||
/>
|
||||
<button
|
||||
className="underline"
|
||||
type="button"
|
||||
onClick={() =>
|
||||
change({
|
||||
windows: draft.windows.filter(
|
||||
(_, i) => i !== index,
|
||||
),
|
||||
})
|
||||
}
|
||||
>
|
||||
Remover janela
|
||||
</button>
|
||||
</fieldset>
|
||||
))}
|
||||
<button
|
||||
className="underline"
|
||||
type="button"
|
||||
disabled={draft.windows.length >= 20}
|
||||
onClick={() =>
|
||||
change({
|
||||
windows: [
|
||||
...draft.windows,
|
||||
{
|
||||
code: newCode(),
|
||||
title: '',
|
||||
mode: 'unknown',
|
||||
start_on: '',
|
||||
end_on: '',
|
||||
coverage: 'programme',
|
||||
coverage_text: '',
|
||||
territory_ids: [],
|
||||
source_url: '',
|
||||
source_reference: '',
|
||||
checked_on: '',
|
||||
application_url: '',
|
||||
criteria: [],
|
||||
},
|
||||
],
|
||||
})
|
||||
}
|
||||
>
|
||||
Acrescentar janela
|
||||
</button>
|
||||
</section>
|
||||
<Field label="Motivo da alteração">
|
||||
<textarea
|
||||
className={input}
|
||||
value={form.data.reason}
|
||||
minLength={20}
|
||||
maxLength={2000}
|
||||
onChange={(e) => form.setData('reason', e.target.value)}
|
||||
required
|
||||
/>
|
||||
</Field>
|
||||
{Object.values(form.errors).map((message, index) => (
|
||||
<p role="alert" key={index}>
|
||||
{message}
|
||||
</p>
|
||||
))}
|
||||
<button className={button} disabled={form.processing || busy}>
|
||||
Guardar rascunho
|
||||
</button>
|
||||
</form>
|
||||
{record && (
|
||||
<section className={card}>
|
||||
<h2>Publicação</h2>
|
||||
<p>
|
||||
A publicação cria uma versão pública; não altera
|
||||
interesses já guardados, não abre candidaturas nem
|
||||
activa cálculos fiscais.
|
||||
</p>
|
||||
<button
|
||||
className={button}
|
||||
disabled={busy || form.processing}
|
||||
onClick={() => void preview()}
|
||||
>
|
||||
Conferir prévia de publicação
|
||||
</button>
|
||||
{error && <p role="alert">{error}</p>}
|
||||
{plan && (
|
||||
<div>
|
||||
<h3 className="font-semibold">
|
||||
{plan.payload.title}
|
||||
</h3>
|
||||
<p>{plan.payload.summary}</p>
|
||||
<p>
|
||||
Gestor: {plan.payload.manager_name}. Fonte:{' '}
|
||||
{plan.payload.source_reference}.
|
||||
</p>
|
||||
<p>
|
||||
{plan.payload.criteria.length} critérios gerais;{' '}
|
||||
{plan.payload.windows.length} janelas.
|
||||
</p>
|
||||
<p>
|
||||
<a
|
||||
className="underline"
|
||||
href={plan.payload.source_url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Abrir fonte conferida
|
||||
</a>{' '}
|
||||
— consulta em {plan.payload.source_checked_on}.
|
||||
</p>
|
||||
<p>
|
||||
Cobertura: {plan.payload.coverage};{' '}
|
||||
{plan.payload.coverage_text}
|
||||
</p>
|
||||
<p>
|
||||
{references.territories
|
||||
.filter((item) =>
|
||||
plan.payload.territory_ids.includes(
|
||||
String(item.id),
|
||||
),
|
||||
)
|
||||
.map((item) => item.name)
|
||||
.join(', ')}
|
||||
</p>
|
||||
<p>
|
||||
Sectores:{' '}
|
||||
{plan.payload.sectors_text ||
|
||||
(plan.payload.sectors_scope === 'all'
|
||||
? 'Todos segundo a fonte'
|
||||
: plan.payload.sectors_scope ===
|
||||
'unknown'
|
||||
? 'Por determinar'
|
||||
: references.sectors
|
||||
.filter((item) =>
|
||||
plan.payload.sector_ids.includes(
|
||||
Number(item.id),
|
||||
),
|
||||
)
|
||||
.map((item) => item.name)
|
||||
.join(', '))}
|
||||
</p>
|
||||
<ul>
|
||||
{plan.payload.criteria.map((item) => (
|
||||
<li key={item.code}>
|
||||
<strong>{item.question}</strong> —{' '}
|
||||
{item.expected === 'yes'
|
||||
? 'Sim'
|
||||
: 'Não'}
|
||||
;{' '}
|
||||
{item.applies_to === 'all'
|
||||
? 'todos os candidatos'
|
||||
: item.applies_to === 'entity'
|
||||
? 'entidades'
|
||||
: 'pessoas singulares'}
|
||||
. {item.explanation} Fonte:{' '}
|
||||
{item.source_reference}.
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{plan.payload.windows.map((window) => (
|
||||
<article key={window.code} className={card}>
|
||||
<h4 className="font-semibold">
|
||||
{window.title}
|
||||
</h4>
|
||||
<p>
|
||||
{windowModes[window.mode]};{' '}
|
||||
{window.start_on ||
|
||||
'Abertura sem data indicada'}
|
||||
;{' '}
|
||||
{window.end_on ||
|
||||
'Sem data-limite indicada'}
|
||||
.
|
||||
</p>
|
||||
<p>{window.coverage_text}</p>
|
||||
<p>
|
||||
{references.territories
|
||||
.filter((item) =>
|
||||
(
|
||||
window.territory_ids ?? []
|
||||
).includes(String(item.id)),
|
||||
)
|
||||
.map((item) => item.name)
|
||||
.join(', ')}
|
||||
</p>
|
||||
<a
|
||||
className="underline"
|
||||
href={window.source_url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
{window.source_reference}
|
||||
</a>
|
||||
<p>Consulta: {window.checked_on}</p>
|
||||
{window.application_url && (
|
||||
<p>
|
||||
Canal indicado:{' '}
|
||||
{window.application_url}
|
||||
</p>
|
||||
)}
|
||||
<ul>
|
||||
{window.criteria.map((item) => (
|
||||
<li key={item.code}>
|
||||
{item.question} —{' '}
|
||||
{item.expected === 'yes'
|
||||
? 'Sim'
|
||||
: 'Não'}
|
||||
; {item.explanation} Fonte:{' '}
|
||||
{item.source_reference}.
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</article>
|
||||
))}
|
||||
<ul>
|
||||
{references.documents
|
||||
.filter((item) =>
|
||||
plan.payload.resource_ids.includes(
|
||||
Number(item.id),
|
||||
),
|
||||
)
|
||||
.map((item) => (
|
||||
<li key={item.id}>
|
||||
Documento: {item.title}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<label className="block">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={confirmed}
|
||||
onChange={(e) =>
|
||||
setConfirmed(e.target.checked)
|
||||
}
|
||||
/>{' '}
|
||||
Confirmei as condições, fontes e efeito da
|
||||
publicação.
|
||||
</label>
|
||||
<button
|
||||
className={button}
|
||||
disabled={
|
||||
!confirmed ||
|
||||
form.processing ||
|
||||
form.data.reason.length < 20
|
||||
}
|
||||
onClick={() =>
|
||||
router.post(
|
||||
`/management/fundos/${record.id}/publicar`,
|
||||
{
|
||||
version: plan.version,
|
||||
hash: plan.hash,
|
||||
reason: form.data.reason,
|
||||
confirm: true,
|
||||
},
|
||||
)
|
||||
}
|
||||
>
|
||||
Publicar versão conferida
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{record.published && (
|
||||
<button
|
||||
className="ml-3 underline"
|
||||
disabled={
|
||||
form.data.reason.length < 20 ||
|
||||
JSON.stringify(draft) !==
|
||||
JSON.stringify({
|
||||
...empty,
|
||||
...record?.draft,
|
||||
})
|
||||
}
|
||||
onClick={() =>
|
||||
router.post(
|
||||
`/management/fundos/${record.id}/retirar`,
|
||||
{
|
||||
version: record.version,
|
||||
reason: form.data.reason,
|
||||
},
|
||||
)
|
||||
}
|
||||
>
|
||||
Retirar publicação
|
||||
</button>
|
||||
)}
|
||||
</section>
|
||||
)}
|
||||
{history.length > 0 && (
|
||||
<section className={card}>
|
||||
<h2>Histórico de publicação</h2>
|
||||
<ul>
|
||||
{history.map((item) => (
|
||||
<li key={item.version}>
|
||||
Versão {item.version} — {item.published_at}:{' '}
|
||||
{item.reason}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
)}
|
||||
</Frame>
|
||||
);
|
||||
}
|
||||
|
||||
export default function Edit(props: Parameters<typeof Editor>[0]) {
|
||||
return (
|
||||
<Editor
|
||||
key={
|
||||
props.record
|
||||
? props.record.id + ':' + props.record.version
|
||||
: 'new'
|
||||
}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
import { Link, useForm } from '@inertiajs/react';
|
||||
import { Frame, card, button } from '@/pages/investment/shared';
|
||||
import { type Programme, windowLabels } from './shared';
|
||||
|
||||
export default function Index({
|
||||
items,
|
||||
filters,
|
||||
kinds,
|
||||
management,
|
||||
options,
|
||||
}: {
|
||||
items: {
|
||||
data: Programme[];
|
||||
links: { url: string | null; label: string; active: boolean }[];
|
||||
};
|
||||
filters: {
|
||||
q?: string;
|
||||
kind?: string;
|
||||
sector?: string;
|
||||
territory?: string;
|
||||
certainty?: string;
|
||||
state?: string;
|
||||
};
|
||||
options: {
|
||||
sectors: { id: number; name: string }[];
|
||||
territories: { id: string; name: string }[];
|
||||
};
|
||||
kinds: Record<string, string>;
|
||||
management: boolean;
|
||||
}) {
|
||||
const form = useForm({
|
||||
q: filters.q ?? '',
|
||||
kind: filters.kind ?? '',
|
||||
sector: filters.sector ?? '',
|
||||
territory: filters.territory ?? '',
|
||||
certainty: filters.certainty ?? 'include_unknown',
|
||||
state: filters.state ?? '',
|
||||
});
|
||||
return (
|
||||
<Frame title="Fundos e programas de apoio">
|
||||
{management && (
|
||||
<Link className={button} href="/management/fundos">
|
||||
Gerir fundos e programas
|
||||
</Link>
|
||||
)}
|
||||
<Link className="underline" href="/fundos/guardados">
|
||||
Programas que guardei
|
||||
</Link>
|
||||
<p>
|
||||
Consulte os programas e as condições documentadas. Cada chamada
|
||||
tem as suas próprias datas e critérios.
|
||||
</p>
|
||||
<form
|
||||
className={`${card} flex flex-wrap gap-4`}
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
form.get('/fundos');
|
||||
}}
|
||||
>
|
||||
<label>
|
||||
Palavras-chave
|
||||
<input
|
||||
className="block rounded border p-2"
|
||||
value={form.data.q}
|
||||
maxLength={150}
|
||||
onChange={(e) => form.setData('q', e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Tipo
|
||||
<select
|
||||
className="block rounded border p-2"
|
||||
value={form.data.kind}
|
||||
onChange={(e) => form.setData('kind', e.target.value)}
|
||||
>
|
||||
<option value="">Todos</option>
|
||||
{Object.entries(kinds).map(([key, name]) => (
|
||||
<option key={key} value={key}>
|
||||
{name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<button className={button} disabled={form.processing}>
|
||||
Pesquisar
|
||||
</button>
|
||||
<label>
|
||||
Sector
|
||||
<select
|
||||
className="block rounded border p-2"
|
||||
value={form.data.sector}
|
||||
onChange={(e) => form.setData('sector', e.target.value)}
|
||||
>
|
||||
<option value="">Todos</option>
|
||||
{options.sectors.map((item) => (
|
||||
<option key={item.id} value={item.id}>
|
||||
{item.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
Local de interesse
|
||||
<select
|
||||
className="block rounded border p-2"
|
||||
value={form.data.territory}
|
||||
onChange={(e) =>
|
||||
form.setData('territory', e.target.value)
|
||||
}
|
||||
>
|
||||
<option value="">Todos</option>
|
||||
{options.territories.map((item) => (
|
||||
<option key={item.id} value={item.id}>
|
||||
{item.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
Informação por confirmar
|
||||
<select
|
||||
className="block rounded border p-2"
|
||||
value={form.data.certainty}
|
||||
onChange={(e) =>
|
||||
form.setData('certainty', e.target.value)
|
||||
}
|
||||
>
|
||||
<option value="include_unknown">
|
||||
Incluir e assinalar
|
||||
</option>
|
||||
<option value="documented">
|
||||
Apenas âmbito documentado para os filtros escolhidos
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
Estado de uma janela
|
||||
<select
|
||||
className="block rounded border p-2"
|
||||
value={form.data.state}
|
||||
onChange={(e) => form.setData('state', e.target.value)}
|
||||
>
|
||||
<option value="">Qualquer estado</option>
|
||||
{Object.entries(windowLabels).map(([key, label]) => (
|
||||
<option key={key} value={key}>
|
||||
{label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
</form>
|
||||
<p className="text-sm">
|
||||
Sector e local filtram o âmbito geral do programa. Cada chamada
|
||||
pode ter uma cobertura mais restrita. O estado indica que existe
|
||||
pelo menos uma janela nesse estado; não confirma elegibilidade
|
||||
nem candidatura aberta no local escolhido.
|
||||
</p>
|
||||
{items.data.length === 0 && (
|
||||
<p>
|
||||
Não foram encontrados programas publicados para esta
|
||||
pesquisa.
|
||||
</p>
|
||||
)}
|
||||
{items.data.map((item) => (
|
||||
<article className={card} key={item.id}>
|
||||
<h2 className="text-xl font-semibold">
|
||||
<Link className="underline" href={`/fundos/${item.id}`}>
|
||||
{item.payload.title}
|
||||
</Link>
|
||||
</h2>
|
||||
<p>{item.payload.summary}</p>
|
||||
<p>Gestor: {item.payload.manager_name}</p>
|
||||
{Object.entries(item.filter_explanation ?? {}).map(
|
||||
([key, message]) => (
|
||||
<p key={key}>{message}</p>
|
||||
),
|
||||
)}
|
||||
{item.payload.windows.length === 0 ? (
|
||||
<p>
|
||||
Não existe uma janela de candidatura confirmada
|
||||
nesta ficha.
|
||||
</p>
|
||||
) : (
|
||||
<ul>
|
||||
{item.payload.windows.map((window) => (
|
||||
<li key={window.code}>
|
||||
{window.title}: {windowLabels[window.state]}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</article>
|
||||
))}
|
||||
<nav aria-label="Páginas do catálogo" className="flex gap-3">
|
||||
{items.links.map((link, index) =>
|
||||
link.url ? (
|
||||
<Link
|
||||
key={index}
|
||||
href={link.url}
|
||||
aria-current={link.active ? 'page' : undefined}
|
||||
className="underline"
|
||||
>
|
||||
{link.label
|
||||
.replace(/«/g, '«')
|
||||
.replace(/»/g, '»')}
|
||||
</Link>
|
||||
) : null,
|
||||
)}
|
||||
</nav>
|
||||
</Frame>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import { Link } from '@inertiajs/react';
|
||||
import { Frame, card, button } from '@/pages/investment/shared';
|
||||
export default function Manage({
|
||||
items,
|
||||
}: {
|
||||
items: {
|
||||
data: {
|
||||
id: string;
|
||||
title: string;
|
||||
version: number;
|
||||
published: boolean;
|
||||
}[];
|
||||
links: { url: string | null; label: string; active: boolean }[];
|
||||
};
|
||||
}) {
|
||||
return (
|
||||
<Frame title="Gerir fundos e programas">
|
||||
<Link className={button} href="/management/fundos/novo">
|
||||
Novo programa
|
||||
</Link>
|
||||
<Link className="ml-4 underline" href="/fundos">
|
||||
Catálogo público
|
||||
</Link>
|
||||
<Link
|
||||
className="ml-4 underline"
|
||||
href="/management/fundos/referencias/fdel"
|
||||
>
|
||||
Preparar referência FDEL
|
||||
</Link>
|
||||
{items.data.map((item) => (
|
||||
<article className={card} key={item.id}>
|
||||
<Link
|
||||
className="underline"
|
||||
href={`/management/fundos/${item.id}`}
|
||||
>
|
||||
{item.title}
|
||||
</Link>
|
||||
<p>
|
||||
Versão de trabalho {item.version} —{' '}
|
||||
{item.published
|
||||
? 'com publicação'
|
||||
: 'sem publicação pública'}
|
||||
</p>
|
||||
</article>
|
||||
))}
|
||||
<nav aria-label="Páginas de gestão" className="flex gap-3">
|
||||
{items.links.map((link, index) =>
|
||||
link.url ? (
|
||||
<Link
|
||||
key={index}
|
||||
href={link.url}
|
||||
className="underline"
|
||||
aria-current={link.active ? 'page' : undefined}
|
||||
>
|
||||
{link.label
|
||||
.replace(/«/g, '«')
|
||||
.replace(/»/g, '»')}
|
||||
</Link>
|
||||
) : null,
|
||||
)}
|
||||
</nav>
|
||||
</Frame>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
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>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
import { Link, router } from '@inertiajs/react';
|
||||
import { Frame, card, button } from '@/pages/investment/shared';
|
||||
|
||||
type SavedProgramme = {
|
||||
id: string;
|
||||
title: string;
|
||||
saved_version: number;
|
||||
saved_at: string;
|
||||
available: boolean;
|
||||
current_version: number | null;
|
||||
};
|
||||
export default function Saved({
|
||||
items,
|
||||
}: {
|
||||
items: {
|
||||
data: SavedProgramme[];
|
||||
links: { url: string | null; label: string; active: boolean }[];
|
||||
};
|
||||
}) {
|
||||
return (
|
||||
<Frame title="Programas que guardei">
|
||||
<Link className="underline" href="/fundos">
|
||||
Consultar fundos e programas
|
||||
</Link>
|
||||
<p>
|
||||
Referências privadas aos programas que seleccionou. Guardar
|
||||
interesse não envia candidatura nem reserva financiamento.
|
||||
</p>
|
||||
{items.data.length === 0 && (
|
||||
<p>Ainda não tem programas guardados.</p>
|
||||
)}
|
||||
{items.data.map((item) => (
|
||||
<article key={item.id} className={card}>
|
||||
<h2 className="text-xl font-semibold">{item.title}</h2>
|
||||
<p>Guardado na versão {item.saved_version}.</p>
|
||||
{item.available ? (
|
||||
<>
|
||||
<Link
|
||||
className="underline"
|
||||
href={`/fundos/${item.id}`}
|
||||
>
|
||||
Consultar ficha publicada
|
||||
</Link>
|
||||
{item.current_version !== item.saved_version && (
|
||||
<p>
|
||||
Existe uma versão pública diferente:{' '}
|
||||
{item.current_version}. A referência
|
||||
guardada conserva a versão que seleccionou.
|
||||
</p>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<p>
|
||||
A ficha já não está disponível publicamente. A sua
|
||||
referência guardada foi conservada.
|
||||
</p>
|
||||
)}
|
||||
<div className="mt-3">
|
||||
<button
|
||||
className={button}
|
||||
onClick={() =>
|
||||
router.delete(`/fundos/${item.id}/interesse`)
|
||||
}
|
||||
>
|
||||
Remover da minha lista
|
||||
</button>
|
||||
</div>
|
||||
</article>
|
||||
))}
|
||||
<nav
|
||||
aria-label="Páginas de programas guardados"
|
||||
className="flex gap-3"
|
||||
>
|
||||
{items.links.map((link, index) =>
|
||||
link.url ? (
|
||||
<Link
|
||||
key={index}
|
||||
href={link.url}
|
||||
aria-current={link.active ? 'page' : undefined}
|
||||
className="underline"
|
||||
>
|
||||
{link.label
|
||||
.replace(/«/g, '«')
|
||||
.replace(/»/g, '»')}
|
||||
</Link>
|
||||
) : null,
|
||||
)}
|
||||
</nav>
|
||||
</Frame>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
export type Criterion = {
|
||||
code: string;
|
||||
question: string;
|
||||
applies_to: 'all' | 'individual' | 'entity';
|
||||
expected: 'yes' | 'no';
|
||||
source_reference: string;
|
||||
explanation: string;
|
||||
};
|
||||
export type FundingWindow = {
|
||||
code: string;
|
||||
title: string;
|
||||
state: string;
|
||||
coverage: string;
|
||||
territory_paths?: { id: string; name: string; type: string }[][];
|
||||
start_on?: string | null;
|
||||
end_on?: string | null;
|
||||
coverage_text?: string | null;
|
||||
source_url: string;
|
||||
source_reference: string;
|
||||
checked_on: string;
|
||||
application_url?: string | null;
|
||||
criteria: Criterion[];
|
||||
};
|
||||
export type Programme = {
|
||||
filter_explanation?: Record<string, string>;
|
||||
id: string;
|
||||
code: string;
|
||||
version_id: string;
|
||||
version: number;
|
||||
published_at: string;
|
||||
payload: {
|
||||
title: string;
|
||||
kind: string;
|
||||
summary: string;
|
||||
manager_name: string;
|
||||
coverage: string;
|
||||
coverage_text?: string | null;
|
||||
territory_paths?: { id: string; name: string; type: string }[][];
|
||||
sector_snapshots?: { id: number; name: string }[];
|
||||
sectors_scope: string;
|
||||
sectors_text?: string | null;
|
||||
source_url: string;
|
||||
source_reference: string;
|
||||
source_checked_on: string;
|
||||
criteria: Criterion[];
|
||||
windows: FundingWindow[];
|
||||
documents: { resource_id: number; title: string; available: boolean }[];
|
||||
};
|
||||
};
|
||||
export const windowLabels: Record<string, string> = {
|
||||
open: 'Janela aberta segundo as datas documentadas',
|
||||
closed: 'Janela encerrada',
|
||||
upcoming: 'Abertura futura',
|
||||
unknown: 'Janela por confirmar',
|
||||
};
|
||||
@@ -0,0 +1,332 @@
|
||||
import { Link, router } from '@inertiajs/react';
|
||||
import { useState } from 'react';
|
||||
import { portalRequest } from '@/lib/portal-api';
|
||||
import { Frame, card, button } from '@/pages/investment/shared';
|
||||
import { type Programme, windowLabels } from './shared';
|
||||
|
||||
type Assessment = {
|
||||
notice: string;
|
||||
criteria: { code: string; status: string }[];
|
||||
};
|
||||
const statusLabels: Record<string, string> = {
|
||||
matches: 'Corresponde à resposta esperada',
|
||||
does_not_match: 'Não corresponde à resposta esperada',
|
||||
unknown: 'Informação por confirmar',
|
||||
not_applicable: 'Não aplicável ao tipo de candidato indicado',
|
||||
};
|
||||
export default function Show({
|
||||
record,
|
||||
saved,
|
||||
authenticated,
|
||||
}: {
|
||||
record: Programme;
|
||||
saved: { version: number; saved_at: string } | null;
|
||||
authenticated: boolean;
|
||||
}) {
|
||||
const [kind, setKind] = useState('unknown');
|
||||
const [windowCode, setWindowCode] = useState('');
|
||||
const [answers, setAnswers] = useState<Record<string, string>>({});
|
||||
const [assessment, setAssessment] = useState<Assessment | null>(null);
|
||||
const [error, setError] = useState('');
|
||||
const [busy, setBusy] = useState(false);
|
||||
const payload = record.payload;
|
||||
const window = payload.windows.find((item) => item.code === windowCode);
|
||||
const criteria = [...payload.criteria, ...(window?.criteria ?? [])];
|
||||
async function assess() {
|
||||
setBusy(true);
|
||||
setError('');
|
||||
setAssessment(null);
|
||||
try {
|
||||
setAssessment(
|
||||
await portalRequest<Assessment>(
|
||||
`/fundos/${record.id}/criterios`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
version_id: record.version_id,
|
||||
applicant_kind: kind,
|
||||
window_code: windowCode || null,
|
||||
answers: Object.fromEntries(
|
||||
criteria.map((c) => [
|
||||
c.code,
|
||||
answers[c.code] ?? 'unknown',
|
||||
]),
|
||||
),
|
||||
}),
|
||||
},
|
||||
),
|
||||
);
|
||||
} catch (failure) {
|
||||
setError(
|
||||
failure instanceof Error
|
||||
? failure.message
|
||||
: 'Não foi possível conferir os critérios.',
|
||||
);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
return (
|
||||
<Frame title={payload.title}>
|
||||
<Link className="underline" href="/fundos/guardados">
|
||||
Programas que guardei
|
||||
</Link>
|
||||
<Link className="underline" href="/fundos">
|
||||
Voltar aos fundos e programas
|
||||
</Link>
|
||||
<p>{payload.summary}</p>
|
||||
<p>
|
||||
Gestor: {payload.manager_name}. Versão publicada:{' '}
|
||||
{record.version}.
|
||||
</p>
|
||||
{(payload.territory_paths ?? []).map((path, index) => (
|
||||
<p key={index}>
|
||||
Local abrangido: {path.map((node) => node.name).join(' / ')}
|
||||
</p>
|
||||
))}
|
||||
<p>
|
||||
Sectores:{' '}
|
||||
{payload.sectors_text ||
|
||||
(payload.sectors_scope === 'all'
|
||||
? 'Todos, segundo a fonte'
|
||||
: payload.sectors_scope === 'unknown'
|
||||
? 'Por confirmar'
|
||||
: (payload.sector_snapshots ?? [])
|
||||
.map((sector) => sector.name)
|
||||
.join(', '))}
|
||||
</p>
|
||||
<p>
|
||||
{payload.coverage === 'national'
|
||||
? 'Cobertura nacional'
|
||||
: payload.coverage === 'territorial'
|
||||
? 'Cobertura territorial'
|
||||
: 'Cobertura por confirmar'}
|
||||
{payload.coverage_text ? ` — ${payload.coverage_text}` : ''}
|
||||
</p>
|
||||
<p>
|
||||
<a
|
||||
className="underline"
|
||||
href={payload.source_url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Consultar fonte: {payload.source_reference}
|
||||
</a>
|
||||
. Consultada em {payload.source_checked_on}.
|
||||
</p>
|
||||
<section className={card}>
|
||||
<h2 className="text-xl font-semibold">
|
||||
Janelas de candidatura
|
||||
</h2>
|
||||
{payload.windows.length === 0 && (
|
||||
<p>
|
||||
Não há uma janela de candidatura confirmada nesta ficha.
|
||||
</p>
|
||||
)}
|
||||
{payload.windows.map((item) => (
|
||||
<article key={item.code} className="my-4">
|
||||
<h3 className="font-semibold">{item.title}</h3>
|
||||
<p>{windowLabels[item.state]}</p>
|
||||
{item.start_on && <p>Abertura: {item.start_on}</p>}
|
||||
{item.end_on && <p>Data-limite: {item.end_on}</p>}
|
||||
{item.coverage_text && <p>{item.coverage_text}</p>}
|
||||
<p>
|
||||
{item.coverage === 'programme'
|
||||
? 'Mesma cobertura do programa'
|
||||
: item.coverage === 'national'
|
||||
? 'Chamada nacional'
|
||||
: item.coverage === 'unknown'
|
||||
? 'Cobertura da chamada por confirmar'
|
||||
: 'Chamada territorial'}
|
||||
</p>
|
||||
{(item.territory_paths ?? []).map((path, index) => (
|
||||
<p key={index}>
|
||||
{path.map((node) => node.name).join(' / ')}
|
||||
</p>
|
||||
))}
|
||||
<a
|
||||
className="underline"
|
||||
href={item.source_url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
{item.source_reference}
|
||||
</a>
|
||||
<p>Fonte consultada em {item.checked_on}.</p>
|
||||
{item.application_url && (
|
||||
<a
|
||||
className="underline"
|
||||
href={item.application_url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Consultar o canal indicado pela entidade
|
||||
</a>
|
||||
)}
|
||||
</article>
|
||||
))}
|
||||
</section>
|
||||
<section className={card}>
|
||||
<h2 className="text-xl font-semibold">
|
||||
Conferir critérios documentados
|
||||
</h2>
|
||||
<p>
|
||||
Esta consulta não envia candidatura nem concede
|
||||
financiamento. As respostas não ficam guardadas.
|
||||
</p>
|
||||
<label className="block">
|
||||
Tipo de candidato
|
||||
<select
|
||||
disabled={busy}
|
||||
className="m-2 rounded border p-2"
|
||||
value={kind}
|
||||
onChange={(e) => {
|
||||
setKind(e.target.value);
|
||||
setAssessment(null);
|
||||
}}
|
||||
>
|
||||
<option value="unknown">Por definir</option>
|
||||
<option value="individual">Pessoa singular</option>
|
||||
<option value="entity">Entidade</option>
|
||||
</select>
|
||||
</label>
|
||||
<label className="block">
|
||||
Janela
|
||||
<select
|
||||
disabled={busy}
|
||||
className="m-2 rounded border p-2"
|
||||
value={windowCode}
|
||||
onChange={(e) => {
|
||||
setWindowCode(e.target.value);
|
||||
setAssessment(null);
|
||||
}}
|
||||
>
|
||||
<option value="">Apenas critérios gerais</option>
|
||||
{payload.windows.map((item) => (
|
||||
<option key={item.code} value={item.code}>
|
||||
{item.title}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
{criteria.length === 0 && (
|
||||
<p>
|
||||
Esta ficha não contém critérios suficientes para
|
||||
conferir a correspondência.
|
||||
</p>
|
||||
)}
|
||||
{criteria.map((criterion) => (
|
||||
<div key={criterion.code} className="my-4">
|
||||
<label>
|
||||
{criterion.question}
|
||||
<select
|
||||
disabled={busy}
|
||||
className="m-2 rounded border p-2"
|
||||
value={answers[criterion.code] ?? 'unknown'}
|
||||
onChange={(e) => {
|
||||
setAnswers({
|
||||
...answers,
|
||||
[criterion.code]: e.target.value,
|
||||
});
|
||||
setAssessment(null);
|
||||
}}
|
||||
>
|
||||
<option value="unknown">
|
||||
Não sei / por confirmar
|
||||
</option>
|
||||
<option value="yes">Sim</option>
|
||||
<option value="no">Não</option>
|
||||
</select>
|
||||
</label>
|
||||
<p>{criterion.explanation}</p>
|
||||
<p>Fonte: {criterion.source_reference}</p>
|
||||
{assessment && (
|
||||
<p>
|
||||
{
|
||||
statusLabels[
|
||||
assessment.criteria.find(
|
||||
(c) => c.code === criterion.code,
|
||||
)?.status ?? 'unknown'
|
||||
]
|
||||
}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
<button
|
||||
className={button}
|
||||
disabled={busy || criteria.length === 0}
|
||||
onClick={() => void assess()}
|
||||
>
|
||||
{busy ? 'A conferir…' : 'Conferir respostas'}
|
||||
</button>
|
||||
{error && <p role="alert">{error}</p>}
|
||||
{assessment && <p role="status">{assessment.notice}</p>}
|
||||
</section>
|
||||
{payload.documents.length > 0 && (
|
||||
<section className={card}>
|
||||
<h2>Documentos associados</h2>
|
||||
<ul>
|
||||
{payload.documents.map((doc) => (
|
||||
<li key={doc.resource_id}>
|
||||
{doc.available ? (
|
||||
<a
|
||||
className="underline"
|
||||
href={`/fundos/${record.id}/versoes/${record.version_id}/documentos/${doc.resource_id}`}
|
||||
>
|
||||
{doc.title}
|
||||
</a>
|
||||
) : (
|
||||
`${doc.title} — versão indisponível para descarga`
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
)}
|
||||
<section className={card}>
|
||||
<h2>Guardar interesse</h2>
|
||||
<p>
|
||||
Guarda uma referência privada ao programa. Não envia uma
|
||||
candidatura nem contacta a entidade.
|
||||
</p>
|
||||
{saved ? (
|
||||
<>
|
||||
<p>
|
||||
Guardado na versão {saved.version}
|
||||
{saved.version !== record.version
|
||||
? '; existe uma versão pública mais recente'
|
||||
: ''}
|
||||
.
|
||||
</p>
|
||||
<button
|
||||
className={button}
|
||||
onClick={() =>
|
||||
router.delete(`/fundos/${record.id}/interesse`)
|
||||
}
|
||||
>
|
||||
Remover da minha lista
|
||||
</button>
|
||||
</>
|
||||
) : authenticated ? (
|
||||
<button
|
||||
className={button}
|
||||
onClick={() =>
|
||||
router.put(`/fundos/${record.id}/interesse`, {
|
||||
version_id: record.version_id,
|
||||
consent: true,
|
||||
})
|
||||
}
|
||||
>
|
||||
Guardar programa na minha área privada
|
||||
</button>
|
||||
) : (
|
||||
<Link className="underline" href="/login">
|
||||
Entrar para guardar interesse
|
||||
</Link>
|
||||
)}
|
||||
</section>
|
||||
</Frame>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user