Merge branch 'pramod_Task#207' into Issue_May_2W
This commit is contained in:
commit
658c2776f1
@ -1,22 +1,83 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import WorkItem from "./WorkItem";
|
import WorkItem from "./WorkItem";
|
||||||
import { useProjectDetails } from "../../../hooks/useProjects";
|
import { useProjectDetails } from "../../../hooks/useProjects";
|
||||||
import { getCachedData } from "../../../slices/apiDataManager";
|
import { cacheData, getCachedData } from "../../../slices/apiDataManager";
|
||||||
|
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 WorkArea = ({ workArea, floor, forBuilding }) => {
|
||||||
const [workItems, setWorkItems] = useState([]);
|
const [ workItems, setWorkItems ] = useState( [] );
|
||||||
|
const dispatch = useDispatch()
|
||||||
|
const [Project,setProject] = useState()
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const project = getCachedData("projectInfo");
|
const project = getCachedData( "projectInfo" );
|
||||||
|
setProject(project)
|
||||||
|
|
||||||
if (!project || !forBuilding?.id || !floor?.id || !workArea?.id) return;
|
if (!project || !forBuilding?.id || !floor?.id || !workArea?.id) return;
|
||||||
|
|
||||||
const building = project.buildings?.find((b) => b.id === forBuilding.id);
|
const building = project.buildings?.find((b) => b.id === forBuilding.id);
|
||||||
const floors = building?.floors?.find((f) => f.id === floor.id);
|
const floors = building?.floors?.find((f) => f.id === floor.id);
|
||||||
const workAreas = floor?.workAreas?.find((wa) => wa.id === workArea.id);
|
const workAreas = floor?.workAreas?.find((wa) => wa.id === workArea.id);
|
||||||
|
|
||||||
setWorkItems(workAreas?.workItems || []);
|
setWorkItems(workAreas?.workItems || []);
|
||||||
}, [workArea, floor, floor]);
|
}, [ workArea, floor, floor ] );
|
||||||
|
|
||||||
|
const HanldeDeleteActivity = async (workItemId) => {
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
const updatedProject = { ...Project.data };
|
||||||
|
const response = await ProjectRepository.deleteProjectTask( workItemId);
|
||||||
|
const newProject = {
|
||||||
|
...updatedProject,
|
||||||
|
buildings: updatedProject?.buildings.map((building) =>
|
||||||
|
building?.id === building?.id
|
||||||
|
? {
|
||||||
|
...building,
|
||||||
|
floors: building?.floors?.map((floor) =>
|
||||||
|
floor.id === floor?.id
|
||||||
|
? {
|
||||||
|
...floor,
|
||||||
|
workAreas: floor.workAreas.map((workArea) =>
|
||||||
|
workArea.id === workArea?.id
|
||||||
|
? {
|
||||||
|
...workArea,
|
||||||
|
workItems: workArea.workItems.filter(
|
||||||
|
(item) =>
|
||||||
|
String(item?.workItem?.id ?? item?.id) !==
|
||||||
|
String(workItemId)
|
||||||
|
),
|
||||||
|
}
|
||||||
|
: workArea
|
||||||
|
),
|
||||||
|
}
|
||||||
|
: floor
|
||||||
|
),
|
||||||
|
}
|
||||||
|
: 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");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment key={workArea.id}>
|
<React.Fragment key={workArea.id}>
|
||||||
<tr>
|
<tr>
|
||||||
@ -70,7 +131,7 @@ const WorkArea = ({ workArea, floor, forBuilding }) => {
|
|||||||
{/* ************************** */}
|
{/* ************************** */}
|
||||||
<th className="infra-activity-table-header">Progress</th>
|
<th className="infra-activity-table-header">Progress</th>
|
||||||
<th className="infra-activity-table-header text-end ">
|
<th className="infra-activity-table-header text-end ">
|
||||||
<span className="px-3"> Actions</span>
|
<span className="px-3">Actions</span>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -83,6 +144,7 @@ const WorkArea = ({ workArea, floor, forBuilding }) => {
|
|||||||
forBuilding={forBuilding}
|
forBuilding={forBuilding}
|
||||||
forFloor={floor}
|
forFloor={floor}
|
||||||
forWorkArea={workArea}
|
forWorkArea={workArea}
|
||||||
|
deleteHandleTask={HanldeDeleteActivity}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
|
@ -9,11 +9,22 @@ import ConfirmModal from "../../common/ConfirmModal";
|
|||||||
import ProjectRepository from "../../../repositories/ProjectRepository";
|
import ProjectRepository from "../../../repositories/ProjectRepository";
|
||||||
import { useProjectDetails } from "../../../hooks/useProjects";
|
import { useProjectDetails } from "../../../hooks/useProjects";
|
||||||
import showToast from "../../../services/toastService";
|
import showToast from "../../../services/toastService";
|
||||||
import { cacheData, getCachedData } from "../../../slices/apiDataManager";
|
import {
|
||||||
|
cacheData,
|
||||||
|
clearCacheKey,
|
||||||
|
getCachedData,
|
||||||
|
} from "../../../slices/apiDataManager";
|
||||||
import { useDispatch } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
import { refreshData } from "../../../slices/localVariablesSlice";
|
import { refreshData } from "../../../slices/localVariablesSlice";
|
||||||
|
|
||||||
const WorkItem = ({ workItem, forBuilding, forFloor, forWorkArea }) => {
|
const WorkItem = ( {
|
||||||
|
key,
|
||||||
|
workItem,
|
||||||
|
forBuilding,
|
||||||
|
forFloor,
|
||||||
|
forWorkArea,
|
||||||
|
deleteHandleTask,
|
||||||
|
}) => {
|
||||||
const { projectId } = useParams();
|
const { projectId } = useParams();
|
||||||
const [itemName, setItemName] = useState("");
|
const [itemName, setItemName] = useState("");
|
||||||
const [NewWorkItem, setNewWorkItem] = useState();
|
const [NewWorkItem, setNewWorkItem] = useState();
|
||||||
@ -26,10 +37,6 @@ const WorkItem = ({ workItem, forBuilding, forFloor, forWorkArea }) => {
|
|||||||
const project = getCachedData("projectInfo");
|
const project = getCachedData("projectInfo");
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
const { projects_Details } = useProjectDetails(
|
|
||||||
projectId || project?.projectId
|
|
||||||
);
|
|
||||||
|
|
||||||
const openModal = () => setIsModalOpen(true);
|
const openModal = () => setIsModalOpen(true);
|
||||||
const closeModal = () => setIsModalOpen(false);
|
const closeModal = () => setIsModalOpen(false);
|
||||||
const getProgress = (planned, completed) => {
|
const getProgress = (planned, completed) => {
|
||||||
@ -66,62 +73,17 @@ const WorkItem = ({ workItem, forBuilding, forFloor, forWorkArea }) => {
|
|||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
setLoadingDelete(true);
|
setLoadingDelete(true);
|
||||||
try
|
let WorkItemId = workItem.workItemId || workItem.id;
|
||||||
{
|
deleteHandleTask( WorkItemId );
|
||||||
const updatedProject = { ...projects_Details };
|
setLoadingDelete(false);
|
||||||
const response = await ProjectRepository.deleteProjectTask( workItem.workItemId || workItem.id);
|
closeModalDelete();
|
||||||
const newProject = {
|
|
||||||
...updatedProject,
|
|
||||||
buildings: updatedProject.buildings.map((building) =>
|
|
||||||
building.id === forBuilding?.id
|
|
||||||
? {
|
|
||||||
...building,
|
|
||||||
floors: building.floors.map((floor) =>
|
|
||||||
floor.id === forFloor?.id
|
|
||||||
? {
|
|
||||||
...floor,
|
|
||||||
workAreas: floor.workAreas.map((workArea) =>
|
|
||||||
workArea.id === forWorkArea?.id
|
|
||||||
? {
|
|
||||||
...workArea,
|
|
||||||
workItems: workArea.workItems.filter(
|
|
||||||
(item) =>
|
|
||||||
String(item?.workItem?.id ?? item?.id) !==
|
|
||||||
String(workItem.workItemId)
|
|
||||||
),
|
|
||||||
}
|
|
||||||
: workArea
|
|
||||||
),
|
|
||||||
}
|
|
||||||
: floor
|
|
||||||
),
|
|
||||||
}
|
|
||||||
: building
|
|
||||||
),
|
|
||||||
};
|
|
||||||
|
|
||||||
cacheData("projectInfo", {
|
|
||||||
projectId: newProject.id,
|
|
||||||
data: newProject,
|
|
||||||
});
|
|
||||||
|
|
||||||
dispatch(refreshData(true));
|
|
||||||
closeModalDelete();
|
|
||||||
setLoadingDelete(false);
|
|
||||||
showToast("Activity Deleted Successfully", "success");
|
|
||||||
} catch (error) {
|
|
||||||
setLoadingDelete(false);
|
|
||||||
closeModalDelete();
|
|
||||||
const message =
|
|
||||||
error.response?.data?.message ||
|
|
||||||
error.message ||
|
|
||||||
"An unexpected error occurred";
|
|
||||||
showToast(message, "error");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const PlannedWork = NewWorkItem?.workItem?.plannedWork || workItem?.plannedWork;
|
const PlannedWork =
|
||||||
const CompletedWork = NewWorkItem?.workItem?.completedWork ?? workItem?.completedWork;
|
NewWorkItem?.workItem?.plannedWork || workItem?.plannedWork;
|
||||||
|
const CompletedWork =
|
||||||
|
NewWorkItem?.workItem?.completedWork ?? workItem?.completedWork;
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{isModalOpen && (
|
{isModalOpen && (
|
||||||
@ -176,7 +138,7 @@ const WorkItem = ({ workItem, forBuilding, forFloor, forWorkArea }) => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<tr>
|
<tr key={key}>
|
||||||
<td className="text-start table-cell-small">
|
<td className="text-start table-cell-small">
|
||||||
<i className="bx bx-right-arrow-alt"></i>
|
<i className="bx bx-right-arrow-alt"></i>
|
||||||
<span className="fw-light">
|
<span className="fw-light">
|
||||||
@ -236,65 +198,66 @@ const WorkItem = ({ workItem, forBuilding, forFloor, forWorkArea }) => {
|
|||||||
></div>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td className="text-end align-middle">
|
<td className="text-end align-middle">
|
||||||
<div className="dropdown w-auto d-inline-flex align-items-center gap-1">
|
<div className="dropdown w-auto d-inline-flex align-items-center gap-1">
|
||||||
{/* Reserve space for Assign button */}
|
{/* Reserve space for Assign button */}
|
||||||
<div style={{ width: 'auto', minWidth: '60px' }}>
|
<div style={{ width: "auto", minWidth: "60px" }}>
|
||||||
{(!projectId && ManageTasks) && (PlannedWork !== CompletedWork) ? (
|
{!projectId && ManageTasks && PlannedWork !== CompletedWork ? (
|
||||||
<button
|
<button
|
||||||
aria-label="Modify"
|
aria-label="Modify"
|
||||||
type="button"
|
type="button"
|
||||||
className="btn p-0"
|
className="btn p-0"
|
||||||
data-bs-toggle="modal"
|
data-bs-toggle="modal"
|
||||||
data-bs-target="#project-modal"
|
data-bs-target="#project-modal"
|
||||||
onClick={openModal}
|
onClick={openModal}
|
||||||
>
|
>
|
||||||
<span className="badge badge-md bg-label-primary me-1">Assign</span>
|
<span className="badge badge-md bg-label-primary me-1">
|
||||||
</button>
|
Assign
|
||||||
) : (
|
</span>
|
||||||
// Hidden placeholder to preserve layout
|
</button>
|
||||||
<span className="invisible">
|
) : (
|
||||||
<span className="badge badge-md bg-label-primary me-1">Assign</span>
|
// Hidden placeholder to preserve layout
|
||||||
</span>
|
<span className="invisible">
|
||||||
)}
|
<span className="badge badge-md bg-label-primary me-1">
|
||||||
</div>
|
Assign
|
||||||
|
</span>
|
||||||
{/* Edit and Delete buttons */}
|
</span>
|
||||||
{ManageInfra && (
|
)}
|
||||||
<>
|
</div>
|
||||||
<button
|
|
||||||
aria-label="Modify"
|
|
||||||
type="button"
|
|
||||||
className="btn p-0"
|
|
||||||
onClick={showModal1}
|
|
||||||
>
|
|
||||||
<i
|
|
||||||
className="bx bxs-edit me-2 text-primary"
|
|
||||||
data-bs-toggle="tooltip"
|
|
||||||
data-bs-placement="top"
|
|
||||||
title="Edit Activity"
|
|
||||||
></i>
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
aria-label="Delete"
|
|
||||||
type="button"
|
|
||||||
className="btn p-0"
|
|
||||||
onClick={showModalDelete}
|
|
||||||
>
|
|
||||||
<i
|
|
||||||
className="bx bx-trash me-1 text-danger"
|
|
||||||
data-bs-toggle="tooltip"
|
|
||||||
data-bs-placement="top"
|
|
||||||
title="Delete Activity"
|
|
||||||
></i>
|
|
||||||
</button>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{/* Edit and Delete buttons */}
|
||||||
|
{ManageInfra && (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
aria-label="Modify"
|
||||||
|
type="button"
|
||||||
|
className="btn p-0"
|
||||||
|
onClick={showModal1}
|
||||||
|
>
|
||||||
|
<i
|
||||||
|
className="bx bxs-edit me-2 text-primary"
|
||||||
|
data-bs-toggle="tooltip"
|
||||||
|
data-bs-placement="top"
|
||||||
|
title="Edit Activity"
|
||||||
|
></i>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
aria-label="Delete"
|
||||||
|
type="button"
|
||||||
|
className="btn p-0"
|
||||||
|
onClick={showModalDelete}
|
||||||
|
>
|
||||||
|
<i
|
||||||
|
className="bx bx-trash me-1 text-danger"
|
||||||
|
data-bs-toggle="tooltip"
|
||||||
|
data-bs-placement="top"
|
||||||
|
title="Delete Activity"
|
||||||
|
></i>
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user