327 lines
13 KiB
TypeScript
327 lines
13 KiB
TypeScript
import {
|
|
financialCategories,
|
|
financialTypes,
|
|
} from '@/components/funding-classification';
|
|
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,
|
|
needs = {},
|
|
}: {
|
|
items: {
|
|
data: Programme[];
|
|
links: { url: string | null; label: string; active: boolean }[];
|
|
};
|
|
filters: {
|
|
q?: string;
|
|
kind?: string;
|
|
sector?: string;
|
|
territory?: string;
|
|
certainty?: string;
|
|
state?: string;
|
|
need?: string;
|
|
context?: string;
|
|
opportunity?: string;
|
|
category?: string;
|
|
institution_type?: string;
|
|
location_mode?: string;
|
|
include_historical?: string;
|
|
};
|
|
options: {
|
|
sectors: { id: number; name: string }[];
|
|
territories: { id: string; name: string }[];
|
|
};
|
|
kinds: Record<string, string>;
|
|
needs?: Record<string, string>;
|
|
management: boolean;
|
|
}) {
|
|
const form = useForm({
|
|
category: filters.category ?? '',
|
|
institution_type: filters.institution_type ?? '',
|
|
location_mode: filters.location_mode ?? 'coverage',
|
|
include_historical: filters.include_historical ?? '0',
|
|
context: filters.context ?? '',
|
|
opportunity: filters.opportunity ?? '',
|
|
need: filters.need ?? '',
|
|
q: filters.q ?? '',
|
|
kind: filters.kind ?? '',
|
|
sector: filters.sector ?? '',
|
|
territory: filters.territory ?? '',
|
|
certainty: filters.certainty ?? 'include_unknown',
|
|
state: filters.state ?? '',
|
|
});
|
|
return (
|
|
<Frame title="Instituições financeiras, 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>
|
|
Categoria
|
|
<select
|
|
className="block rounded border p-2"
|
|
value={form.data.category}
|
|
onChange={(e) =>
|
|
form.setData('category', e.target.value)
|
|
}
|
|
>
|
|
<option value="">Todas</option>
|
|
{Object.entries(financialCategories).map(
|
|
([id, label]) => (
|
|
<option key={id} value={id}>
|
|
{label}
|
|
</option>
|
|
),
|
|
)}
|
|
</select>
|
|
</label>
|
|
<label>
|
|
Tipo
|
|
<select
|
|
className="block rounded border p-2"
|
|
value={form.data.institution_type}
|
|
onChange={(e) =>
|
|
form.setData('institution_type', e.target.value)
|
|
}
|
|
>
|
|
<option value="">Todos</option>
|
|
{Object.entries(financialTypes).map(([id, label]) => (
|
|
<option key={id} value={id}>
|
|
{label}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<label>
|
|
Localização a pesquisar
|
|
<select
|
|
className="block rounded border p-2"
|
|
value={form.data.location_mode}
|
|
onChange={(e) =>
|
|
form.setData('location_mode', e.target.value)
|
|
}
|
|
>
|
|
<option value="physical">
|
|
Sede, balcão ou presença física
|
|
</option>
|
|
<option value="coverage">
|
|
Cobertura do financiamento/produto
|
|
</option>
|
|
</select>
|
|
</label>
|
|
<label>
|
|
<input
|
|
type="checkbox"
|
|
checked={form.data.include_historical === '1'}
|
|
onChange={(e) =>
|
|
form.setData(
|
|
'include_historical',
|
|
e.target.checked ? '1' : '0',
|
|
)
|
|
}
|
|
/>
|
|
Incluir instituições históricas/fundidas, identificadas como
|
|
tal
|
|
</label>
|
|
<label>
|
|
Necessidade do processo
|
|
<select
|
|
className="block rounded border p-2"
|
|
value={form.data.need}
|
|
onChange={(e) => form.setData('need', e.target.value)}
|
|
>
|
|
<option value="">Todas / por identificar</option>
|
|
{Object.entries(needs).map(([id, label]) => (
|
|
<option key={id} value={id}>
|
|
{label}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<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}?${new URLSearchParams(Object.entries(filters).filter((entry): entry is [string, string] => typeof entry[1] === 'string'))}`}
|
|
>
|
|
{item.payload.title}
|
|
</Link>
|
|
</h2>
|
|
<p>{item.payload.summary}</p>
|
|
<p>
|
|
{(item.payload.institution_categories ?? [])
|
|
.map((k) => financialCategories[k] ?? k)
|
|
.join(' · ')}{' '}
|
|
·{' '}
|
|
{(item.payload.institution_types ?? [])
|
|
.map((k) => financialTypes[k] ?? k)
|
|
.join(' · ')}
|
|
</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>
|
|
);
|
|
}
|