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

🔒 Registration form hardening #1160

Merged
merged 3 commits into from
Jun 19, 2024
Merged

Conversation

lukevella
Copy link
Owner

@lukevella lukevella commented Jun 18, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced form validation using Zod for better error handling during user registration.
  • Bug Fixes

    • Improved error messages and validation for participant names and emails to ensure data integrity.
  • Style

    • Updated the font size for large buttons for better readability.

Copy link

vercel bot commented Jun 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 18, 2024 7:22pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
landing ⬜️ Ignored (Inspect) Visit Preview Jun 18, 2024 7:22pm

Copy link
Contributor

coderabbitai bot commented Jun 18, 2024

Walkthrough

The recent updates across multiple files emphasize improved validation and error handling using Zod and TRPCClientError. Key modifications include form input validation in the registration page, enhanced participant validation schemas, streamlined email formatting rules, and a UI adjustment for button text sizes. These changes enhance data integrity, user experience, and maintainability of forms and validation logic.

Changes

Files/Paths Summary of Changes
apps/web/src/.../register-page.tsx Integrated Zod validation for form inputs, updated form handling logic, and added error handling for TRPCClientError.
apps/web/src/.../new-participant-modal.tsx Imported FormMessage and TRPCClientError, updated validation schemas for 'name' field, and added error handling logic.
packages/backend/trpc/routers/... Updated requestRegistration and participants.ts with stricter validation rules for name and email fields.
packages/ui/src/button.tsx Changed font size for large button variant from "text-sm" to "text-base".

Poem

Amongst the code, where changes lay,
A rabbit hops to lead the way.
With Zod and TRPC in hand,
Error-free forms now grace the land.
Larger font on buttons too,
For a clearer, bolder view. 🚀🐇


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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
Contributor

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 093ed11 and 13af35b.

Files selected for processing (5)
  • apps/web/src/app/[locale]/(auth)/register/register-page.tsx (2 hunks)
  • apps/web/src/components/new-participant-modal.tsx (5 hunks)
  • packages/backend/trpc/routers/auth.ts (1 hunks)
  • packages/backend/trpc/routers/polls/participants.ts (1 hunks)
  • packages/ui/src/button.tsx (1 hunks)
Additional comments not posted (14)
packages/ui/src/button.tsx (1)

32-32: Updated the font size for large buttons from "text-sm" to "text-base" enhances readability and aligns with typical design standards for larger interactive elements.

packages/backend/trpc/routers/auth.ts (1)

15-16: Enhanced validation for registration: name field now requires a non-empty string with a maximum of 100 characters, and email must be a valid email address. These changes improve data integrity and user experience by preventing invalid entries at the source.

apps/web/src/components/new-participant-modal.tsx (3)

5-7: Added necessary imports for FormMessage and TRPCClientError to enhance form error handling capabilities.


21-21: Updated validation rules for participant names to require a non-empty string with a maximum of 100 characters, aligning with backend validation rules and ensuring consistency across the application.

Also applies to: 27-27


107-121: Enhanced error handling in form submission: now correctly identifies and handles TRPCClientError, providing user feedback through FormMessage. This improves the robustness and user-friendliness of the form.

packages/backend/trpc/routers/polls/participants.ts (1)

56-57: Updated validation rules for name to require a non-empty string with a maximum of 100 characters and for email to be an optional valid email address. These changes ensure data consistency and meet the standards set in other parts of the application.

apps/web/src/app/[locale]/(auth)/register/register-page.tsx (8)

21-21: Integrate Zod for enhanced type safety and validation.

This import is crucial for leveraging Zod's capabilities within the form validation schema.


29-32: Define a robust form schema using Zod.

This schema ensures that 'name' and 'email' fields meet specific criteria, which enhances data integrity.


34-34: Utilize Zod to infer types for form data.

This approach promotes type safety by ensuring that the form data adheres to the defined schema.


41-44: Configure React Hook Form to use the Zod resolver.

This setup integrates Zod validation with React Hook Form, enhancing form data validation and error handling.


46-46: Extract necessary hooks and states from the form.

Properly structured for managing form state and handling submissions.


127-131: Handle TRPCClientError specifically in form submission.

This error handling ensures that TRPC client errors are caught and managed appropriately, improving user experience during form submission failures.


145-165: Render input fields with validation feedback.

These components are well-integrated with the form's validation logic, providing immediate feedback on input errors, which enhances user interaction.

Also applies to: 167-185


197-201: Display a generic error message if any unspecified errors occur.

This is a good practice as it informs the user of errors not related to specific fields.

Copy link
Contributor

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 13af35b and c49d16f.

Files selected for processing (1)
  • packages/backend/trpc/routers/polls/participants.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/backend/trpc/routers/polls/participants.ts

@lukevella lukevella merged commit c307963 into main Jun 19, 2024
7 checks passed
@lukevella lukevella deleted the registration-form-hardening branch June 19, 2024 08:16
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.

1 participant