Skip to content

Fix newsletter subscription functionality using EmailJS#495

Closed
GkBuilds16 wants to merge 3 commits into
GitMetricsLab:mainfrom
GkBuilds16:fix-subscribe-feature
Closed

Fix newsletter subscription functionality using EmailJS#495
GkBuilds16 wants to merge 3 commits into
GitMetricsLab:mainfrom
GkBuilds16:fix-subscribe-feature

Conversation

@GkBuilds16
Copy link
Copy Markdown

@GkBuilds16 GkBuilds16 commented May 25, 2026

Related Issue


Description

Implemented working newsletter subscription functionality using EmailJS.

The previous Subscribe button only displayed a success alert without actually sending any email. This update integrates EmailJS to provide real email subscription support with proper validation and user feedback.


How Has This Been Tested?

  • Tested locally using Vite development server
  • Verified successful email delivery after subscription
  • Tested invalid and empty email handling
  • Confirmed success and failure alerts are working properly

Screenshots (if applicable)

  • Added screenshots of successful subscription flow
  • Added screenshot of received email confirmation

Type of Change

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

Summary by CodeRabbit

  • Enhancements

    • Newsletter subscription now sends emails through an integrated email service
    • Added email validation for newsletter signup
  • Dependencies

    • Added email delivery library for transactional email functionality

Review Change Stack

@netlify
Copy link
Copy Markdown

netlify Bot commented May 25, 2026

Deploy Preview for github-spy ready!

Name Link
🔨 Latest commit a786982
🔍 Latest deploy log https://app.netlify.com/projects/github-spy/deploys/6a13e79406074500086711c3
😎 Deploy Preview https://deploy-preview-495--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

@GkBuilds16, we couldn't start this review because you've used your available PR reviews for now.

Your plan includes 1 review of capacity. Refill in 26 minutes and 14 seconds.

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

⌛ How to resolve this issue?

After more review capacity refills, 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 trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ad11c23e-cfb0-4bfa-b05d-4d76d6cfd227

📥 Commits

Reviewing files that changed from the base of the PR and between 52a3d43 and a786982.

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

Walkthrough

This PR integrates EmailJS into the newsletter subscription form, adding environment variable configuration, the @emailjs/browser package dependency, and replacing the placeholder alert-based subscription handler with async email submission logic that validates input and handles success/error feedback.

Changes

EmailJS Newsletter Subscription

Layer / File(s) Summary
Environment and dependency setup
.env.example, package.json, .gitignore
EmailJS configuration variables (VITE_EMAILJS_SERVICE_ID, VITE_EMAILJS_TEMPLATE_ID, VITE_EMAILJS_PUBLIC_KEY) are added to .env.example, @emailjs/browser is installed as a dependency in package.json, and .env is ignored in .gitignore.
Newsletter submission handler with EmailJS
src/components/Footer.tsx
Footer imports @emailjs/browser and replaces the placeholder handleSubscribe with async EmailJS integration that validates email input, calls emailjs.send with environment credentials, alerts success and clears the input on completion, and logs/alerts errors on failure.

Sequence Diagram

sequenceDiagram
  participant User
  participant Footer
  participant EmailJS
  User->>Footer: Submit email form
  Footer->>Footer: Validate email not empty
  Footer->>EmailJS: emailjs.send with VITE_EMAILJS_* config
  EmailJS->>EmailJS: Send email via service
  alt Success
    EmailJS-->>Footer: Promise resolved
    Footer->>User: Alert success, clear input
  else Failure
    EmailJS-->>Footer: Promise rejected
    Footer->>Footer: Log error
    Footer->>User: Alert failure message
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • GitMetricsLab/github_tracker#295: Both PRs modify newsletter subscription functionality in src/components/Footer.tsx, with this PR adding EmailJS email submission while PR #295 rewrites the subscription UI.
  • GitMetricsLab/github_tracker#304: Both PRs update the footer subscription handler in src/components/Footer.tsx—this PR adds EmailJS submission logic while PR #304 adjusts confirmation behavior and styling.
  • GitMetricsLab/github_tracker#292: Both PRs modify the newsletter subscription flow in Footer, with PR #292 adding the form structure and this PR adding the EmailJS submission wiring.

