Preserve installed dossier and support presentation while delivering authorised quick search
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-13 15:17:26 +02:00
6 changed files with 304 additions and 10 deletions
@@ -1,6 +1,7 @@
import { useState } from 'react';
import { useEffect, useState } from 'react';
import {
createInvestorDossierReport,
createInvestorStageReport,
investorDossierReportIndex,
type InvestorDossierReportInput,
} from '@/lib/investor-dossier-report';
@@ -13,9 +14,33 @@ export function InvestorDossierReports({
dossier,
}: {
dossier: InvestorDossierReportInput;
}) {
return (
<InvestorDossierReportsContent
key={`${dossier.case.id}:${dossier.case.version}:${dossier.context_opportunity ?? ''}`}
dossier={dossier}
/>
);
}
function InvestorDossierReportsContent({
dossier,
}: {
dossier: InvestorDossierReportInput;
}) {
const [busy, setBusy] = useState(false);
const [error, setError] = useState('');
const [stage, setStage] = useState('');
const [download, setDownload] = useState<{
url: string;
name: string;
} | null>(null);
useEffect(
() => () => {
if (download) URL.revokeObjectURL(download.url);
},
[download],
);
const requiresChoice =
dossier.opportunity_options.length > 1 && !dossier.context_opportunity;
const entries = requiresChoice ? [] : investorDossierReportIndex(dossier);
@@ -23,7 +48,9 @@ export function InvestorDossierReports({
setBusy(true);
setError('');
try {
const model = createInvestorDossierReport(dossier);
const model = stage
? createInvestorStageReport(dossier, stage)
: createInvestorDossierReport(dossier);
const blob =
format === 'word'
? await generateProjectDossierDocx(model, [], true)
@@ -38,11 +65,8 @@ export function InvestorDossierReports({
{ type: 'text/html;charset=utf-8' },
);
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = `dossier-${dossier.case.id}-v${dossier.case.version}-${dossier.context_opportunity ? encodeURIComponent(dossier.context_opportunity) : 'comum'}.${format === 'word' ? 'docx' : 'html'}`;
link.click();
window.setTimeout(() => URL.revokeObjectURL(url), 1000);
const name = `dossier-${dossier.case.id}-v${dossier.case.version}-${dossier.context_opportunity ? encodeURIComponent(dossier.context_opportunity) : 'comum'}${stage ? `-${stage}` : ''}.${format === 'word' ? 'docx' : 'html'}`;
setDownload({ url, name });
} catch (cause) {
setError(
cause instanceof Error
@@ -72,22 +96,61 @@ export function InvestorDossierReports({
</p>
) : (
<>
<label className="block">
Relatório a consultar e descarregar
<select
className="mt-1 block w-full rounded border p-2"
value={stage}
disabled={busy}
onChange={(event) => {
setStage(event.target.value);
setDownload(null);
}}
>
<option value="">Dossier completo</option>
{dossier.steps.map((step) => (
<option key={step.code} value={step.code}>
{step.code} — {step.title}
</option>
))}
</select>
</label>
{stage && (
<StageReportPreview dossier={dossier} stage={stage} />
)}
<div className="flex flex-wrap gap-3">
<button
className="rounded border px-3 py-2"
disabled={busy}
onClick={() => exportReport('word')}
>
Descarregar relatório consolidado (Word)
Preparar{' '}
{stage
? `relatório ${stage}`
: 'relatório consolidado'}{' '}
(Word)
</button>
<button
className="rounded border px-3 py-2"
disabled={busy}
onClick={() => exportReport('html')}
>
Descarregar versão para impressão/PDF
Preparar versão para impressão/PDF
</button>
</div>
{busy && <p role="status">A preparar o ficheiro…</p>}
{download && (
<p role="status">
Ficheiro pronto.{' '}
<a
className="font-medium underline"
href={download.url}
download={download.name}
>
Descarregar {download.name}
</a>
</p>
)}
<p className="text-sm">
A versão HTML pode ser aberta e impressa ou guardada
como PDF. As descargas são privadas; não enviam
@@ -163,3 +226,46 @@ export function InvestorDossierReports({
</section>
);
}
function StageReportPreview({
dossier,
stage,
}: {
dossier: InvestorDossierReportInput;
stage: string;
}) {
const report = createInvestorStageReport(dossier, stage);
return (
<article
className="space-y-3 rounded border p-3"
aria-label={`Relatório da etapa ${stage}`}
>
<h3 className="font-semibold">{report.title}</h3>
<p className="text-sm">{report.version}</p>
{report.sections.map((section) => (
<section key={section.id} className="space-y-2">
<h4 className="font-medium">{section.title}</h4>
{section.paragraphs.map((text) => (
<p key={text}>{text}</p>
))}
<dl className="space-y-2">
{section.rows.map((row, index) => (
<div key={index} className="break-words">
<dt className="font-medium">{row.field}</dt>
<dd>{row.value}</dd>
<dd className="text-sm">
{row.classification} · {row.origin}
</dd>
</div>
))}
</dl>
</section>
))}
{report.limitations.map((text) => (
<p className="text-sm" key={text}>
{text}
</p>
))}
</article>
);
}