Skip to content

Commit

Permalink
Merge branch 'main' into add-newsletter-form
Browse files Browse the repository at this point in the history
  • Loading branch information
meghanakn473 authored Oct 26, 2024
2 parents d5e8550 + 5598b6f commit 8dc108c
Show file tree
Hide file tree
Showing 28 changed files with 373 additions and 210 deletions.
41 changes: 0 additions & 41 deletions .github/workflows/close-old-issue.yml

This file was deleted.

119 changes: 99 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,51 @@ The PlayCafe website communicates with a backend API to manage data. Here’s a
| GET | `/api/bookings/:id` | Retrieves details of a specific booking by ID. |
| DELETE | `/api/bookings/:id` | Cancels a specific booking by ID. |

## Troubleshooting

If you encounter issues while setting up or using the PlayCafe website, here are some common problems and solutions:

### 1. Issue: Unable to install dependencies
**Solution:** Make sure that you have Node.js installed. Run `npm install` again after confirming the Node.js installation.

### 2. Issue: Website not starting
**Solution:** Run `npm start` and ensure that the correct port is open. If the error persists, check for any error logs in the terminal and ensure no other applications are using the same port.

### 3. Issue: Database connection error
**Solution:** Verify that your database is running, and the connection details (host, username, password) are correct in the `.env` file.

### 4. Issue: CSS/JavaScript not loading properly
**Solution:** Check if all static assets are being served correctly. Ensure that the paths to your CSS and JS files are correct and that they are being compiled if you're using a build tool like Webpack or Gulp.

### 5. Issue: CORS (Cross-Origin Resource Sharing) error
**Solution:** Ensure the backend server has appropriate CORS policies configured to allow the frontend to communicate with it. If you're working with APIs, make sure that the necessary headers are included in server responses.

### 6. Issue: Environment variables not working
**Solution:** Double-check the `.env` file configuration. Ensure that all required variables are defined and that the file is correctly loaded by your server or build system.

### Debugging Tips
- Use `console.log` statements to track the flow of the code.
- Check browser developer tools for any front-end errors.
- Look into server logs for detailed error messages.
- **Use Logging Libraries:** Incorporate logging libraries like `winston` or `morgan` for better server-side error tracking.
- **Check Permissions:** If you're running the server on a remote machine, ensure that you have the necessary permissions (e.g., read/write access to necessary directories).
- **API Testing:** Use tools like Postman or Insomnia to test API endpoints individually if issues arise in data fetching.
- **Browser DevTools:** Use Chrome DevTools (F12) or Firefox Developer Tools (F12) for debugging.
- **React DevTools:** Install React Developer Tools browser extension for component debugging.
- **Network Tab:** Monitor API calls and responses in the Network tab.
- **Console Patterns:** Use `console.table()` for debugging arrays and objects.

