diff --git a/frontend/src/components/ui/FeedbackForm.jsx b/frontend/src/components/ui/FeedbackForm.jsx index 0865750f..53823742 100644 --- a/frontend/src/components/ui/FeedbackForm.jsx +++ b/frontend/src/components/ui/FeedbackForm.jsx @@ -1,3 +1,4 @@ +/* eslint-disable prettier/prettier */ /* eslint-disable no-unused-vars */ import { useState } from 'react'; import { motion } from 'framer-motion'; @@ -15,33 +16,30 @@ const FeedbackForm = () => { hidden: { opacity: 0, y: 50 }, visible: { opacity: 1, y: 0, transition: { duration: 0.5 } }, }; - const API_URL = import.meta.env.VITE_BACKEND_URI || 'http://localhost:3000'; + + // Use an environment variable for backend URL + const API_URL = import.meta.env.VITE_BACKEND_URL || 'http://localhost:3000'; const [name, setName] = useState(''); const [email, setEmail] = useState(''); const [feedback, setFeedback] = useState(''); const [submitted, setSubmitted] = useState(false); - const [rating, setRating] = useState(null); - const [hover, setHover] = useState(null); - const [totalStars, setTotalStars] = useState(5); + const [totalStars] = useState(5); // No need to set this dynamically unless you plan to change it later const [error, setError] = useState(null); const [isLoading, setIsLoading] = useState(false); const handleSubmit = async (e) => { e.preventDefault(); - console.log( - `Name: ${name}, Email: ${email}, Feedback: ${feedback}, rating: ${rating}` - ); - setSubmitted(true); - setTimeout(() => { - setName(''); - setEmail(''); - setFeedback(''); - setRating(null); - setSubmitted(false); - }, 3000); + // Basic client-side validation for security + if (!name || !email || !feedback || !rating) { + setError('All fields are required, including the rating.'); + return; + } + + // Clear any previous errors + setError(null); setIsLoading(true); try { @@ -52,7 +50,15 @@ const FeedbackForm = () => { }, body: JSON.stringify({ name, email, feedback, rating }), }); - const data = await response.json(); + + // Check for JSON response + let data; + try { + data = await response.json(); + } catch (jsonError) { + throw new Error('Invalid response format.'); + } + if (!response.ok) { const errorMessage = data.message || 'An error occurred while submitting feedback.'; @@ -62,11 +68,11 @@ const FeedbackForm = () => { } setSubmitted(true); - setError(null); setTimeout(() => { setName(''); setEmail(''); setFeedback(''); + setRating(null); setSubmitted(false); }, 3000); } catch (error) { @@ -92,10 +98,9 @@ const FeedbackForm = () => { We value Your Feedback!

- Your thoughts help us improve. Share your experience and - suggestions with us! + Your thoughts help us improve. Share your experience and suggestions with us!

-
+
Chess {
- {/* */} { />
- {/* */} { />
- {/* */}