diff --git a/client/src/components/Testimonial-Section.js b/client/src/components/Testimonial-Section.js index 7e966ae..0c86f8f 100644 --- a/client/src/components/Testimonial-Section.js +++ b/client/src/components/Testimonial-Section.js @@ -14,21 +14,30 @@ const Testimonials = (movieId) => { const response = await axios.get( `${process.env.REACT_APP_API_PATH}/feedbacks/movie/${movieId.movieId}` ); - console.log(response); const formattedTestimonials = response.data.map((item) => ({ quote: item.comment, - name: `${item.userId.firstName} ${item.userId.lastName}`, // Replace with user's name if available - position: "Movie Viewer", // Replace with user's position if available + name: `${item.userId.firstName} ${item.userId.lastName}`, + position: "Movie Viewer", rating: item.rating, })); setTestimonials(formattedTestimonials); } catch (error) { - console.error("Error fetching testimonials", error); + if (axios.isAxiosError(error) && error.response) { + if (error.response.status !== 404) { + // Handle all errors except 404 + console.error("An error occurred:", error); + } + } else { + // Handle non-Axios errors + console.error("An error occurred:", error); + } + // If the error is 404, it will not be caught here } }; fetchTestimonials(); }, [movieId.movieId]); + const settings = { dots: true, infinite: true, diff --git a/client/src/components/pages/Booking.js b/client/src/components/pages/Booking.js index f02cad1..5c76247 100644 --- a/client/src/components/pages/Booking.js +++ b/client/src/components/pages/Booking.js @@ -1,18 +1,18 @@ import React, { useState, useEffect } from "react"; import "../css/Booking.css"; -import { Link, useParams } from "react-router-dom"; +import { Link, useParams, useNavigate } from "react-router-dom"; import axios from "axios"; import { useLoading } from "../LoadingContext.js"; import { TailSpin } from "react-loader-spinner"; import Chat from "../Chat"; - +import Swal from "sweetalert2"; const Booking = () => { const { id } = useParams(); const [movieDetails, setMovieDetails] = useState(null); const [showTimes, setShowTimes] = useState([]); const [selectedDate, setSelectedDate] = useState(""); const { loading, setLoading } = useLoading(); - + const navigate = useNavigate(); const convertTo12HourFormat = (time24) => { const [hours, minutes] = time24.split(":"); const hours12 = hours % 12 || 12; @@ -39,7 +39,16 @@ const Booking = () => { setSelectedDate(showTimesResponse.data[0].date); } } catch (error) { - console.error("Error fetching data", error); + Swal.fire({ + title: "Error!", + text: "Failed to load movie data.", + icon: "error", + confirmButtonText: "OK", + }).then((result) => { + if (result.isConfirmed) { + navigate("/"); // Redirect to home page using navigate + } + }); } setLoading(false); }; diff --git a/client/src/components/pages/Movie.js b/client/src/components/pages/Movie.js index 11abea6..384c72a 100644 --- a/client/src/components/pages/Movie.js +++ b/client/src/components/pages/Movie.js @@ -1,5 +1,5 @@ import React, { useState, useEffect } from "react"; -import { useParams } from "react-router-dom"; +import { useParams, useNavigate } from "react-router-dom"; import { FaTicketAlt, FaPlayCircle } from "react-icons/fa"; import "../css/Movie.css"; import Testimonial from "../Testimonial-Section.js"; @@ -42,7 +42,7 @@ const MovieFeedbackForm = () => { ); if (!response.ok) { - throw new Error("Network response was not ok"); + throw response; } // Handle success @@ -57,16 +57,24 @@ const MovieFeedbackForm = () => { setMessage(""); setRating(0); } catch (error) { - console.error("Error submitting feedback:", error); - Swal.fire({ - title: "Error!", - text: "There was a problem submitting your feedback.", - icon: "error", - confirmButtonText: "OK", - }); + if (error.status === 404) { + Swal.fire({ + title: "Error!", + text: "You have to purchase the movie first!", + icon: "error", + confirmButtonText: "OK", + }); + } else { + console.error("Error submitting feedback:", error); + Swal.fire({ + title: "Error!", + text: "There was a problem submitting your feedback.", + icon: "error", + confirmButtonText: "OK", + }); + } } }; - return (
@@ -84,9 +92,9 @@ const MovieFeedbackForm = () => { return ( setHover(ratingValue)} onMouseLeave={() => setHover(rating)} onClick={() => setRating(ratingValue)} @@ -109,6 +117,8 @@ function MoviePage() { const [movieData, setMovieData] = useState({}); const [feedbacks, setFeedbacks] = useState([]); const { loading, setLoading } = useLoading(); + const navigate = useNavigate(); + var { id } = useParams(); useEffect(() => { @@ -133,7 +143,16 @@ function MoviePage() { const feedbackData = await feedbackResponse.json(); setFeedbacks(feedbackData); } catch (error) { - console.error("Error fetching movie data:", error); + Swal.fire({ + title: "Error!", + text: "Failed to load movie data.", + icon: "error", + confirmButtonText: "OK", + }).then((result) => { + if (result.isConfirmed) { + navigate("/"); // Redirect to home page using navigate + } + }); } finally { setLoading(false); } diff --git a/client/src/components/pages/Seating.js b/client/src/components/pages/Seating.js index ecd485b..15d5a9d 100644 --- a/client/src/components/pages/Seating.js +++ b/client/src/components/pages/Seating.js @@ -39,7 +39,16 @@ export default function Seating() { setSeatPrice(response.data.price); setLoading(false); } catch (error) { - console.error("Error fetching movie data:", error); + Swal.fire({ + title: "Error!", + text: "Failed to load movie data.", + icon: "error", + confirmButtonText: "OK", + }).then((result) => { + if (result.isConfirmed) { + navigate("/"); // Redirect to home page using navigate + } + }); } }; fetchData(); @@ -128,7 +137,7 @@ export default function Seating() { const totalPrice = selectedSeats.length * seatPrice; // Check if userData is empty, and if so, navigate to the login page - useEffect(() => { }, [userData, navigate]); + useEffect(() => {}, [userData, navigate]); return (
@@ -245,7 +254,6 @@ function Cinema({ bookedSeats, selectedSeats, onSelectedSeatsChange }) { ); })}
-