From 56f7052c61d95373d437c94fbd3fa6b572e56f61 Mon Sep 17 00:00:00 2001 From: PriyanshuValiya <147643182+PriyanshuValiya@users.noreply.github.com> Date: Tue, 22 Oct 2024 14:48:19 +0530 Subject: [PATCH 01/17] add feat/ContactUs-form branch --- backend/config/oauth.config.js | 2 +- backend/controller/contact.controller.js | 73 +++++++++ backend/index.js | 2 +- backend/routes/contactUsRouter.js | 7 + backend/routes/index.js | 60 +++---- frontend/package.json | 1 + frontend/src/components/Pages/ContactUs.jsx | 165 ++++++++++++++++++++ frontend/src/components/Shared/Navbar.jsx | 1 + frontend/src/router/index.jsx | 3 +- package-lock.json | 6 + 10 files changed, 281 insertions(+), 39 deletions(-) create mode 100644 backend/controller/contact.controller.js create mode 100644 backend/routes/contactUsRouter.js create mode 100644 frontend/src/components/Pages/ContactUs.jsx create mode 100644 package-lock.json diff --git a/backend/config/oauth.config.js b/backend/config/oauth.config.js index 919e5e50..f60e24cd 100644 --- a/backend/config/oauth.config.js +++ b/backend/config/oauth.config.js @@ -3,7 +3,7 @@ const GoogleStrategy = require("passport-google-oauth20").Strategy; const passport = require("passport"); const Customer = require("../models/customer.model"); // Adjust the path as needed const config = require("./secret"); // Import your secrets (client ID, client secret) -console.log("config", config); +// console.log("config", config); passport.use( new GoogleStrategy( { diff --git a/backend/controller/contact.controller.js b/backend/controller/contact.controller.js new file mode 100644 index 00000000..6cac8760 --- /dev/null +++ b/backend/controller/contact.controller.js @@ -0,0 +1,73 @@ +const { z } = require("zod"); +const nodemailer = require("nodemailer"); +require("dotenv").config(); + +// data require form .env file : EMAIL_USER, EMAIL_PASS + +// Define the Zod schema for contact form validation +const contactSchema = z.object({ + mail: z.string().email(), + subject: z.string().min(5, "Subject must be at least 5 characters long."), + message: z.string().min(5, "Message must be at least 5 characters long."), +}); + +const info = { messageId: "23DCS141" }; + +const createContactUs = async (req, res) => { + const validation = contactSchema.safeParse(req.body); + + if (!validation.success) { + console.log("Error at validation"); + return res.status(400).json({ + status: "error", + errors: "contactSchema is not validate", + }); + } + + const { mail, subject, message } = req.body; + + try { + const transporter = nodemailer.createTransport({ + service: "gmail", + host: "smtp.gmail.com", + port: 587, + secure: false, + auth: { + user: process.env.EMAIL_USER, + pass: process.env.EMAIL_PASS, + }, + tls: { + rejectUnauthorized: false, // Disable strict SSL verification + }, + }); + + const mailOptions = { + from: mail, + to: process.env.EMAIL_USER, + subject: subject, + text: message, + }; + + // Send mail with defined transport object + transporter.sendMail(mailOptions, (error, mailOptions) => { + if (error) { + return console.log("Error occurred: " + error.message); + } + + }); + + res.status(200).json({ + status: "success", + message: "Your contact request has been successfully received.", + }); + } catch (err) { + console.log(`Error at transport: ${err}`); + res.status(500).json({ + status: "error", + message: + "There was an error sending your message. Please try again later.", + }); + } +}; + +module.exports = { createContactUs }; diff --git a/backend/index.js b/backend/index.js index b8d9e76b..2d0c7f70 100644 --- a/backend/index.js +++ b/backend/index.js @@ -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("../backend/middlewares/errrorMiddleware"); // Corrected typo const passport = require("passport"); const { handleGoogleOAuth } = require("./controller/googleOAuth.controller"); const app = express(); diff --git a/backend/routes/contactUsRouter.js b/backend/routes/contactUsRouter.js new file mode 100644 index 00000000..9beea1e2 --- /dev/null +++ b/backend/routes/contactUsRouter.js @@ -0,0 +1,7 @@ +const express = require("express"); +const router = express.Router(); +const { createContactUs } = require("../controller/contact.controller"); // Correct controller path + +router.post("/contactus", createContactUs); + +module.exports = router; diff --git a/backend/routes/index.js b/backend/routes/index.js index 27a2b8bd..096551dd 100644 --- a/backend/routes/index.js +++ b/backend/routes/index.js @@ -1,39 +1,25 @@ const express = require("express"); -const logger = require("../config/logger"); // Import your Winston logger +const logger = require("../config/logger"); // Import Winston logger require("dotenv").config(); -const config = { - JWT_SECRET: process.env.JWT_SECRET, - GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID, - GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET, -}; - const router = express.Router(); -let feedbackRouter; - -try { - feedbackRouter = require("./feedbackRouter"); -} catch (error) { - logger.error("Error loading feedbackRouter:", error); // Log the error with Winston - feedbackRouter = (req, res) => { - res - .status(500) - .json({ error: "Feedback functionality is currently unavailable" }); - }; -} +// Utility function to safely load modules and handle errors +const safeRequire = (modulePath, fallbackMessage) => { + try { + return require(modulePath); + } catch (error) { + logger.error(`Error loading ${modulePath}:`, error); + return (req, res) => { + res.status(500).json({ error: fallbackMessage }); + }; + } +}; -let eventRouter; -try { - eventRouter = require("./eventRouter"); -} catch (error) { - logger.error("Error loading eventRouter:", error); // Log the error with Winston - eventRouter = (req, res) => { - res - .status(500) - .json({ error: "Event functionality is currently unavailable" }); - }; -} +// Safely load routers with error handling +const feedbackRouter = safeRequire("./feedbackRouter", "Feedback functionality is currently unavailable"); +const contactUsRouter = safeRequire("./contactUsRouter", "Contact Us functionality is currently unavailable"); +const eventRouter = safeRequire("./eventRouter", "Event functionality is currently unavailable"); router.get("/", (req, res) => { return res.json({ @@ -41,17 +27,19 @@ router.get("/", (req, res) => { version: "1.0.0", endpoints: { Reservation: "/reservation", - Feedback: "/feedback", // Added feedback endpoint documentation + Feedback: "/feedback", }, documentation: "https://api-docs-url.com", }); }); router.use("/event", eventRouter); -router.use("/admin", require("./adminRouter")); +router.use("/admin", safeRequire("./adminRouter", "Admin functionality is currently unavailable")); router.use("/feedback", feedbackRouter); -router.use("/user", require("./customerRouter")); -router.use("/reservation", require("./reservationRouter")); -router.use("/newsletter", require("./newsletterRoute")); -router.use("/forgot", require("./forgotRouter")); +router.use("/user", safeRequire("./customerRouter", "User functionality is currently unavailable")); +router.use("/reservation", safeRequire("./reservationRouter", "Reservation functionality is currently unavailable")); +router.use("/newsletter", safeRequire("./newsletterRoute", "Newsletter functionality is currently unavailable")); +router.use("/forgot", safeRequire("./forgotRouter", "Forgot password functionality is currently unavailable")); +router.use("/contact", contactUsRouter); + module.exports = router; diff --git a/frontend/package.json b/frontend/package.json index 30175db5..6c4b4576 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -24,6 +24,7 @@ "framer-motion": "^11.5.6", "gsap": "^3.12.5", "js-cookie": "^3.0.5", + "lucide-react": "^0.453.0", "react": "^18.3.1", "react-dom": "^18.3.1", "react-icons": "^5.2.1", diff --git a/frontend/src/components/Pages/ContactUs.jsx b/frontend/src/components/Pages/ContactUs.jsx new file mode 100644 index 00000000..1e34397b --- /dev/null +++ b/frontend/src/components/Pages/ContactUs.jsx @@ -0,0 +1,165 @@ +/* eslint-disable prettier/prettier */ +/* eslint-disable no-unused-vars */ +import { useState } from 'react'; +import { motion } from 'framer-motion'; +import { useInView } from 'react-intersection-observer'; +import chess from '../../assets/img/chess.gif'; +import { FaStar } from 'react-icons/fa6'; + +const ContactUs = () => { + const { ref, inView } = useInView({ + threshold: 0.2, + triggerOnce: true, + }); + + const animationVariants = { + hidden: { opacity: 0, y: 50 }, + visible: { opacity: 1, y: 0, transition: { duration: 0.5 } }, + }; + + // Use an environment variable for backend URL + const API_URL = import.meta.env.VITE_BACKEND_URL || 'http://localhost:3000'; + const [mail, setMail] = useState(''); + const [subject, setSubject] = useState(''); + const [message, setMessage] = useState(''); + const [submitted, setSubmitted] = useState(false); + const [hover, setHover] = useState(null); + const [error, setError] = useState(null); + const [isLoading, setIsLoading] = useState(false); + + const handleSubmit = async (e) => { + e.preventDefault(); + + // Basic client-side validation for security + if (!mail || !subject || !message) { + setError('All fields are required, including the rating.'); + return; + } + + // Clear any previous errors + setError(null); + + setIsLoading(true); + try { + const response = await fetch(`${API_URL}/api/contact/contactus`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ mail, subject, message }), + }); + + setSubmitted(true); + setTimeout(() => { + setMail(''); + setSubject(''); + setMessage(''); + setSubmitted(false); + }, 3000); + } catch (error) { + setError('An error occurred while sending Mail...'); + console.error('Mail sending failed : ', error); + } finally { + setIsLoading(false); + } + }; + + return ( +
+
+ +
+

