Skip to content

Fix: Handle duplicate email and validation errors in newsletter subscription .#404

Closed
vidhiii1711 wants to merge 2 commits into
Sachinchaurasiya360:mainfrom
vidhiii1711:fix/newsletter-validation-and-duplicate-check
Closed

Fix: Handle duplicate email and validation errors in newsletter subscription .#404
vidhiii1711 wants to merge 2 commits into
Sachinchaurasiya360:mainfrom
vidhiii1711:fix/newsletter-validation-and-duplicate-check

Conversation

@vidhiii1711
Copy link
Copy Markdown

@vidhiii1711 vidhiii1711 commented May 22, 2026

Summary

Handle backend response cases in newsletter subscription form
that were previously ignored by the frontend.

Changes

  • Handle 201 response: show success message for new subscribers
  • Handle 200 response: show "already subscribed" error message
  • Handle 400 error: show "valid email required" message from backend
  • Handle 409 error: show duplicate email message as extra safety net

How to test

  1. Go to the footer of the landing page
  2. Enter a new valid email → should show "subscribed. see you monday."
  3. Enter the same email again → should show "You're already subscribed!"
  4. Enter invalid email like abc@ → should show validation error

Fixes #363

Summary by CodeRabbit

  • Bug Fixes
    • Improved newsletter subscription flow with clearer, specific messages for invalid emails and duplicate subscriptions; prevents duplicate success notifications and correctly reports when an address is already subscribed.
    • Ensures submit button state is cleared after submission attempts so the UI remains responsive.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 61bba356-a830-4c98-ad4e-5a68f0a507ce

📥 Commits

Reviewing files that changed from the base of the PR and between 4669490 and f53c30c.

📒 Files selected for processing (1)
  • client/src/components/Footer.tsx

📝 Walkthrough

Walkthrough

The footer's handleSubscribe now posts to /newsletter/subscribe, inspects the response status to distinguish success (201) vs "already subscribed" (200), and maps caught error status codes (400, 409) to specific user messages; submitting state is cleared in finally.

Changes

Newsletter subscription status handling

Layer / File(s) Summary
Subscription response and error handling
client/src/components/Footer.tsx
handleSubscribe captures the API response status to branch between success (201), "already subscribed" (200), and error conditions (400 invalid email, 409 duplicate), setting the appropriate user-facing message and resetting the submitting state.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Poem

🐰 A footer once posted without care,
Now checks the status with patient stare,
201 nods, 200 sighs—
400, 409 wise,
A rabbit hops in to tidy the air.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR addresses the frontend requirements from issue #363: handling specific HTTP response codes (201, 200, 400, 409) and displaying appropriate user-facing messages, but does not implement backend route, database model, or email validation logic. Complete backend implementation: create POST /api/newsletter/subscribe route with email validation (returning 400), duplicate check (returning 409), and Prisma Newsletter model with unique email constraint.
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 (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: handling duplicate email and validation errors in newsletter subscription, which directly matches the PR's core objective.
Out of Scope Changes check ✅ Passed All changes in Footer.tsx directly relate to handling newsletter subscription responses and errors as specified in issue #363; no unrelated modifications detected.

✏️ 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
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 `@client/src/components/Footer.tsx`:
- Around line 38-40: Replace the hardcoded 400 error message in the Footer
component's error handling so that when err.response?.status === 400 you first
read the backend validation message (e.g., err.response?.data?.message or
err.response?.data?.errors[0]?.message) and pass that to setError, falling back
to "Please enter a valid email address." if no message exists; update the branch
that currently calls setError("Please enter a valid email address.") to use the
API payload with safe optional chaining and a fallback.
🪄 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: 8f51a5a3-8cc1-4e5a-9db6-07bf9890ea19

📥 Commits

Reviewing files that changed from the base of the PR and between 8611468 and 4669490.

📒 Files selected for processing (1)
  • client/src/components/Footer.tsx

Comment thread client/src/components/Footer.tsx Outdated
@vidhiii1711
Copy link
Copy Markdown
Author

@Sachinchaurasiya360
The 224 ESLint errors are pre-existing in the codebase and are unrelated to my changes. My change is limited only to client/src/components/Footer.tsx.

CodeRabbit has also reviewed and approved the changes.
Happy to fix the pre-existing issues in a separate PR if needed!

@Sachinchaurasiya360 Sachinchaurasiya360 added gssoc:approved Approved for GSSoC scoring type:bug Bug fixes level:beginner Good for first-time contributors labels May 23, 2026
@Sachinchaurasiya360
Copy link
Copy Markdown
Owner

Changes applied manually to main with the following fixes: removed duplicate e.preventDefault(), changed catch (err: any) to catch (err: unknown) with proper type narrowing, fixed broken indentation in catch/finally blocks.

Sachinchaurasiya360 added a commit that referenced this pull request May 23, 2026
…ription (#404)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved Approved for GSSoC scoring level:beginner Good for first-time contributors type:bug Bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug + Feature]: Newsletter subscription is frontend-only — no backend, no validation, no duplicate check

2 participants