Skip to content
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

Enhancement: Resolve [604] Email Field Shouldn't Allow Spaces #613

Conversation

anthonyheitzeberg
Copy link

@anthonyheitzeberg anthonyheitzeberg commented Feb 13, 2025

What kind of change does this PR introduce?

Bug Fix, but this seems more like a UX enhancement regarding email input field

Why was this change needed?

Addressing this UX issue brought up here: Email Field Shouldn't Allow Spaces Issue # 604

Other information:

eg: Did you discuss this change with anybody before working on it (not required, but can be a good idea for bigger changes). Any plans for the future, etc?

Checklist:

  • I have read the CONTRIBUTING guide.
  • I checked that there were not similar issues or PRs already open for this.
  • This PR fixes just ONE issue (do not include multiple issues or types of change in the same PR) For example, don't try and fix a UI issue and include new dependencies in the same PR.

Summary by CodeRabbit

  • New Features
    • Enhanced email input fields now enforce proper formatting and validation.
    • Improved input behavior by disallowing spaces in email addresses during entry.

Copy link

vercel bot commented Feb 13, 2025

@anthonyheitzeberg is attempting to deploy a commit to the Listinai Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

coderabbitai bot commented Feb 13, 2025

Warning

Rate limit exceeded

@anthonyheitzeberg has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 22 minutes and 54 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 5f9a4e8 and b0cef98.

📒 Files selected for processing (1)
  • libraries/react-shared-libraries/src/form/input.tsx (3 hunks)

Walkthrough

The pull request updates the email input behavior by introducing an explicit type prop to the Input component. In the teams component, the AddMember function now passes type="email" to enforce email-specific formatting. Simultaneously, the shared Input component has been enhanced to include an onKeyDown event handler that prevents space characters in email inputs. Other behaviors and control flows remain unchanged.

Changes

File(s) Change Summary
apps/frontend/.../teams.component.tsx Updated the AddMember function: Modified the Input usage to include type="email" for proper email validation.
libraries/.../input.tsx Added an onKeyDown event handler to prevent spaces in the email input field.

Poem

I hopped through lines of evolving code,
Where emails now have their proper abode.
A tiny tweak with type="email" in sight,
Keeps each keystroke just perfectly right.
This bunny cheers in a whimsical light,
Hopping ahead with joy and carrot delight!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.

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. (Beta)
  • @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.

@nevo-david
Copy link
Contributor

Thank you!
Not sure how much I like the keyDown solution, I would prefer to use the native setValueAs for react-hook-form and modify the onChange without the hook form.

Also, the type email for registration and login is missing.

I will let other people comment on what they think :)

@anthonyheitzeberg anthonyheitzeberg marked this pull request as ready for review February 13, 2025 04:09
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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b4a8a13 and 73734df.

📒 Files selected for processing (2)
  • apps/frontend/src/components/settings/teams.component.tsx (1 hunks)
  • libraries/react-shared-libraries/src/form/input.tsx (3 hunks)
🔇 Additional comments (2)
libraries/react-shared-libraries/src/form/input.tsx (1)

29-30: LGTM! Type prop addition looks good.

The type prop is correctly destructured from props and will be useful for input-specific behaviors.

apps/frontend/src/components/settings/teams.component.tsx (1)

108-113:

✅ Verification successful

LGTM! Email input configuration looks good.

The type="email" attribute is correctly added to the Input component.

Let's check if AddTeamMemberDto already includes email validation:


🏁 Script executed:

#!/bin/bash
# Search for AddTeamMemberDto definition and its validation decorators
ast-grep --pattern 'export class AddTeamMemberDto {
  $$$
  email$$$
  $$$
}'

Length of output: 79


Please verify email validation in AddTeamMemberDto.

  • The Input component changes (lines 108-113 in apps/frontend/src/components/settings/teams.component.tsx) correctly add type="email"—this aligns with validation expectations on the frontend.
  • Automated searches did not return clear evidence of email validation (e.g., via @IsEmail decorators) in the AddTeamMemberDto definition. Please manually inspect or update AddTeamMemberDto to ensure that email inputs are suitably validated.

🏁 Script executed:

[run_scripts]
#!/bin/bash
# 1. Print out context around the definition of AddTeamMemberDto
echo "Searching for 'class AddTeamMemberDto' with context:"
rg -n "class AddTeamMemberDto" -C 10 .

# 2. Look for any email validation decorator usage (e.g., '@IsEmail') in the repository:
echo "Searching for '@IsEmail' in the repository:"
rg -n "@IsEmail" .

Length of output: 1949


LGTM! Email input configuration and validation are correctly implemented.

  • The Input component in apps/frontend/src/components/settings/teams.component.tsx now correctly uses type="email".
  • Backend validation is confirmed in AddTeamMemberDto (in libraries/nestjs-libraries/src/dtos/settings/add.team.member.dto.ts), where the @IsEmail() decorator validates the email field.

@anthonyheitzeberg
Copy link
Author

anthonyheitzeberg commented Feb 13, 2025

Hello @nevo-david thank you for your feedback, so I understand it would be better to use the preferred react-form-hook and have applied the suggested changes of code rabbit.

