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

Add feedback mail #390

Merged

Conversation

haseebzaki-07
Copy link
Contributor

@haseebzaki-07 haseebzaki-07 commented Oct 23, 2024

fixes #362

This PR adds mail service for the users submitting feedback to the website.

Screenshot 2024-10-23 232437
Screenshot 2024-10-23 232614
WhatsApp Image 2024-10-23 at 11 30 31 PM

Summary by CodeRabbit

  • New Features

    • Integrated a thank-you email notification after feedback submission.
  • Bug Fixes

    • Improved consistency of class names in the Event component for better styling.

These updates enhance user experience by confirming feedback submission and maintaining a polished interface.

Copy link

vercel bot commented Oct 23, 2024

@haseebzaki-07 is attempting to deploy a commit to the bunty's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Oct 23, 2024

Walkthrough

The changes in this pull request primarily enhance the feedback submission process by integrating a thank-you email notification feature. The feedback.controller.js file has been updated to include a new function, sendThankYouEmail, which utilizes the nodemailer package to send emails. The createFeedback function has been modified to call this new function upon successful feedback creation. Additionally, minor formatting adjustments were made in the Event.jsx component, focusing on class name consistency without altering functionality.

Changes

File Path Change Summary
backend/controller/feedback.controller.js Added sendThankYouEmail(feedback) method; updated createFeedback(req, res) to include email sending.
frontend/src/components/Pages/Event.jsx Minor adjustments to class names in JSX structure for consistency.

Assessment against linked issues

Objective Addressed Explanation
User feedback should receive a confirmation message (362)
Feedback should reflect in the database for users (362)

Possibly related PRs

  • Created Feedback Submission System  #65: This PR introduces the createFeedback function in the same feedback.controller.js file, which is directly related to the modifications made in the main PR that also updates the createFeedback function to include email sending functionality.
  • Email is sent on successful reservation  #121: This PR implements email sending functionality in the context of reservations, which is similar to the email notification feature added in the main PR for feedback submissions.
  • Newsletter saved to db and a thank you mail is sent to email #174: This PR also involves sending a thank-you email upon a successful action (newsletter subscription), paralleling the thank-you email feature introduced in the main PR for feedback creation.

Suggested labels

enhancement, level3, gssoc-ext, hacktoberfest accepted

🐰 "In the meadow where feedback flows,
A thank-you email now brightly glows.
With nodemailer, joy takes flight,
Each message sent brings pure delight!
Hopping through code with a happy cheer,
Thank you for the feedback, my dear!" 🐇


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

Copy link
Contributor

Thank you for submitting your pull request! 🙌 We'll review it as soon as possible. In the meantime, please ensure that your changes align with our CONTRIBUTING.md. If there are any specific instructions or feedback regarding your PR, we'll provide them here. Thanks again for your contribution! 😊

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

🧹 Outside diff range and nitpick comments (1)
backend/controller/feedback.controller.js (1)

15-21: Consider using a dedicated email service provider instead of Gmail.

Gmail's SMTP service has limitations for production use:

  • Daily sending limits
  • Potential blocking of automated emails
  • Requires "Less secure app access" which is not recommended

