Skip to content

Email Validation Done#516

Open
jeetvasoya21 wants to merge 4 commits into
GitMetricsLab:mainfrom
jeetvasoya21:email-validation
Open

Email Validation Done#516
jeetvasoya21 wants to merge 4 commits into
GitMetricsLab:mainfrom
jeetvasoya21:email-validation

Conversation

@jeetvasoya21
Copy link
Copy Markdown
Contributor

@jeetvasoya21 jeetvasoya21 commented May 25, 2026

Related Issue


Description

Implemented comprehensive form validation for the Contact page to improve user input handling and provide clear validation feedback.

Changes Added

  • Added frontend form validation with state management

  • Implemented email regex validation:

    const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
  • Added real-time error handling that clears validation messages while typing

  • Added HTML5 type="email" validation support

Validation Features

  • Full name validation (required)
  • Email validation with regex format checking
  • Subject selection validation (required)
  • Message validation (required, minimum 10 characters)
  • Inline error messages with alert icons
  • Red border highlighting for invalid fields

Email Validation Logic

if (!formData.email.trim()) {
  newErrors.email = "Email address is required";
} else if (!emailRegex.test(formData.email)) {
  newErrors.email = "Please enter a valid email address";
}

Files Modified

  • Contact.tsx — Added form validation, error handling, and user feedback improvements

How Has This Been Tested?

Invalid Email Test

  • Entered: demo
  • Validation error displayed: "Please enter a valid email address"
  • Invalid field highlighted with red border
  • Form submission prevented

Valid Email Test

  • Entered: john.doe@example.com
  • Validation error cleared automatically
  • Form submitted successfully
  • Success notification displayed:
    "Thank you for contacting us! We will get back to you shortly."
  • Form fields reset after successful submission

Screenshots (if applicable)

  • Added screenshots for:

    • Invalid email validation state:
  • Screenshot 2026-05-25 194921
    • Successful form submission state:
Screenshot 2026-05-25 195147

Type of Change

  • Bug fix
  • New feature
  • Code style update
  • Breaking change
  • Documentation update

Summary by CodeRabbit

  • New Features
    • Contact form now includes client-side validation for all fields, including email format
    • Real-time inline error messages appear below each field as users type
    • Form submission is blocked when validation fails
    • Controlled inputs with submit state: shows a submitting indicator, success popup on completion, and automatic form reset after success

Review Change Stack

@netlify
Copy link
Copy Markdown

netlify Bot commented May 25, 2026

Deploy Preview for github-spy ready!

Name Link
🔨 Latest commit 78457f3
🔍 Latest deploy log https://app.netlify.com/projects/github-spy/deploys/6a19c4ebee87de0008e9c5a5
😎 Deploy Preview https://deploy-preview-516--github-spy.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 25, 2026

Warning

Review limit reached

@mehul-m-prajapati, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 36 minutes and 59 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, 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 include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 639e37ff-b3ba-44fe-9de4-e326aef89ef8

📥 Commits

Reviewing files that changed from the base of the PR and between 3d48796 and 78457f3.

📒 Files selected for processing (1)
  • src/pages/Contact/Contact.tsx
📝 Walkthrough

Walkthrough

Contact page inputs are now controlled and wrapped in a <form>. Client-side validation (including email regex) populates per-field errors; submission is prevented when invalid, shows a loading state, then displays success and resets the form on completion.

Changes

Contact Form Validation & Controlled Inputs

Layer / File(s) Summary
Form validation and submit handling
src/pages/Contact/Contact.tsx
Adds module email regex, validateForm(), handleInputChange(), handleSubmit(), isSubmitting state, and resets formData/errors on success.
Form element wiring
src/pages/Contact/Contact.tsx
Wraps contact fields in an HTML <form> and wires onSubmit={handleSubmit} (adds opening and closing form tags).
Controlled fields and inline error rendering
src/pages/Contact/Contact.tsx
Converts Full Name, Email, Subject, and Message to controlled inputs (name/value/onChange), applies conditional error styling, renders inline AlertCircle error messages per field, and disables submit while submitting.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • GitMetricsLab/github_tracker#319: Similar edits to src/pages/Contact/Contact.tsx converting the contact form to controlled inputs with shared validation and updated submit handling.

Poem

