720 lines
28 KiB
TypeScript
720 lines
28 KiB
TypeScript
import {
|
|
ClassificationFields,
|
|
ClassificationSummary,
|
|
evidenceLabels,
|
|
type Classification,
|
|
} from '@/components/funding-classification';
|
|
import { card, input, button } from '@/pages/investment/shared';
|
|
|
|
export type FundingSource = {
|
|
source_url: string | null;
|
|
source_document_name?: string | null;
|
|
source_document_sha256?: string | null;
|
|
evidence_status?: string | null;
|
|
origin?: string;
|
|
source_refs?: string[];
|
|
source_reference: string;
|
|
checked_on: string;
|
|
};
|
|
export type FundingContact = FundingSource & { kind: string; value: string };
|
|
export type FundingLocation = FundingSource & {
|
|
id?: string;
|
|
location_text?: string;
|
|
hours?: string;
|
|
role: string;
|
|
label: string;
|
|
address: string;
|
|
territory_id: string;
|
|
territory_path?: { name: string }[];
|
|
};
|
|
export type FundingProduct = FundingSource & {
|
|
code: string;
|
|
title: string;
|
|
instrument: string;
|
|
needs: string[];
|
|
coverage: string;
|
|
coverage_text: string;
|
|
territory_ids: string[];
|
|
territory_paths?: { name: string }[][];
|
|
conditions: string;
|
|
amounts: string;
|
|
availability: string;
|
|
contact_url: string;
|
|
};
|
|
export type InstitutionDetails = Classification & {
|
|
institution_key: string;
|
|
institution_nature: string;
|
|
contacts: FundingContact[];
|
|
locations: FundingLocation[];
|
|
products: FundingProduct[];
|
|
};
|
|
export const emptyInstitution: InstitutionDetails = {
|
|
institution_key: '',
|
|
institution_nature: 'unknown',
|
|
contacts: [],
|
|
locations: [],
|
|
products: [],
|
|
};
|
|
const source: FundingSource = {
|
|
source_url: '',
|
|
source_reference: '',
|
|
checked_on: '',
|
|
};
|
|
function Text({
|
|
label,
|
|
value,
|
|
change,
|
|
type = 'text',
|
|
}: {
|
|
label: string;
|
|
value: string;
|
|
change: (v: string) => void;
|
|
type?: string;
|
|
}) {
|
|
return (
|
|
<label className="my-2 block">
|
|
{label}
|
|
<input
|
|
className={input}
|
|
type={type}
|
|
value={value ?? ''}
|
|
maxLength={type === 'text' ? 1500 : undefined}
|
|
onChange={(e) => change(e.target.value)}
|
|
/>
|
|
</label>
|
|
);
|
|
}
|
|
function Sources({
|
|
value,
|
|
change,
|
|
}: {
|
|
value: FundingSource;
|
|
change: (v: Partial<FundingSource>) => void;
|
|
}) {
|
|
return (
|
|
<details>
|
|
<summary>Fonte e data deste elemento — Alterar</summary>
|
|
<Text
|
|
label="Endereço da fonte"
|
|
type="url"
|
|
value={value.source_url ?? ''}
|
|
change={(source_url) => change({ source_url })}
|
|
/>
|
|
{!value.source_url && (
|
|
<>
|
|
<Text
|
|
label="Documento de origem"
|
|
value={value.source_document_name ?? ''}
|
|
change={(source_document_name) =>
|
|
change({ source_document_name })
|
|
}
|
|
/>
|
|
<Text
|
|
label="SHA-256 do original"
|
|
value={value.source_document_sha256 ?? ''}
|
|
change={(source_document_sha256) =>
|
|
change({ source_document_sha256 })
|
|
}
|
|
/>
|
|
</>
|
|
)}
|
|
{value.source_document_sha256 && (
|
|
<label>
|
|
Situação desta informação
|
|
<select
|
|
className={input}
|
|
value={value.evidence_status ?? 'to_confirm'}
|
|
onChange={(e) =>
|
|
change({ evidence_status: e.target.value })
|
|
}
|
|
>
|
|
{Object.entries(evidenceLabels).map(([key, label]) => (
|
|
<option key={key} value={key}>
|
|
{label}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
)}
|
|
<Text
|
|
label="Referência/edição"
|
|
value={value.source_reference}
|
|
change={(source_reference) => change({ source_reference })}
|
|
/>
|
|
<Text
|
|
label="Data de consulta"
|
|
type="date"
|
|
value={value.checked_on}
|
|
change={(checked_on) => change({ checked_on })}
|
|
/>
|
|
</details>
|
|
);
|
|
}
|
|
export function InstitutionFields({
|
|
value,
|
|
change,
|
|
territories,
|
|
natures,
|
|
needs,
|
|
}: {
|
|
value: InstitutionDetails;
|
|
change: (patch: Partial<InstitutionDetails>) => void;
|
|
territories: { id: string | number; name?: string }[];
|
|
natures: Record<string, string>;
|
|
needs: Record<string, string>;
|
|
}) {
|
|
const update = <K extends 'contacts' | 'locations' | 'products'>(
|
|
key: K,
|
|
index: number,
|
|
patch: Partial<InstitutionDetails[K][number]>,
|
|
) =>
|
|
change({
|
|
[key]: value[key].map((row, i) =>
|
|
i === index ? { ...row, ...patch } : row,
|
|
),
|
|
});
|
|
return (
|
|
<section className={card}>
|
|
<h2>Instituição, presença física e produtos</h2>
|
|
<p>
|
|
A sede ou balcão não determina a cobertura do financiamento. Não
|
|
preencha condições desconhecidas por inferência.
|
|
</p>
|
|
<ClassificationFields value={value} change={change} needs={needs} />
|
|
<Text
|
|
label="Identidade estável da instituição (referência do cadastro/fonte)"
|
|
value={value.institution_key}
|
|
change={(institution_key) => change({ institution_key })}
|
|
/>
|
|
<label>
|
|
Natureza
|
|
<select
|
|
className={input}
|
|
value={value.institution_nature}
|
|
onChange={(e) =>
|
|
change({ institution_nature: e.target.value })
|
|
}
|
|
>
|
|
{Object.entries(natures).map(([id, label]) => (
|
|
<option key={id} value={id}>
|
|
{label}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<details>
|
|
<summary>Contactos ({value.contacts.length}) — Alterar</summary>
|
|
{value.contacts.map((row, i) => (
|
|
<fieldset className={card} key={i}>
|
|
<legend>Contacto {i + 1}</legend>
|
|
<select
|
|
className={input}
|
|
value={row.kind}
|
|
onChange={(e) =>
|
|
update('contacts', i, { kind: e.target.value })
|
|
}
|
|
>
|
|
{Object.entries({
|
|
website: 'Página institucional',
|
|
email: 'Email',
|
|
phone: 'Telefone',
|
|
address: 'Endereço postal',
|
|
}).map(([id, label]) => (
|
|
<option key={id} value={id}>
|
|
{label}
|
|
</option>
|
|
))}
|
|
</select>
|
|
<Text
|
|
label="Contacto documentado"
|
|
value={row.value}
|
|
change={(v) => update('contacts', i, { value: v })}
|
|
/>
|
|
<Sources
|
|
value={row}
|
|
change={(v) => update('contacts', i, v)}
|
|
/>
|
|
<button
|
|
type="button"
|
|
onClick={() =>
|
|
change({
|
|
contacts: value.contacts.filter(
|
|
(_, n) => n !== i,
|
|
),
|
|
})
|
|
}
|
|
>
|
|
Remover contacto
|
|
</button>
|
|
</fieldset>
|
|
))}
|
|
<button
|
|
type="button"
|
|
className={button}
|
|
disabled={value.contacts.length >= 20}
|
|
onClick={() =>
|
|
change({
|
|
contacts: [
|
|
...value.contacts,
|
|
{ ...source, kind: 'website', value: '' },
|
|
],
|
|
})
|
|
}
|
|
>
|
|
Acrescentar contacto
|
|
</button>
|
|
</details>
|
|
<details>
|
|
<summary>
|
|
Sede e balcões ({value.locations.length}) — Alterar
|
|
</summary>
|
|
{value.locations.map((row, i) => (
|
|
<fieldset className={card} key={i}>
|
|
<legend>Local físico {i + 1}</legend>
|
|
<select
|
|
className={input}
|
|
value={row.role}
|
|
onChange={(e) =>
|
|
update('locations', i, { role: e.target.value })
|
|
}
|
|
>
|
|
<option value="headquarters">Sede</option>
|
|
<option value="branch">Balcão</option>
|
|
<option value="contact_point">
|
|
Contacto institucional — tipo por confirmar
|
|
</option>
|
|
</select>
|
|
<Text
|
|
label="Designação"
|
|
value={row.label}
|
|
change={(label) =>
|
|
update('locations', i, { label })
|
|
}
|
|
/>
|
|
<Text
|
|
label="Morada documentada"
|
|
value={row.address}
|
|
change={(address) =>
|
|
update('locations', i, { address })
|
|
}
|
|
/>
|
|
<label>
|
|
Local do cadastro
|
|
<select
|
|
className={input}
|
|
value={row.territory_id ?? ''}
|
|
onChange={(e) =>
|
|
update('locations', i, {
|
|
territory_id: e.target.value,
|
|
})
|
|
}
|
|
>
|
|
<option value="">
|
|
Correspondência por confirmar
|
|
</option>
|
|
{territories.map((t) => (
|
|
<option key={t.id} value={t.id}>
|
|
{t.name}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<Sources
|
|
value={row}
|
|
change={(v) => update('locations', i, v)}
|
|
/>
|
|
<button
|
|
type="button"
|
|
onClick={() =>
|
|
change({
|
|
locations: value.locations.filter(
|
|
(_, n) => n !== i,
|
|
),
|
|
})
|
|
}
|
|
>
|
|
Remover local
|
|
</button>
|
|
</fieldset>
|
|
))}
|
|
<button
|
|
type="button"
|
|
className={button}
|
|
disabled={value.locations.length >= 50}
|
|
onClick={() =>
|
|
change({
|
|
locations: [
|
|
...value.locations,
|
|
{
|
|
...source,
|
|
role: 'headquarters',
|
|
label: '',
|
|
address: '',
|
|
territory_id: '',
|
|
},
|
|
],
|
|
})
|
|
}
|
|
>
|
|
Acrescentar sede/balcão
|
|
</button>
|
|
</details>
|
|
<details>
|
|
<summary>
|
|
Programas/produtos ({value.products.length}) — Alterar
|
|
</summary>
|
|
{value.products.map((row, i) => (
|
|
<fieldset className={card} key={row.code}>
|
|
<legend>Produto {i + 1}</legend>
|
|
<Text
|
|
label="Nome documentado"
|
|
value={row.title}
|
|
change={(title) => update('products', i, { title })}
|
|
/>
|
|
<Text
|
|
label="Instrumento"
|
|
value={row.instrument}
|
|
change={(instrument) =>
|
|
update('products', i, { instrument })
|
|
}
|
|
/>
|
|
<label>
|
|
Necessidades documentadas
|
|
<select
|
|
multiple
|
|
className={input}
|
|
value={row.needs}
|
|
onChange={(e) =>
|
|
update('products', i, {
|
|
needs: Array.from(
|
|
e.target.selectedOptions,
|
|
(o) => o.value,
|
|
),
|
|
})
|
|
}
|
|
>
|
|
{Object.entries(needs).map(([id, label]) => (
|
|
<option key={id} value={id}>
|
|
{label}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<label>
|
|
Cobertura deste produto
|
|
<select
|
|
className={input}
|
|
value={row.coverage}
|
|
onChange={(e) =>
|
|
update('products', i, {
|
|
coverage: e.target.value,
|
|
territory_ids: [],
|
|
})
|
|
}
|
|
>
|
|
<option value="unknown">Por confirmar</option>
|
|
<option value="national">
|
|
Nacional, segundo a fonte
|
|
</option>
|
|
<option value="territorial">
|
|
Locais documentados
|
|
</option>
|
|
</select>
|
|
</label>
|
|
{row.coverage === 'territorial' && (
|
|
<label>
|
|
Locais abrangidos
|
|
<select
|
|
multiple
|
|
className={input}
|
|
value={row.territory_ids}
|
|
onChange={(e) =>
|
|
update('products', i, {
|
|
territory_ids: Array.from(
|
|
e.target.selectedOptions,
|
|
(o) => o.value,
|
|
),
|
|
})
|
|
}
|
|
>
|
|
{territories.map((t) => (
|
|
<option key={t.id} value={t.id}>
|
|
{t.name}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
)}
|
|
<Text
|
|
label="Explicação da cobertura"
|
|
value={row.coverage_text}
|
|
change={(coverage_text) =>
|
|
update('products', i, { coverage_text })
|
|
}
|
|
/>
|
|
<label>
|
|
Condições — vazio significa por confirmar
|
|
<textarea
|
|
className={input}
|
|
value={row.conditions}
|
|
maxLength={4000}
|
|
onChange={(e) =>
|
|
update('products', i, {
|
|
conditions: e.target.value,
|
|
})
|
|
}
|
|
/>
|
|
</label>
|
|
<Text
|
|
label="Montantes/moeda/prazos documentados — se conhecidos"
|
|
value={row.amounts}
|
|
change={(amounts) =>
|
|
update('products', i, { amounts })
|
|
}
|
|
/>
|
|
<label>
|
|
Disponibilidade
|
|
<select
|
|
className={input}
|
|
value={row.availability}
|
|
onChange={(e) =>
|
|
update('products', i, {
|
|
availability: e.target.value,
|
|
})
|
|
}
|
|
>
|
|
<option value="unknown">Por confirmar</option>
|
|
<option value="documented">
|
|
Oferta identificada na fonte (não é
|
|
concessão)
|
|
</option>
|
|
<option value="closed">
|
|
Encerrada segundo a fonte
|
|
</option>
|
|
</select>
|
|
</label>
|
|
<Text
|
|
label="Canal de contacto do produto"
|
|
type="url"
|
|
value={row.contact_url}
|
|
change={(contact_url) =>
|
|
update('products', i, { contact_url })
|
|
}
|
|
/>
|
|
<Sources
|
|
value={row}
|
|
change={(v) => update('products', i, v)}
|
|
/>
|
|
<button
|
|
type="button"
|
|
onClick={() =>
|
|
change({
|
|
products: value.products.filter(
|
|
(_, n) => n !== i,
|
|
),
|
|
})
|
|
}
|
|
>
|
|
Remover produto
|
|
</button>
|
|
</fieldset>
|
|
))}
|
|
<button
|
|
type="button"
|
|
className={button}
|
|
disabled={value.products.length >= 40}
|
|
onClick={() =>
|
|
change({
|
|
products: [
|
|
...value.products,
|
|
{
|
|
...source,
|
|
code: crypto.randomUUID(),
|
|
title: '',
|
|
instrument: '',
|
|
needs: [],
|
|
coverage: 'unknown',
|
|
coverage_text: '',
|
|
territory_ids: [],
|
|
conditions: '',
|
|
amounts: '',
|
|
availability: 'unknown',
|
|
contact_url: '',
|
|
},
|
|
],
|
|
})
|
|
}
|
|
>
|
|
Acrescentar programa/produto
|
|
</button>
|
|
</details>
|
|
</section>
|
|
);
|
|
}
|
|
function Source({ value }: { value: FundingSource }) {
|
|
return (
|
|
<div>
|
|
<p>
|
|
{value.source_url ? (
|
|
<a
|
|
className="underline"
|
|
href={value.source_url}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
>
|
|
{value.source_reference}
|
|
</a>
|
|
) : (
|
|
value.source_reference
|
|
)}{' '}
|
|
· consulta {value.checked_on}
|
|
</p>
|
|
{value.source_document_name && (
|
|
<p>
|
|
Documento: {value.source_document_name} · SHA-256{' '}
|
|
{value.source_document_sha256}
|
|
</p>
|
|
)}
|
|
{value.evidence_status && (
|
|
<p>
|
|
{evidenceLabels[value.evidence_status] ??
|
|
value.evidence_status}{' '}
|
|
· {value.origin}
|
|
</p>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
export function InstitutionView({ value }: { value: InstitutionDetails }) {
|
|
return (
|
|
<section className={card}>
|
|
<h2>Instituição financeira</h2>
|
|
<ClassificationSummary value={value} />
|
|
{!value.institution_types?.length && (
|
|
<p>
|
|
Natureza:{' '}
|
|
{
|
|
(
|
|
{
|
|
bank: 'Banco',
|
|
credit: 'Instituição de crédito',
|
|
microfinance: 'Microfinanças',
|
|
investment_fund: 'Fundo de investimento',
|
|
development:
|
|
'Agência de desenvolvimento/financiamento',
|
|
other: 'Outra natureza documentada',
|
|
unknown: 'Por confirmar',
|
|
} as Record<string, string>
|
|
)[value.institution_nature]
|
|
}
|
|
</p>
|
|
)}
|
|
|
|
<h3>Contactos</h3>
|
|
{value.contacts.length === 0 && <p>Contactos por confirmar.</p>}
|
|
{value.contacts.map((c, i) => (
|
|
<article key={i}>
|
|
<p>
|
|
{c.kind === 'website' ? (
|
|
<a
|
|
className="underline"
|
|
href={c.value}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
>
|
|
{c.value}
|
|
</a>
|
|
) : (
|
|
c.value
|
|
)}
|
|
</p>
|
|
<Source value={c} />
|
|
</article>
|
|
))}
|
|
<h3>Sede e balcões — presença física</h3>
|
|
{value.locations.length === 0 && (
|
|
<p>Localização física por confirmar.</p>
|
|
)}
|
|
{value.locations.map((l, i) => (
|
|
<article key={i}>
|
|
<p>
|
|
{l.role === 'headquarters'
|
|
? 'Sede'
|
|
: l.role === 'branch'
|
|
? 'Balcão'
|
|
: 'Ponto de contacto institucional'}
|
|
: {l.label} · {l.address}
|
|
</p>
|
|
<p>
|
|
{l.territory_path?.map((n) => n.name).join(' / ') ||
|
|
'Correspondência ao cadastro territorial por confirmar'}
|
|
</p>
|
|
{l.location_text && (
|
|
<p>Local indicado: {l.location_text}</p>
|
|
)}
|
|
{l.hours && (
|
|
<p>
|
|
Horário indicado na fonte (pode ter mudado):{' '}
|
|
{l.hours}
|
|
</p>
|
|
)}
|
|
<Source value={l} />
|
|
</article>
|
|
))}
|
|
<h3>Produtos e programas</h3>
|
|
{value.products.length === 0 && (
|
|
<p>
|
|
Produtos e condições por confirmar; a identificação da
|
|
instituição não confirma oferta disponível.
|
|
</p>
|
|
)}
|
|
{value.products.map((p) => (
|
|
<article className={card} key={p.code}>
|
|
<h4>{p.title}</h4>
|
|
<p>{p.instrument}</p>
|
|
<p>
|
|
Cobertura do financiamento:{' '}
|
|
{p.coverage === 'national'
|
|
? 'Nacional, segundo a fonte'
|
|
: p.coverage === 'territorial'
|
|
? 'Locais documentados'
|
|
: 'Por confirmar'}{' '}
|
|
· {p.coverage_text}
|
|
</p>
|
|
{p.territory_paths?.map((path, i) => (
|
|
<p key={i}>{path.map((n) => n.name).join(' / ')}</p>
|
|
))}
|
|
<p>Condições: {p.conditions || 'Por confirmar'}</p>
|
|
<p>
|
|
Montantes/moeda/prazos: {p.amounts || 'Por confirmar'}
|
|
</p>
|
|
<p>
|
|
Disponibilidade:{' '}
|
|
{p.availability === 'unknown'
|
|
? 'Por confirmar'
|
|
: p.availability === 'closed'
|
|
? 'Encerrada segundo a fonte'
|
|
: 'Oferta identificada na fonte; confirmar condições actuais com a instituição'}
|
|
</p>
|
|
{p.contact_url && (
|
|
<a
|
|
href={p.contact_url}
|
|
className="underline"
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
>
|
|
Contactar/consultar o produto
|
|
</a>
|
|
)}
|
|
<Source value={p} />
|
|
</article>
|
|
))}
|
|
<p>
|
|
Uma referência não é elegibilidade confirmada, aprovação nem
|
|
garantia de financiamento. O portal não envia pedidos ou dados à
|
|
instituição.
|
|
</p>
|
|
</section>
|
|
);
|
|
}
|