diff --git a/src/components/Project/Infrastructure/WorkArea.jsx b/src/components/Project/Infrastructure/WorkArea.jsx index f2a35b3b..dfebe350 100644 --- a/src/components/Project/Infrastructure/WorkArea.jsx +++ b/src/components/Project/Infrastructure/WorkArea.jsx @@ -2,37 +2,31 @@ import React, { useEffect, useState } from "react"; import WorkItem from "./WorkItem"; import { useProjectDetails } from "../../../hooks/useProjects"; import { cacheData, getCachedData } from "../../../slices/apiDataManager"; -import {useDispatch} from "react-redux"; -import {refreshData} from "../../../slices/localVariablesSlice"; +import { useDispatch } from "react-redux"; +import { refreshData } from "../../../slices/localVariablesSlice"; import ProjectRepository from "../../../repositories/ProjectRepository"; import showToast from "../../../services/toastService"; const WorkArea = ({ workArea, floor, forBuilding }) => { - const [ workItems, setWorkItems ] = useState( [] ); - const dispatch = useDispatch() - const [ Project, setProject ] = useState() - - const [isExpanded, setIsExpanded] = useState(false); - - const toggleExpand = () => setIsExpanded(!isExpanded); + const [workItems, setWorkItems] = useState([]); + const dispatch = useDispatch(); + const [Project, setProject] = useState(); useEffect(() => { - const project = getCachedData( "projectInfo" ); - setProject(project) - + const project = getCachedData("projectInfo"); + setProject(project); + if (!project || !forBuilding?.id || !floor?.id || !workArea?.id) return; const building = project.buildings?.find((b) => b.id === forBuilding.id); const floors = building?.floors?.find((f) => f.id === floor.id); const workAreas = floor?.workAreas?.find((wa) => wa.id === workArea.id); setWorkItems(workAreas?.workItems || []); - }, [ workArea, floor, floor ] ); + }, [workArea, floor, floor]); - const HanldeDeleteActivity = async (workItemId) => { - - try - { + const HanldeDeleteActivity = async (workItemId) => { + try { const updatedProject = { ...Project.data }; - const response = await ProjectRepository.deleteProjectTask( workItemId); + const response = await ProjectRepository.deleteProjectTask(workItemId); const newProject = { ...updatedProject, buildings: updatedProject?.buildings.map((building) => @@ -62,108 +56,167 @@ const WorkArea = ({ workArea, floor, forBuilding }) => { : building ), }; - + cacheData("projectInfo", { projectId: newProject.id, data: newProject, - } ); + }); dispatch(refreshData(true)); - - + showToast("Activity Deleted Successfully", "success"); } catch (error) { const message = error.response?.data?.message || error.message || "An unexpected error occurred"; - showToast(message, "error"); + showToast(message, "error"); } }; - + + useEffect(() => { + const toggleButtons = document.querySelectorAll(".accordion-button"); + + toggleButtons.forEach((btn) => { + const icon = btn.querySelector(".toggle-icon"); + + btn.addEventListener("click", () => { + setTimeout(() => { + if (btn.classList.contains("collapsed")) { + icon.classList.remove("bx-minus-circle"); + icon.classList.add("bx-plus-circle"); + } else { + icon.classList.remove("bx-plus-circle"); + icon.classList.add("bx-minus-circle"); + } + }, 300); // allow Bootstrap collapse to complete + }); + }); + + return () => { + toggleButtons.forEach((btn) => { + btn.removeEventListener("click", () => {}); + }); + }; + }, []); + return ( - - -
- - {/*
- - -
*/} -
- {workArea?.workItems?.length > 0 && ( + + +
+
+ {/* Accordion Header */} +

-)} - {/* Floor:  */} - 0 ? "ps-2" : "ps-7" }`}>Floor:  - {floor.floorName} - Work Area:  - {workArea.areaName} +

+ + {/* Accordion Body */} + {workItems && workItems.length > 0 && ( +
+
+ + + + + + + + + + + + + + {workArea.workItems.map((workItem) => ( + + ))} + +
+ Activity + + Status + + Category + + Planned + + Completed + + Progress + + Actions +
+
+
+ )} +
- -
- - - - - {isExpanded && workArea?.workItems?.length > 0 && ( - - - - - - - {/* for mobile view */} - - - {/* for greather than mobile view ************* */} - - - {/* ************************** */} - - - - - - {workArea.workItems.map((workItem) => ( - - ))} - -
- Activity - - Status - - Category - - Planned - - Completed - Progress - Actions -
- - - )} - - {isExpanded && (!workArea?.workItems || workArea?.workItems.length === 0) && ( - - No Data - - )} + + ); };