Wire grounded private investment preparation into QA dossier path

This commit is contained in:
2026-10-22 10:00:23 +02:00
parent 52fbb1468a
commit a1fbda06ad
16 changed files with 1566 additions and 87 deletions
+180 -26
View File
@@ -1,3 +1,7 @@
import {
PreparationEditor,
PreparationImpact,
} from '@/components/private-investment-preparation';
import { InvestmentContextAssessment } from '@/components/investment-context-assessment';
import ContextDocuments from '@/components/context-documents';
import { Link } from '@inertiajs/react';
@@ -36,6 +40,7 @@ export default function ContextEditor({
}) {
const navigation = useNavigationContext();
const [view, setView] = useState(initial);
const [preparation, setPreparation] = useState(initial.private_investment);
const [options, setOptions] = useState(initialOptions);
const [query, setQuery] = useState('');
const [changes, setChanges] = useState<Partial<Record<Slot, string>>>(() =>
@@ -49,6 +54,9 @@ export default function ContextEditor({
const [declarations, setDeclarations] = useState<Record<string, string>>(
{},
);
const [documentLinks, setDocumentLinks] = useState<
Record<string, string | null>
>({});
const [replace, setReplace] = useState<string[]>([]);
const [plan, setPlan] = useState<ContextPlan | null>(null);
const [busy, setBusy] = useState(false);
@@ -59,6 +67,32 @@ export default function ContextEditor({
string,
unknown
> | null>(null);
const displayValue = (
field: string,
value: string | null | undefined,
): string => {
if (value === null || value === undefined || value === '')
return 'não informado';
const question = view.private_investment?.questions.find(
(q) => q.key === field,
);
return (
question?.options?.[value] ??
(
{
being_formed: 'Em constituição',
existing: 'Existente',
national: 'Nacional',
foreign: 'Estrangeiro',
mixed: 'Misto',
yes: 'Sim',
no: 'Não',
unknown: 'Por determinar',
} as Record<string, string>
)[value] ??
value
);
};
const selected = (slot: Slot) =>
Object.hasOwn(changes, slot)
? (changes[slot] ?? '')
@@ -77,6 +111,7 @@ export default function ContextEditor({
selection: changes,
declarations,
replace_fields: replace,
document_links: documentLinks,
};
try {
const result = await contextApi<ContextPlan>(
@@ -85,6 +120,9 @@ export default function ContextEditor({
);
setRequestBody(body);
setPlan(result);
setPreparation(
result.private_investment?.after ?? view.private_investment,
);
} catch (e) {
setError(
e instanceof Error ? e.message : 'Não foi possível comparar.',
@@ -111,9 +149,11 @@ export default function ContextEditor({
`/investimentos/${view.case.id}/contexto`,
);
setView(next);
setPreparation(next.private_investment);
navigation.refresh();
setChanges({});
setDeclarations({});
setDocumentLinks({});
setReplace([]);
setPlan(null);
setOperation(createOperationKey());
@@ -132,7 +172,10 @@ export default function ContextEditor({
}
return (
<Frame title="Contexto do investimento">
<InvestmentContextAssessment contextId={view.case.id} raw={view.prefill.simulator?.context_applicability_snapshot} />
<InvestmentContextAssessment
contextId={view.case.id}
raw={view.prefill.simulator?.context_applicability_snapshot}
/>
<ContextDocuments source={view.context.selection.opportunity} />
<div className="space-y-5 [overflow-wrap:anywhere]">
<Link
@@ -337,17 +380,107 @@ export default function ContextEditor({
Estes campos pertencem ao processo. Alterá-los não muda
o cadastro da oportunidade nem o perfil da organização.
</p>
<p>Origem do investidor, residência fiscal e constituição da entidade são declarações distintas. A localização não confirma benefícios. A prévia identifica o impacto antes de guardar.</p>
<p>
Origem do investidor, residência fiscal e constituição
da entidade são declarações distintas. A localização não
confirma benefícios. A prévia identifica o impacto antes
de guardar.
</p>
{[
['currency','Moeda do projecto',null],
['expected_start_date','Data prevista de início',null],
['investor_origin','Origem do investidor',[['national','Nacional'],['foreign','Estrangeiro'],['mixed','Misto']]],
['person_type','Tipo de entidade',[['singular','Pessoa singular'],['collective','Pessoa colectiva'],['consortium','Consórcio']]],
['entity_stage','Situação da entidade',[['existing','Existente'],['being_formed','Em constituição']]],
['tax_residency_country','País de residência fiscal declarado (ISO de duas letras)',null],
].map(([key,label,choices]) => <label className="grid gap-1" key={String(key)}>{String(label)}{Array.isArray(choices)
? <select className={input} value={declarations[String(key)] ?? view.context.fields[String(key)] ?? ''} onChange={e=>{setDeclarations({...declarations,[String(key)]:e.target.value});setPlan(null);}}><option value="">Por indicar</option>{choices.map(([value,text])=><option key={value} value={value}>{text}</option>)}</select>
: <input className={input} type={key==='expected_start_date'?'date':'text'} maxLength={key==='currency'?3:key==='tax_residency_country'?2:10} value={declarations[String(key)] ?? view.context.fields[String(key)] ?? ''} onChange={e=>{setDeclarations({...declarations,[String(key)]:e.target.value});setPlan(null);}} />}</label>)}
['currency', 'Moeda do projecto', null],
[
'expected_start_date',
'Data prevista de início',
null,
],
[
'investor_origin',
'Origem do investidor',
[
['national', 'Nacional'],
['foreign', 'Estrangeiro'],
['mixed', 'Misto'],
],
],
[
'person_type',
'Tipo de entidade',
[
['singular', 'Pessoa singular'],
['collective', 'Pessoa colectiva'],
['consortium', 'Consórcio'],
],
],
[
'entity_stage',
'Situação da entidade',
[
['existing', 'Existente'],
['being_formed', 'Em constituição'],
],
],
[
'tax_residency_country',
'País de residência fiscal declarado (ISO de duas letras)',
null,
],
].map(([key, label, choices]) => (
<label className="grid gap-1" key={String(key)}>
{String(label)}
{Array.isArray(choices) ? (
<select
className={input}
value={
declarations[String(key)] ??
view.context.fields[String(key)] ??
''
}
onChange={(e) => {
setDeclarations({
...declarations,
[String(key)]: e.target.value,
});
setPlan(null);
}}
>
<option value="">Por indicar</option>
{choices.map(([value, text]) => (
<option key={value} value={value}>
{text}
</option>
))}
</select>
) : (
<input
className={input}
type={
key === 'expected_start_date'
? 'date'
: 'text'
}
maxLength={
key === 'currency'
? 3
: key === 'tax_residency_country'
? 2
: 10
}
value={
declarations[String(key)] ??
view.context.fields[String(key)] ??
''
}
onChange={(e) => {
setDeclarations({
...declarations,
[String(key)]: e.target.value,
});
setPlan(null);
}}
/>
)}
</label>
))}
{['project_title', 'project_summary'].map((k) => (
<label className="grid gap-1" key={k}>
{contextFieldNames[k]}
@@ -379,18 +512,7 @@ export default function ContextEditor({
declarações do utilizador. Autorize somente os
campos que pretende substituir pelo cadastro.
</p>
<p>Origem do investidor, residência fiscal e constituição da entidade são declarações distintas. A localização não confirma benefícios. A prévia identifica o impacto antes de guardar.</p>
{[
['currency','Moeda do projecto',null],
['expected_start_date','Data prevista de início',null],
['investor_origin','Origem do investidor',[['national','Nacional'],['foreign','Estrangeiro'],['mixed','Misto']]],
['person_type','Tipo de entidade',[['singular','Pessoa singular'],['collective','Pessoa colectiva'],['consortium','Consórcio']]],
['entity_stage','Situação da entidade',[['existing','Existente'],['being_formed','Em constituição']]],
['tax_residency_country','País de residência fiscal declarado (ISO de duas letras)',null],
].map(([key,label,choices]) => <label className="grid gap-1" key={String(key)}>{String(label)}{Array.isArray(choices)
? <select className={input} value={declarations[String(key)] ?? view.context.fields[String(key)] ?? ''} onChange={e=>{setDeclarations({...declarations,[String(key)]:e.target.value});setPlan(null);}}><option value="">Por indicar</option>{choices.map(([value,text])=><option key={value} value={value}>{text}</option>)}</select>
: <input className={input} type={key==='expected_start_date'?'date':'text'} maxLength={key==='currency'?3:key==='tax_residency_country'?2:10} value={declarations[String(key)] ?? view.context.fields[String(key)] ?? ''} onChange={e=>{setDeclarations({...declarations,[String(key)]:e.target.value});setPlan(null);}} />}</label>)}
{['project_title', 'project_summary'].map((k) => (
{['project_title', 'project_summary'].map((k) => (
<label className="block" key={k}>
<input
type="checkbox"
@@ -411,6 +533,30 @@ export default function ContextEditor({
</label>
))}
</details>
{view.private_investment && (
<PreparationEditor
data={preparation ?? view.private_investment}
fields={view.context.fields}
changes={declarations}
documents={view.preparation_documents ?? []}
links={documentLinks}
disabled={busy || !view.can_write}
onChange={(key, value) => {
setDeclarations({
...declarations,
[key]: value,
});
setPlan(null);
}}
onLink={(key, value) => {
setDocumentLinks({
...documentLinks,
[key]: value,
});
setPlan(null);
}}
/>
)}
<button
className={button}
type="button"
@@ -467,10 +613,15 @@ export default function ContextEditor({
x.field
] ?? x.field}
:{' '}
{x.before ??
'não informado'}{' '}
{displayValue(
x.field,
x.before,
)}{' '}
→{' '}
{x.after ?? 'não informado'}
{displayValue(
x.field,
x.after,
)}
</p>
))}
{Object.values(plan.selection).map(
@@ -530,6 +681,9 @@ export default function ContextEditor({
</tbody>
</table>
</div>
{plan.private_investment && (
<PreparationImpact {...plan.private_investment} />
)}
<p>{plan.notice}</p>
<div className="flex flex-wrap gap-3">
<button
+31
View File
@@ -1,3 +1,7 @@
import {
PreparationSummary,
type Preparation,
} from '@/components/private-investment-preparation';
import ContextDocuments from '@/components/context-documents';
import type { DossierContext } from '@/lib/investor-context';
import FintechInvestment, {
@@ -27,6 +31,7 @@ type Step = {
source_paragraph: number;
};
type Path = {
private_investment?: Preparation | null;
fintech: FintechView | null;
investment_context: DossierContext | null;
zone_contexts?: {
@@ -180,6 +185,28 @@ function Stage({ step, path }: { step: Step; path: Path }) {
independente.
</label>
)}
{path.private_investment?.enabled && (
<div className="space-y-2">
{path.private_investment.requirements
.filter((r) => r.stage === step.code)
.map((r) => (
<p className="text-sm" key={r.key}>
<strong>{r.label}:</strong>{' '}
{r.state === 'not_applicable'
? 'não exigido neste contexto; histórico preservado'
: r.state === 'associated'
? 'documento associado; conteúdo por conferir'
: r.state === 'missing'
? 'documento por associar'
: 'aplicabilidade por determinar'}
. {r.reason}{' '}
<a className="underline" href={r.source.url}>
{r.source.reference}
</a>
</p>
))}
</div>
)}
{step.reason && (
<p className="text-sm">Fundamento: {step.reason}</p>
)}
@@ -415,6 +442,10 @@ export default function InvestmentPath(path: Path) {
<ContextDocuments
source={path.investment_context?.selection.opportunity}
/>
<PreparationSummary
data={path.private_investment}
caseId={path.case.id}
/>
{path.investment_context && (
<section className="space-y-2 rounded border border-emerald-300 bg-emerald-50 p-4">
<h2 className="font-semibold">