fix: complete InvesteMoz validation and error corrections

This commit is contained in:
2026-10-29 21:47:33 +02:00
parent 63147312e2
commit daf8623441
718 changed files with 127308 additions and 20959 deletions
@@ -1,3 +1,4 @@
import { inputText } from '../lib/input-text.ts';
import {
PreparationSummary,
type Preparation,
@@ -53,7 +54,7 @@ export function InvestmentContextAssessment({
}) {
let snapshot: Snapshot | null = null;
try {
const value = JSON.parse(String(raw ?? ''));
const value = JSON.parse(inputText(raw ?? ''));
if (value.version === 1) snapshot = value;
} catch {
/* Missing context remains explicit. */
@@ -61,8 +62,16 @@ export function InvestmentContextAssessment({
if (!snapshot) return null;
const fields = snapshot.fields ?? {};
const zone = snapshot.zone;
const steps = (snapshot.path?.steps ?? []).filter(step => !!step.title?.trim());
if (!zone && !fields.investor_origin && !fields.tax_residency_country && !snapshot.preparation?.enabled) return null;
const steps = (snapshot.path?.steps ?? []).filter(
(step) => !!step.title?.trim(),
);
if (
!zone &&
!fields.investor_origin &&
!fields.tax_residency_country &&
!snapshot.preparation?.enabled
)
return null;
const regime = zone?.fields?.investment_regime ?? fields.investment_regime;
const names: Record<string, string> = {
zee: 'ZEE',
@@ -74,19 +83,19 @@ export function InvestmentContextAssessment({
className="space-y-2 rounded border border-amber-400 p-3"
aria-label="Aplicabilidade ao investimento"
>
<h3 className="font-semibold">
Condições do investimento
</h3>
{(fields.investor_origin || fields.tax_residency_country) && <p>
Origem do investidor:{' '}
{{
national: 'nacional',
foreign: 'estrangeiro',
mixed: 'misto',
}[fields.investor_origin] ?? 'informação em falta'}
. Residência fiscal declarada:{' '}
{fields.tax_residency_country || 'Por preencher'}.
</p>}
<h3 className="font-semibold">Condições do investimento</h3>
{(fields.investor_origin || fields.tax_residency_country) && (
<p>
Origem do investidor:{' '}
{{
national: 'nacional',
foreign: 'estrangeiro',
mixed: 'misto',
}[fields.investor_origin] ?? 'informação em falta'}
. Residência fiscal declarada:{' '}
{fields.tax_residency_country || 'Por preencher'}.
</p>
)}
{zone ? (
<>
<p>
@@ -161,15 +170,15 @@ export function InvestmentContextAssessment({
</p>
)}
<p role="status">
Os benefícios desta zona ainda não estão disponíveis no simulador. O cenário geral disponível não inclui benefícios especiais nem apuramento fiscal final.
Os benefícios desta zona ainda não estão disponíveis no
simulador. O cenário geral disponível não inclui
benefícios especiais nem apuramento fiscal final.
</p>
</>
) : null}
{!!steps.length && (
<details>
<summary>
Etapas a preparar
</summary>
<summary>Etapas a preparar</summary>
<ul className="list-disc pl-5">
{steps.map((step) => (
<li key={step.code}>