Entrega dashboard e correccoes transversais preservando Ofertas instalado
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-15 18:56:39 +02:00
parent 1349789226
commit fb076c174f
117 changed files with 10380 additions and 1905 deletions
@@ -3,6 +3,7 @@ import {
persistOpportunitySelection,
} from '@/lib/opportunity-selection';
import CatalogueGuideLinks from '@/components/catalogue-guide-links';
import PublishedOpportunitiesEmpty from '@/components/published-opportunities-empty';
import DemographicContext from '@/components/demographic-context';
import OpportunityCorridorGroups, {
type CorridorGroup,
@@ -409,6 +410,10 @@ export default function Catalogue({
: 'Catálogo de investimento'
}
>
<section className="my-4 space-y-3 rounded border p-4" aria-label="Estudar a localização">
<h2 className="font-semibold">Estudar a localização e preparar uma ideia</h2>
<p>A análise territorial é independente dos anúncios publicados. Os filtros comerciais abaixo aplicam-se à pesquisa de oportunidades.</p>
<div className="flex flex-wrap items-center gap-4">
<Link
className="underline"
href={
@@ -435,6 +440,8 @@ export default function Catalogue({
Iniciar ou continuar ideia nesta localização
</Link>
)}
</div>
</section>
<p className="catalogue-intro">
Combine os filtros para encontrar oportunidades publicadas.
Nenhum critério é alargado automaticamente.
@@ -506,6 +513,15 @@ export default function Catalogue({
error={searchError}
total={results.total}
/>
{!searchLoading &&
!searchError &&
results.total === 0 &&
selectedStructures.length === 0 && (
<PublishedOpportunitiesEmpty
href="/localizacoes/demografia"
label="Consultar indicadores territoriais"
/>
)}
{!searchLoading &&
!searchError &&
results.total === 0 &&
@@ -36,6 +36,7 @@ type Result = {
}[];
};
type Props = {
entity_kind?: string;
definition: { version: string; questions: Record<string, Question> };
case: { id: string; title: string; version: number } | null;
canWrite: boolean;
@@ -98,7 +99,7 @@ function Comparator(props: Props) {
}),
);
};
async function save() {
async function save(next?: string) {
if (!dossier || busy) return;
setBusy(true);
setError('');
@@ -107,8 +108,9 @@ function Comparator(props: Props) {
version: dossier.version,
operation_key: operation.current,
answers: currentValues(),
...(next ? { continue_preparation: true } : {}),
});
router.visit(base, { preserveState: false });
router.visit(next ?? base, { preserveState: false });
} catch (e) {
setError(
e instanceof Error
@@ -222,7 +224,7 @@ function Comparator(props: Props) {
type="button"
className={button}
disabled={busy}
onClick={save}
onClick={() => void save()}
>
{busy ? 'A guardar…' : 'Guardar no dossier'}
</button>
@@ -321,9 +323,36 @@ function Comparator(props: Props) {
</article>
))}
</div>
<h3 className="mt-4 font-semibold">
Preparar a próxima conversa
</h3>
<h3 className="mt-4 font-semibold">Continuar a preparação</h3>
{dossier &&
!['company', 'organization'].includes(
props.entity_kind ?? '',
) &&
!readOnly &&
props.canWrite &&
answers.preferred &&
answers.preferred !== 'unknown' && (
<button
className={button}
type="button"
disabled={busy}
onClick={() =>
void save(
`/investimentos/${dossier.id}/preparar-empresa?form=${encodeURIComponent(answers.preferred)}`,
)
}
>
Usar esta opção e continuar a preparação da empresa
</button>
)}
{dossier && (
<Link
className="block underline"
href={`/simulador-fiscal?context=${dossier.id}`}
>
Continuar a viabilidade sem repetir esta comparação
</Link>
)}
<ul className="list-disc pl-5">
{result.preparation.map((item) => (
<li key={item}>{item}</li>
@@ -1,9 +1,11 @@
import CurrencySelect from '@/components/currency-select';
import { useRef, useState } from 'react';
import { Link, router } from '@inertiajs/react';
import { Frame, card, input, button } from './shared';
import { profileJson, ProfileValidationError } from '@/lib/profile-json';
import { createOperationKey } from '@/lib/operation-key';
import {
companyPreparationNotice,
preparationValues,
type CompanyFacts,
type Party,
@@ -34,12 +36,17 @@ type Props = {
>;
history: { id: string; revision: number; at: string }[];
historyNext: number | null;
entity?: {
kind: string;
snapshot?: { name?: string; legal_form?: string };
} | null;
proposedForm?: string | null;
};
export default function CompanyPreparation(props: Props) {
return (
<Preparation
key={`${props.case.id}:${props.saved?.revision}:${props.historical}`}
key={`${props.case.id}:${props.saved?.revision}:${props.historical}:${props.proposedForm ?? ''}`}
{...props}
/>
);
@@ -86,19 +93,19 @@ function Preparation(props: Props) {
onChange={(e) => update(key, e.target.value)}
maxLength={2000}
/>
) : key === 'currency' ? (
<CurrencySelect
label="Moeda"
value={facts[key] ?? ''}
onChange={(value) => update(key, value)}
/>
) : (
<input
className={input}
name={key}
value={facts[key] ?? ''}
onChange={(e) => update(key, e.target.value)}
maxLength={
key === 'proposed_name'
? 250
: key === 'currency'
? 3
: 25
}
maxLength={key === 'proposed_name' ? 250 : 25}
/>
)}
</label>
@@ -138,7 +145,7 @@ function Preparation(props: Props) {
</label>
);
}
async function save() {
async function save(next?: string) {
if (busy || readOnly) return;
setBusy(true);
setError('');
@@ -151,7 +158,7 @@ function Preparation(props: Props) {
operation_key: operation.current,
facts: values,
});
router.visit(base, { preserveState: false });
router.visit(next ?? base, { preserveState: false });
} catch (e) {
setError(
e instanceof Error
@@ -178,7 +185,41 @@ function Preparation(props: Props) {
}
}
return (
<Frame title="Preparar a constituição da empresa">
<Frame
title={
['company', 'organization'].includes(props.entity?.kind ?? '')
? 'Preparação da empresa existente'
: 'Preparar a constituição da empresa'
}
>
{props.entity?.snapshot?.name && (
<p>
Entidade associada: {props.entity.snapshot.name}. Os dados
recuperados não alteram o cadastro nem comprovam um acto
legal.
</p>
)}
{props.proposedForm &&
facts.form !== props.proposedForm &&
!readOnly && (
<aside className={card}>
<p>
A alternativa escolhida não substituiu a forma já
preparada.
</p>
<button
type="button"
className="underline"
onClick={() => {
update('form', props.proposedForm!);
setDirty(true);
operation.current = createOperationKey();
}}
>
Usar a alternativa escolhida nesta preparação
</button>
</aside>
)}
<p>
<Link
className="underline"
@@ -194,7 +235,7 @@ function Preparation(props: Props) {
Comparar formas jurídicas
</Link>
</p>
<p>{props.definition.template_notice}</p>
<p>{companyPreparationNotice(props.definition.template_notice)}</p>
<p>
Guarde mesmo que faltem dados. Só se pedem informações desta
preparação; valores indicados como realizados são declarações,
@@ -619,6 +660,18 @@ function Preparation(props: Props) {
<button type="submit" className={button}>
Guardar ficha no dossier
</button>
<button
type="button"
className={button}
disabled={busy}
onClick={() =>
void save(
`/simulador-fiscal?context=${props.case.id}`,
)
}
>
Guardar e continuar para a viabilidade
</button>
</section>
</fieldset>
</form>
+126 -23
View File
@@ -1,11 +1,21 @@
import { router } from '@inertiajs/react';
import { useState } from 'react';
import CatalogueChoiceSelect from '@/components/catalogue-choice-select';
import DemographicEvidence, {
type DemographicAnalysis,
} from '@/components/demographic-evidence';
import { Frame, button } from './shared';
export default function Demography({
export default function Demography(
props: Parameters<typeof DemographySelection>[0],
) {
// Server filters identify this consultation, including browser back/forward.
return (
<DemographySelection key={JSON.stringify(props.filters)} {...props} />
);
}
function DemographySelection({
evidence,
filters,
territories,
@@ -27,6 +37,10 @@ export default function Demography({
sectors: Record<string, string>;
}) {
const [selected, setSelected] = useState(filters.territories ?? []);
const [province, setProvince] = useState('');
const [district, setDistrict] = useState('');
const [selectionNotice, setSelectionNotice] = useState('');
const candidate = district || province;
const [start, setStart] = useState(
filters.start_year ?? new Date().getFullYear(),
);
@@ -55,31 +69,96 @@ export default function Demography({
);
}}
>
<label>
Províncias ou distritos (até quatro)
<select
multiple
className="block h-48 w-full rounded border p-2"
value={selected}
onChange={(e) =>
setSelected(
Array.from(
e.target.selectedOptions,
(o) => o.value,
).slice(0, 4),
<fieldset className="min-w-0 space-y-3">
<legend>Localizações a comparar (até quatro)</legend>
<label htmlFor="demography-province" className="block">
Província
</label>
<CatalogueChoiceSelect
id="demography-province"
label="Província da comparação"
value={province}
options={territories
.filter((t) => t.location_type === 'province')
.map((t) => ({ value: t.id, label: t.name }))}
onChange={(value) => {
setProvince(value);
if (district)
setSelectionNotice(
'A escolha do distrito foi limpa. Os locais já acrescentados à comparação foram mantidos.',
);
setDistrict('');
}}
/>
<label htmlFor="demography-district" className="block">
Distrito (opcional)
</label>
<CatalogueChoiceSelect
id="demography-district"
label="Distrito da comparação (opcional)"
value={district}
disabled={!province}
options={territories
.filter(
(t) =>
t.location_type === 'district' &&
t.parent_id === province,
)
.map((t) => ({ value: t.id, label: t.name }))}
onChange={setDistrict}
/>
<p>
Pode comparar apenas a província ou escolher um dos seus
distritos.
</p>
{selectionNotice && <p role="status">{selectionNotice}</p>}
<button
type="button"
className={button}
disabled={
!candidate ||
selected.length >= 4 ||
selected.includes(candidate)
}
onClick={() =>
setSelected((current) => [...current, candidate])
}
>
{territories.map((t) => (
<option key={t.id} value={t.id}>
{t.name} —{' '}
{t.location_type === 'province'
? 'Província'
: `Distrito (${territories.find((p) => p.id === t.parent_id)?.name ?? ''})`}
</option>
))}
</select>
</label>
Acrescentar à comparação
</button>
<ul className="space-y-2">
{selected.map((id) => {
const t = territories.find(
(item) => item.id === id,
);
const label = t
? `${t.name} — ${t.location_type === 'province' ? 'Província' : 'Distrito'}`
: 'Localização guardada';
return (
<li
key={id}
className="flex flex-wrap items-center gap-2"
>
<span>{label}</span>
<button
type="button"
className="underline"
aria-label={`Retirar ${label} da comparação`}
onClick={() =>
setSelected((current) =>
current.filter(
(value) => value !== id,
),
)
}
>
Retirar
</button>
</li>
);
})}
</ul>
</fieldset>
<div className="space-y-3">
<label className="block">
Sector
@@ -123,6 +202,30 @@ export default function Demography({
</div>
</form>
<DemographicEvidence evidence={evidence} />
{evidence.territories.length > 0 && (
<section className="space-y-3 rounded border p-4">
<h2 className="text-xl font-semibold">
Transformar a análise numa ideia
</h2>
<p>
Prepare uma ideia nesta localização e confronte-a com a
oferta existente. Não é necessário haver uma
oportunidade publicada para iniciar a análise.
</p>
{evidence.territories.map((t) => (
<a
key={t.id}
className="block py-2 underline"
href={
'/investimentos/iniciar?source=' +
encodeURIComponent('territory:' + t.id)
}
>
Preparar ideia em {t.name}
</a>
))}
</section>
)}
</Frame>
);
}
+21
View File
@@ -34,6 +34,7 @@ const labels: Record<string, string> = {
investment_capacity: 'Capacidade de investimento declarada',
name: 'Nome da empresa',
registration: 'Referência de registo / NUIT',
legal_form: 'Forma jurídica declarada',
role: 'Função ou relação com a empresa',
description: 'Actividade e observações',
};
@@ -45,9 +46,13 @@ export default function Profile({
countries,
organizations = [],
organizationCountryAvailable = false,
continuation = null,
legalForms = [],
}: {
account: RecordData;
actorId: number;
continuation?: { id: string; title: string; href: string } | null;
legalForms?: { value: string; label: string }[];
companies: Company[];
countries: Country[];
organizations?: Organization[];
@@ -69,6 +74,17 @@ export default function Profile({
);
return (
<Frame title="Perfil de investimento e empresas">
{continuation && (
<aside className={card}>
<p>
Preparação de {continuation.title}. O cadastro no portal
não comprova a constituição legal.
</p>
<Link className="underline" href={continuation.href}>
Voltar ao dossier e associar esta empresa
</Link>
</aside>
)}
<Link className="underline" href="/formas-juridicas">
Comparar formas jurídicas antes de constituir uma entidade
</Link>
@@ -88,6 +104,7 @@ export default function Profile({
actorId={actorId}
editorId="account"
labels={labels}
legalForms={legalForms}
reportDirty={reportDirty}
record={account}
countries={countries}
@@ -132,6 +149,7 @@ export default function Profile({
actorId={actorId}
editorId={company.id}
labels={labels}
legalForms={legalForms}
reportDirty={reportDirty}
record={company}
organizations={organizations}
@@ -140,6 +158,7 @@ export default function Profile({
'name',
'incorporation_country_code',
'registration',
'legal_form',
'sector',
'role',
'description',
@@ -172,6 +191,7 @@ export default function Profile({
actorId={actorId}
editorId="new-company"
labels={labels}
legalForms={legalForms}
reportDirty={reportDirty}
record={{ version: 0, payload: {} }}
company
@@ -180,6 +200,7 @@ export default function Profile({
'name',
'incorporation_country_code',
'registration',
'legal_form',
'sector',
'role',
'description',