diff --git a/src/components/ProjectTasksSection.js b/src/components/ProjectTasksSection.js index cbd3a85..07ead22 100644 --- a/src/components/ProjectTasksSection.js +++ b/src/components/ProjectTasksSection.js @@ -12,6 +12,7 @@ export default function ProjectTasksSection({ projectId }) { const [taskNotes, setTaskNotes] = useState({}); const [newNote, setNewNote] = useState({}); const [loadingNotes, setLoadingNotes] = useState({}); + const [showAddTaskModal, setShowAddTaskModal] = useState(false); useEffect(() => { const fetchProjectTasks = async () => { try { @@ -46,6 +47,67 @@ export default function ProjectTasksSection({ projectId }) { fetchProjectTasks(); }, [projectId]); + // Handle escape key to close modal + useEffect(() => { + const handleEscape = (e) => { + if (e.key === "Escape" && showAddTaskModal) { + setShowAddTaskModal(false); + } + }; + + document.addEventListener("keydown", handleEscape); + return () => document.removeEventListener("keydown", handleEscape); + }, [showAddTaskModal]); + // Prevent body scroll when modal is open and handle map z-index + useEffect(() => { + if (showAddTaskModal) { + // Prevent body scroll + document.body.style.overflow = "hidden"; + + // Find and temporarily lower z-index of leaflet containers + const leafletContainers = document.querySelectorAll(".leaflet-container"); + leafletContainers.forEach((container) => { + container.style.zIndex = "1"; + }); + + // Also handle navigation and other potential high z-index elements + const navElements = document.querySelectorAll("nav"); + navElements.forEach((nav) => { + nav.style.position = "relative"; + nav.style.zIndex = "1"; + }); + } else { + // Restore body scroll + document.body.style.overflow = "unset"; + + // Restore leaflet container z-index + const leafletContainers = document.querySelectorAll(".leaflet-container"); + leafletContainers.forEach((container) => { + container.style.zIndex = ""; + }); + + // Restore navigation z-index + const navElements = document.querySelectorAll("nav"); + navElements.forEach((nav) => { + nav.style.position = ""; + nav.style.zIndex = ""; + }); + } + + // Cleanup function + return () => { + document.body.style.overflow = "unset"; + const leafletContainers = document.querySelectorAll(".leaflet-container"); + leafletContainers.forEach((container) => { + container.style.zIndex = ""; + }); + const navElements = document.querySelectorAll("nav"); + navElements.forEach((nav) => { + nav.style.position = ""; + nav.style.zIndex = ""; + }); + }; + }, [showAddTaskModal]); const refetchTasks = async () => { try { const res = await fetch(`/api/project-tasks?project_id=${projectId}`); @@ -76,6 +138,7 @@ export default function ProjectTasksSection({ projectId }) { }; const handleTaskAdded = () => { refetchTasks(); // Refresh the list + setShowAddTaskModal(false); // Close the modal }; const handleStatusChange = async (taskId, newStatus) => { @@ -197,24 +260,79 @@ export default function ProjectTasksSection({ projectId }) {

Project Tasks

- - {projectTasks.length} {projectTasks.length === 1 ? "task" : "tasks"} - -
- - {/* Add New Task Card */} - - -

Add New Task

-
- - - -
- +
+ + {projectTasks.length} {projectTasks.length === 1 ? "task" : "tasks"} + + +
+
{" "} + {/* Add Task Modal */} + {showAddTaskModal && ( +
{ + if (e.target === e.currentTarget) { + setShowAddTaskModal(false); + } + }} + > +
+
+

+ Add New Task +

+ +
+
+ +
+
+
+ )} {/* Current Tasks */}