fix: retain editable investment plans and record partial QA continuity evidence

This commit is contained in:
2026-11-20 09:25:49 +02:00
parent bae996e10d
commit 04d8db6c1b
17 changed files with 1011 additions and 290 deletions
@@ -1,7 +1,8 @@
import CurrencySelect from '@/components/currency-select';
import { useEffect, useState } from 'react';
import { useEffect, useId, useState } from 'react';
import {
compareBusinessScenarios,
businessPlanNumberError,
exportBusinessPlanCsv,
forecastBusinessPlan,
MAX_BUSINESS_PLAN_SNAPSHOT_LENGTH,
@@ -74,23 +75,45 @@ function MoneyInput({
value,
onChange,
allowNegative = false,
step = '0.01',
}: {
label: string;
value: string;
onChange: (value: string) => void;
allowNegative?: boolean;
step?: string;
}) {
const errorId = useId();
const [touched, setTouched] = useState(false);
const error = touched
? businessPlanNumberError(value, { allowNegative })
: '';
return (
<label className="block text-sm font-medium">
{label}
<input
type="number"
min={allowNegative ? undefined : '0'}
step="0.01"
step={step}
value={value}
onChange={(event) => onChange(event.target.value)}
onChange={(event) => {
setTouched(true);
onChange(event.target.value);
}}
onBlur={() => setTouched(true)}
aria-invalid={!!error}
aria-describedby={error ? errorId : undefined}
className="mt-1 w-full rounded border p-2"
/>
{error && (
<span
id={errorId}
role="alert"
className="mt-1 block text-sm text-red-800"
>
{error}
</span>
)}
</label>
);
}
@@ -252,7 +275,7 @@ export function SimulationBusinessPlan({
unitVariableCostByPeriod: 'unitVariableCost',
};
const plan = workingPlan ??
restoreBusinessPlanSnapshot(snapshot) ?? {
restoreBusinessPlanSnapshot(snapshot, { editable: true }) ?? {
...emptyPlan,
currency: projectCurrency,
};
@@ -857,7 +880,11 @@ export function SimulationBusinessPlan({
const fiscalBridge = result ? buildFinancialFiscalBridge(result) : null;
return (
<details className="rounded-lg border border-slate-300 p-4" open>
<details
id="business-financial-plan"
className="rounded-lg border border-slate-300 p-4"
open
>
<summary className="cursor-pointer text-lg font-semibold">
Plano financeiro empresarial (pressupostos editáveis)
</summary>
@@ -1092,25 +1119,18 @@ export function SimulationBusinessPlan({
className="mt-1 w-full rounded border p-2"
/>
</label>
<label className="block text-sm">
{product.monthlyUnitsByPeriod
? 'Unidades mensais base'
: 'Unidades por mes'}
<input
type="number"
min="0"
step="0.001"
value={product.monthlyUnits}
onChange={(event) =>
updateProduct(
index,
'monthlyUnits',
event.target.value,
)
}
className="mt-1 w-full rounded border p-2"
/>
</label>
<MoneyInput
label={
product.monthlyUnitsByPeriod
? 'Unidades mensais base'
: 'Unidades por mes'
}
step="0.001"
value={product.monthlyUnits}
onChange={(value) =>
updateProduct(index, 'monthlyUnits', value)
}
/>
<MoneyInput
label="Preço por unidade"
value={product.unitPrice}
@@ -3298,6 +3298,21 @@ export function SimulationForm() {
>
{current.title}
</h3>
{errors.business_plan_snapshot && (
<p
role="alert"
className="rounded border border-red-400 bg-red-50 p-3 text-red-900"
>
<a
className="underline"
href="#business-financial-plan"
>
{errors.business_plan_snapshot}
</a>{' '}
Os dados permanecem no rascunho; corrija o plano
financeiro para continuar.
</p>
)}
<button
type="button"
data-form-help-open