Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jainaryan04 authored Oct 22, 2024
2 parents 019537f + 047ec75 commit 0e34340
Show file tree
Hide file tree
Showing 12 changed files with 297 additions and 31 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,13 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
<sub><b>Vishnu Prasad Korada</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/Sumanbhadra">
<img src="https://avatars.githubusercontent.com/u/93245252?v=4" width="100;" alt="Sumanbhadra"/>
<br />
<sub><b>Suman Bhadra</b></sub>
</a>
</td>
<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
55 changes: 54 additions & 1 deletion backend/controller/event.controller.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const logger = require("../config/logger");
const Customer = require("../models/customer.model");
const Event = require("../models/events.model");

// Create a new event
Expand Down Expand Up @@ -67,4 +68,56 @@ const getEvents = async (req, res) => {
}
};

module.exports = { createEvent, getEvents, deleteEvent };

const bookEvent = async (req, res) => {
try {
const { customerId, eventId } = req.body;

const customer = await Customer.findById(customerId);
const event = await Event.findById(eventId);

if (!customer || !event) {
return res.status(404).json({ message: "Customer or Event not found" });
}

if (customer.bookedEvents.includes(eventId)) {
return res.status(400).json({ message: "Event already booked" });
}

customer.bookedEvents.push(eventId);
await customer.save();

event.bookedCustomers.push(customerId);
await event.save();

res.status(200).json({ message: "Event booked successfully!" });
} catch (error) {
logger.error("Error booking event:", error);
res.status(500).json({ message: "Server error" });
}
};

// Get all booked events for a customer
const getBookedEvents = async (req, res) => {
try {
const { customerId } = req.params;


const customer = await Customer.findById(customerId).populate("bookedEvents");

if (!customer) {
return res.status(404).json({ message: "Customer not found" });
}

res.status(200).json({ bookedEvents: customer.bookedEvents });
} catch (error) {
logger.error("Error fetching event:", error);
res.status(500).json({ message: "Server error" });
}
};

module.exports = {
getBookedEvents,
};

module.exports = { createEvent, getEvents, deleteEvent, bookEvent, getBookedEvents };
2 changes: 1 addition & 1 deletion backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require("dotenv").config();
const cors = require("cors");
const mongoose = require("mongoose");
const logger = require("./config/logger");
const errorMiddleware = require("./middlewares/errorMiddleware"); // Corrected typo
const errorMiddleware = require("./middlewares/errrorMiddleware"); // Corrected typo
const passport = require("passport");
const { handleGoogleOAuth } = require("./controller/googleOAuth.controller");
const app = express();
Expand Down
5 changes: 4 additions & 1 deletion backend/models/customer.model.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-useless-escape */
const mongoose = require("mongoose");
const Schema = mongoose.Schema;

Expand Down Expand Up @@ -27,6 +26,10 @@ const customerSchema = new Schema(
},
bio: String,
profilePicture: String,
bookedEvents: [{
type: Schema.Types.ObjectId,
ref: "Event", // Reference to the Event model
}],
},
{ timestamps: true },
);
Expand Down
10 changes: 5 additions & 5 deletions backend/models/events.model.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
/* eslint-disable no-unused-vars */
/* eslint-disable no-useless-escape */
// models/Event.js

const mongoose = require("mongoose");
const { string } = require("zod");

// Define the Event schema
const eventSchema = new mongoose.Schema({
Expand Down Expand Up @@ -41,7 +36,12 @@ const eventSchema = new mongoose.Schema({
message: (props) => `${props.value} is not a valid URL!`,
},
},
bookedCustomers: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'Customer' // Reference to the Customer model
}]
});

// Create the Event model
const Event = mongoose.model("Event", eventSchema);

Expand Down
11 changes: 10 additions & 1 deletion backend/routes/eventRouter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
// Add this at the top of eventRouter.js to check if it's being loaded correctly
console.log("eventRouter loaded");

const express = require("express");
const logger = require("../config/logger");
const {
createEvent,
getEvents,
deleteEvent,
bookEvent,
getBookedEvents,
} = require("../controller/event.controller");

const router = express.Router();
Expand All @@ -16,6 +21,8 @@ router.get("/", async (req, res) => {
endpoints: {
CreateEvent: "/event/create",
GetEvents: "/event/all",
bookEvents : "/event/book-events",
GetBookedEvents : "/event/get-booked-events/:customerId",
},
documentation: "https://api-docs-url.com",
});
Expand All @@ -26,6 +33,8 @@ router.get("/", async (req, res) => {
});
router.post("/create", createEvent);
router.get("/all", getEvents);
router.get("/delete", deleteEvent);
router.delete("/delete/:id", deleteEvent);
router.post("/book-events", bookEvent);
router.get("/get-booked-events/:customerId", getBookedEvents);

module.exports = router;
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@splidejs/react-splide": "^0.7.12",
"@splidejs/splide": "^4.1.4",
"@splidejs/splide-extension-auto-scroll": "^0.5.3",
"antd": "^5.21.2",
"antd": "^5.21.5",
"autoprefixer": "^10.4.19",
"axios": "^1.7.7",
"clsx": "^2.1.1",
Expand Down
116 changes: 116 additions & 0 deletions frontend/src/components/Pages/HelpAndSupport.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import React, { useState } from 'react';
import { MdKeyboardArrowDown } from 'react-icons/md';
import { IoMdCall, IoMdMail } from 'react-icons/io';

