Skip to content

Commit

Permalink
Merge pull request #73 from DFanso/api-connections-too
Browse files Browse the repository at this point in the history
bug fix
  • Loading branch information
VidwaDeSeram authored Jan 6, 2024
2 parents 2e0d3b8 + 6845c89 commit 1da389d
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 25 deletions.
17 changes: 13 additions & 4 deletions client/src/components/Testimonial-Section.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 13 additions & 4 deletions client/src/components/pages/Booking.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
};
Expand Down
47 changes: 33 additions & 14 deletions client/src/components/pages/Movie.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -42,7 +42,7 @@ const MovieFeedbackForm = () => {
);

if (!response.ok) {
throw new Error("Network response was not ok");
throw response;
}

// Handle success
Expand All @@ -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 (
<div className="feedback-section">
<div className="feedback-container">
Expand All @@ -84,9 +92,9 @@ const MovieFeedbackForm = () => {
return (
<span
key={index}

className={`feedback-star ${ratingValue <= (hover || rating) ? "filled" : "empty"}`}

className={`feedback-star ${
ratingValue <= (hover || rating) ? "filled" : "empty"
}`}
onMouseEnter={() => setHover(ratingValue)}
onMouseLeave={() => setHover(rating)}
onClick={() => setRating(ratingValue)}
Expand All @@ -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(() => {
Expand All @@ -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);
}
Expand Down
14 changes: 11 additions & 3 deletions client/src/components/pages/Seating.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 (
<div className="App">
Expand Down Expand Up @@ -245,7 +254,6 @@ function Cinema({ bookedSeats, selectedSeats, onSelectedSeatsChange }) {
);
})}
</div>

</div>
<Chat />
</div>
Expand Down

0 comments on commit 1da389d

Please sign in to comment.