### Resources
- [Node.js Documentation](https://nodejs.org/en/docs/)
- [Express.js Guide](https://expressjs.com/en/starter/installing.html)
- [Common npm errors](https://docs.npmjs.com/common-errors)
- [How to Debug JavaScript Errors](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/What_went_wrong)
- [Troubleshooting Common CORS Issues](https://www.codecademy.com/articles/what-is-cors)
- [Webpack Documentation](https://webpack.js.org/concepts/)
- [React DevTools Guide](https://react.dev/learn/react-developer-tools)
- [React Error Boundaries](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary)
- [React Performance Optimization](https://react.dev/learn/render-and-commit)


## 🤝 Contributing
We love contributions! 💙 Whether you're a participant in **GSSoC** or an open-source enthusiast, we welcome your input. Here's how you can contribute:
Expand Down Expand Up @@ -215,10 +260,17 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
</a>
</td>
<td align="center">
<a href="https://github.com/alo7lika">
<img src="https://avatars.githubusercontent.com/u/152315710?v=4" width="100;" alt="alo7lika"/>
<a href="https://github.com/jainaryan04">
<img src="https://avatars.githubusercontent.com/u/138214350?v=4" width="100;" alt="jainaryan04"/>
<br />
<sub><b>alolika bhowmik</b></sub>
<sub><b>Aryan Ramesh Jain</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/haseebzaki-07">
<img src="https://avatars.githubusercontent.com/u/147314463?v=4" width="100;" alt="haseebzaki-07"/>
<br />
<sub><b>Haseeb Zaki</b></sub>
</a>
</td>
<td align="center">
Expand All @@ -227,6 +279,15 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
<br />
<sub><b>Ashwini_ab</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center">
<a href="https://github.com/alo7lika">
<img src="https://avatars.githubusercontent.com/u/152315710?v=4" width="100;" alt="alo7lika"/>
<br />
<sub><b>alolika bhowmik</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/itznayan">
Expand All @@ -235,8 +296,6 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
<sub><b>Mahera Nayan</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center">
<a href="https://github.com/tejasbenibagde">
<img src="https://avatars.githubusercontent.com/u/124677750?v=4" width="100;" alt="tejasbenibagde"/>
Expand All @@ -251,13 +310,22 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
<sub><b>Tyarla Shirisha</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/VinayLodhi1712">
<img src="https://avatars.githubusercontent.com/u/135756009?v=4" width="100;" alt="VinayLodhi1712"/>
<br />
<sub><b>Vinay Anand Lodhi</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/Amnyadav">
<img src="https://avatars.githubusercontent.com/u/127370497?v=4" width="100;" alt="Amnyadav"/>
<br />
<sub><b>Aman Yadav</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center">
<a href="https://github.com/NilanchalaPanda">
<img src="https://avatars.githubusercontent.com/u/110488337?v=4" width="100;" alt="NilanchalaPanda"/>
Expand All @@ -266,21 +334,19 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
</a>
</td>
<td align="center">
<a href="https://github.com/haseebzaki-07">
<img src="https://avatars.githubusercontent.com/u/147314463?v=4" width="100;" alt="haseebzaki-07"/>
<a href="https://github.com/Sawan-Kushwah">
<img src="https://avatars.githubusercontent.com/u/138680328?v=4" width="100;" alt="Sawan-Kushwah"/>
<br />
<sub><b>Haseeb Zaki</b></sub>
<sub><b>Sawan kushwah </b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/Sawan-Kushwah">
<img src="https://avatars.githubusercontent.com/u/138680328?v=4" width="100;" alt="Sawan-Kushwah"/>
<a href="https://github.com/Sumanbhadra">
<img src="https://avatars.githubusercontent.com/u/93245252?v=4" width="100;" alt="Sumanbhadra"/>
<br />
<sub><b>Sawan kushwah </b></sub>
<sub><b>Suman Bhadra</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center">
<a href="https://github.com/Suhas-Koheda">
<img src="https://avatars.githubusercontent.com/u/72063139?v=4" width="100;" alt="Suhas-Koheda"/>
Expand All @@ -302,6 +368,9 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
<sub><b>Vishnu Prasad Korada</b></sub>
</a>
</td>

<tr>

<td align="center">
<a href="https://github.com/sajalbatra">
<img src="https://avatars.githubusercontent.com/u/125984550?v=4" width="100;" alt="sajalbatra"/>
Expand Down Expand Up @@ -332,13 +401,6 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
<sub><b>Navneet Dadhich</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/VinayLodhi1712">
<img src="https://avatars.githubusercontent.com/u/135756009?v=4" width="100;" alt="VinayLodhi1712"/>
<br />
<sub><b>Vinay Anand Lodhi</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/lade6501">
<img src="https://avatars.githubusercontent.com/u/83055827?v=4" width="100;" alt="lade6501"/>
Expand All @@ -353,6 +415,8 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
<sub><b>MD REHAN</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center">
<a href="https://github.com/T-Rahul-prabhu-38">
<img src="https://avatars.githubusercontent.com/u/167653990?v=4" width="100;" alt="T-Rahul-prabhu-38"/>
Expand All @@ -369,6 +433,13 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
</td>
</tr>
<tr>
<td align="center">
<a href="https://github.com/vaishnavipal1869">
<img src="https://avatars.githubusercontent.com/u/180996531?v=4" width="100;" alt="vaishnavipal1869"/>
<br />
<sub><b>vaishnavipal1869</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/tanishirai">
<img src="https://avatars.githubusercontent.com/u/178164785?v=4" width="100;" alt="tanishirai"/>
Expand All @@ -390,6 +461,8 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
<sub><b>Sourabh Singh Rawat</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center">
<a href="https://github.com/Shiva-Bajpai">
<img src="https://avatars.githubusercontent.com/u/141490705?v=4" width="100;" alt="Shiva-Bajpai"/>
Expand Down Expand Up @@ -420,6 +493,8 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
<sub><b>Ali Gates</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center">
<a href="https://github.com/chikatlarakesh">
<img src="https://avatars.githubusercontent.com/u/178009894?v=4" width="100;" alt="chikatlarakesh"/>
Expand Down Expand Up @@ -464,6 +539,8 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
<sub><b>Sapna Kul</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center">
<a href="https://github.com/stutxi">
<img src="https://avatars.githubusercontent.com/u/95741837?v=4" width="100;" alt="stutxi"/>
Expand All @@ -472,8 +549,10 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
</a>
</td>
<td align="center">

<a href="https://github.com/Syed-Farazuddin">
<img src="https://avatars.githubusercontent.com/u/119295880?v=4" width="100;" alt="Syed-Farazuddin"/>

<br />
<sub><b>Syed Faraz</b></sub>
</a>
Expand Down
61 changes: 47 additions & 14 deletions backend/controller/feedback.controller.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,87 @@
const { z } = require("zod");
const { Feedback } = require("../models/feedback.model");
const logger = require("../config/logger"); // Import your logger
const logger = require("../config/logger");
const nodemailer = require("nodemailer");


// Define the Zod schema for feedback validation
const feedbackSchema = z.object({
name: z.string().min(2).max(100),
email: z.string().email(),
feedback: z.string().min(10),
rating: z.number().min(1).max(5),
});


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

async function createFeedback(req, res) {
try {
const validationResult = feedbackSchema.safeParse(req.body);

if (!validationResult.success) {
logger.error("Validation error:", {
errors: validationResult.error.errors, // Log the detailed validation errors
body: req.body, // Optionally log the request body for context
}); // Use logger for validation errors
errors: validationResult.error.errors,
body: req.body,
});
return res.status(400).json({
success: false,
message: "Validation failed",
errors: validationResult.error.errors,
});
}


const feedback = await Feedback.create(validationResult.data);

await sendThankYouEmail(feedback);

res.status(201).json({
success: true,
message: "Feedback created successfully",
message: "Feedback created successfully and email sent",
data: feedback,
});
} catch (error) {
logger.error("Error creating feedback:", error); // Log the error using Winston
logger.error("Error creating feedback:", error);
res.status(500).json({
success: false,
message: "An error occurred while creating the feedback",
});
}
}


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);
}
}

module.exports = {
createFeedback,
};

// Dummy API call for feedback
// {
// "name": "John Doe",
// "email": "[email protected]",
// "feedback": "This is a dummy feedback"
// }
3 changes: 3 additions & 0 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Outlet } from 'react-router-dom';
import BackToTopButton from './components/Shared/BackToTopButton';
import Preloader from './components/Preloader';


function App() {
return (
<>
Expand All @@ -14,6 +15,8 @@ function App() {
<Navbar />
<Outlet />
<Footer />


</>
);
}
Expand Down
Loading

0 comments on commit 8dc108c

Please sign in to comment.