Consider using dedicated email services like SendGrid, Amazon SES, or Mailgun which offer:

  • Higher sending limits
  • Better deliverability
  • Proper API authentication
  • Production-grade reliability
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5627c2f and cc94f55.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • backend/controller/feedback.controller.js (1 hunks)
  • frontend/src/components/Pages/Event.jsx (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • frontend/src/components/Pages/Event.jsx
🧰 Additional context used
🔇 Additional comments (1)
backend/controller/feedback.controller.js (1)

15-21: Add explicit TLS configuration for email security.

The current email transport configuration lacks explicit TLS settings.
[security]
Add secure transport configuration:

 const transporter = nodemailer.createTransport({
   service: "gmail", 
   auth: {
     user: process.env.EMAIL_USER, 
     pass: process.env.EMAIL_PASS, 
   },
+  secure: true,
+  tls: {
+    rejectUnauthorized: true
+  }
 });

Comment on lines +42 to +46
await sendThankYouEmail(feedback);

res.status(201).json({
success: true,
message: "Feedback created successfully",
message: "Feedback created successfully and email sent",
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Improve error handling for the email sending process.

The feedback is considered successful even if the email fails to send. This could lead to inconsistent user experience.

Consider this improved implementation:

-    await sendThankYouEmail(feedback);
+    try {
+      await sendThankYouEmail(feedback);
+    } catch (error) {
+      logger.error("Failed to send thank you email:", {
+        feedbackId: feedback._id,
+        error: error.message
+      });
+      return res.status(201).json({
+        success: true,
+        message: "Feedback created successfully but failed to send email",
+        data: feedback,
+      });
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
await sendThankYouEmail(feedback);
res.status(201).json({
success: true,
message: "Feedback created successfully",
message: "Feedback created successfully and email sent",
try {
await sendThankYouEmail(feedback);
} catch (error) {
logger.error("Failed to send thank you email:", {
feedbackId: feedback._id,
error: error.message
});
return res.status(201).json({
success: true,
message: "Feedback created successfully but failed to send email",
data: feedback,
});
}
res.status(201).json({
success: true,
message: "Feedback created successfully and email sent",

Comment on lines +59 to +83
async function sendThankYouEmail(feedback) {
const mailOptions = {
from: process.env.EMAIL_USER, // Sender email
to: feedback.email, // Receiver email
subject: "Thank you for your feedback!",
text: `Hi ${feedback.name},

Thank you for your valuable feedback. Here are the details:

- Feedback: ${feedback.feedback}
- Rating: ${feedback.rating}/5

We appreciate you taking the time to share your thoughts with us!

Best regards,
Play Cafe`,
};

try {
await transporter.sendMail(mailOptions);
logger.info(`Thank-you email sent to ${feedback.email}`);
} catch (error) {
logger.error("Error sending email:", error);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance email template management and format.

The current implementation has several areas for improvement:

  1. Hardcoded email template
  2. Missing HTML version
  3. Silent error handling

Consider these improvements:

 async function sendThankYouEmail(feedback) {
+  const htmlContent = `
+    <h2>Thank you for your feedback!</h2>
+    <p>Hi ${feedback.name},</p>
+    <p>Thank you for your valuable feedback. Here are the details:</p>
+    <ul>
+      <li>Feedback: ${feedback.feedback}</li>
+      <li>Rating: ${feedback.rating}/5</li>
+    </ul>
+    <p>We appreciate you taking the time to share your thoughts with us!</p>
+    <p>Best regards,<br>Play Cafe</p>
+  `;
+
   const mailOptions = {
     from: process.env.EMAIL_USER,
     to: feedback.email,
     subject: "Thank you for your feedback!",
     text: `Hi ${feedback.name},\n\nThank you...`, // Keep plain text version
+    html: htmlContent,
   };

   try {
     await transporter.sendMail(mailOptions);
     logger.info(`Thank-you email sent to ${feedback.email}`);
   } catch (error) {
-    logger.error("Error sending email:", error);
+    logger.error("Failed to send thank you email:", {
+      feedbackId: feedback._id,
+      email: feedback.email,
+      error: error.message
+    });
+    throw error; // Propagate error to handle it in createFeedback
   }
 }

Additionally, consider moving the email template to a separate file or using a template engine for better maintainability.

Committable suggestion was skipped due to low confidence.

Comment on lines +18 to +19
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS,
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Environment variables need documentation and example configuration

The verification reveals that while EMAIL_USER and EMAIL_PASS are consistently used across the codebase (in feedback.controller.js and nodemailer.js), there is no documentation or example configuration file (.env.example, .env.template, etc.) to guide developers on setting up these required environment variables.

Action items needed:

  • Create a .env.example file documenting these required environment variables
  • Add setup instructions in the README.md for configuring email credentials
  • Consider documenting the expected format/requirements for these credentials (e.g., if using specific email providers)
🔗 Analysis chain

Verify environment variable configuration.

Ensure that the required environment variables are properly documented and configured:

  • EMAIL_USER
  • EMAIL_PASS

Let me try a different approach to verify the environment variables configuration by searching through the entire codebase for any documentation or template files.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if environment variables are documented
echo "Checking for environment variables documentation..."
rg -l "EMAIL_USER|EMAIL_PASS" "README*" ".env*"

Length of output: 256


Script:

#!/bin/bash
# Search for environment variable documentation in common config and docs locations
echo "Searching for environment variables documentation..."
fd -t f ".(env|example|sample|template|md|txt)$" -X rg -l "EMAIL_USER|EMAIL_PASS"

# Search for actual usage of these environment variables
echo -e "\nSearching for environment variable usage..."
rg "process\.env\.(EMAIL_USER|EMAIL_PASS)"

Length of output: 913

@RamakrushnaBiswal RamakrushnaBiswal merged commit abe91c3 into RamakrushnaBiswal:main Oct 24, 2024
4 of 5 checks passed
@RamakrushnaBiswal RamakrushnaBiswal added enhancement New feature or request level2 for 25 points gssoc-ext gssoc-extd program hacktoberfest accepted hacktoberfest-accepted repo labels Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request gssoc-ext gssoc-extd program hacktoberfest accepted hacktoberfest-accepted repo level2 for 25 points
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feat: Backend for feedback
2 participants