Suggested labels

level:intermediate, quality:clean

Poem

🐰 A rabbit's hop toward email success,
With EmailJS keys, no more distress!
The footer now sends each subscribed address,
Through async await—what a digital caress! ✨

🚥 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 clearly and accurately describes the main change: implementing EmailJS integration to fix the newsletter subscription functionality.
Description check ✅ Passed The description follows the template structure with all required sections: Related Issue, Description, How Has This Been Tested, Screenshots, and Type of Change. All sections are adequately filled out.
Linked Issues check ✅ Passed The PR successfully implements all key requirements from issue #491: integrates EmailJS for real email sending, adds email validation, and provides success/failure feedback to users.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing newsletter subscription: EmailJS dependency added, environment variables configured, Footer component updated with email sending logic, and .env/.gitignore updated appropriately.

✏️ 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 @GkBuilds16 for your contribution. Please make sure your PR follows https://github.com/GitMetricsLab/github_tracker/blob/main/CONTRIBUTING.md#-pull-request-guidelines

@GkBuilds16
Copy link
Copy Markdown
Author

Implemented the newsletter subscription functionality using EmailJS with validation and environment variable support. Kindly review the PR.

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: 3

🧹 Nitpick comments (2)
src/components/Footer.tsx (2)

28-35: ⚡ Quick win

Add environment variable validation.

The code assumes EmailJS environment variables are configured but doesn't validate them. If these are missing or undefined, emailjs.send() will fail with a cryptic error.

