fix: connect documentary anchors to investment preparation and recover accepted territories
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-10-23 19:17:15 +02:00
parent cdf8fcfba4
commit 3fd5128c62
21 changed files with 1668 additions and 33 deletions
@@ -12,6 +12,7 @@ export default function ContextStart({
step = null,
entryQuery = {},
entryComplements = [],
entrySubmission = null,
}: {
contexts: { id: string; title: string; version: number }[];
source: ContextReference | null;
@@ -19,6 +20,7 @@ export default function ContextStart({
step?: string | null;
entryQuery?: Record<string, string>;
entryComplements?: Complement[];
entrySubmission?: {id:string;version:number} | null;
}) {
const [chosen, setChosen] = useState('');
const [title, setTitle] = useState(entryComplements[0]?.kind === 'need' ? `Preparação de ${entryComplements[0].title} — ${entryComplements[0].origin.title}`.slice(0,200) : source?.title ?? opportunityChoices[0]?.opportunity.title ?? '');
@@ -28,6 +30,13 @@ export default function ContextStart({
const [key] = useState(createOperationKey);
const sourceSuffix = opportunityChoices.length ? '?' + opportunityChoices.map(c => `opportunities[]=${encodeURIComponent(c.opportunity.id)}`).join('&') : source ? '?source=' + encodeURIComponent(source.key) : '';
const suffix = sourceSuffix || Object.keys(entryQuery).length ? (sourceSuffix || '?')+(sourceSuffix ? '&' : '')+'selection_key='+encodeURIComponent(key)+'&'+new URLSearchParams(entryQuery).toString() : '';
const continueIn = async (id: string) => {
if (entrySubmission) {
const view = await contextApi<{case:{version:number}}>(`/investimentos/${id}/contexto`);
await contextApi(`/investidor/manifestacoes/${entrySubmission.id}/contexto`, {case_id:id,case_version:view.case.version,version:entrySubmission.version});
}
window.location.assign(`/investimentos/${id}/contexto/editar${suffix}`);
};
return (
<Frame title="Iniciar ou continuar um investimento">
<SelectedComplements items={entryComplements}/>
@@ -44,9 +53,11 @@ export default function ContextStart({
<Link className="underline" href={source.href}>
{source.title}
</Link>
{source.kind === 'portfolio' && <p>Sector documentado: {source.analysis?.documented_sector ?? 'Por definir'}. Cobertura documental: {source.analysis?.documented_location ?? 'Por definir'}. Confirme o enquadramento e a localização do seu investimento no dossier.</p>}
</section>
)}
<section className={card + ' space-y-3'}>
{entrySubmission && <p>Ao continuar, esta manifestação será associada ao dossier escolhido, conservando a ficha de origem. Nenhum pedido será submetido.</p>}
<h2 className="text-xl font-bold">
Continuar um dossier existente
</h2>
@@ -65,20 +76,23 @@ export default function ContextStart({
))}
</select>
</label>
{chosen && (
<Link
{chosen && entrySubmission && (
<button
className={button}
href={
step && !source && !opportunityChoices.length
? `/investimentos/${chosen}#${step}`
: `/investimentos/${chosen}/contexto/editar${suffix}`
}
disabled={busy}
onClick={() => {
if (step && !source && !opportunityChoices.length) {window.location.assign(`/investimentos/${chosen}#${step}`);return;}
setBusy(true);setError('');void continueIn(chosen).catch(e=>{setError(e.message);setBusy(false);});
}}
>
{step && !source && !opportunityChoices.length
? 'Abrir ' + step + ' no mesmo dossier'
: 'Preparar neste dossier'}
</Link>
</button>
)}
{chosen && !entrySubmission && <Link className={button} href={step && !source && !opportunityChoices.length ? `/investimentos/${chosen}#${step}` : `/investimentos/${chosen}/contexto/editar${suffix}`}>
{step && !source && !opportunityChoices.length ? 'Abrir ' + step + ' no mesmo dossier' : 'Preparar neste dossier'}
</Link>}
<p>
Se já preparou este investimento, continue nele. Não é
necessário criar outro dossier.
@@ -95,11 +109,7 @@ export default function ContextStart({
client_key: key,
reuse_consent: consent,
})
.then((r) =>
window.location.assign(
`/investimentos/${r.id}/contexto/editar${suffix}`,
),
)
.then((r) => continueIn(r.id))
.catch((e) => setError(e.message))
.finally(() => setBusy(false));
}}