Skip to content

Issue-2238: Fixes the error messages on various forms. #2239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

sonvir249
Copy link

@sonvir249 sonvir249 commented May 10, 2025

Describe your changes

Fixes the error message on signup and reset form.

Write your issue number after "Fixes "

Fixes #2238

  • My PR is granular and targeted to one specific feature.
  • I took a screenshot or a video and attached to this PR if there is a UI change.

Screenshots

Form Name Current behavior Expected behavior
Reset Password Image Image
Signup form step 1 Image Image
Signup form step 2 Image Image

Summary by CodeRabbit

  • New Features

    • Error messages for email fields in Forgot Password and Register forms are now localized.
    • Surname validation now provides specific error messages distinct from first name validation.
  • Refactor

    • Improved consistency in form validation schemas for better maintainability and readability.

Copy link

coderabbitai bot commented May 10, 2025

"""

Walkthrough

The changes update error message handling and validation for user authentication forms. Error messages for email fields in the Forgot Password and Register forms are now consistently passed through the translation function. A dedicated surname validation schema is introduced, and validation schemas are reformatted for clarity without altering logic.

Changes

File(s) Change Summary
client/src/Pages/Auth/ForgotPassword.jsx Modified email field's error message to use the translation function for localization.
client/src/Pages/Auth/Register/StepTwo/index.jsx Refactored email field's error message logic to ensure all errors are translated before display.
client/src/Validation/validation.js Added lastnameSchema for surname-specific validation messages; updated credentials schema to use it.

Assessment against linked issues

Objective Addressed Explanation
Ensure error messages on Reset Password and Signup forms are translated and display correct messages (#2238)
Surname field in Signup form step 1 shows "Surname is required" error message (#2238)
Email errors in Forgot Password and Signup forms show localized, user-friendly messages (#2238)

Why did the Canadian developer apologize after fixing the translation bug? Because even their code says "sorry" when it gets things right, eh!

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4efbd4b and f0d2c57.

📒 Files selected for processing (3)
  • client/src/Pages/Auth/ForgotPassword.jsx (1 hunks)
  • client/src/Pages/Auth/Register/StepTwo/index.jsx (1 hunks)
  • client/src/Validation/validation.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • client/src/Pages/Auth/Register/StepTwo/index.jsx
  • client/src/Pages/Auth/ForgotPassword.jsx
  • client/src/Validation/validation.js
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
client/src/Validation/validation.js (1)

175-175: Ignore static analysis warning about 'then' property

The static analysis warning about "Do not add then to an object" appears to be a false positive. This is standard Joi validation syntax where .when() takes an object with is and then properties. No change needed.

You could add a comment to suppress this specific linting warning if it shows up in your CI pipeline:

 .when("type", {
+			// biome-ignore lint/suspicious/noThenProperty: This is valid Joi syntax
 			is: "port",
 			then: joi.required().messages({
🧰 Tools
🪛 Biome (1.9.4)

[error] 175-175: Do not add then to an object.

(lint/suspicious/noThenProperty)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6188d0c and 4efbd4b.

📒 Files selected for processing (3)
  • client/src/Pages/Auth/ForgotPassword.jsx (1 hunks)
  • client/src/Pages/Auth/Register/StepTwo/index.jsx (1 hunks)
  • client/src/Validation/validation.js (6 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
client/src/Validation/validation.js

[error] 175-175: Do not add then to an object.

(lint/suspicious/noThenProperty)

🔇 Additional comments (8)
client/src/Pages/Auth/ForgotPassword.jsx (1)

188-188: Improved localization of error messages - good job!

Nice work passing the error message through the translation function. This ensures consistent localization of validation messages across the application, improving the experience for international users.

Just like an American and Canadian agreeing on hockey (but not how to spell "color"), this change brings harmony to your error handling!

client/src/Pages/Auth/Register/StepTwo/index.jsx (1)

71-78: Well-structured error message translation logic!

This refactoring improves the error message handling by:

  1. Ensuring all error messages go through the translation function
  2. Using specific translation keys for common errors
  3. Applying a hierarchical approach to message selection

This is a more robust approach that aligns with the same pattern applied in the ForgotPassword component.

As a Canadian might say, this code is now as organized as a Tim Hortons drive-thru line during morning rush!

client/src/Validation/validation.js (6)

18-28: Great introduction of a dedicated surname schema!

Creating a dedicated schema for surnames with specific error messages improves the user experience by providing clearer validation feedback. Users will now see "Surname is required" instead of the generic "Name is required" when the last name field is empty.

This reminds me of how Americans and Canadians both speak English, but with just enough differences to notice - like your schemas now!


69-69: Proper integration of surname schema - good!

This change correctly implements the new surnameSchema for the lastName field, ensuring users receive surname-specific validation messages.


269-278: Improved formatting for settings validation schema

The reformatting of the settingsValidation schema with consistent indentation and structure improves code readability and maintainability.


381-385: Enhanced readability for email validation

The multiline formatting of the email address validation improves code readability while maintaining the same validation rules.


398-398: Added trailing comma in export list

Adding a trailing comma in the export list is a good practice that makes future additions cleaner in git diffs. Like a Canadian apologizing for something that wasn't their fault, this little comma makes everything more polite!


168-182:

❓ Verification inconclusive

Improved port validation schema formatting

The reformatting of the port validation schema improves code readability without changing functionality. The explicit otherwise: joi.optional() clause adds clarity to the conditional validation logic.

You know what they say - Americans and Canadians may disagree on whether it's called a "washroom" or "restroom," but they both agree that readable code is important!


🏁 Script executed:

#!/bin/bash
# Description: Verify if there are any other Joi validation schemas that could benefit from similar explicit otherwise clauses

# Look for .when() calls that might not have explicit otherwise clauses
rg -n "\.when\([^)]+\)\s*\.\s*[a-zA-Z]+" --type js client/src/Validation

Length of output: 74


Conditional Joi validations check

I ran a quick search for other .when() calls in client/src/Validation and didn’t find any without an explicit otherwise clause. It looks like this is the only schema that needs the explicit otherwise: joi.optional() for clarity, but please give it a quick once-over to be sure there aren’t any edge cases missed.

Canadians may call it a “washroom,” Americans call it a “restroom,” but both agree that validating ports from 1–65535 is non-negotiable!

🧰 Tools
🪛 Biome (1.9.4)

[error] 175-175: Do not add then to an object.

(lint/suspicious/noThenProperty)

Copy link

@llamapreview llamapreview bot left a comment

Choose a reason for hiding this comment

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

Auto Pull Request Review from LlamaPReview

1. Overview

1.1 Core Changes

  • Primary purpose: Fix translation issues and validation messages across authentication forms
  • Key components: ForgotPassword, Register StepTwo, validation schemas
  • Cross-component impacts: Internationalization system integration, validation logic consistency
  • Business value: Improved user experience through clear localized error messages

1.2 Technical Architecture

  • System design: Enhanced validation message handling in UI layer
  • Integration points: Joi validation schemas now drive localized error messages
  • Dependency changes: Modified schema definitions impact form validation across multiple flows

2. Critical Findings

2.1 Must Fix (P0🔴)

Issue: Incorrect error message fallback in Register StepTwo email validation

  • Analysis Confidence: High
  • Impact: Untranslated raw error strings displayed to users
  • Resolution: Revert fallback to original error message display

Issue: Empty error messages in infrastructureMonitorValidation

  • Analysis Confidence: High
  • Impact: Missing validation feedback for infrastructure monitors
  • Resolution: Remove empty .messages() call in validation schema

2.2 Should Fix (P1🟡)

Issue: Brittle error message matching via string.includes()

  • Analysis Confidence: Medium
  • Impact: Prone to breakage if validation messages change
  • Suggested Solution: Implement error code mapping in validation schemas

2.3 Consider (P2🟢)

Area: Test coverage for validation messages

  • Analysis Confidence: High
  • Improvement Opportunity: Ensure message stability across locales

2.4 Summary of Action Items

  1. Fix Register StepTwo fallback (P0) - Immediate
  2. Restore infrastructure monitor messages (P0) - Immediate
  3. Refactor error matching logic (P1) - Next sprint
  4. Add validation message tests (P2) - Future

3. Technical Analysis

3.1 Code Logic Analysis

📁 client/src/Pages/Auth/Register/StepTwo/index.jsx - Email validation

  • Submitted PR Code:
    helperText={
        errors.email &&
        (errors.email.includes("required")
            ? t("authRegisterEmailRequired")
            : errors.email.includes("valid email")
                ? t("authRegisterEmailInvalid")
                : t(errors.email))
    }
  • Analysis:
    • Fallback translation attempt of raw Joi messages
    • Breaks non-specifically handled error display
    • Creates dependency on validation message content
  • LlamaPReview Suggested Improvements:
    helperText={
        errors.email &&
        (errors.email.includes("required")
            ? t("authRegisterEmailRequired")
            : errors.email.includes("valid email")
                ? t("authRegisterEmailInvalid")
                : errors.email)  // Reverted fallback
    }
  • Improvement rationale:
    • Preserves original validation messages
    • Avoids incorrect translation attempts

📁 client/src/Validation/validation.js - Infrastructure monitor validation

  • Submitted PR Code:
    notifications: joi.array().items(
        joi.object({
            type: joi.string().valid("email").required(),
            address: joi.string().email({ tlds: { allow: false } }).required(),
        })
    ),
  • Analysis:
    • Missing error message customization
    • Removed default Joi validation messages
    • Users receive empty error feedback
  • LlamaPReview Suggested Improvements:
    notifications: joi.array().items(
        joi.object({
            type: joi.string().valid("email").required()
                .messages({ 'any.only': 'Invalid notification type' }),
            address: joi.string().email({ tlds: { allow: false } }).required()
                .messages({ 'string.email': 'Invalid email format' }),
        })
    ).messages({
        'array.base': 'Notifications must be an array'
    }),
  • Improvement rationale:
    • Restores critical validation feedback
    • Maintains consistent error messaging

4. Overall Evaluation

  • Technical assessment: Addresses core issues with some implementation gaps
  • Business impact: High value UX improvement when fixes applied
  • Risk evaluation: Medium risk without test coverage
  • Positive aspects: Good schema separation, improved i18n integration
  • Implementation quality: Requires critical fixes before merging
  • Final Recommendation: Request Changes (P0 fixes required)

💡 LlamaPReview Community
Have feedback on this AI Code review tool? Join our GitHub Discussions to share your thoughts and help shape the future of LlamaPReview.

pagespeedApiKey: joi.string().allow("").optional(),
})
.unknown(true);
const settingsValidation = joi
Copy link
Contributor

Choose a reason for hiding this comment

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

@sonvir249 , why is this getting formatted, please try and format those codes which you have changed or else the PR looks long for no reason.

Copy link
Author

Choose a reason for hiding this comment

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

@Owaiseimdad Removed this formatting change.

Copy link
Member

@Br0wnHammer Br0wnHammer left a comment

Choose a reason for hiding this comment

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

Overall a UI SS is needed to review completely. Apart from that formatted code needs to omitted out of the PR. Larger diffs than required.

@@ -185,7 +185,7 @@ const ForgotPassword = () => {
value={form.email}
onChange={handleChange}
error={errors.email ? true : false}
helperText={errors.email}
helperText={t(errors.email)}
Copy link
Member

Choose a reason for hiding this comment

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

Any particular reason for this change? Also, can you share a UI SS.

Copy link
Author

@sonvir249 sonvir249 May 11, 2025

Choose a reason for hiding this comment

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

@Br0wnHammer I added the detailed screenshots in the issue #2238. I've attached the SS in PR too. Here errors.email returns the authRegisterEmailInvalid and authRegisterEmailRequired and it should be passed in t() to print the translation string.

? t("authRegisterEmailRequired")
: errors.email.includes("valid email")
? t("authRegisterEmailInvalid")
: t(errors.email))
Copy link
Member

Choose a reason for hiding this comment

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

Same thing here.

Copy link
Author

Choose a reason for hiding this comment

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

@Br0wnHammer removed unnecessary changes.

@@ -53,7 +66,7 @@ const passwordSchema = joi

const credentials = joi.object({
firstName: nameSchema,
lastName: nameSchema,
lastName: surnameSchema,
Copy link
Member

Choose a reason for hiding this comment

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

A better name would be lastnameSchema.

Copy link
Author

Choose a reason for hiding this comment

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

@Br0wnHammer done.

port: joi
.number()
.integer()
.min(1)
Copy link
Member

Choose a reason for hiding this comment

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

What is the change here?

Copy link
Author

@sonvir249 sonvir249 May 11, 2025

Choose a reason for hiding this comment

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

@Br0wnHammer removed unnecessary change

}),
pagespeedApiKey: joi.string().allow("").optional(),
})
.unknown(true);
Copy link
Member

Choose a reason for hiding this comment

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

Again, please refrain from using formatting on the code that is not supported by us. Makes the diff larger than it is.

Copy link
Author

Choose a reason for hiding this comment

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

@Br0wnHammer removed unnecessary change

@@ -377,5 +395,5 @@ export {
advancedSettingsValidation,
infrastructureMonitorValidation,
statusPageValidation,
logoImageValidation
logoImageValidation,
Copy link
Member

Choose a reason for hiding this comment

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

Same.

Copy link
Author

Choose a reason for hiding this comment

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

@Br0wnHammer removed unnecessary change

"Name must contain only letters, spaces, apostrophes, or hyphens",
});

const surnameSchema = joi
Copy link
Contributor

Choose a reason for hiding this comment

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

@sonvir249 , it looks like the same Joi schema is being repeated. Let's simplify this by renaming it to nameStringSchema. Also, instead of using name and surname, let's generalize it to something like characters or simply indicate that input is required. Please make sure to apply the DRY (Don't Repeat Yourself) principle wherever applicable.

Copy link
Author

Choose a reason for hiding this comment

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

@Br0wnHammer removed unnecessary change

? t("authRegisterEmailRequired")
: errors.email.includes("valid email")
? t("authRegisterEmailInvalid")
: t(errors.email))
Copy link
Contributor

Choose a reason for hiding this comment

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

@sonvir249 does anything like t(errors.email) exists in local file and, is it even intented to be from translation or is it just errors.email?

Copy link
Author

Choose a reason for hiding this comment

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

@Owaiseimdad errors.email returns the authRegisterEmailInvalid and authRegisterEmailRequired and it should be passed in t() to print the translation string.

@@ -185,7 +185,7 @@ const ForgotPassword = () => {
value={form.email}
onChange={handleChange}
error={errors.email ? true : false}
helperText={errors.email}
helperText={t(errors.email)}
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, I don't see anything like errors.email in translation file, let me know if I am missing anything here.
@sonvir249

Copy link
Author

Choose a reason for hiding this comment

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

@Owaiseimdad errors.email returns the authRegisterEmailInvalid and authRegisterEmailRequired and it should be passed in t() to print the translation string.

Copy link
Contributor

@Owaiseimdad Owaiseimdad left a comment

Choose a reason for hiding this comment

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

@sonvir249 please make your changes and test it locally and add screenshots for reference.

@sonvir249 sonvir249 force-pushed the bug/fix-form-errors branch from 4efbd4b to f0d2c57 Compare May 11, 2025 00:51
@sonvir249
Copy link
Author

@sonvir249 please make your changes and test it locally and add screenshots for reference.

@Owaiseimdad @Owaiseimdad thanks for the review and detailed comments. I appreciate that.
I added all the details and screenshots in #2239 when I created the issue. As per you comment I've updated the PR description.

@gorkem-bwl
Copy link
Contributor

@sonvir249 please make your changes and test it locally and add screenshots for reference.

@Owaiseimdad @Owaiseimdad thanks for the review and detailed comments. I appreciate that. I added all the details and screenshots in #2239 when I created the issue. As per you comment I've updated the PR description.

Thanks @sonvir249. The screenshot is for the PR, not the issue, eg. reflects what you did rather than what the issue is. For this reason we are asking it to be added to the PR instead.

Copy link
Member

@Br0wnHammer Br0wnHammer left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the quick revisions and for explaining your approach to us. We appreciate your contributions.

@Br0wnHammer
Copy link
Member

@ajhollid this is fine for merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Translation message issues on various forms
4 participants