🛡️ Proposed validation
  const handleSubscribe = async (
   e: React.FormEvent<HTMLFormElement>
 ) => {
   e.preventDefault();

   if (!email) {
     toast.error('Please enter a valid email');
     return;
   }

+  const serviceId = import.meta.env.VITE_EMAILJS_SERVICE_ID;
+  const templateId = import.meta.env.VITE_EMAILJS_TEMPLATE_ID;
+  const publicKey = import.meta.env.VITE_EMAILJS_PUBLIC_KEY;
+
+  if (!serviceId || !templateId || !publicKey) {
+    console.error('EmailJS configuration missing');
+    toast.error('Newsletter service is not configured. Please contact support.');
+    return;
+  }

   setIsSubmitting(true);
   try {
    await emailjs.send(
-  import.meta.env.VITE_EMAILJS_SERVICE_ID,
-  import.meta.env.VITE_EMAILJS_TEMPLATE_ID,
+  serviceId,
+  templateId,
   {
     user_email: email,
   },
-  import.meta.env.VITE_EMAILJS_PUBLIC_KEY
+  publicKey
 );
🤖 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/components/Footer.tsx` around lines 28 - 35, Validate the EmailJS
environment variables before calling emailjs.send: check
import.meta.env.VITE_EMAILJS_SERVICE_ID,
import.meta.env.VITE_EMAILJS_TEMPLATE_ID, and
import.meta.env.VITE_EMAILJS_PUBLIC_KEY for non-empty values (and the email
param) inside the Footer component or the function that invokes emailjs.send; if
any are missing, short-circuit and surface a clear error (e.g., throw or display
a user-friendly message/log via console.error or the component's error state)
instead of calling emailjs.send to avoid cryptic failures.

17-43: 🏗️ Heavy lift

Consider adding bot protection for client-side email submission.

Since EmailJS credentials are exposed in client-side code, the subscription endpoint can be abused by bots to send spam. While EmailJS has some built-in rate limiting, consider adding additional protection like reCAPTCHA v3, honeypot fields, or moving email handling to a backend endpoint with rate limiting.

🤖 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/components/Footer.tsx` around lines 17 - 43, The client-side
handleSubscribe function currently calls emailjs.send with exposed env keys
(import.meta.env.VITE_EMAILJS_*) which risks abuse; to fix, remove direct public
key usage from the browser by moving subscription handling to a backend endpoint
(create a POST /subscribe handler) that receives the email and a bot-proof
token, verifies the token (e.g., verify reCAPTCHA v3/enterprise server-side) and
calls EmailJS (or sends the email) from the server with rate limiting and
logging; alternatively, if you must keep client-side sending, integrate
reCAPTCHA v3 in the handleSubscribe flow to obtain a token and require
server-side verification or add a hidden honeypot input that handleSubscribe
checks and aborts if filled, and implement rate limiting/validation around the
send logic (referencing handleSubscribe and emailjs.send to locate where to
change).
🤖 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 @.gitignore:
- Line 49: Duplicate .env ignore entry found in .gitignore; remove the later
".env" line so only the original entry (the one in the "Environment Variables"
section) remains. Locate the ".env" token in the file (the duplicate entry) and
delete that line, leaving the existing earlier ".env" entry intact.

In `@src/components/Footer.tsx`:
- Around line 17-43: Replace blocking alert() calls in handleSubscribe with
react-hot-toast notifications and add a loading state: add a boolean state like
isLoading with setIsLoading in the Footer component, set isLoading(true) before
calling emailjs.send and setIsLoading(false) in finally; replace
alert('Subscribed successfully!') with toast.success(...) and
alert('Subscription failed...') with toast.error(...), and replace the
empty-email alert with toast.error(...) as well; update the form submit button
(the element that triggers handleSubscribe) to be disabled when isLoading is
true and show a loading indicator/changed label while loading so users cannot
resubmit while the async emailjs.send call is in progress.
- Line 3: The call to emailjs.send in Footer.tsx passes
import.meta.env.VITE_EMAILJS_PUBLIC_KEY directly as the 4th arg but EmailJS v4
requires an options object; locate the emailjs.send(...) invocation in the
Footer component and replace the fourth parameter with an object like {
publicKey: import.meta.env.VITE_EMAILJS_PUBLIC_KEY } so the call becomes
emailjs.send(serviceID, templateID, templateParams, { publicKey:
import.meta.env.VITE_EMAILJS_PUBLIC_KEY }).

---

Nitpick comments:
In `@src/components/Footer.tsx`:
- Around line 28-35: Validate the EmailJS environment variables before calling
emailjs.send: check import.meta.env.VITE_EMAILJS_SERVICE_ID,
import.meta.env.VITE_EMAILJS_TEMPLATE_ID, and
import.meta.env.VITE_EMAILJS_PUBLIC_KEY for non-empty values (and the email
param) inside the Footer component or the function that invokes emailjs.send; if
any are missing, short-circuit and surface a clear error (e.g., throw or display
a user-friendly message/log via console.error or the component's error state)
instead of calling emailjs.send to avoid cryptic failures.
- Around line 17-43: The client-side handleSubscribe function currently calls
emailjs.send with exposed env keys (import.meta.env.VITE_EMAILJS_*) which risks
abuse; to fix, remove direct public key usage from the browser by moving
subscription handling to a backend endpoint (create a POST /subscribe handler)
that receives the email and a bot-proof token, verifies the token (e.g., verify
reCAPTCHA v3/enterprise server-side) and calls EmailJS (or sends the email) from
the server with rate limiting and logging; alternatively, if you must keep
client-side sending, integrate reCAPTCHA v3 in the handleSubscribe flow to
obtain a token and require server-side verification or add a hidden honeypot
input that handleSubscribe checks and aborts if filled, and implement rate
limiting/validation around the send logic (referencing handleSubscribe and
emailjs.send to locate where to change).
🪄 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: e0095902-cc6a-4b89-812e-e64e794761bd

📥 Commits

Reviewing files that changed from the base of the PR and between 6c6bc3e and 52a3d43.

📒 Files selected for processing (4)
  • .env.example
  • .gitignore
  • package.json
  • src/components/Footer.tsx

Comment thread .gitignore Outdated
Comment thread src/components/Footer.tsx
Comment thread src/components/Footer.tsx
@GkBuilds16
Copy link
Copy Markdown
Author

Addressed the review comments by updating the EmailJS v4 send configuration and cleaning up duplicate .env entries in .gitignore.

@GkBuilds16
Copy link
Copy Markdown
Author

Implemented the suggested UX improvements by replacing alert() with toast notifications, adding loading state handling, and updating the EmailJS v4 configuration.

@GkBuilds16
Copy link
Copy Markdown
Author

Please review the changes...

@mehul-m-prajapati
Copy link
Copy Markdown
Collaborator

not needed as of now

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.

Bug: Subscribe Feature Does Not Send Email Confirmation

2 participants