+ Feel Free To Mail Us.. +

+

+ Have questions or need assistance ? Reach out to us, and we'll be + happy to help !! +

+
+ Chess +
+
+ +
+
+
+ setMail(e.target.value)} + required + className="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-[#004D43] focus:border-[#004D43]" + /> +
+
+ setSubject(e.target.value)} + required + className="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-[#004D43] focus:border-[#004D43]" + /> +
+
+ +
+
+ +
+
+ {submitted && ( + + Thank you, We will reply you soon... + + )} + {error && ( + + {error} + + )} +
+
+
+
+ ); +}; + +export default ContactUs; diff --git a/frontend/src/components/Shared/Navbar.jsx b/frontend/src/components/Shared/Navbar.jsx index 560478d2..609f742b 100644 --- a/frontend/src/components/Shared/Navbar.jsx +++ b/frontend/src/components/Shared/Navbar.jsx @@ -19,6 +19,7 @@ const Navbar = () => { { name: 'RESERVATION', path: '/reservation' }, { name: 'BOARDGAMES', path: '/boardgame' }, { name: 'MEMBERSHIP', path: '/membership' }, // Add Membership here + { name: 'CONTACTUS', path: '/contactus'} ]; useEffect(() => { diff --git a/frontend/src/router/index.jsx b/frontend/src/router/index.jsx index a14a06db..5233b77b 100644 --- a/frontend/src/router/index.jsx +++ b/frontend/src/router/index.jsx @@ -21,6 +21,7 @@ import Admin from '../components/Pages/Admin'; import VerifyOtp from '../components/Pages/VerifyOtp'; import EmailVerify from '../components/Pages/EmailVerify'; import Membership from '../components/Membership'; +import ContactUs from '../components/Pages/ContactUs'; const router = createBrowserRouter( createRoutesFromElements( }> @@ -39,7 +40,7 @@ const router = createBrowserRouter( } /> } /> } /> - + } /> ) ); diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..a0c27c60 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "PlayCafe", + "lockfileVersion": 3, + "requires": true, + "packages": {} +} From a03eecc0d52de03d1cc28fb173eb1b1813b86b4e Mon Sep 17 00:00:00 2001 From: PriyanshuValiya <147643182+PriyanshuValiya@users.noreply.github.com> Date: Tue, 22 Oct 2024 15:03:18 +0530 Subject: [PATCH 02/17] Update index.js --- backend/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/index.js b/backend/index.js index 2d0c7f70..223647fa 100644 --- a/backend/index.js +++ b/backend/index.js @@ -3,7 +3,7 @@ require("dotenv").config(); const cors = require("cors"); const mongoose = require("mongoose"); const logger = require("./config/logger"); -const errorMiddleware = require("../backend/middlewares/errrorMiddleware"); // Corrected typo +const errorMiddleware = require("../backend/middlewares/errorMiddleware"); // Corrected typo const passport = require("passport"); const { handleGoogleOAuth } = require("./controller/googleOAuth.controller"); const app = express(); From cfc2fa8a3a7e1a5a1ba1fa5c004a3a9aa5bf3354 Mon Sep 17 00:00:00 2001 From: PriyanshuValiya <147643182+PriyanshuValiya@users.noreply.github.com> Date: Tue, 22 Oct 2024 15:04:07 +0530 Subject: [PATCH 03/17] Update oauth.config.js --- backend/config/oauth.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/config/oauth.config.js b/backend/config/oauth.config.js index f60e24cd..919e5e50 100644 --- a/backend/config/oauth.config.js +++ b/backend/config/oauth.config.js @@ -3,7 +3,7 @@ const GoogleStrategy = require("passport-google-oauth20").Strategy; const passport = require("passport"); const Customer = require("../models/customer.model"); // Adjust the path as needed const config = require("./secret"); // Import your secrets (client ID, client secret) -// console.log("config", config); +console.log("config", config); passport.use( new GoogleStrategy( { From cc084c0d8d5c941d06e3b993fa37860b1038f56c Mon Sep 17 00:00:00 2001 From: PriyanshuValiya <147643182+PriyanshuValiya@users.noreply.github.com> Date: Tue, 22 Oct 2024 15:07:59 +0530 Subject: [PATCH 04/17] Update contact.controller.js --- backend/controller/contact.controller.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/backend/controller/contact.controller.js b/backend/controller/contact.controller.js index 6cac8760..4d6872b4 100644 --- a/backend/controller/contact.controller.js +++ b/backend/controller/contact.controller.js @@ -2,8 +2,6 @@ const { z } = require("zod"); const nodemailer = require("nodemailer"); require("dotenv").config(); -// data require form .env file : EMAIL_USER, EMAIL_PASS - // Define the Zod schema for contact form validation const contactSchema = z.object({ mail: z.string().email(), @@ -11,8 +9,6 @@ const contactSchema = z.object({ message: z.string().min(5, "Message must be at least 5 characters long."), }); -const info = { messageId: "23DCS141" }; - const createContactUs = async (req, res) => { const validation = contactSchema.safeParse(req.body); From 6a933b9f8929fe64cf4a8621c455cb472454f159 Mon Sep 17 00:00:00 2001 From: PriyanshuValiya <147643182+PriyanshuValiya@users.noreply.github.com> Date: Tue, 22 Oct 2024 15:11:30 +0530 Subject: [PATCH 05/17] Update contact.controller.js --- backend/controller/contact.controller.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/controller/contact.controller.js b/backend/controller/contact.controller.js index 4d6872b4..8a228880 100644 --- a/backend/controller/contact.controller.js +++ b/backend/controller/contact.controller.js @@ -13,7 +13,7 @@ const createContactUs = async (req, res) => { const validation = contactSchema.safeParse(req.body); if (!validation.success) { - console.log("Error at validation"); + console.error("Error at validation"); return res.status(400).json({ status: "error", errors: "contactSchema is not validate", @@ -47,7 +47,7 @@ const createContactUs = async (req, res) => { // Send mail with defined transport object transporter.sendMail(mailOptions, (error, mailOptions) => { if (error) { - return console.log("Error occurred: " + error.message); + return console.error("Error occurred: " + error.message); } }); @@ -57,7 +57,7 @@ const createContactUs = async (req, res) => { message: "Your contact request has been successfully received.", }); } catch (err) { - console.log(`Error at transport: ${err}`); + console.error(`Error at transport: ${err}`); res.status(500).json({ status: "error", message: From 012d5aeee34ea1c1a18ae4e5b2dde69bb562c257 Mon Sep 17 00:00:00 2001 From: PriyanshuValiya <147643182+PriyanshuValiya@users.noreply.github.com> Date: Tue, 22 Oct 2024 15:12:38 +0530 Subject: [PATCH 06/17] Update contact.controller.js --- backend/controller/contact.controller.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/controller/contact.controller.js b/backend/controller/contact.controller.js index 8a228880..c99045fe 100644 --- a/backend/controller/contact.controller.js +++ b/backend/controller/contact.controller.js @@ -32,9 +32,10 @@ const createContactUs = async (req, res) => { user: process.env.EMAIL_USER, pass: process.env.EMAIL_PASS, }, - tls: { - rejectUnauthorized: false, // Disable strict SSL verification - }, + // Uncomment this if needed + // tls: { + // rejectUnauthorized: false, // Disable strict SSL verification + // }, }); const mailOptions = { From a760726eddb2e921ab03506a60ce6489c27fdfbc Mon Sep 17 00:00:00 2001 From: PriyanshuValiya <147643182+PriyanshuValiya@users.noreply.github.com> Date: Tue, 22 Oct 2024 15:15:05 +0530 Subject: [PATCH 07/17] Update ContactUs.jsx --- frontend/src/components/Pages/ContactUs.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/Pages/ContactUs.jsx b/frontend/src/components/Pages/ContactUs.jsx index 1e34397b..5701c1af 100644 --- a/frontend/src/components/Pages/ContactUs.jsx +++ b/frontend/src/components/Pages/ContactUs.jsx @@ -96,7 +96,7 @@ const ContactUs = () => {
Date: Tue, 22 Oct 2024 15:16:15 +0530 Subject: [PATCH 08/17] Update ContactUs.jsx --- frontend/src/components/Pages/ContactUs.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/Pages/ContactUs.jsx b/frontend/src/components/Pages/ContactUs.jsx index 5701c1af..e5b43954 100644 --- a/frontend/src/components/Pages/ContactUs.jsx +++ b/frontend/src/components/Pages/ContactUs.jsx @@ -32,7 +32,7 @@ const ContactUs = () => { // Basic client-side validation for security if (!mail || !subject || !message) { - setError('All fields are required, including the rating.'); + setError('All fields are required.'); return; } From 58fcfba1056b69dbbbacae9e0670c9b8bb3c2819 Mon Sep 17 00:00:00 2001 From: PriyanshuValiya <147643182+PriyanshuValiya@users.noreply.github.com> Date: Tue, 22 Oct 2024 15:17:13 +0530 Subject: [PATCH 09/17] Update ContactUs.jsx --- frontend/src/components/Pages/ContactUs.jsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frontend/src/components/Pages/ContactUs.jsx b/frontend/src/components/Pages/ContactUs.jsx index e5b43954..a62c8a5c 100644 --- a/frontend/src/components/Pages/ContactUs.jsx +++ b/frontend/src/components/Pages/ContactUs.jsx @@ -49,6 +49,10 @@ const ContactUs = () => { body: JSON.stringify({ mail, subject, message }), }); + if (!response.ok) { ++ throw new Error('Network response was not ok'); ++ } + setSubmitted(true); setTimeout(() => { setMail(''); From 90e0fa0739ea28d8e86363dfe149362a0def0ce5 Mon Sep 17 00:00:00 2001 From: PriyanshuValiya <147643182+PriyanshuValiya@users.noreply.github.com> Date: Tue, 22 Oct 2024 15:19:31 +0530 Subject: [PATCH 10/17] Update contact.controller.js --- backend/controller/contact.controller.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/controller/contact.controller.js b/backend/controller/contact.controller.js index c99045fe..2be4334a 100644 --- a/backend/controller/contact.controller.js +++ b/backend/controller/contact.controller.js @@ -39,7 +39,9 @@ const createContactUs = async (req, res) => { }); const mailOptions = { - from: mail, + // from: mail, + from: process.env.EMAIL_USER, ++ replyTo: mail, to: process.env.EMAIL_USER, subject: subject, text: message, From c9bf8af219d1a8e31e1bf9b5409bc83366c9fb1e Mon Sep 17 00:00:00 2001 From: PriyanshuValiya <147643182+PriyanshuValiya@users.noreply.github.com> Date: Thu, 24 Oct 2024 17:00:01 +0530 Subject: [PATCH 11/17] Update contact.controller.js --- backend/controller/contact.controller.js | 27 ++++++++++++++---------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/backend/controller/contact.controller.js b/backend/controller/contact.controller.js index 2be4334a..c1636909 100644 --- a/backend/controller/contact.controller.js +++ b/backend/controller/contact.controller.js @@ -47,18 +47,23 @@ const createContactUs = async (req, res) => { text: message, }; - // Send mail with defined transport object - transporter.sendMail(mailOptions, (error, mailOptions) => { - if (error) { - return console.error("Error occurred: " + error.message); - } + // Send mail with defined transport object + + + await new Promise((resolve, reject) => { ++ transporter.sendMail(mailOptions, (error, info) => { ++ if (error) { ++ console.error("Error occurred: " + error.message); ++ reject(error); ++ } ++ resolve(info); ++ }); ++ }); ++ ++ res.status(200).json({ ++ status: "success", ++ message: "Your contact request has been successfully received.", ++ }); - }); - - res.status(200).json({ - status: "success", - message: "Your contact request has been successfully received.", - }); } catch (err) { console.error(`Error at transport: ${err}`); res.status(500).json({ From 429c94e1a52ac32bd29c1bb8514be8f84f27d00c Mon Sep 17 00:00:00 2001 From: PriyanshuValiya <147643182+PriyanshuValiya@users.noreply.github.com> Date: Thu, 24 Oct 2024 17:01:03 +0530 Subject: [PATCH 12/17] Update ContactUs.jsx --- frontend/src/components/Pages/ContactUs.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/src/components/Pages/ContactUs.jsx b/frontend/src/components/Pages/ContactUs.jsx index a62c8a5c..2364d727 100644 --- a/frontend/src/components/Pages/ContactUs.jsx +++ b/frontend/src/components/Pages/ContactUs.jsx @@ -4,7 +4,6 @@ import { useState } from 'react'; import { motion } from 'framer-motion'; import { useInView } from 'react-intersection-observer'; import chess from '../../assets/img/chess.gif'; -import { FaStar } from 'react-icons/fa6'; const ContactUs = () => { const { ref, inView } = useInView({ From c472329c46707949fdd45d59fc601635731646ee Mon Sep 17 00:00:00 2001 From: PriyanshuValiya <147643182+PriyanshuValiya@users.noreply.github.com> Date: Thu, 24 Oct 2024 17:01:38 +0530 Subject: [PATCH 13/17] Update ContactUs.jsx --- frontend/src/components/Pages/ContactUs.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/src/components/Pages/ContactUs.jsx b/frontend/src/components/Pages/ContactUs.jsx index 2364d727..82583334 100644 --- a/frontend/src/components/Pages/ContactUs.jsx +++ b/frontend/src/components/Pages/ContactUs.jsx @@ -22,7 +22,6 @@ const ContactUs = () => { const [subject, setSubject] = useState(''); const [message, setMessage] = useState(''); const [submitted, setSubmitted] = useState(false); - const [hover, setHover] = useState(null); const [error, setError] = useState(null); const [isLoading, setIsLoading] = useState(false); From ff1422f1a545969dde868ee5850626205774888a Mon Sep 17 00:00:00 2001 From: PriyanshuValiya <147643182+PriyanshuValiya@users.noreply.github.com> Date: Thu, 24 Oct 2024 17:03:33 +0530 Subject: [PATCH 14/17] Update ContactUs.jsx --- frontend/src/components/Pages/ContactUs.jsx | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/Pages/ContactUs.jsx b/frontend/src/components/Pages/ContactUs.jsx index 82583334..14b2be41 100644 --- a/frontend/src/components/Pages/ContactUs.jsx +++ b/frontend/src/components/Pages/ContactUs.jsx @@ -29,10 +29,23 @@ const ContactUs = () => { e.preventDefault(); // Basic client-side validation for security - if (!mail || !subject || !message) { - setError('All fields are required.'); - return; - } + + const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; ++ if (!mail || !subject || !message) { ++ setError('All fields are required.'); ++ return; ++ } ++ if (!emailRegex.test(mail)) { ++ setError('Please enter a valid email address.'); ++ return; ++ } ++ if (subject.length > 100) { ++ setError('Subject must be less than 100 characters.'); ++ return; ++ } ++ if (message.length > 1000) { ++ setError('Message must be less than 1000 characters.'); ++ return; ++ } // Clear any previous errors setError(null); From 8cebaec694699cb3602eab49d8e31b8619f00204 Mon Sep 17 00:00:00 2001 From: PriyanshuValiya <147643182+PriyanshuValiya@users.noreply.github.com> Date: Thu, 24 Oct 2024 17:15:20 +0530 Subject: [PATCH 15/17] Update ContactUs.jsx --- frontend/src/components/Pages/ContactUs.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/Pages/ContactUs.jsx b/frontend/src/components/Pages/ContactUs.jsx index 14b2be41..57745cf5 100644 --- a/frontend/src/components/Pages/ContactUs.jsx +++ b/frontend/src/components/Pages/ContactUs.jsx @@ -61,7 +61,7 @@ const ContactUs = () => { }); if (!response.ok) { -+ throw new Error('Network response was not ok'); ++ throw new Error(`Network response was not ok: ${response.status}`); + } setSubmitted(true); From bb5409f1d85293cdbaecd8246adb76b877473c33 Mon Sep 17 00:00:00 2001 From: PriyanshuValiya <147643182+PriyanshuValiya@users.noreply.github.com> Date: Thu, 24 Oct 2024 17:16:30 +0530 Subject: [PATCH 16/17] Update ContactUs.jsx --- frontend/src/components/Pages/ContactUs.jsx | 24 +++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/frontend/src/components/Pages/ContactUs.jsx b/frontend/src/components/Pages/ContactUs.jsx index 57745cf5..5a943ded 100644 --- a/frontend/src/components/Pages/ContactUs.jsx +++ b/frontend/src/components/Pages/ContactUs.jsx @@ -109,17 +109,19 @@ const ContactUs = () => {
-
- setMail(e.target.value)} - required - className="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-[#004D43] focus:border-[#004D43]" - /> -
+
++ + setMail(e.target.value)} + required + className="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-[#004D43] focus:border-[#004D43]" + /> +
Date: Thu, 24 Oct 2024 17:17:57 +0530 Subject: [PATCH 17/17] Update ContactUs.jsx --- frontend/src/components/Pages/ContactUs.jsx | 24 ++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/frontend/src/components/Pages/ContactUs.jsx b/frontend/src/components/Pages/ContactUs.jsx index 5a943ded..5866f466 100644 --- a/frontend/src/components/Pages/ContactUs.jsx +++ b/frontend/src/components/Pages/ContactUs.jsx @@ -52,18 +52,18 @@ const ContactUs = () => { setIsLoading(true); try { - const response = await fetch(`${API_URL}/api/contact/contactus`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ mail, subject, message }), - }); - - if (!response.ok) { -+ throw new Error(`Network response was not ok: ${response.status}`); -+ } - + const response = await fetch(`${API_URL}/api/contact/contactus`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ mail, subject, message }), + }); ++ if (!response.ok) { ++ throw new Error('Network response was not ok'); ++ } + setSubmitted(true); + } setSubmitted(true); setTimeout(() => { setMail('');