Skip to content

Commit 3bbfc28

Browse files
committed
fix(declaration): pad euro values at form init + dev fill (#3255)
1 parent ac7c669 commit 3bbfc28

10 files changed

Lines changed: 63 additions & 40 deletions

File tree

packages/app/src/modules/declaration-remuneration/steps/Step2PayGap.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useRouter } from "next/navigation";
44
import { useState } from "react";
55

66
import { useIsImpersonating } from "~/modules/auth";
7-
import { normalizeDecimalInput } from "~/modules/domain";
7+
import { normalizeDecimalInput, padDecimalToTwo } from "~/modules/domain";
88
import { useZodForm } from "~/modules/shared/useZodForm";
99
import { api } from "~/trpc/react";
1010
import { updateStep2Schema } from "../schemas";
@@ -39,11 +39,14 @@ export function Step2PayGap({
3939
const isImpersonating = useIsImpersonating();
4040

4141
const hasSavedData = Object.values(initialData).some((v) => v !== "");
42-
const defaultValues = hasSavedData
42+
const rawDefaults = hasSavedData
4343
? initialData
4444
: gipPrefillData
4545
? gipToStep2(gipPrefillData.step2)
4646
: initialData;
47+
const defaultValues = Object.fromEntries(
48+
Object.entries(rawDefaults).map(([k, v]) => [k, padDecimalToTwo(v)]),
49+
) as Step2Data;
4750

4851
const hasInitialData = hasSavedData;
4952

@@ -87,8 +90,8 @@ export function Step2PayGap({
8790
DEV_STEP2_ROWS.forEach((row, i) => {
8891
const womenField = getStep2FieldName(i, "womenValue");
8992
const menField = getStep2FieldName(i, "menValue");
90-
form.setValue(womenField, row.womenValue);
91-
form.setValue(menField, row.menValue);
93+
form.setValue(womenField, padDecimalToTwo(row.womenValue));
94+
form.setValue(menField, padDecimalToTwo(row.menValue));
9295
});
9396
setSaved(false);
9497
}}

packages/app/src/modules/declaration-remuneration/steps/Step3VariablePay.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
import { useRouter } from "next/navigation";
44
import { useState } from "react";
55
import { useIsImpersonating } from "~/modules/auth";
6-
import { computeProportion, normalizeDecimalInput } from "~/modules/domain";
6+
import {
7+
computeProportion,
8+
normalizeDecimalInput,
9+
padDecimalToTwo,
10+
} from "~/modules/domain";
711
import { useZodForm } from "~/modules/shared/useZodForm";
812
import { api } from "~/trpc/react";
913
import { updateStep3Schema } from "../schemas";
@@ -47,11 +51,18 @@ export function Step3VariablePay({
4751
const isImpersonating = useIsImpersonating();
4852

4953
const hasSavedData = Object.values(initialData).some((v) => v !== "");
50-
const defaultValues = hasSavedData
54+
const rawDefaults = hasSavedData
5155
? initialData
5256
: gipPrefillData
5357
? gipToStep3(gipPrefillData.step3)
5458
: initialData;
59+
const defaultValues = Object.fromEntries(
60+
Object.entries(rawDefaults).map(([k, v]) =>
61+
k === "indicatorEWomen" || k === "indicatorEMen"
62+
? [k, v]
63+
: [k, padDecimalToTwo(v)],
64+
),
65+
) as Step3Data;
5566

5667
const hasInitialData = hasSavedData;
5768

@@ -125,8 +136,8 @@ export function Step3VariablePay({
125136
DEV_STEP3_ROWS.forEach((row, i) => {
126137
const womenField = getStep3FieldName(i, "womenValue");
127138
const menField = getStep3FieldName(i, "menValue");
128-
form.setValue(womenField, row.womenValue);
129-
form.setValue(menField, row.menValue);
139+
form.setValue(womenField, padDecimalToTwo(row.womenValue));
140+
form.setValue(menField, padDecimalToTwo(row.menValue));
130141
});
131142
form.setValue("indicatorEWomen", DEV_STEP3_BENEFICIARY_WOMEN);
132143
form.setValue("indicatorEMen", DEV_STEP3_BENEFICIARY_MEN);

packages/app/src/modules/declaration-remuneration/steps/Step4QuartileDistribution.tsx

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { useRouter } from "next/navigation";
44
import { useState } from "react";
55
import { useIsImpersonating } from "~/modules/auth";
6-
import { normalizeDecimalInput } from "~/modules/domain";
6+
import { normalizeDecimalInput, padDecimalToTwo } from "~/modules/domain";
77
import { useZodForm } from "~/modules/shared/useZodForm";
88
import { api } from "~/trpc/react";
99
import { updateStep4Schema } from "../schemas";
@@ -29,7 +29,7 @@ function toQuartileData(c: {
2929
menCount: number;
3030
}): QuartileData {
3131
return {
32-
threshold: c.womenValue ?? "",
32+
threshold: padDecimalToTwo(c.womenValue ?? ""),
3333
women: c.womenCount,
3434
men: c.menCount,
3535
};
@@ -78,17 +78,26 @@ export function Step4QuartileDistribution({
7878
(q) => q.threshold || q.women !== undefined || q.men !== undefined,
7979
);
8080

81-
const defaultAnnual = hasSavedData
82-
? initialData.annual
83-
: gipPrefillData
84-
? gipToQuartiles(gipPrefillData.step4.annual)
85-
: emptyQuartiles();
81+
const padThresholds = (quartiles: QuartileData[]): QuartileData[] =>
82+
quartiles.map((q) =>
83+
q.threshold ? { ...q, threshold: padDecimalToTwo(q.threshold) } : q,
84+
);
85+
86+
const defaultAnnual = padThresholds(
87+
hasSavedData
88+
? initialData.annual
89+
: gipPrefillData
90+
? gipToQuartiles(gipPrefillData.step4.annual)
91+
: emptyQuartiles(),
92+
);
8693

87-
const defaultHourly = hasSavedData
88-
? initialData.hourly
89-
: gipPrefillData
90-
? gipToQuartiles(gipPrefillData.step4.hourly)
91-
: emptyQuartiles();
94+
const defaultHourly = padThresholds(
95+
hasSavedData
96+
? initialData.hourly
97+
: gipPrefillData
98+
? gipToQuartiles(gipPrefillData.step4.hourly)
99+
: emptyQuartiles(),
100+
);
92101

93102
const form = useZodForm(updateStep4Schema, {
94103
defaultValues: {

packages/app/src/modules/declaration-remuneration/steps/__tests__/Step2DevFill.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe("Step2PayGap dev fill", () => {
4848
const menInput = screen.getByLabelText(
4949
"Annuelle brute moyenne — Hommes",
5050
) as HTMLInputElement;
51-
expect(womenInput.value.replace(/\s/g, " ")).toBe("35 000");
52-
expect(menInput.value.replace(/\s/g, " ")).toBe("38 000");
51+
expect(womenInput.value.replace(/\s/g, " ")).toBe("35 000,00");
52+
expect(menInput.value.replace(/\s/g, " ")).toBe("38 000,00");
5353
});
5454
});

packages/app/src/modules/declaration-remuneration/steps/__tests__/Step2PayGap.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ describe("Step2PayGap", () => {
214214
);
215215
// GIP rows should be used — check prefilled values
216216
const womenInput = screen.getByLabelText("Annuelle brute moyenne — Femmes");
217-
expect(womenInput).toHaveValue("35\u202f000");
217+
expect(womenInput).toHaveValue("35\u202f000,00");
218218
});
219219

220220
it("shows validation error on submit when fields are incomplete", async () => {

packages/app/src/modules/declaration-remuneration/steps/__tests__/Step3DevFill.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe("Step3VariablePay dev fill", () => {
5050
const womenInput = screen.getByLabelText(
5151
"Annuelle brute moyenne — Femmes",
5252
) as HTMLInputElement;
53-
expect(womenInput.value.replace(/\s/g, " ")).toBe("2 500");
53+
expect(womenInput.value.replace(/\s/g, " ")).toBe("2 500,00");
5454
expect(screen.getByLabelText("Bénéficiaires femmes")).toHaveValue("95");
5555
expect(screen.getByLabelText("Bénéficiaires hommes")).toHaveValue("110");
5656
});

packages/app/src/modules/declaration-remuneration/steps/__tests__/Step3VariablePay.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ describe("Step3VariablePay", () => {
272272
/>,
273273
);
274274
const womenInput = screen.getByLabelText("Annuelle brute moyenne — Femmes");
275-
expect(womenInput).toHaveValue("5\u202f000");
275+
expect(womenInput).toHaveValue("5\u202f000,00");
276276
const benefWomenInput = screen.getByLabelText("Bénéficiaires femmes");
277277
expect(benefWomenInput).toHaveValue("45");
278278
const benefMenInput = screen.getByLabelText("Bénéficiaires hommes");
@@ -326,7 +326,7 @@ describe("Step3VariablePay", () => {
326326
/>,
327327
);
328328
const womenInput = screen.getByLabelText("Annuelle brute moyenne — Femmes");
329-
expect(womenInput).toHaveValue("900");
329+
expect(womenInput).toHaveValue("900,00");
330330
// Beneficiary inputs should be empty (null converted to "")
331331
const benefWomenInput = screen.getByLabelText("Bénéficiaires femmes");
332332
expect(benefWomenInput).toHaveValue("");

packages/app/src/modules/declaration-remuneration/steps/__tests__/Step4DevFill.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe("Step4QuartileDistribution dev fill", () => {
5151
// Intl.NumberFormat("fr-FR") uses U+202F as thousands separator
5252
const remuInputs = screen.getAllByLabelText(/Rémunération brute/);
5353
const firstRemuInput = remuInputs[0] as HTMLInputElement;
54-
expect(firstRemuInput.value.replace(/\s/g, " ")).toBe("22 000");
54+
expect(firstRemuInput.value.replace(/\s/g, " ")).toBe("22 000,00");
5555

5656
const womenInputs = screen.getAllByLabelText(/Nombre de femmes/);
5757
expect(womenInputs[0]).toHaveValue("35");

packages/app/src/modules/declaration-remuneration/steps/__tests__/Step4QuartileDistribution.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ describe("Step4QuartileDistribution", () => {
129129

130130
// Check annual remuneration inputs have values
131131
const remuInputs = screen.getAllByLabelText(/Rémunération brute/);
132-
expect(remuInputs[0]).toHaveValue("980");
132+
expect(remuInputs[0]).toHaveValue("980,00");
133133

134134
// Check annual women count inputs
135135
const womenCountInputs = screen.getAllByLabelText(/Nombre de femmes/);
@@ -313,7 +313,7 @@ describe("Step4QuartileDistribution", () => {
313313
);
314314
// Check annual remuneration inputs have prefilled values
315315
const remuInputs = screen.getAllByLabelText(/Rémunération brute/);
316-
expect(remuInputs[0]).toHaveValue("25\u202f000");
316+
expect(remuInputs[0]).toHaveValue("25\u202f000,00");
317317
// Check women count inputs
318318
const womenCountInputs = screen.getAllByLabelText(/Nombre de femmes/);
319319
expect(womenCountInputs[0]).toHaveValue("30");
@@ -370,8 +370,8 @@ describe("Step4QuartileDistribution", () => {
370370
);
371371
// First 3 quartiles should be prefilled
372372
const remuInputs = screen.getAllByLabelText(/Rémunération brute/);
373-
expect(remuInputs[0]).toHaveValue("25\u202f000");
374-
expect(remuInputs[2]).toHaveValue("40\u202f000");
373+
expect(remuInputs[0]).toHaveValue("25\u202f000,00");
374+
expect(remuInputs[2]).toHaveValue("40\u202f000,00");
375375
// Q4 should be empty (null threshold)
376376
expect(remuInputs[3]).toHaveValue("");
377377
});

packages/app/src/modules/declaration-remuneration/steps/step5/CategoryForm.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type {
1818
EmployeeCategoryRow,
1919
EmployeeCategorySubmitData,
2020
} from "~/modules/declaration-remuneration/types";
21-
import { padDecimalOnBlur } from "~/modules/domain";
21+
import { padDecimalOnBlur, padDecimalToTwo } from "~/modules/domain";
2222
import { useZodForm } from "~/modules/shared/useZodForm";
2323
import stepStyles from "../Step5EmployeeCategories.module.scss";
2424
import { CategoryDataTable } from "./CategoryDataTable";
@@ -49,14 +49,14 @@ function toFormValues(cats: EmployeeCategory[]) {
4949
detail: c.detail,
5050
womenCount: c.womenCount,
5151
menCount: c.menCount,
52-
annualBaseWomen: c.annualBaseWomen,
53-
annualBaseMen: c.annualBaseMen,
54-
annualVariableWomen: c.annualVariableWomen,
55-
annualVariableMen: c.annualVariableMen,
56-
hourlyBaseWomen: c.hourlyBaseWomen,
57-
hourlyBaseMen: c.hourlyBaseMen,
58-
hourlyVariableWomen: c.hourlyVariableWomen,
59-
hourlyVariableMen: c.hourlyVariableMen,
52+
annualBaseWomen: padDecimalToTwo(c.annualBaseWomen),
53+
annualBaseMen: padDecimalToTwo(c.annualBaseMen),
54+
annualVariableWomen: padDecimalToTwo(c.annualVariableWomen),
55+
annualVariableMen: padDecimalToTwo(c.annualVariableMen),
56+
hourlyBaseWomen: padDecimalToTwo(c.hourlyBaseWomen),
57+
hourlyBaseMen: padDecimalToTwo(c.hourlyBaseMen),
58+
hourlyVariableWomen: padDecimalToTwo(c.hourlyVariableWomen),
59+
hourlyVariableMen: padDecimalToTwo(c.hourlyVariableMen),
6060
}));
6161
}
6262

0 commit comments

Comments
 (0)