Skip to content

[Bug-fix] Improve i18n for input error messages - #4266

Merged
ThaminduDilshan merged 1 commit into
thunder-id:mainfrom
NutharaNR:fix/improve-i18n-support-for-input-validation
Jul 30, 2026
Merged

[Bug-fix] Improve i18n for input error messages#4266
ThaminduDilshan merged 1 commit into
thunder-id:mainfrom
NutharaNR:fix/improve-i18n-support-for-input-validation

Conversation

@NutharaNR

@NutharaNR NutharaNR commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Purpose

Fixes: #3994

Approach

  1. On every keystroke, a 600ms debounce timer starts (resets if the user keeps typing).
  2. After 600ms of inactivity, the field is validated:
    • If it's an email field with an invalid format → error is shown inline.
    • If the email is corrected → error clears automatically.
    • Non-email fields (username, password, etc.) are not validated inline.
  3. On submit, all fields are validated for both required and format rules (unchanged behavior).

Key changes

  • Design package (shared adapters): Added an optional onBlur callback prop through the component chain (FlowComponentRendererPropsFlowFieldPropsBlockAdapterStackAdapter → input adapters). The onBlur plumbing is in place for future use but is not actively wired in this change.
  • SignInBox: Added collectInputComponents to walk the nested component tree (BLOCK → STACK → inputs) so that validateFieldFormat can find input fields regardless of nesting depth. Previously, only top-level components were stored, causing per-field validation to silently skip nested inputs. The updateInput handler debounces 600ms then runs format-only validation.
  • SignUpBox / RecoveryBox: Same debounced format validation pattern. Since the @thunderid/react SDK does not expose handleInputBlur in SignUp/Recovery render props, local validation state is maintained and merged with SDK-provided errors via mergeErrors.
  • AcceptInviteBox: Removed handleInputBlur wiring for consistency with the other forms (required validation on submit only).
Screen.Recording.2026-07-28.at.11.42.31.mov

Related Issues

Related PRs

  • N/A

Checklist

  • Followed the contribution guidelines.
  • Manual test round performed and verified.
  • Documentation provided. (Add links if there are any)
    • Ran Vale and fixed all errors and warnings
  • Tests provided. (Add links if there are any)
    • Unit Tests
    • Integration Tests
  • Breaking changes. (Fill if applicable)
    • Breaking changes section filled.
    • breaking change label added.

Security checks

  • Followed secure coding standards in WSO2 Secure Coding Guidelines
  • Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets.

Summary by CodeRabbit

  • New Features

    • Added email format validation to sign-in forms.
    • Added clear feedback for invalid email addresses.
    • Validation messages now clear as users correct their input.
    • Optional email fields can be submitted empty.
  • Bug Fixes

    • Improved required-field validation and error handling during sign-in.

Copilot AI review requested due to automatic review settings July 23, 2026 04:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Email validation

Layer / File(s) Summary
Sign-in validation and error display
frontend/apps/gate/src/components/SignIn/SignInBox.tsx, frontend/packages/i18n/src/locales/en-US.ts
Sign-in validation tracks touched fields, validates required and email formats, passes touched state to the renderer, and adds the invalid-email translation.
Email validation test coverage
frontend/apps/gate/src/components/SignIn/__tests__/SignInBox.test.tsx
Tests cover email rendering, required and format errors, error clearing, valid submission, and optional email behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: brionmario, jeradrutnam, donomalvindula, copilot

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant SignInBox
  participant FlowComponentRenderer
  User->>SignInBox: Submit email input
  SignInBox->>SignInBox: Validate required and email format
  SignInBox->>FlowComponentRenderer: Pass errors and touched state
  FlowComponentRenderer-->>User: Display validation result
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes add the missing invalid-email translation and wire it into validation, which addresses #3994's i18n issue.
Out of Scope Changes check ✅ Passed All changes are tied to email validation, touched-state handling, tests, and the new translation key, with no unrelated scope visible.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title is concise and clearly tied to the i18n/input-validation changes in this PR.
Description check ✅ Passed The PR description covers Purpose, Approach, Related Issues, Related PRs, Checklist, and Security checks, matching the template well.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
frontend/apps/gate/src/components/SignIn/__tests__/SignInBox.test.tsx (1)

1999-2355: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider extracting a shared fixture builder for the repeated EMAIL_INPUT component array.

Nine tests redeclare a near-identical ~25-line components array (BLOCK > EMAIL_INPUT + submit ACTION), differing only by required or the typed value. A small helper like buildEmailInputComponents({required}) would cut duplication and make future edits (e.g., adding a new field) less error-prone.

