diff --git a/frontend/src/components/ConditionCheckViewerModal.tsx b/frontend/src/components/ConditionCheckViewerModal.tsx index 85b62f7..7ea56d8 100644 --- a/frontend/src/components/ConditionCheckViewerModal.tsx +++ b/frontend/src/components/ConditionCheckViewerModal.tsx @@ -24,6 +24,16 @@ const ConditionCheckViewerModal: React.FC = ({ const [selectedImage, setSelectedImage] = useState(0); const [loading, setLoading] = useState(false); + useEffect(() => { + const handleKeyDown = (e: KeyboardEvent) => { + if (e.key === "Escape") onHide(); + }; + if (show) { + document.addEventListener("keydown", handleKeyDown); + } + return () => document.removeEventListener("keydown", handleKeyDown); + }, [show, onHide]); + useEffect(() => { const fetchImageUrls = async () => { if (!conditionCheck?.imageFilenames?.length) return; diff --git a/frontend/src/components/DeclineRentalModal.tsx b/frontend/src/components/DeclineRentalModal.tsx index a55a2ba..5c3b9a5 100644 --- a/frontend/src/components/DeclineRentalModal.tsx +++ b/frontend/src/components/DeclineRentalModal.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect, useCallback } from "react"; +import React, { useState, useEffect } from "react"; import { rentalAPI } from "../services/api"; import { Rental } from "../types"; @@ -65,38 +65,17 @@ const DeclineRentalModal: React.FC = ({ onHide(); }; - const handleBackdropClick = useCallback( - (e: React.MouseEvent) => { - if (e.target === e.currentTarget && !processing) { - handleClose(); - } - }, - [handleClose, processing] - ); - - const handleKeyDown = useCallback( - (e: KeyboardEvent) => { - if (e.key === "Escape" && !processing) { - handleClose(); - } - }, - [handleClose, processing] - ); - useEffect(() => { if (show) { - document.addEventListener("keydown", handleKeyDown); document.body.style.overflow = "hidden"; } else { - document.removeEventListener("keydown", handleKeyDown); document.body.style.overflow = "unset"; } return () => { - document.removeEventListener("keydown", handleKeyDown); document.body.style.overflow = "unset"; }; - }, [show, handleKeyDown]); + }, [show]); if (!show) return null; @@ -104,7 +83,6 @@ const DeclineRentalModal: React.FC = ({
diff --git a/frontend/src/components/RentalCancellationModal.tsx b/frontend/src/components/RentalCancellationModal.tsx index 7af2161..2a23a26 100644 --- a/frontend/src/components/RentalCancellationModal.tsx +++ b/frontend/src/components/RentalCancellationModal.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect, useCallback } from "react"; +import React, { useState, useEffect } from "react"; import { rentalAPI } from "../services/api"; import { RefundPreview, Rental } from "../types"; @@ -129,38 +129,17 @@ const RentalCancellationModal: React.FC = ({ return "success"; }; - const handleBackdropClick = useCallback( - (e: React.MouseEvent) => { - if (e.target === e.currentTarget) { - handleClose(); - } - }, - [handleClose] - ); - - const handleKeyDown = useCallback( - (e: KeyboardEvent) => { - if (e.key === "Escape") { - handleClose(); - } - }, - [handleClose] - ); - useEffect(() => { if (show) { - document.addEventListener("keydown", handleKeyDown); document.body.style.overflow = "hidden"; } else { - document.removeEventListener("keydown", handleKeyDown); document.body.style.overflow = "unset"; } return () => { - document.removeEventListener("keydown", handleKeyDown); document.body.style.overflow = "unset"; }; - }, [show, handleKeyDown]); + }, [show]); if (!show) return null; @@ -168,7 +147,6 @@ const RentalCancellationModal: React.FC = ({
diff --git a/frontend/src/components/ReturnStatusModal.tsx b/frontend/src/components/ReturnStatusModal.tsx index 53c88be..8edad11 100644 --- a/frontend/src/components/ReturnStatusModal.tsx +++ b/frontend/src/components/ReturnStatusModal.tsx @@ -353,38 +353,17 @@ const ReturnStatusModal: React.FC = ({ onHide(); }, [onHide]); - const handleBackdropClick = useCallback( - (e: React.MouseEvent) => { - if (e.target === e.currentTarget) { - handleClose(); - } - }, - [handleClose] - ); - - const handleKeyDown = useCallback( - (e: KeyboardEvent) => { - if (e.key === "Escape") { - handleClose(); - } - }, - [handleClose] - ); - useEffect(() => { if (show) { - document.addEventListener("keydown", handleKeyDown); document.body.style.overflow = "hidden"; } else { - document.removeEventListener("keydown", handleKeyDown); document.body.style.overflow = "unset"; } return () => { - document.removeEventListener("keydown", handleKeyDown); document.body.style.overflow = "unset"; }; - }, [show, handleKeyDown]); + }, [show]); if (!show) return null; @@ -392,7 +371,6 @@ const ReturnStatusModal: React.FC = ({
diff --git a/frontend/src/components/ReviewDetailsModal.tsx b/frontend/src/components/ReviewDetailsModal.tsx index 0b90143..6497430 100644 --- a/frontend/src/components/ReviewDetailsModal.tsx +++ b/frontend/src/components/ReviewDetailsModal.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useEffect } from "react"; import { Rental } from "../types"; import StarRating from "./StarRating"; @@ -15,6 +15,16 @@ const ReviewDetailsModal: React.FC = ({ rental, userType, }) => { + useEffect(() => { + const handleKeyDown = (e: KeyboardEvent) => { + if (e.key === "Escape") onClose(); + }; + if (show) { + document.addEventListener("keydown", handleKeyDown); + } + return () => document.removeEventListener("keydown", handleKeyDown); + }, [show, onClose]); + if (!show) return null; const formatDateTime = (dateString: string) => { @@ -29,6 +39,9 @@ const ReviewDetailsModal: React.FC = ({ className="modal d-block" tabIndex={-1} style={{ backgroundColor: "rgba(0,0,0,0.5)" }} + onClick={(e) => { + if (e.target === e.currentTarget) onClose(); + }} >
diff --git a/frontend/src/components/SuccessModal.tsx b/frontend/src/components/SuccessModal.tsx index bae4508..8c94b2b 100644 --- a/frontend/src/components/SuccessModal.tsx +++ b/frontend/src/components/SuccessModal.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect } from 'react'; interface SuccessModalProps { show: boolean; @@ -7,19 +7,32 @@ interface SuccessModalProps { message: string; } -const SuccessModal: React.FC = ({ - show, - onClose, +const SuccessModal: React.FC = ({ + show, + onClose, title = "Success!", - message + message }) => { + useEffect(() => { + const handleKeyDown = (e: KeyboardEvent) => { + if (e.key === 'Escape') onClose(); + }; + if (show) { + document.addEventListener('keydown', handleKeyDown); + } + return () => document.removeEventListener('keydown', handleKeyDown); + }, [show, onClose]); + if (!show) return null; return ( -
{ + if (e.target === e.currentTarget) onClose(); + }} >