From 508391bcc6ffe928b9e43f7f8273026f23bd60ca Mon Sep 17 00:00:00 2001 From: A-Axisa Date: Sat, 16 May 2026 18:44:44 +0930 Subject: [PATCH 1/6] Add function to parse numbers with comma decimal separators --- src/components/Weight/forms/WeightForm.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/Weight/forms/WeightForm.tsx b/src/components/Weight/forms/WeightForm.tsx index 26ad3964b..40f0388e4 100644 --- a/src/components/Weight/forms/WeightForm.tsx +++ b/src/components/Weight/forms/WeightForm.tsx @@ -15,6 +15,10 @@ interface WeightFormProps { closeFn?: () => void, } +const parseLocaleNumber = (numString: string) => { + return Number(numString.replace(/,/, '.')); +}; + export const WeightForm = ({ weightEntry, closeFn }: WeightFormProps) => { const weightEntriesQuery = useBodyWeightQuery(); From f7a04db29e11c055ba55c893e69c2679e5f32bec Mon Sep 17 00:00:00 2001 From: A-Axisa Date: Sat, 16 May 2026 18:58:13 +0930 Subject: [PATCH 2/6] Accept comma as valid decimal separator for weight --- src/components/Weight/forms/WeightForm.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/Weight/forms/WeightForm.tsx b/src/components/Weight/forms/WeightForm.tsx index 40f0388e4..b0518b615 100644 --- a/src/components/Weight/forms/WeightForm.tsx +++ b/src/components/Weight/forms/WeightForm.tsx @@ -31,6 +31,9 @@ export const WeightForm = ({ weightEntry, closeFn }: WeightFormProps) => { const validationSchema = yup.object({ weight: yup .number() + .transform((_, value) => { + return parseLocaleNumber(value); + }) .min(30, 'Min weight is 30 kg') .max(300, 'Max weight is 300 kg') .required('Weight field is required'), @@ -49,15 +52,17 @@ export const WeightForm = ({ weightEntry, closeFn }: WeightFormProps) => { validationSchema={validationSchema} onSubmit={async (values) => { + const normalizedWeight = parseLocaleNumber(values.weight); + // Edit existing weight entry if (weightEntry) { - weightEntry.weight = values.weight; + weightEntry.weight = normalizedWeight; weightEntry.date = values.date; editWeightQuery.mutate(weightEntry); // Create a new weight entry } else { - weightEntry = new WeightEntry(values.date, values.weight); + weightEntry = new WeightEntry(values.date, normalizedWeight); addWeightQuery.mutate(weightEntry); } From d5bef914dac7a7643821eedd98984a967b8d23ad Mon Sep 17 00:00:00 2001 From: A-Axisa Date: Sat, 16 May 2026 19:38:24 +0930 Subject: [PATCH 3/6] Accept comma decimal separators when editing weight column --- src/components/Weight/widgets/Table/index.tsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/components/Weight/widgets/Table/index.tsx b/src/components/Weight/widgets/Table/index.tsx index 4c011df01..f88659c73 100644 --- a/src/components/Weight/widgets/Table/index.tsx +++ b/src/components/Weight/widgets/Table/index.tsx @@ -39,6 +39,10 @@ const buildRows = (weights: WeightEntry[]): GridRowsProp => days: +row.days.toFixed(1), })); +const parseLocaleNumber = (numString: string) => { + return Number(numString.replace(/,/, '.')); +}; + export const WeightTable = ({ weights }: WeightTableProps) => { const [t] = useTranslation(); const rows = buildRows(weights); @@ -73,7 +77,8 @@ export const WeightTable = ({ weights }: WeightTableProps) => { const processRowUpdate = (newRow: GridRowModel) => { const date = newRow.date instanceof Date ? newRow.date : new Date(newRow.date); - editEntryQuery.mutate(new WeightEntry(date, Number(newRow.weight), Number(newRow.id))); + const sanitizedWeight = parseLocaleNumber(newRow.weight); + editEntryQuery.mutate(new WeightEntry(date, sanitizedWeight, Number(newRow.id))); return newRow; }; @@ -98,9 +103,17 @@ export const WeightTable = ({ weights }: WeightTableProps) => { { field: 'weight', headerName: t('weight'), - type: 'number', + type: 'string', width: 100, editable: true, + headerAlign: 'right', + align: 'right', + valueFormatter: (value?: string) => { + if (typeof(value) === 'string'){ + return parseLocaleNumber(value); + } + return value; + }, }, { field: 'change', From 694adac4c23bfb10811f9c72fc835f2097e5c5b6 Mon Sep 17 00:00:00 2001 From: A-Axisa Date: Sat, 16 May 2026 22:09:59 +0930 Subject: [PATCH 4/6] Prevent calling replace function on types other than strings --- src/components/Weight/forms/WeightForm.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/Weight/forms/WeightForm.tsx b/src/components/Weight/forms/WeightForm.tsx index b0518b615..24ae56d6b 100644 --- a/src/components/Weight/forms/WeightForm.tsx +++ b/src/components/Weight/forms/WeightForm.tsx @@ -15,8 +15,11 @@ interface WeightFormProps { closeFn?: () => void, } -const parseLocaleNumber = (numString: string) => { - return Number(numString.replace(/,/, '.')); +const parseLocaleNumber = (numString: string | number) => { + if (typeof(numString) === 'string'){ + return Number(numString.replace(/,/, '.')); + } + return numString; }; export const WeightForm = ({ weightEntry, closeFn }: WeightFormProps) => { From 93acf927facd08554696fee1b4ff9f89f8a4d187 Mon Sep 17 00:00:00 2001 From: A-Axisa Date: Sun, 17 May 2026 00:15:05 +0930 Subject: [PATCH 5/6] Test for entering weight with a comma decimal separator --- src/components/Weight/forms/WeightForm.test.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/components/Weight/forms/WeightForm.test.tsx b/src/components/Weight/forms/WeightForm.test.tsx index 0f5f49726..51862198e 100644 --- a/src/components/Weight/forms/WeightForm.test.tsx +++ b/src/components/Weight/forms/WeightForm.test.tsx @@ -97,4 +97,21 @@ describe("Test WeightForm component", () => { }); }); + test('Creating a new weight entry using a comma decimal separator', async () => { + + // Arrange + const user = userEvent.setup(); + render( + + + + ); + + const weightInput = await screen.findByLabelText('weight'); + + // Act + await user.type(weightInput, "69,1"); + await user.tab(); + expect(screen.queryByText(/weight must be a `number` type/i)).not.toBeInTheDocument(); + }); }); From d965a61cd1c7841b62e07d9fa4851e9a92eda2a3 Mon Sep 17 00:00:00 2001 From: A-Axisa Date: Sun, 17 May 2026 00:16:08 +0930 Subject: [PATCH 6/6] Stop test from leaking user inputs into other tests --- src/components/Weight/forms/WeightForm.test.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Weight/forms/WeightForm.test.tsx b/src/components/Weight/forms/WeightForm.test.tsx index 51862198e..802eeb292 100644 --- a/src/components/Weight/forms/WeightForm.test.tsx +++ b/src/components/Weight/forms/WeightForm.test.tsx @@ -84,8 +84,8 @@ describe("Test WeightForm component", () => { const submitButton = screen.getByRole('button', { name: 'submit' }); // Act - user.type(dateInput, '2022-02-28'); - user.type(weightInput, '80'); + await user.type(dateInput, '2022-02-28'); + await user.type(weightInput, '80'); // Assert expect(dateInput).toBeInTheDocument();