fix: validate simulator dates and reconcile QA calculations reports and language
This commit is contained in:
@@ -864,6 +864,10 @@ export function SimulationForm() {
|
||||
const [isCalculating, setIsCalculating] = useState(false);
|
||||
const [hasSaveConflict, setHasSaveConflict] = useState(false);
|
||||
const [result, setResult] = useState<ApiSimulationExecutionV1 | null>(null);
|
||||
const [calculationStale, setCalculationStale] = useState(false);
|
||||
useEffect(() => {
|
||||
if (result) setCalculationStale(false);
|
||||
}, [result]);
|
||||
const arithmeticResult = useMemo(
|
||||
() => readArithmeticSnapshot(result?.result_snapshot),
|
||||
[result],
|
||||
@@ -1039,6 +1043,13 @@ export function SimulationForm() {
|
||||
: (simulationFieldGroups[current.id] ?? []);
|
||||
const fields = fieldsForCurrent.filter(
|
||||
(field) =>
|
||||
!(
|
||||
current.id === 'tax' &&
|
||||
draft.fiscal_scenario_mode === 'custom_planning' &&
|
||||
!['fiscal_scenario_mode', 'base', 'rate', 'reduction'].includes(
|
||||
field.key,
|
||||
)
|
||||
) &&
|
||||
(!field.showWhen || field.showWhen(draft)) &&
|
||||
!(
|
||||
draft.purpose === 'simulate_only' &&
|
||||
@@ -1943,7 +1954,8 @@ export function SimulationForm() {
|
||||
return next;
|
||||
});
|
||||
if (key === 'purpose') setStep(0);
|
||||
if (key !== 'purpose') setResult(null);
|
||||
if (result) setCalculationStale(true);
|
||||
setResult(null);
|
||||
}
|
||||
|
||||
async function clearDraft() {
|
||||
@@ -2274,6 +2286,18 @@ export function SimulationForm() {
|
||||
)
|
||||
setResult(simulation ?? null);
|
||||
if (canSavePersonalData) void loadSimulationHistory();
|
||||
if (simulation?.status === 'completed') {
|
||||
setSaveStatus(
|
||||
'Cálculo concluído. Reveja o resultado e os pressupostos.',
|
||||
);
|
||||
} else if (
|
||||
simulation?.status === 'failed' ||
|
||||
simulation?.status === 'cancelled'
|
||||
) {
|
||||
setSaveStatus(
|
||||
'O cálculo não foi concluído. Os dados introduzidos foram preservados.',
|
||||
);
|
||||
}
|
||||
sessionStorage.removeItem(idempotencyStorageKey);
|
||||
} catch (cause) {
|
||||
setServerError(
|
||||
@@ -2396,6 +2420,16 @@ export function SimulationForm() {
|
||||
aria-labelledby="simulator-step-title"
|
||||
aria-busy={!ready}
|
||||
>
|
||||
{calculationStale && (
|
||||
<p
|
||||
role="status"
|
||||
className="rounded border border-amber-700 bg-amber-50 p-3 text-amber-950"
|
||||
>
|
||||
As entradas foram alteradas. Calcule novamente antes de
|
||||
guardar ou exportar um novo resultado. Os resultados
|
||||
anteriores mantêm-se no histórico.
|
||||
</p>
|
||||
)}
|
||||
{!ready && (
|
||||
<p role="status">
|
||||
A recuperar o rascunho. Aguarde para editar.
|
||||
|
||||
Reference in New Issue
Block a user