From 4745331ebd51d8c4d6edcf27cc9996acd595a5e2 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Dec 2026 22:54:09 +0200 Subject: [PATCH] =?UTF-8?q?Simulador:=20os=20campos=20num=C3=A9ricos=20ace?= =?UTF-8?q?itam=20=C2=AB25.000=C2=BB,=20=C2=AB1=20500=C2=BB=20e=20=C2=AB15?= =?UTF-8?q?00,50=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit O campo numérico do navegador segue a língua do navegador: «25.000» era lido como 25 e a vírgula decimal podia ser recusada, pelo que o investidor via o valor mudar ou não conseguia escrever. Os campos de montantes do simulador, do plano de negócio e do orçamento inicial passam a usar um campo de texto decimal que lê os números como se escrevem em Moçambique, mostra «Lido como …» quando reinterpreta e deixa o texto inválido chegar à validação, que o explica. Os campos inteiros (horizonte, prazo de entrega, vida útil, mês económico) deixam de saltar para 1 quando se apaga para reescrever; se o valor escrito não for aceite, ao sair do campo volta o valor em vigor. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jM --- resources/js/components/decimal-input.tsx | 89 ++++++++++ .../js/components/financial-day-terms.tsx | 9 +- .../js/components/financial-plan-details.tsx | 13 +- .../js/components/financial-ratios-plan.tsx | 8 +- .../js/components/integral-financial-plan.tsx | 34 ++-- .../js/components/investment-budget-range.tsx | 8 +- .../components/investment-initial-budget.tsx | 8 +- .../investment-operating-assistance.tsx | 15 +- resources/js/components/project-planning.tsx | 27 ++-- resources/js/components/project-readiness.tsx | 9 +- .../components/simulation-annual-example.tsx | 6 +- .../components/simulation-business-plan.tsx | 70 ++++---- .../simulation-cashflow-planner.tsx | 20 ++- .../components/simulation-financial-tools.tsx | 6 +- resources/js/components/simulation-form.tsx | 34 ++-- .../components/startup-asset-requirements.tsx | 6 +- resources/js/lib/decimal-input.ts | 56 +++++++ tests/frontend/business-plan-editing.test.mjs | 5 +- .../business-plan-guidance-ui.test.mjs | 7 +- tests/frontend/decimal-input.test.mjs | 152 ++++++++++++++++++ ...nancial-plan-pending-requirements.test.mjs | 20 ++- .../frontend/financial-tools-source.test.mjs | 3 +- tests/frontend/helpers/decimal-input.mjs | 57 +++++++ .../integral-financial-plan-ui.test.mjs | 33 ++-- .../investment-assistance-controls.test.mjs | 33 ++-- .../startup-example-correspondence.test.mjs | 13 +- tests/frontend/v12-diagnostics.test.mjs | 7 +- tests/frontend/v12-final-gaps.test.mjs | 7 +- 28 files changed, 559 insertions(+), 196 deletions(-) create mode 100644 resources/js/components/decimal-input.tsx create mode 100644 resources/js/lib/decimal-input.ts create mode 100644 tests/frontend/decimal-input.test.mjs create mode 100644 tests/frontend/helpers/decimal-input.mjs diff --git a/resources/js/components/decimal-input.tsx b/resources/js/components/decimal-input.tsx new file mode 100644 index 00000000..9c587f35 --- /dev/null +++ b/resources/js/components/decimal-input.tsx @@ -0,0 +1,89 @@ +import { + useEffect, + useId, + useRef, + useState, + type InputHTMLAttributes, +} from 'react'; +import { normalizeDecimalInput, presentDecimal } from '@/lib/decimal-input'; + +type Props = Omit< + InputHTMLAttributes, + 'type' | 'value' | 'onChange' | 'min' | 'max' | 'step' +> & { + value: string | number | null | undefined; + /** Receives the stored format ("1500.50"), or the raw text when it is not a number, so validation can explain it. */ + onValueChange: (value: string) => void; + min?: string | number; + max?: string | number; + step?: string | number; +}; + +/** + * Number field that reads «25.000», «1 500» and «1500,50» as written in + * Mozambique, instead of the browser's number input, which follows the + * browser locale (25.000 → 25; a comma may be refused). + */ +export function DecimalInput({ + value: rawValue, + onValueChange, + min: _min, + max: _max, + step: _step, + onBlur, + ...rest +}: Props) { + const value = + rawValue === null || rawValue === undefined ? '' : String(rawValue); + const hintId = useId(); + const [text, setText] = useState(value); + const emitted = useRef(value); + useEffect(() => { + // A value set elsewhere (draft recovery, another field) replaces the text. + if (normalizeDecimalInput(text) !== value) setText(value); + emitted.current = value; + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [value]); + const read = normalizeDecimalInput(text); + const reinterpreted = + read !== null && read !== '' && read !== text.trim() ? read : null; + return ( + <> + { + // A field the plan did not accept (an emptied horizon, a + // fraction of a month) shows again the value still in force. + if (emitted.current !== value) { + setText(value); + emitted.current = value; + } + onBlur?.(event); + }} + aria-describedby={ + [rest['aria-describedby'], reinterpreted ? hintId : null] + .filter(Boolean) + .join(' ') || undefined + } + onChange={(event) => { + setText(event.target.value); + const normalized = normalizeDecimalInput( + event.target.value, + ); + emitted.current = + normalized === null ? event.target.value : normalized; + onValueChange(emitted.current); + }} + /> + {reinterpreted && ( + + Lido como {presentDecimal(reinterpreted)} + + )} + + ); +} diff --git a/resources/js/components/financial-day-terms.tsx b/resources/js/components/financial-day-terms.tsx index 427e449d..efaff049 100644 --- a/resources/js/components/financial-day-terms.tsx +++ b/resources/js/components/financial-day-terms.tsx @@ -1,3 +1,4 @@ +import { DecimalInput } from '@/components/decimal-input'; import { forecastBusinessPlan, type BusinessFinancialPlanInput, @@ -198,15 +199,15 @@ export function FinancialDayTerms({ ))} diff --git a/resources/js/components/integral-financial-plan.tsx b/resources/js/components/integral-financial-plan.tsx index 67ef9ebd..1cb790fa 100644 --- a/resources/js/components/integral-financial-plan.tsx +++ b/resources/js/components/integral-financial-plan.tsx @@ -1,3 +1,4 @@ +import { DecimalInput } from '@/components/decimal-input'; import type { BusinessFinancialPlanInput } from '@/lib/business-financial-plan'; import { buildIntegralFinancialTables, @@ -49,13 +50,12 @@ export function IntegralFinancialPlan({ ) => ( ); @@ -78,16 +78,13 @@ export function IntegralFinancialPlan({
{!plan.startupAssetRequirements && @@ -319,8 +316,8 @@ function TaxScenario({

Cenário fiscal

Escolha o cenário e o simulador calcula o IRPC de cada ano a - partir do lucro antes de impostos, para ver o lucro líquido - e a viabilidade. Pode depois ajustar mês a mês. + partir do lucro antes de impostos, para ver o lucro líquido e a + viabilidade. Pode depois ajustar mês a mês.