Edit: still working on getting this to work, my bad

@anthonyheitzeberg anthonyheitzeberg changed the title Enhancement: Resolve [604] remove the keypress event for space on email Enhancement: Resolve [604] Email Field Shouldn't Allow Spaces Feb 13, 2025
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: 2

🧹 Nitpick comments (1)
libraries/react-shared-libraries/src/form/input.tsx (1)

47-48: Remove unused email pattern.

The email pattern can be moved inside the registration options since it's only used there.

Apply this diff:

-const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
-
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 73734df and 187c54e.

📒 Files selected for processing (1)
  • libraries/react-shared-libraries/src/form/input.tsx (4 hunks)

@egelhaus egelhaus linked an issue Feb 13, 2025 that may be closed by this pull request
1 task
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: 1

🔭 Outside diff range comments (1)
libraries/react-shared-libraries/src/form/input.tsx (1)

10-20: ⚠️ Potential issue

Add type prop to component interface.

The component interface is missing the type prop which is needed for proper email validation.

Update the interface:

export const Input: FC<
  DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> & {
    removeError?: boolean;
    error?: any;
    disableForm?: boolean;
    customUpdate?: () => void;
    label: string;
    name: string;
+   type?: string;
    icon?: ReactNode;
  }
> = (props) => {
♻️ Duplicate comments (1)
libraries/react-shared-libraries/src/form/input.tsx (1)

61-65: 🛠️ Refactor suggestion

Switch to react-hook-form's built-in validation instead of keyDown event.

The current implementation only prevents typing spaces but doesn't handle paste events or trailing spaces. Using react-hook-form's built-in validation would be more robust.

Replace the keyDown handler with react-hook-form's built-in validation:

-onKeyDown={(e) => {
-  if (props.name === 'email' && e.key === ' ') {
-    e.preventDefault();
-  }
-}}

And update the form registration to use built-in validation:

{...(disableForm ? {} : form.register(props.name, {
  ...(props.type === 'email' ? {
    pattern: {
      value: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
      message: 'Please enter a valid email address'
    },
    setValueAs: (value: string) => value?.trim()
  } : {})
}))}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 187c54e and 5f9a4e8.

📒 Files selected for processing (1)
  • libraries/react-shared-libraries/src/form/input.tsx (1 hunks)

Copy link
Collaborator

@egelhaus egelhaus left a comment

Choose a reason for hiding this comment

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

LGTM

@anthonyheitzeberg
Copy link
Author

Hello @nevo-david, have verified that the type field exist on all email fields in the frontend, resorted to still use onkeydown to prevent the field from even receiving a space at all so no need to set the form value. Thanks for the approval @egelhaus!

It did try using the onChange and setValueAs in the register options of the hook but it wasn't a smooth experience as using the onKeydown.

Copy link
Collaborator

@egelhaus egelhaus left a comment

Choose a reason for hiding this comment

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

The build failed for some Reason (I will provide the Error Log) but please fix it, because this hasn't been an issue before.

@egelhaus
Copy link
Collaborator

./src/components/billing/lifetime.deal.tsx:176:16
Type error: Property 'type' is missing in type '{ label: string; placeholder: string; disableForm: true; name: string; value: string; onChange: (e: ChangeEvent) => void; }' but required in type '{ removeError?: boolean | undefined; error?: any; disableForm?: boolean | undefined; customUpdate?: (() => void) | undefined; label: string; name: string; type: string; icon?: ReactNode; }'.

174 |           <div className="mt-[20px] flex items-center gap-[10px]">
175 |             <div className="flex-1">

176 | <Input
| ^
177 | label="Code"
178 | placeholder="Enter your code"
179 | disableForm={true}
Static worker exited with code: 1 and signal: null
Build process exited due to code 1

@egelhaus
Copy link
Collaborator

I will be trying this again on a different PR.

@nevo-david
Copy link
Contributor

type should be an optional field defaulting to text.
At the moment, I can't merge this; there is a better solution, that's a bit overkill for something so small.

You add an extra even listener to every input on the page in exchange for preventing a space in the email (that doesn't pass validation anyway from the dto)

(It would have been better to add the onKeyDown, only the type is email)

I am closing it for now

@nevo-david nevo-david closed this Feb 13, 2025
@egelhaus
Copy link
Collaborator

Hey, this hasn't been an Issue on a different PR, so this PR is the Issue.

@egelhaus
Copy link
Collaborator

@nevo-david I wouldn't close it, I would make it an Draft. But your choice.

@anthonyheitzeberg
Copy link
Author

Okay I see @nevo-david, i think i understand what you mean, I can open another PR , but reopening this is also fine.

@nevo-david
Copy link
Contributor

I closed the issue.
That's not a bug - that's a controversial enhancement - some people might want to add spaces while they copy the email.
You can't save the email as there is an email validation both on the client and the server

@anthonyheitzeberg
Copy link
Author

Alright thats true, thank you @nevo-david @egelhaus, will try another issue and play around the project.

@anthonyheitzeberg anthonyheitzeberg deleted the bugfix/604-email-field-no-spaces-allowed branch February 13, 2025 08:09
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.

Email Field Shouldn't Allow Spaces
3 participants