🐰 I hop to check each name and mail,
I tidy errors, follow the trail,
Fields now talk back when inputs stray,
Submit waits kindly, then clears the way,
A little rabbit cheers: "Send away!"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Email Validation Done' clearly describes the main feature added: email validation for the contact form.
Description check ✅ Passed The description follows the template with all required sections: Related Issue (#502), detailed Description, testing steps, screenshots, and Type of Change correctly marked as bug fix.
Linked Issues check ✅ Passed The PR fully addresses issue #502 requirements: implements email validation with regex, displays error messages, prevents invalid submissions, and provides user-friendly feedback.
Out of Scope Changes check ✅ Passed All changes are scoped to the Contact form validation feature. The PR includes comprehensive form validation (full name, email, subject, message) consistently with issue #502 objectives, with no unrelated modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

🎉 Thank you @jeetvasoya21 for your contribution. Please make sure your PR follows https://github.com/GitMetricsLab/github_tracker/blob/main/CONTRIBUTING.md#-pull-request-guidelines

Copy link
Copy Markdown
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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/pages/Contact/Contact.tsx (1)

268-449: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Wrap form inputs in a semantic <form> element.

The form inputs are currently wrapped in a <div> instead of a <form> element, and the submit button uses onClick instead of type="submit". This creates accessibility and UX issues:

  1. Keyboard accessibility: Users cannot press Enter in an input field to submit the form, which is standard expected behavior.
  2. Screen reader support: Assistive technologies rely on semantic <form> elements to properly announce form context and structure.
  3. Type mismatch: handleSubmit expects FormEvent but receives MouseEvent from the button's onClick.
♿ Recommended fix for accessibility

Replace the outer <div> wrapper with a <form> element and move handleSubmit to the form's onSubmit:

-<div
+<form
+  onSubmit={handleSubmit}
   className={`p-4 sm:p-6 rounded-xl sm:rounded-3xl shadow-2xl h-full flex flex-col backdrop-blur-lg ${
     mode === "dark"
       ? "bg-white/10 border border-white/20"
       : "bg-white border border-gray-300"
   }`}
 >
   ...
   <button
-    onClick={handleSubmit}
+    type="submit"
     disabled={isSubmitting}
     ...
   >

Then close with </form> instead of </div> at the end of the form container (around line 449).

🤖 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 `@src/pages/Contact/Contact.tsx` around lines 268 - 449, The inputs are inside
a <div> so pressing Enter and assistive tech can't treat this as a form; replace
the outer form container div with a semantic <form> that uses
onSubmit={handleSubmit} (leave handleInputChange, formData, errors, isSubmitting
as-is) and move the submit behavior off the button: change the Send button to
type="submit" and remove its onClick; ensure handleSubmit signature matches a
FormEvent handler and still calls event.preventDefault() and sets isSubmitting
appropriately.
🧹 Nitpick comments (1)
src/pages/Contact/Contact.tsx (1)

33-34: 💤 Low value

Consider moving emailRegex outside the component.

Defining the regex inside the component causes it to be recreated on every render. Moving it to module scope would be a minor performance optimization.

♻️ Suggested refactor
+// Email validation regex
+const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
+
 function Contact() {
   const [showPopup, setShowPopup] = useState(false);
   const [isSubmitting, setIsSubmitting] = useState(false);
   ...
-  // Email validation regex
-  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
🤖 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 `@src/pages/Contact/Contact.tsx` around lines 33 - 34, Move the emailRegex
constant out of the React component to module scope to avoid recreating it on
every render: define the regex at top-level in the Contact.tsx module (e.g.,
alongside imports) and leave the component (Contact) to reference that top-level
emailRegex; update any usages inside the component (e.g., validateEmail or
onSubmit handlers) to use the module-scoped emailRegex.
🤖 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 `@src/pages/Contact/Contact.tsx`:
- Around line 98-103: When resetting the form after successful submission (where
you call setFormData to clear fullName, email, subject, message), also reset the
errors state so previous validation errors are cleared; locate the errors state
updater (setErrors) and set it to the initial/empty errors object (matching the
shape used elsewhere) at the same point you call setFormData.

---

Outside diff comments:
In `@src/pages/Contact/Contact.tsx`:
- Around line 268-449: The inputs are inside a <div> so pressing Enter and
assistive tech can't treat this as a form; replace the outer form container div
with a semantic <form> that uses onSubmit={handleSubmit} (leave
handleInputChange, formData, errors, isSubmitting as-is) and move the submit
behavior off the button: change the Send button to type="submit" and remove its
onClick; ensure handleSubmit signature matches a FormEvent handler and still
calls event.preventDefault() and sets isSubmitting appropriately.

---

Nitpick comments:
In `@src/pages/Contact/Contact.tsx`:
- Around line 33-34: Move the emailRegex constant out of the React component to
module scope to avoid recreating it on every render: define the regex at
top-level in the Contact.tsx module (e.g., alongside imports) and leave the
component (Contact) to reference that top-level emailRegex; update any usages
inside the component (e.g., validateEmail or onSubmit handlers) to use the
module-scoped emailRegex.
🪄 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: 4e78ffde-e81e-4722-9d8b-d2f84201d129

📥 Commits

Reviewing files that changed from the base of the PR and between 6c6bc3e and 51599e8.

📒 Files selected for processing (1)
  • src/pages/Contact/Contact.tsx

Comment thread src/pages/Contact/Contact.tsx
Copy link
Copy Markdown
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

🤖 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 `@src/pages/Contact/Contact.tsx`:
- Around line 269-270: The Contact form's browser-native validation can block
React's handleSubmit and prevent your setErrors/inline rendering from running;
update the form element in Contact.tsx (the component containing handleSubmit)
to include the noValidate attribute on the <form> so the browser won't intercept
submission and your custom validation in handleSubmit will always run. Ensure
the attribute is added to the same form element that currently has
onSubmit={handleSubmit} so no other behavior changes are required.
🪄 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: 25b4ffb1-c842-42eb-a7f2-3e6269393634

📥 Commits

Reviewing files that changed from the base of the PR and between 51599e8 and 3d48796.

📒 Files selected for processing (1)
  • src/pages/Contact/Contact.tsx

Comment thread src/pages/Contact/Contact.tsx
@jeetvasoya21
Copy link
Copy Markdown
Contributor Author

Fixed the requested changes. Please review again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Email Validation Missing in Contact Form

2 participants