fix(benefit): translations and error messages - #4188
Conversation
Translation was missing. Correct translation added. Refs: HL-1824
📝 WalkthroughWalkthroughAdds recursive touched-state handling to ChangesForm Validation and Localization
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@frontend/benefit/handler/public/locales/en/common.json`:
- Around line 1885-1887: The new companyNumberOfEmployees label in the English
locale still uses Finnish text, so replace the value in the common.json English
translation entry with proper English copy. Update the companyNumberOfEmployees
object in the locale file so English users see a translated label instead of the
current untranslated string.
In `@frontend/benefit/handler/public/locales/sv/common.json`:
- Around line 1885-1887: The Swedish locale entry for companyNumberOfEmployees
still uses Finnish text, so replace the label value in common.json with proper
Swedish copy. Update the companyNumberOfEmployees label in the Swedish
translations to match the rest of the sv locale and ensure no Finnish text
remains for that key.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b495cec0-0128-408e-96ba-9b119941e57a
📒 Files selected for processing (5)
frontend/benefit/handler/public/locales/en/common.jsonfrontend/benefit/handler/public/locales/fi/common.jsonfrontend/benefit/handler/public/locales/sv/common.jsonfrontend/benefit/handler/src/components/applicationForm/formContent/companySection/CompanySection.tsxfrontend/benefit/handler/src/components/applicationForm/useApplicationForm.ts
|
YJDH-HELSINKILISA-API branch is deployed to platta: https://helsinkilisa-pr4188.api.dev.hel.ninja 🚀🚀🚀 |
|
HANDLER branch is deployed to platta: https://helsinkilisa-ui-handler-pr4188.dev.hel.ninja 🚀🚀🚀 |
|
APPLICANT is deployed to platta: https://helsinkilisa-ui-pr4188.dev.hel.ninja 🚀🚀🚀 |
TestCafe result is success for https://helsinkilisa-ui-pr4188.dev.hel.ninja 😆🎉🎉🎉 |
TestCafe result is success for https://helsinkilisa-ui-handler-pr4188.dev.hel.ninja 😆🎉🎉🎉 |
64f96f5 to
6a912e8
Compare
|
YJDH-HELSINKILISA-API branch is deployed to platta: https://helsinkilisa-pr4188.api.dev.hel.ninja 🚀🚀🚀 |
|
APPLICANT is deployed to platta: https://helsinkilisa-ui-pr4188.dev.hel.ninja 🚀🚀🚀 |
TestCafe result is success for https://helsinkilisa-ui-pr4188.dev.hel.ninja 😆🎉🎉🎉 |
Boolean fields did not give error message. Fixed by adding proper properties. Refs: HL-1840
6a912e8 to
e195fd2
Compare
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
frontend/benefit/handler/src/components/applicationForm/useApplicationForm.ts (1)
317-324: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winMark Formik errors before the de minimis early return.
Line 318 exits
handleSave()beforesetTouched()runs. If the de minimis row is unfinished and regular fields are invalid, users only see the de minimis toast and the inline required-field errors stay hidden, which misses the validation goal of this PR.Proposed fix
const handleSave = async (): Promise<void> => { const errors = await formik.validateForm(); + if (Object.keys(errors).length > 0) { + await formik.setTouched(getTouchedFromErrors(errors), true); + } + if (!checkDeMinimisForm()) { return; } - - if (Object.keys(errors).length > 0) { - await formik.setTouched(getTouchedFromErrors(errors), true); - } if (!errorActions(errors)) { await formik.submitForm(); } };🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@frontend/benefit/handler/src/components/applicationForm/useApplicationForm.ts` around lines 317 - 324, In handleSave() inside useApplicationForm, the de minimis early return is happening before Formik’s validation state is surfaced, so invalid regular fields can remain hidden. Move the setTouched(getTouchedFromErrors(errors), true) handling to run before returning from checkDeMinimisForm(), using the existing validateForm() result and the touched/error flow in formik so inline errors are shown even when the de minimis row is incomplete.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In
`@frontend/benefit/handler/src/components/applicationForm/useApplicationForm.ts`:
- Around line 317-324: In handleSave() inside useApplicationForm, the de minimis
early return is happening before Formik’s validation state is surfaced, so
invalid regular fields can remain hidden. Move the
setTouched(getTouchedFromErrors(errors), true) handling to run before returning
from checkDeMinimisForm(), using the existing validateForm() result and the
touched/error flow in formik so inline errors are shown even when the de minimis
row is incomplete.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 57054139-1caf-49e8-beb5-5ac40aebdc23
📒 Files selected for processing (3)
frontend/benefit/handler/src/components/applicationForm/__tests__/useApplicationForm.test.tsxfrontend/benefit/handler/src/components/applicationForm/formContent/companySection/CompanySection.tsxfrontend/benefit/handler/src/components/applicationForm/useApplicationForm.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- frontend/benefit/handler/src/components/applicationForm/formContent/companySection/CompanySection.tsx
|
YJDH-HELSINKILISA-API branch is deployed to platta: https://helsinkilisa-pr4188.api.dev.hel.ninja 🚀🚀🚀 |
|
APPLICANT is deployed to platta: https://helsinkilisa-ui-pr4188.dev.hel.ninja 🚀🚀🚀 |
TestCafe result is success for https://helsinkilisa-ui-pr4188.dev.hel.ninja 😆🎉🎉🎉 |
|
HANDLER branch is deployed to platta: https://helsinkilisa-ui-handler-pr4188.dev.hel.ninja 🚀🚀🚀 |
TestCafe result is success for https://helsinkilisa-ui-handler-pr4188.dev.hel.ninja 😆🎉🎉🎉 |
There was a problem hiding this comment.
Pull request overview
This PR improves the benefit application form UX by ensuring validation errors are surfaced more reliably (marking invalid fields as touched and setting invalid/aria-invalid states), and adds the missing i18n key for an employee-count label.
Changes:
- Mark fields as touched when
validateForm()returns errors (both for validation-only flow and save flow). - Add
invalid/aria-invalidwiring for radio selection groups to improve accessibility states. - Add Jest coverage for the updated validation/save behavior, and add the missing
companyNumberOfEmployeesi18n key across locales.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/benefit/handler/src/components/applicationForm/useApplicationForm.ts | Adds helper to derive touched from validation errors and applies it during validation/save. |
| frontend/benefit/handler/src/components/applicationForm/formContent/companySection/CompanySection.tsx | Sets invalid/aria-invalid for specific SelectionGroup fields to reflect validation state. |
| frontend/benefit/handler/src/components/applicationForm/tests/useApplicationForm.test.tsx | Adds tests covering touched-marking and submit behavior for valid/invalid forms. |
| frontend/benefit/handler/public/locales/sv/common.json | Adds companyNumberOfEmployees label key. |
| frontend/benefit/handler/public/locales/en/common.json | Adds companyNumberOfEmployees label key. |
| frontend/benefit/handler/public/locales/fi/common.json | Adds companyNumberOfEmployees label key. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const getTouchedFromErrors = <TValues,>( | ||
| errors: FormikErrors<TValues> | ||
| ): FormikTouched<TValues> => | ||
| Object.keys(errors).reduce((touched, key) => { | ||
| const error = errors[key as keyof FormikErrors<TValues>]; | ||
|
|
||
| return { | ||
| ...touched, | ||
| [key]: Array.isArray(error) | ||
| ? error.map((item) => | ||
| item && typeof item === 'object' | ||
| ? getTouchedFromErrors(item as FormikErrors<unknown>) | ||
| : true | ||
| ) | ||
| : error && typeof error === 'object' | ||
| ? getTouchedFromErrors(error as FormikErrors<unknown>) | ||
| : true, | ||
| }; | ||
| }, {} as FormikTouched<TValues>); |
| const { result } = renderHook(() => useApplicationForm(), { wrapper }); | ||
|
|
||
| await act(() => result.current.handleSave() as unknown as Promise<void>); | ||
|
|
| const { result } = renderHook(() => useApplicationForm(), { wrapper }); | ||
|
|
||
| await act(() => result.current.handleSave() as unknown as Promise<void>); | ||
|
|
| "companyNumberOfEmployees": { | ||
| "label": "Työntekijöiden määrä ennen työllistettyä" | ||
| }, |
| "companyNumberOfEmployees": { | ||
| "label": "Työntekijöiden määrä ennen työllistettyä" | ||
| }, |



Description ✨
Translations were missing from one field.
Missing oolean fields did not give error message if on submit.
Issues 🐛
HL-1824
HL-1840
Testing ⚗️
Jest tests
Summary by CodeRabbit
New Features
Bug Fixes
Tests