🤖 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/apps/gate/src/components/SignIn/__tests__/SignInBox.test.tsx` around
lines 1999 - 2355, The repeated BLOCK > EMAIL_INPUT plus submit ACTION fixture
across the EMAIL_INPUT tests should be centralized. Add a shared builder such as
buildEmailInputComponents accepting the required setting, replace each
duplicated components array with the builder, and preserve each test’s existing
required behavior and other component properties.
🤖 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/apps/gate/src/components/SignIn/SignInBox.tsx`:
- Around line 61-63: Update the required-field validation message in the
component validation block to provide fallback default strings for both the
outer validation-key t() call and the nested field-label t() call, matching the
fallback pattern used by the email-invalid message below. Preserve the existing
translated values when available while ensuring unresolved keys produce
user-facing text.

---

Nitpick comments:
In `@frontend/apps/gate/src/components/SignIn/__tests__/SignInBox.test.tsx`:
- Around line 1999-2355: The repeated BLOCK > EMAIL_INPUT plus submit ACTION
fixture across the EMAIL_INPUT tests should be centralized. Add a shared builder
such as buildEmailInputComponents accepting the required setting, replace each
duplicated components array with the builder, and preserve each test’s existing
required behavior and other component properties.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: af076f31-8ca4-416c-9da5-0cb8c318f861

📥 Commits

Reviewing files that changed from the base of the PR and between 0bc3cbb and 8f73555.

📒 Files selected for processing (3)
  • frontend/apps/gate/src/components/SignIn/SignInBox.tsx
  • frontend/apps/gate/src/components/SignIn/__tests__/SignInBox.test.tsx
  • frontend/packages/i18n/src/locales/en-US.ts

Comment thread frontend/apps/gate/src/components/SignIn/SignInBox.tsx Outdated
Comment thread frontend/apps/gate/src/components/SignIn/SignInBox.tsx
@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.73913% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...tend/apps/gate/src/components/SignIn/SignInBox.tsx 94.87% 2 Missing ⚠️
...tend/apps/gate/src/components/SignUp/SignUpBox.tsx 98.11% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@NutharaNR
NutharaNR force-pushed the fix/improve-i18n-support-for-input-validation branch from 8f73555 to e5da69e Compare July 23, 2026 05:19
Copilot AI review requested due to automatic review settings July 23, 2026 05:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings July 23, 2026 05:57
@NutharaNR
NutharaNR force-pushed the fix/improve-i18n-support-for-input-validation branch from e5da69e to ea71be2 Compare July 23, 2026 05:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@ThaminduDilshan
ThaminduDilshan marked this pull request as draft July 23, 2026 19:25
@NutharaNR
NutharaNR force-pushed the fix/improve-i18n-support-for-input-validation branch 2 times, most recently from b1ae2f3 to bc63d61 Compare July 28, 2026 05:25
@NutharaNR
NutharaNR marked this pull request as ready for review July 28, 2026 05:30
@thiva-k thiva-k added the trigger-pr-builder Add when the PR is ready for CI; starts the PR Builder for this and all later pushes label Jul 28, 2026
@NutharaNR
NutharaNR force-pushed the fix/improve-i18n-support-for-input-validation branch 2 times, most recently from 736fcae to 208d51c Compare July 28, 2026 06:36
Comment thread frontend/apps/gate/src/components/SignIn/SignInBox.tsx Outdated
Comment thread frontend/apps/gate/src/components/SignIn/SignInBox.tsx Outdated
if (!component) return;

let error = '';
if (component.type === 'EMAIL_INPUT' && value.trim() && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regex is repeated in multiple places. Better if we can keep a single definition and reuse it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the regex to utils and updated to be reused.

<Alert severity="error" sx={{mb: 2}}>
<AlertTitle>{t('signup:errors.signup.failed.message')}</AlertTitle>
{error.message ?? t('signup:errors.signup.failed.description')}
<AlertTitle>{t("Oops, that didn't work")}</AlertTitle>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we keep i18n keys too? Use fixed text as the fallback only

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted the change

// ============================================================================
validations: {
'form.field.required': '{{field}} is required.',
'field.email.invalid': 'Please enter a valid email address.',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hope we have added all i18n keys or other translations already exists

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the i18n keys provided returned by input validator

@NutharaNR
NutharaNR force-pushed the fix/improve-i18n-support-for-input-validation branch 2 times, most recently from a0fa51e to 6035eaa Compare July 28, 2026 11:20
@NutharaNR
NutharaNR force-pushed the fix/improve-i18n-support-for-input-validation branch from 6035eaa to f46bf4d Compare July 30, 2026 03:19
@NutharaNR
NutharaNR force-pushed the fix/improve-i18n-support-for-input-validation branch from f46bf4d to 316c585 Compare July 30, 2026 03:22
@ThaminduDilshan
ThaminduDilshan added this pull request to the merge queue Jul 30, 2026
Merged via the queue into thunder-id:main with commit d22b1a4 Jul 30, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

trigger-pr-builder Add when the PR is ready for CI; starts the PR Builder for this and all later pushes Type/Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Need better i18n support

4 participants