export default function HelpAndSupport() {
const FAqs = [
{
question: 'How to create an account?',
answer:
"To create an account, click on the 'Sign Up' button on the top right corner of the page. Fill in your details and click on 'Create Account'.",
},
{
question: 'How to reset password?',
answer:
"To reset your password, click on 'Forgot Password' on the login page. Enter your email address and follow the instructions sent to your email.",
},
{
question: 'What is Sip & Play?',
answer:
"Sip & Play is a board game cafe in Park Slope, Brooklyn. It's a place where you can come with friends and family to play board games, enjoy coffee, boba, sandwiches, and snacks.",
},
{
question: 'How does it work?',
answer:
"You can come in with your friends and family to play any board game from our library of 300+ games. There's no cover charge, just pay for your food and drinks.",
},
{
question: 'What kind of games do you have?',
answer:
'We have a wide variety of board games, including classics like Monopoly and Scrabble, as well as newer and more unique games.',
},
{
question: 'Can I bring my own food and drinks?',
answer:
'No, we do not allow outside food or drinks. We have a full menu of food and drinks available for purchase.',
},
{
question: 'Is there parking available?',
answer:
' There is limited street parking available near the cafe. You may also want to consider using public transportation.',
},
{
question: 'Is there a cover charge?',
answer:
'No, there is no cover charge. Just pay for your food and drinks.',
},
];

const [activeFAQ, setActiveFAQ] = useState(null);

const handleFAQClick = (index) => {
if (activeFAQ === index) {
setActiveFAQ(null);
} else {
setActiveFAQ(index);
}
};

return (
<>
<section className="w-full pt-10 md:pt-20 lg:pt-28">
<div className="container mx-auto space-y-10 xl:space-y-16">
<div className="flex flex-col items-center space-y-4 text-center">
<div className="space-y-2">
<h1 className="text-3xl font-bold tracking-tighter sm:text-4xl md:text-5xl lg:text-6xl">
Lost? Let's find your way.
</h1>
<p className="mx-auto max-w-[700px] text-muted-foreground md:text-xl">
Explore our FAQs, tutorials, and user guides to learn how to
make the most of our platform. If you can't find the answer
you're looking for, don't hesitate to contact our friendly
support team. We're always happy to help.
</p>
</div>
</div>
</div>
</section>

{/* FAQ section */}

<section className="pb-10">
<h1 className="my-4 text-3xl font-bold tracking-tighter text-center">
{' '}
Frequenty Asked Questions
</h1>
{FAqs.map((faq, index) => (
<div
key={index}
className="container mx-auto space-y-4 md:space-y-6 lg:space-y-8 mb-3"
>
<div className="flex flex-col items-center space-y-2 sm:w-full md:w-3/4 m-auto">
<div
className="flex items-center justify-between w-full rounded-lg pr-4 sm:text-lg md:text-xl lg:text-2xl bg-[#FDF3C7]"
onClick={() => {
handleFAQClick(index);
}}
>
<h1 className="font-bold tracking-tighter p-3">
{faq.question}
</h1>
<MdKeyboardArrowDown
className={`m1 ease-in-out duration-300 ${activeFAQ == index ? `rotate-180 ` : ``}`}
/>
</div>
<p
className={` mx-auto text-muted-foreground md:text-lg w-full p-2 ${activeFAQ == index ? `block` : `hidden`} `}
>
{faq.answer}
</p>
</div>
</div>
))}
</section>
</>
);
}
44 changes: 39 additions & 5 deletions frontend/src/components/Pages/Login.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React, { useState, useEffect } from 'react';
import photo from '../../assets/login.png';
import { Link, useNavigate } from 'react-router-dom';
import { message } from 'antd';
import { message } from 'antd'; // Ant Design message component
import Cookies from 'js-cookie';
import { FaEye } from 'react-icons/fa';
import { FaEyeSlash } from 'react-icons/fa6';

const Login = () => {
const API_URL = import.meta.env.VITE_BACKEND_URL || 'http://localhost:3000';
const [data, setData] = useState({
Expand All @@ -18,10 +17,19 @@ const Login = () => {

const navigate = useNavigate();

// Configuring the message to show at a certain top distance
message.config({
top: 80, // Distance from the top of the viewport
duration: 2, // Auto close time in seconds
maxCount: 3, // Max number of messages
});

// Function to handle changes in the form inputs
const handleChange = (e) => {
setData({ ...data, [e.target.name]: e.target.value });
};

// Function to handle form submission (login)
const handleSubmit = async (e) => {
e.preventDefault();
setIsLoading(true);
Expand All @@ -35,14 +43,40 @@ const Login = () => {
body: JSON.stringify(data),
});
const result = await response.json();

if (!response.ok) {
throw new Error(result.message || 'Login failed');
}

// Successful login message with a light green line below
message.success({
content: 'Login successful',
className: 'success-message', // Add custom class for styling
style: {
fontSize: '22px',
right: '50px', // Position it on the right side
position: 'fixed', // Fix it to the viewport
paddingTop: '10px', // Add padding to move the text down
paddingBottom: '10px', // Padding for balance
},
});
// Set token in cookies
Cookies.set('authToken', result.token, { expire: '1h', secure: true });
message.success('Login successful');
navigate('/');
navigate('/'); // Navigate to homepage after successful login
} catch (err) {
setError(err.message || 'An error occurred. Please try again.');
// Show error message if login fails with a red line below
message.error({
content: 'Something went wrong while logging in.',
className: 'error-message', // Add custom class for styling
style: {
fontSize: '18px',
right: '50px', // Position it on the right side
position: 'fixed', // Fix it to the viewport
paddingTop: '10px', // Add padding to move the text down
paddingBottom: '10px', // Padding for balance
},
});
setError('An error occurred. Please try again.');
} finally {
setIsLoading(false);
}
Expand Down
Loading

0 comments on commit 0e34340

Please sign in to comment.