From 918300c64ced5d592d8198934a0ace93617b2ee7 Mon Sep 17 00:00:00 2001 From: pramod mahajan Date: Mon, 14 Jul 2025 16:59:31 +0530 Subject: [PATCH 01/14] fixed css bug --- public/assets/vendor/css/core.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/assets/vendor/css/core.css b/public/assets/vendor/css/core.css index e73f6706..5001fa1a 100644 --- a/public/assets/vendor/css/core.css +++ b/public/assets/vendor/css/core.css @@ -836,7 +836,7 @@ progress { } .row { - --bs-gutter-x: 3.625rem; + --bs-gutter-x: 0.500rem; --bs-gutter-y: 0; display: flex; flex-wrap: wrap; -- 2.43.0 From 1718638a4b6d64a81a3006e4729230935640f6ee Mon Sep 17 00:00:00 2001 From: pramod mahajan Date: Mon, 14 Jul 2025 18:17:07 +0530 Subject: [PATCH 02/14] fixed card width in core.css --- public/assets/vendor/css/core.css | 2 +- src/pages/Directory/Directory.jsx | 2 +- src/pages/project/ProjectList.jsx | 288 +++++++++++++++--------------- 3 files changed, 145 insertions(+), 147 deletions(-) diff --git a/public/assets/vendor/css/core.css b/public/assets/vendor/css/core.css index 5001fa1a..aca2dc05 100644 --- a/public/assets/vendor/css/core.css +++ b/public/assets/vendor/css/core.css @@ -2553,7 +2553,7 @@ progress { } .table-responsive { - /* overflow-x: auto; */ + overflow-x: auto; -webkit-overflow-scrolling: touch; } diff --git a/src/pages/Directory/Directory.jsx b/src/pages/Directory/Directory.jsx index ca95181f..8f72ac81 100644 --- a/src/pages/Directory/Directory.jsx +++ b/src/pages/Directory/Directory.jsx @@ -260,7 +260,7 @@ const Directory = ({ IsPage = true, prefernceContacts }) => { }, [prefernceContacts]); return ( -
+
{IsPage && ( {

No projects found.

)} - {listView ? ( -
-
-
- - - - - - - - - - - - - - {currentItems.length === 0 ? ( - - - - ) : ( - currentItems.map((project) => ( - - )) - )} - -
- Project Name - Contact PersonSTART DATEDEADLINETaskProgress -
- -
    - {[ - { - id: "b74da4c2-d07e-46f2-9919-e75e49b12731", - label: "Active", - }, - { - id: "603e994b-a27f-4e5d-a251-f3d69b0498ba", - label: "On Hold", - }, - { - id: "ef1c356e-0fe0-42df-a5d3-8daee355492d", - label: "Inactive", - }, - { - id: "33deaef9-9af1-4f2a-b443-681ea0d04f81", - label: "Completed", - }, - ].map(({ id, label }) => ( -
  • -
    - handleStatusChange(id)} - /> - + {listView ? ( +
    +
    +
    + + + + + + + + + + - + + + + {currentItems.length === 0 ? ( + + + + ) : ( + currentItems.map((project) => ( + + )) + )} + +
    + Project Name + Contact PersonSTART DATEDEADLINETaskProgress +
    + +
      + {[ + { + id: "b74da4c2-d07e-46f2-9919-e75e49b12731", + label: "Active", + }, + { + id: "cdad86aa-8a56-4ff4-b633-9c629057dfef", + label:"In Progress" + }, + { + id: "603e994b-a27f-4e5d-a251-f3d69b0498ba", + label: "On Hold", + }, + { + id: "ef1c356e-0fe0-42df-a5d3-8daee355492d", + label: "Inactive", + }, + { + id: "33deaef9-9af1-4f2a-b443-681ea0d04f81", + label: "Completed", + }, + ].map(({ id, label }) => ( +
    • +
      + handleStatusChange(id)} + /> + +
      +
    • + ))} +
    - - ))} - - -
    + + Action +
    + No projects found +
    +
    {" "} +
    {" "} +
    + ) : ( +
    + {currentItems.map((project) => ( + + ))} +
    + )} + + {!loading && totalPages > 1 && ( +
+ setCurrentPage((p) => Math.min(totalPages, p + 1)) + } > -
-

No projects found

-
-
-
-
-
-) : ( -
- {currentItems.map((project) => ( - - ))} -
-)} - -{!loading && totalPages > 1 && ( - -)} - + » + + + + + )}
); -- 2.43.0 From 788f0baee42f6bff85f4d6f9eae7c4c6d21d3c17 Mon Sep 17 00:00:00 2001 From: pramod mahajan Date: Mon, 14 Jul 2025 20:18:36 +0530 Subject: [PATCH 03/14] dynamically update planned and completed work in ProjectInfra and project list card on activity create/edit/delete --- .../Infrastructure/EditActivityModal.jsx | 12 +- .../Project/Infrastructure/TaskModel.jsx | 13 +- .../Project/Infrastructure/WorkItem.jsx | 77 +-- src/hooks/useProjects.js | 478 ++++++++++++------ 4 files changed, 376 insertions(+), 204 deletions(-) diff --git a/src/components/Project/Infrastructure/EditActivityModal.jsx b/src/components/Project/Infrastructure/EditActivityModal.jsx index 06a6e41e..14b64b53 100644 --- a/src/components/Project/Infrastructure/EditActivityModal.jsx +++ b/src/components/Project/Infrastructure/EditActivityModal.jsx @@ -116,7 +116,17 @@ useEffect(() => { floorId: floor?.id, workAreaId: workArea?.id, }; - UpdateTask([payload]) + let plannedTask = + workItem?.workItem?.plannedWork || workItem?.plannedWork || 0; + let completedTask = workItem?.workItem?.completedWork || workItem?.completedWork || 0 + UpdateTask({ + payload: [payload], + PreviousPlannedWork: plannedTask, + buildingId: building?.id, + floorId: floor?.id, + workAreaId: workArea?.id, + previousCompletedWork:completedTask + }); } return (
diff --git a/src/components/Project/Infrastructure/TaskModel.jsx b/src/components/Project/Infrastructure/TaskModel.jsx index 12cf8c87..06261603 100644 --- a/src/components/Project/Infrastructure/TaskModel.jsx +++ b/src/components/Project/Infrastructure/TaskModel.jsx @@ -69,10 +69,9 @@ const TaskModel = ({ project, onSubmit, onClose }) => { const selectedCategory = categoryData?.find((c) => c.id === watchCategoryId); const { mutate: CreateTask, isPending } = useManageTask({ - onSuccessCallback: ( response ) => - { - showToast( response?.message, "success" ) - onClose?.() + onSuccessCallback: (response) => { + showToast(response?.message, "success"); + onClose?.(); }, }); useEffect(() => { @@ -96,8 +95,10 @@ const TaskModel = ({ project, onSubmit, onClose }) => { }, [categories]); const onSubmitForm = async (data) => { - const payload = [data]; - CreateTask(payload); + const payload = [data]; + CreateTask({payload:payload,buildingId: data.buildingID, + floorId: data.floorId, + workAreaId: data.workAreaId, PreviousPlannedWork:0,previousCompletedWork:0}); }; return ( diff --git a/src/components/Project/Infrastructure/WorkItem.jsx b/src/components/Project/Infrastructure/WorkItem.jsx index 1116991c..df1f2bc1 100644 --- a/src/components/Project/Infrastructure/WorkItem.jsx +++ b/src/components/Project/Infrastructure/WorkItem.jsx @@ -10,7 +10,10 @@ import { } from "../../../utils/constants"; import ConfirmModal from "../../common/ConfirmModal"; import ProjectRepository from "../../../repositories/ProjectRepository"; -import { useDeleteProjectTask, useProjectDetails } from "../../../hooks/useProjects"; +import { + useDeleteProjectTask, + useProjectDetails, +} from "../../../hooks/useProjects"; import showToast from "../../../services/toastService"; import { cacheData, @@ -19,7 +22,7 @@ import { } from "../../../slices/apiDataManager"; import { refreshData } from "../../../slices/localVariablesSlice"; import GlobalModel from "../../common/GlobalModel"; -import {useDeleteMasterItem} from "../../../hooks/masterHook/useMaster"; +import { useDeleteMasterItem } from "../../../hooks/masterHook/useMaster"; const WorkItem = ({ workItem, @@ -40,19 +43,18 @@ const WorkItem = ({ const [loadingDelete, setLoadingDelete] = useState(false); const project = getCachedData("projectInfo"); - const openModal = () => setIsModalOpen(true); - const closeModal = () => setIsModalOpen( false ); - - const showModalDelete = () => setShowModal2(true); + const closeModal = () => setIsModalOpen(false); + + const showModalDelete = () => setShowModal2(true); const closeModalDelete = () => setShowModal2(false); const getProgress = (planned, completed) => { return (completed * 100) / planned + "%"; }; - - const {mutate:DeleteTask,isPending } = useDeleteProjectTask(() => { - closeModalDelete?.(); - }); + + const { mutate: DeleteTask, isPending } = useDeleteProjectTask(() => { + closeModalDelete?.(); + }); const handleAssignTask = () => { setItemName(""); @@ -61,15 +63,15 @@ const WorkItem = ({ setNewWorkItem(workItem); }, [workItem]); - const refreshWorkItem = (plannedTask) =>{ + const refreshWorkItem = (plannedTask) => { if (workItem) { - const updated = { - ...workItem, - todaysAssigned: (workItem.todaysAssigned || 0) + plannedTask, - }; - setNewWorkItem(updated); - } - } + const updated = { + ...workItem, + todaysAssigned: (workItem.todaysAssigned || 0) + plannedTask, + }; + setNewWorkItem(updated); + } + }; let assigndata = { building: forBuilding, floor: forFloor, @@ -85,15 +87,17 @@ const WorkItem = ({ tooltipTriggerList.forEach((el) => new bootstrap.Tooltip(el)); }, []); - - - - - const handleSubmit = async () => { let WorkItemId = workItem.workItemId || workItem.id; - DeleteTask({workItemId:WorkItemId,workAreaId:forWorkArea?.id}) - + debugger + DeleteTask({ + workItemId: WorkItemId, + workAreaId: forWorkArea?.id, + completedTask: workItem?.completedWork, + plannedTask: workItem?.plannedWork, + buildingId: forBuilding?.id, + floorId: forFloor?.id, + }); }; const PlannedWork = @@ -104,18 +108,26 @@ const WorkItem = ({ <> {isModalOpen && ( - + )} {showModal && ( - setShowModal(false)}> + setShowModal(false)} + > setShowModal(false)} + onClose={() => setShowModal(false)} /> )} @@ -167,7 +179,6 @@ const WorkItem = ({ : "NA"} - {hasWorkItem @@ -195,9 +206,7 @@ const WorkItem = ({ {hasWorkItem ? `${ - NewWorkItem?.todaysAssigned ?? - workItem?.todaysAssigned ?? - "0" + NewWorkItem?.todaysAssigned ?? workItem?.todaysAssigned ?? "0" }` : "NA"} @@ -251,7 +260,7 @@ const WorkItem = ({ setShowModal(true)} + onClick={() => setShowModal(true)} role="button" > setShowModal(true) } + onClick={() => setShowModal(true)} > Edit diff --git a/src/hooks/useProjects.js b/src/hooks/useProjects.js index 2cc5ee1d..daf705fa 100644 --- a/src/hooks/useProjects.js +++ b/src/hooks/useProjects.js @@ -6,7 +6,12 @@ import { useDispatch, useSelector } from "react-redux"; import { setProjectId } from "../slices/localVariablesSlice"; import EmployeeList from "../components/Directory/EmployeeList"; import eventBus from "../services/eventBus"; -import {Mutation, useMutation, useQuery, useQueryClient} from "@tanstack/react-query"; +import { + Mutation, + useMutation, + useQuery, + useQueryClient, +} from "@tanstack/react-query"; import showToast from "../services/toastService"; // export const useProjects = () => { @@ -211,7 +216,7 @@ export const useProjects = () => { error, refetch, } = useQuery({ - queryKey: ['ProjectsList'], + queryKey: ["ProjectsList"], queryFn: async () => { const response = await ProjectRepository.getProjectList(); return response.data; @@ -227,97 +232,112 @@ export const useProjects = () => { }; }; -export const useEmployeesByProjectAllocated = (selectedProject) => -{ - const {data = [], isLoading, refetch, error} = useQuery( { - queryKey: ["empListByProjectAllocated", selectedProject ], - queryFn: async () => - { - const res = await ProjectRepository.getProjectAllocation( selectedProject ); - return res.data || res +export const useEmployeesByProjectAllocated = (selectedProject) => { + const { + data = [], + isLoading, + refetch, + error, + } = useQuery({ + queryKey: ["empListByProjectAllocated", selectedProject], + queryFn: async () => { + const res = await ProjectRepository.getProjectAllocation(selectedProject); + return res.data || res; }, enabled: !!selectedProject, - onError: ( error ) => - { - showToast(error.message || "Error while Fetching project Allocated Employees", "error"); - } - } ) - + onError: (error) => { + showToast( + error.message || "Error while Fetching project Allocated Employees", + "error" + ); + }, + }); + return { projectEmployees: data, - loading:isLoading, + loading: isLoading, error, - refetch - } -} + refetch, + }; +}; -export const useProjectDetails = ( projectId,isAuto = true ) => -{ - const {data: projects_Details, isLoading, error, refetch} = useQuery( { - queryKey: [ "projectInfo", projectId ], - queryFn: async () => - { - const res = await ProjectRepository.getProjectByprojectId( projectId ); +export const useProjectDetails = (projectId, isAuto = true) => { + const { + data: projects_Details, + isLoading, + error, + refetch, + } = useQuery({ + queryKey: ["projectInfo", projectId], + queryFn: async () => { + const res = await ProjectRepository.getProjectByprojectId(projectId); return res.data || res; }, enabled: !!projectId && isAuto, - onError: ( error ) => - { - showToast(error.message || "Error while Fetching project Details", "error"); - } - } ) - return { projects_Details, loading:isLoading, error, refetch }; -} + onError: (error) => { + showToast( + error.message || "Error while Fetching project Details", + "error" + ); + }, + }); + return { projects_Details, loading: isLoading, error, refetch }; +}; -export const useProjectsByEmployee = (employeeId) => -{ - const { data:projectNameList =[],isLoading,error,refetch} = useQuery( { - queryKey: [ "ProjectsByEmployee", employeeId ], - queryFn: async () => - { - const res = await ProjectRepository.getProjectsByEmployee( employeeId ); +export const useProjectsByEmployee = (employeeId) => { + const { + data: projectNameList = [], + isLoading, + error, + refetch, + } = useQuery({ + queryKey: ["ProjectsByEmployee", employeeId], + queryFn: async () => { + const res = await ProjectRepository.getProjectsByEmployee(employeeId); return res.data || res; }, enabled: !!employeeId, - onError: ( error ) => - { - showToast(error.message || "Error while Fetching project Employee", "error"); - } - }) - return {projectList, loading:isLoading,error,refetch } -} + onError: (error) => { + showToast( + error.message || "Error while Fetching project Employee", + "error" + ); + }, + }); + return { projectList, loading: isLoading, error, refetch }; +}; -export const useProjectName = () => -{ - const {data = [],isLoading,error,refetch} = useQuery( { - queryKey: [ "basicProjectNameList" ], - queryFn: async () => - { +export const useProjectName = () => { + const { + data = [], + isLoading, + error, + refetch, + } = useQuery({ + queryKey: ["basicProjectNameList"], + queryFn: async () => { const res = await ProjectRepository.projectNameList(); return res.data || res; }, - onError: ( error ) => - { - showToast(error.message || "Error while Fetching project Name", "error"); - } - } ) - return {projectNames:data,loading:isLoading,Error:error,refetch} -} + onError: (error) => { + showToast(error.message || "Error while Fetching project Name", "error"); + }, + }); + return { projectNames: data, loading: isLoading, Error: error, refetch }; +}; - - export const useProjectInfra = (projectId) => { const { data: projectInfra, isLoading, error, } = useQuery({ - queryKey: ["ProjectInfra", projectId], + queryKey: ["ProjectInfra", projectId], queryFn: async () => { const res = await ProjectRepository.getProjectInfraByproject(projectId); return res.data; }, - enabled: !!projectId , + enabled: !!projectId, onError: (error) => { showToast(error.message || "Error while fetching project infra", "error"); }, @@ -326,30 +346,27 @@ export const useProjectInfra = (projectId) => { return { projectInfra, isLoading, error }; }; - -export const useProjectTasks = (workAreaId,IsExpandedArea=false) => -{ - const { data:ProjectTaskList,isLoading,error } = useQuery( { - queryKey: [ "WorkItems",workAreaId ], - queryFn: async () => - { +export const useProjectTasks = (workAreaId, IsExpandedArea = false) => { + const { + data: ProjectTaskList, + isLoading, + error, + } = useQuery({ + queryKey: ["WorkItems", workAreaId], + queryFn: async () => { const res = await ProjectRepository.getProjectTasksByWorkArea(workAreaId); return res.data; }, enabled: !!workAreaId && !!IsExpandedArea, - onError: ( error ) => - { - showToast(error.message || "Error while Fetching project Tasks", "error"); - } - } ) - return {ProjectTaskList,isLoading,error} -} - + onError: (error) => { + showToast(error.message || "Error while Fetching project Tasks", "error"); + }, + }); + return { ProjectTaskList, isLoading, error }; +}; // -- -------------Mutation------------------------------- - - export const useCreateProject = ({ onSuccessCallback }) => { const queryClient = useQueryClient(); @@ -360,8 +377,8 @@ export const useCreateProject = ({ onSuccessCallback }) => { }, onSuccess: (data) => { // Invalidate the cache - queryClient.invalidateQueries( {queryKey: [ 'ProjectsList' ]} ); - queryClient.invalidateQueries({queryKey:['basicProjectNameList']}); + queryClient.invalidateQueries({ queryKey: ["ProjectsList"] }); + queryClient.invalidateQueries({ queryKey: ["basicProjectNameList"] }); // Emit event for consumers (like useProjects or others) eventBus.emit("project", { @@ -381,27 +398,19 @@ export const useCreateProject = ({ onSuccessCallback }) => { }); }; - export const useUpdateProject = ({ onSuccessCallback }) => { const queryClient = useQueryClient(); - const { - mutate, - isPending, - isSuccess, - isError, - } = useMutation({ - mutationFn: async ( {projectId, updatedData} ) => - { + const { mutate, isPending, isSuccess, isError } = useMutation({ + mutationFn: async ({ projectId, updatedData }) => { return await ProjectRepository.updateProject(projectId, updatedData); }, - onSuccess: ( data, variables ) => - { + onSuccess: (data, variables) => { const { projectId } = variables; - - queryClient.invalidateQueries({queryKey:["ProjectsList"]}); - queryClient.invalidateQueries( {queryKey: [ "projectInfo", projectId ]} ); - queryClient.invalidateQueries({queryKey:['basicProjectNameList']}); + + queryClient.invalidateQueries({ queryKey: ["ProjectsList"] }); + queryClient.invalidateQueries({ queryKey: ["projectInfo", projectId] }); + queryClient.invalidateQueries({ queryKey: ["basicProjectNameList"] }); eventBus.emit("project", { keyword: "Update_Project", @@ -415,9 +424,8 @@ export const useUpdateProject = ({ onSuccessCallback }) => { } }, - onError: ( error ) => - { - console.log(error) + onError: (error) => { + console.log(error); showToast(error?.message || "Error while updating project", "error"); }, }); @@ -430,20 +438,16 @@ export const useUpdateProject = ({ onSuccessCallback }) => { }; }; - -export const useManageProjectInfra = ( {onSuccessCallback} ) => -{ +export const useManageProjectInfra = ({ onSuccessCallback }) => { const queryClient = useQueryClient(); return useMutation({ - mutationFn: async ( {infraObject, projectId} ) => - { + mutationFn: async ({ infraObject, projectId }) => { return await ProjectRepository.manageProjectInfra(infraObject); }, - onSuccess: ( data, variables ) => - { - const { projectId } = variables; - queryClient.invalidateQueries({queryKey:["ProjectInfra", projectId]}); - if (onSuccessCallback) onSuccessCallback(data,variables); + onSuccess: (data, variables) => { + const { projectId } = variables; + queryClient.invalidateQueries({ queryKey: ["ProjectInfra", projectId] }); + if (onSuccessCallback) onSuccessCallback(data, variables); }, onError: (error) => { showToast(error.message || "Failed to update Project Infra", "error"); @@ -451,39 +455,36 @@ export const useManageProjectInfra = ( {onSuccessCallback} ) => }); }; - export const useManageProjectAllocation = ({ onSuccessCallback, onErrorCallback, }) => { const queryClient = useQueryClient(); - const { - mutate, - isPending, - isSuccess, - isError, - } = useMutation({ - mutationFn: async ( {items} ) => - { + const { mutate, isPending, isSuccess, isError } = useMutation({ + mutationFn: async ({ items }) => { const response = await ProjectRepository.manageProjectAllocation(items); return response.data; }, onSuccess: (data, variables, context) => { - queryClient.invalidateQueries({queryKey:['empListByProjectAllocated']}); - queryClient.removeQueries({queryKey:["projectEmployees"]}) + queryClient.invalidateQueries({ + queryKey: ["empListByProjectAllocated"], + }); + queryClient.removeQueries({ queryKey: ["projectEmployees"] }); if (variables?.added) { - showToast('Employee Assigned Successfully', 'success'); + showToast("Employee Assigned Successfully", "success"); } else { - showToast('Removed Employee Successfully', 'success'); + showToast("Removed Employee Successfully", "success"); } if (onSuccessCallback) onSuccessCallback(data, context); }, onError: (error) => { const message = - error?.response?.data?.message || error.message || 'Error occurred during API call'; - showToast(message, 'error'); + error?.response?.data?.message || + error.message || + "Error occurred during API call"; + showToast(message, "error"); if (onErrorCallback) onErrorCallback(error); }, }); @@ -496,48 +497,199 @@ export const useManageProjectAllocation = ({ }; }; -export const useManageTask = ({onSuccessCallback}) => -{ +export const useManageTask = ({ onSuccessCallback }) => { const queryClient = useQueryClient(); + const selectedProject = useSelector( + (store) => store.localVariables.projectId + ); + return useMutation({ + mutationFn: async ({ + payload, + PreviousPlannedWork, + previousCompletedWork, + buildingId, + floorId, + workAreaId, + }) => await ProjectRepository.manageProjectTasks(payload), + onSuccess: (data, variables) => { + const { + workAreaId, + buildingId, + floorId, + PreviousPlannedWork, + previousCompletedWork, + } = variables; + queryClient.invalidateQueries({ queryKey: ["WorkItems"] }); + const getPlannedDelta = (previous, current) => current - previous; + queryClient.setQueryData(["ProjectInfra", selectedProject], (oldData) => { + if (!oldData) return oldData; + const { workAreaId, floorId, buildingId } = variables; + const updatedData = JSON.parse(JSON.stringify(oldData)); + return updatedData.map((building) => { + if (building.id !== buildingId) return building; + return { + ...building, + floors: building.floors.map((floor) => { + if (floor.id !== floorId) return floor; - return useMutation( { - mutationFn: async ( payload ) => await ProjectRepository.manageProjectTasks( payload ), - onSuccess: ( data, variables ) => - { - queryClient.invalidateQueries({ queryKey: ["WorkItems"] }) + return { + ...floor, + workAreas: floor.workAreas.map((area) => { + if (area.id !== workAreaId) return area; + + const previousPlanned = PreviousPlannedWork ?? 0; + const currentPlanned = + data?.data[0]?.workItem.plannedWork ?? 0; + + const plannedWorkDelta = getPlannedDelta( + previousPlanned, + currentPlanned + ); + const updatedPlannedWork = + (area.plannedWork ?? 0) + plannedWorkDelta; + const previousCompleted = previousCompletedWork; + + const currentCompleted = + data?.data[0]?.workItem.completedWork ?? 0; + const completedWorkDelta = getPlannedDelta( + previousCompleted, + currentCompleted + ); + const updatedCompletedWork = + (area.completedWork ?? 0) + completedWorkDelta; + return { + ...area, + plannedWork: updatedPlannedWork, + completedWork: updatedCompletedWork, + }; + }), + }; + }), + }; + }); + }); + + queryClient.setQueryData(["ProjectsList"], (projects) => { + if (!projects) return projects; + + return projects.map((project) => { + if (project.id !== selectedProject) return project; + + const previousPlanned = PreviousPlannedWork ?? 0; + const currentPlanned = data?.data[0]?.workItem.plannedWork ?? 0; + + const plannedWorkDelta = getPlannedDelta( + previousPlanned, + currentPlanned + ); + const updatedPlannedWork = + (project.plannedWork ?? 0) + plannedWorkDelta; + const previousCompleted = previousCompletedWork; + const currentCompleted = data?.data[0]?.workItem.completedWork ?? 0; + const completedWorkDelta = getPlannedDelta( + previousCompleted, + currentCompleted + ); + const updatedCompletedWork = + (project.completedWork ?? 0) + completedWorkDelta; + return { + ...project, + plannedWork: updatedPlannedWork, + completedWork: updatedCompletedWork, + }; + }); + }); if (onSuccessCallback) onSuccessCallback(data); }, - onError: (error) => - { - const message = - error?.response?.data?.message || error.message || 'Error occurred during API call'; - showToast(message, 'error'); - } - - }) -} - -export const useDeleteProjectTask = (onSuccessCallback) => { - const queryClient = useQueryClient(); - - return useMutation({ - mutationFn: async ( {workItemId, workAreaId} ) => - { - return await ProjectRepository.deleteProjectTask(workItemId); - }, - onSuccess: ( _, variables ) => - { - showToast("Task deleted successfully", "success"); - queryClient.invalidateQueries({queryKey:[ "WorkItems",variables.workAreaId]}); - if (onSuccessCallback) onSuccessCallback(); - }, onError: (error) => { - showToast( - error?.response?.data?.message || error.message || "Failed to delete task", - "error" - ); - if (onSuccessCallback) onSuccessCallback(); + const message = + error?.response?.data?.message || + error.message || + "Error occurred during API call"; + showToast(message, "error"); }, }); }; +export const useDeleteProjectTask = (onSuccessCallback) => { + const queryClient = useQueryClient(); + const selectedProject = useSelector( + (store) => store.localVariables.projectId + ); + return useMutation({ + mutationFn: async ({ + workItemId, + workAreaId, + completedTask, + plannedTask, + }) => { + return await ProjectRepository.deleteProjectTask(workItemId); + }, + onSuccess: (_, variables) => { + const { completedTask, plannedTask, workAreaId, buildingId, floorId } = + variables; + + queryClient.invalidateQueries({ + queryKey: ["WorkItems", variables.workAreaId], + }); + + queryClient.setQueryData(["ProjectInfra", selectedProject], (oldData) => { + if (!oldData) return oldData; + + const { workAreaId, floorId, buildingId, plannedTask, completedTask } = + variables; + + const updatedData = JSON.parse(JSON.stringify(oldData)); + + return updatedData.map((building) => { + if (building.id !== buildingId) return building; + + return { + ...building, + floors: building.floors.map((floor) => { + if (floor.id !== floorId) return floor; + + return { + ...floor, + workAreas: floor.workAreas.map((area) => { + if (area.id !== workAreaId) return area; + + return { + ...area, + plannedWork: (area.plannedWork ?? 0) - plannedTask, + completedWork: (area.completedWork ?? 0) - completedTask, + }; + }), + }; + }), + }; + }); + }); + + queryClient.setQueryData(["ProjectsList"], (projects) => { + if (!projects) return projects; + + return projects.map((project) => { + if (project.id !== selectedProject) return project; + + return { + ...project, + plannedWork: (project.plannedWork ?? 0) - plannedTask, + completedWork: (project.completedWork ?? 0) - completedTask, + }; + }); + }); + showToast("Task deleted successfully", "success"); + if (onSuccessCallback) onSuccessCallback(); + }, + onError: (error) => { + showToast( + error?.response?.data?.message || + error.message || + "Failed to delete task", + "error" + ); + if (onSuccessCallback) onSuccessCallback(); + }, + }); +}; -- 2.43.0 From d2b80b4f02f02fcac7d4493a6f80176e8ba6ef6f Mon Sep 17 00:00:00 2001 From: pramod mahajan Date: Mon, 14 Jul 2025 20:19:25 +0530 Subject: [PATCH 04/14] dynamically update planned and completed work in ProjectInfra and project list card on Task reported --- src/components/Activities/ReportTask.jsx | 7 +- src/hooks/useTasks.js | 131 ++++++++++++++--------- 2 files changed, 86 insertions(+), 52 deletions(-) diff --git a/src/components/Activities/ReportTask.jsx b/src/components/Activities/ReportTask.jsx index 8194a5cc..a3550683 100644 --- a/src/components/Activities/ReportTask.jsx +++ b/src/components/Activities/ReportTask.jsx @@ -62,7 +62,12 @@ export const ReportTask = ({ report, closeModal }) => { checkList: [], }; - reportTask({ reportData, workAreaId: report?.workItem?.workArea?.id }); + reportTask({ + reportData, + workAreaId: report?.workItem?.workArea?.id, + buildingId: report?.workItem?.workArea?.floor?.building.id, + floorId: report?.workItem?.workArea?.floor?.id, + }); }; const handleClose = () => { closeModal(); diff --git a/src/hooks/useTasks.js b/src/hooks/useTasks.js index 1cf531c0..b793ced4 100644 --- a/src/hooks/useTasks.js +++ b/src/hooks/useTasks.js @@ -1,11 +1,10 @@ import { useEffect, useState } from "react"; import { TasksRepository } from "../repositories/TaskRepository"; import { cacheData, getCachedData } from "../slices/apiDataManager"; -import {MasterRespository} from "../repositories/MastersRepository"; +import { MasterRespository } from "../repositories/MastersRepository"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import showToast from "../services/toastService"; -import {useSelector} from "react-redux"; - +import { useSelector } from "react-redux"; // ---------Query--------------------------------- @@ -28,7 +27,6 @@ export const useTaskList = (projectId, dateFrom, toDate) => { return response.data; }, enabled, - }); return { TaskList, loading, error, refetch }; @@ -46,7 +44,7 @@ export const useTaskById = (TaskId) => { const res = await TasksRepository.getTaskById(TaskId); return res.data; }, - enabled: !!TaskId, + enabled: !!TaskId, }); return { Task, loading, error, refetch }; @@ -75,47 +73,80 @@ export const useAuditStatus = () => { const res = await MasterRespository.getAuditStatus(); return res.data; }, - }); return { status, loading, error, refetch }; }; - // -----------------------Mutation------------------------ -const toDate = new Date().toISOString().split('T')[0]; -const dateFrom = new Date(Date.now() - 6 * 24 * 60 * 60 * 1000).toISOString().split('T')[0]; +const toDate = new Date().toISOString().split("T")[0]; +const dateFrom = new Date(Date.now() - 6 * 24 * 60 * 60 * 1000) + .toISOString() + .split("T")[0]; - - -export const useReportTask = ( {onSuccessCallback, onErrorCallback} = {} ) => -{ +export const useReportTask = ({ onSuccessCallback, onErrorCallback } = {}) => { const queryClient = useQueryClient(); - const { - mutate, - isPending, - isSuccess, - isError, - error, - } = useMutation({ - mutationFn: async ( {reportData,workAreaId} ) => - { - debugger + const selectedProject = useSelector( + (store) => store.localVariables.projectId + ); + const { mutate, isPending, isSuccess, isError, error } = useMutation({ + mutationFn: async ({ reportData, workAreaId }) => { return await TasksRepository.reportTask(reportData); }, - onSuccess: ( data, variables ) => - { - const {workAreaId} = variables; - queryClient.invalidateQueries( {queryKey: [ "taskList" ]} ); - queryClient.invalidateQueries( {queryKey: [ "WorkItems", workAreaId ]} ); - queryClient.invalidateQueries( {queryKey: [ 'ProjectsList' ]} ); - showToast( "Task Reported Successfully.", "success" ); + onSuccess: (data, variables) => { + const { workAreaId, buildingId, floorId } = variables; + queryClient.invalidateQueries({ queryKey: ["taskList"] }); + queryClient.invalidateQueries({ queryKey: ["WorkItems", workAreaId] }); + queryClient.setQueryData(["ProjectInfra", selectedProject], (oldData) => { + if (!oldData) return oldData; + const { workAreaId, floorId, buildingId } = variables; + const updatedData = JSON.parse(JSON.stringify(oldData)); + + return updatedData.map((building) => { + if (building.id !== buildingId) return building; + return { + ...building, + floors: building.floors.map((floor) => { + if (floor.id !== floorId) return floor; + + return { + ...floor, + workAreas: floor.workAreas.map((area) => { + if (area.id !== workAreaId) return area; + return { + ...area, + completedWork: + (area.completedWork ?? 0) + + (data?.data?.completedTask ?? 0), + }; + }), + }; + }), + }; + }); + }); + queryClient.setQueryData(["ProjectsList"], (projects) => { + if (!projects) return projects; + const updatedProject = JSON.parse(JSON.stringify(projects)); + return updatedProject.map((project) => { + if (project.id !== selectedProject) return project; + + return { + ...project, + completedWork: + (project.completedWork ?? 0) + (data?.data?.completedTask ?? 0), + }; + }); + }); + showToast("Task Reported Successfully.", "success"); if (onSuccessCallback) onSuccessCallback(data); }, onError: (error) => { const msg = - error?.response?.data?.message || error.message || "Error occurred during API call"; - showToast( msg, "error" ); + error?.response?.data?.message || + error.message || + "Error occurred during API call"; + showToast(msg, "error"); }, }); @@ -145,16 +176,12 @@ export const useSubmitTaskComment = ({ actionAllow, onSuccessCallback }) => { return response.data; }, - onSuccess: ( data,variables ) => - { - + onSuccess: (data, variables) => { const workAreaId = variables?.commentsData?.workItem?.workArea?.id; queryClient.invalidateQueries({ queryKey: ["taskList"] }); if (actionAllow) { - showToast( "Review submitted successfully.", "success" ); - - } else - { + showToast("Review submitted successfully.", "success"); + } else { showToast("Comment sent successfully.", "success"); } @@ -162,7 +189,10 @@ export const useSubmitTaskComment = ({ actionAllow, onSuccessCallback }) => { }, onError: (error) => { - const msg = error?.response?.data?.message || error.message || "Error during API call"; + const msg = + error?.response?.data?.message || + error.message || + "Error during API call"; showToast(msg, "error"); }, }); @@ -170,24 +200,23 @@ export const useSubmitTaskComment = ({ actionAllow, onSuccessCallback }) => { return { submitComment: mutate, isPending }; }; -export const useCreateTask = ( {onSuccessCallback, onErrorCallback} = {} ) => -{ +export const useCreateTask = ({ onSuccessCallback, onErrorCallback } = {}) => { const queryClient = useQueryClient(); return useMutation({ - mutationFn: async ({payload,workAreaId}) => { + mutationFn: async ({ payload, workAreaId }) => { return await TasksRepository.assignTask(payload); }, - onSuccess: ( _, variables ) => - { - queryClient.invalidateQueries( {queryKey: [ "taskList" ]} ); - queryClient.invalidateQueries( {queryKey: [ "WorkItems", variables?.workAreaId ]} ); - showToast( "Task Assigned Successfully.", "success" ); + onSuccess: (_, variables) => { + queryClient.invalidateQueries({ queryKey: ["taskList"] }); + queryClient.invalidateQueries({ + queryKey: ["WorkItems", variables?.workAreaId], + }); + showToast("Task Assigned Successfully.", "success"); if (onSuccessCallback) onSuccessCallback(variables); }, - onError: ( error ) => - { + onError: (error) => { showToast("Something went wrong. Please try again.", "error"); if (onErrorCallback) onErrorCallback(error); }, }); -}; \ No newline at end of file +}; -- 2.43.0 From 01ccd2e75869b6e40382cc8bf1268405d9b718a2 Mon Sep 17 00:00:00 2001 From: pramod mahajan Date: Mon, 14 Jul 2025 20:30:53 +0530 Subject: [PATCH 05/14] add utility to calculate and format completion percentage from planned and completed work --- src/components/Project/ProjectCard.jsx | 9 ++------- src/components/Project/ProjectOverview.jsx | 7 +++---- src/utils/dateUtils.jsx | 9 +++++++++ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/components/Project/ProjectCard.jsx b/src/components/Project/ProjectCard.jsx index 015312fe..7ff4350b 100644 --- a/src/components/Project/ProjectCard.jsx +++ b/src/components/Project/ProjectCard.jsx @@ -1,6 +1,6 @@ import React, { useEffect, useState } from "react"; import moment from "moment"; -import { formatNumber, getDateDifferenceInDays } from "../../utils/dateUtils"; +import { formatNumber, getCompletionPercentage, getDateDifferenceInDays } from "../../utils/dateUtils"; import { useNavigate } from "react-router-dom"; import { useProjectDetails, useUpdateProject } from "../../hooks/useProjects"; import ManageProjectInfo from "./ManageProjectInfo"; @@ -227,12 +227,7 @@ const ProjectCard = ({ projectData, recall }) => { Task: {formatNumber(projectInfo.completedWork)} / {formatNumber(projectInfo.plannedWork)} - {Math.floor( - getProgressInNumber( - projectInfo.plannedWork, - projectInfo.completedWork - ) - ) || 0}{" "} + {getCompletionPercentage(projectInfo.completedWork, projectInfo.plannedWork)} % Completed
diff --git a/src/components/Project/ProjectOverview.jsx b/src/components/Project/ProjectOverview.jsx index c489c339..f258ce8b 100644 --- a/src/components/Project/ProjectOverview.jsx +++ b/src/components/Project/ProjectOverview.jsx @@ -3,7 +3,7 @@ import { useEmployeesByProjectAllocated, useProjects, } from "../../hooks/useProjects"; -import { formatNumber } from "../../utils/dateUtils"; +import { formatNumber, getCompletionPercentage } from "../../utils/dateUtils"; import ProgressBar from "../common/ProgressBar"; const ProjectOverview = ({ project }) => { @@ -49,9 +49,8 @@ const ProjectOverview = ({ project }) => { ) ) || 0}{" "} */} { - (formatNumber(project_detail.plannedWork), - "/", - formatNumber(project_detail.completedWork)) + getCompletionPercentage( formatNumber(project_detail.completedWork),formatNumber(project_detail.plannedWork)) + } % Completed diff --git a/src/utils/dateUtils.jsx b/src/utils/dateUtils.jsx index 0105d4aa..4d6643b6 100644 --- a/src/utils/dateUtils.jsx +++ b/src/utils/dateUtils.jsx @@ -69,4 +69,13 @@ export const formatNumber = (num) => { }; export const formatUTCToLocalTime = (datetime) =>{ return moment.utc(datetime).local().format("MMMM DD, YYYY [at] hh:mm A"); +} + +export const getCompletionPercentage = (completedWork, plannedWork)=> { + if (!plannedWork || plannedWork === 0) return 0; + + const percentage = (completedWork / plannedWork) * 100; + const clamped = Math.min(Math.max(percentage, 0), 100); + + return clamped.toFixed(2); } \ No newline at end of file -- 2.43.0 From 679d5d167f450479c4f09b2731eaa3b6c8f3c6d8 Mon Sep 17 00:00:00 2001 From: pramod mahajan Date: Mon, 14 Jul 2025 23:41:51 +0530 Subject: [PATCH 06/14] dynamically updated completed planned work at project lis and workarea when going to create new sub task --- src/components/Activities/SubTask.jsx | 46 ++++++++++++++++----------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/src/components/Activities/SubTask.jsx b/src/components/Activities/SubTask.jsx index 43a3c049..4014673b 100644 --- a/src/components/Activities/SubTask.jsx +++ b/src/components/Activities/SubTask.jsx @@ -9,7 +9,7 @@ import { import showToast from "../../services/toastService"; import ProjectRepository from "../../repositories/ProjectRepository"; import { useTaskById } from "../../hooks/useTasks"; -import {useManageTask} from "../../hooks/useProjects"; +import { useManageTask } from "../../hooks/useProjects"; const subTaskSchema = z.object({ activityId: z.string().min(1, "Activity is required"), @@ -37,14 +37,13 @@ const SubTask = ({ activity, onClose }) => { }); const selectedActivityId = watch("activityId"); const selectedActivity = activities?.find((a) => a.id === selectedActivityId); - const {mutate:createSubTask,isPending } = useManageTask( { - onSuccessCallback: () => - { - showToast("Sub Task Created Successfully","success") + const { mutate: createSubTask, isPending } = useManageTask({ + onSuccessCallback: () => { + showToast("Sub Task Created Successfully", "success"); reset(); onClose(); - } - } ) + }, + }); useEffect(() => { setCategoryData(categories); @@ -73,7 +72,7 @@ const SubTask = ({ activity, onClose }) => { }; const onSubmitForm = async (formData) => { - let payload = { + let data = { workAreaID: Task.workItem.workAreaId, workCategoryId: formData.workCategoryId, activityID: formData.activityId, @@ -82,8 +81,19 @@ const SubTask = ({ activity, onClose }) => { parentTaskId: activity?.id, comment: formData.comment, }; - - createSubTask([payload]) + + const payload = [data]; + let buildingId = activity.workItem.workArea.floor.building.id; + let floorId = activity.workItem.workArea.floor.id; + let workAreaId = activity.workItem.workArea.id; + createSubTask({ + payload: payload, + buildingId: buildingId, + floorId: floorId, + workAreaId: workAreaId, + PreviousPlannedWork:0, + previousCompletedWork:0 + }); }; return (
@@ -147,15 +157,15 @@ const SubTask = ({ activity, onClose }) => { disabled > + {loading ? "Loading..." : "-- Select Activity --"} + - {!loading && - activities?.map((activity) => ( - - ))} + {!loading && + activities?.map((activity) => ( + + ))} {errors.activityId && (
{errors.activityId.message}
-- 2.43.0 From 5ec982778d0ef232a9c44b3ba8e110b04b5c05ae Mon Sep 17 00:00:00 2001 From: pramod mahajan Date: Tue, 15 Jul 2025 10:21:17 +0530 Subject: [PATCH 07/14] added view team memeber and all employee --- src/pages/employee/EmployeeList.jsx | 36 +++++++++++++---------------- src/utils/constants.jsx | 5 ++++ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/pages/employee/EmployeeList.jsx b/src/pages/employee/EmployeeList.jsx index ef470979..002d77d4 100644 --- a/src/pages/employee/EmployeeList.jsx +++ b/src/pages/employee/EmployeeList.jsx @@ -9,7 +9,7 @@ import { useEmployeesAllOrByProjectId, useSuspendEmployee } from "../../hooks/us import { useProjects } from "../../hooks/useProjects"; import { useProfile } from "../../hooks/useProfile"; import { hasUserPermission } from "../../utils/authUtils"; -import { ITEMS_PER_PAGE, MANAGE_EMPLOYEES } from "../../utils/constants"; +import { ITEMS_PER_PAGE, MANAGE_EMPLOYEES, VIEW_ALL_EMPLOYEES, VIEW_TEAM_MEMBERS } from "../../utils/constants"; import { clearCacheKey } from "../../slices/apiDataManager"; import { useHasUserPermission } from "../../hooks/useHasUserPermission"; import SuspendEmp from "../../components/Employee/SuspendEmp"; // Keep if you use SuspendEmp @@ -56,6 +56,8 @@ const EmployeeList = () => { const [IsDeleteModalOpen, setIsDeleteModalOpen] = useState(false); const [selectedEmpFordelete, setSelectedEmpFordelete] = useState(null); const [ employeeLodaing, setemployeeLodaing ] = useState( false ); + const ViewTeamMember = useHasUserPermission(VIEW_TEAM_MEMBERS) + const ViewAllEmployee = useHasUserPermission(VIEW_ALL_EMPLOYEES) const { mutate: suspendEmployee, isPending: empLodaing @@ -120,23 +122,6 @@ useEffect(() => { setIsCreateModalOpen(true); }; - // const closeModal = () => { - // setIsCreateModalOpen(false); - - // const modalElement = document.getElementById("managerole-modal"); - // if (modalElement && !showModal) { - // modalElement.classList.remove("show"); - // modalElement.style.display = "none"; - // document.body.classList.remove("modal-open"); - // document.querySelector(".modal-backdrop")?.remove(); - // } - // setShowModal(false); - // clearCacheKey("employeeProfile"); - // recallEmployeeData(showInactive, showAllEmployees ? null : selectedProjectId); // Use selectedProjectId here - // }; - // const handleShow = () => setShowModal(true); - // const handleClose = () => setShowModal( false ); - useEffect(() => { if (!loading && Array.isArray(employees)) { const sorted = [...employees].sort((a, b) => { @@ -296,7 +281,9 @@ const handleAllEmployeesToggle = (e) => { { label: "Employees", link: null }, ]} > -
+ + + {ViewTeamMember ? (
@@ -309,6 +296,7 @@ const handleAllEmployeesToggle = (e) => { {/* Switches: All Employees + Inactive */}
{/* All Employees Switch */} + {ViewAllEmployee && (
{ All Employees
+ ) } {/* Show Inactive Employees Switch */} {showAllEmployees && ( @@ -702,7 +691,14 @@ const handleAllEmployeesToggle = (e) => {
-
+
):( +
+
+ +

Access Denied: You don't have permission to perform this action. !

+
+
+ )}
); diff --git a/src/utils/constants.jsx b/src/utils/constants.jsx index fca560af..f8d14a30 100644 --- a/src/utils/constants.jsx +++ b/src/utils/constants.jsx @@ -11,6 +11,11 @@ export const VIEW_PROJECTS = "6ea44136-987e-44ba-9e5d-1cf8f5837ebc" export const MANAGE_EMPLOYEES = "a97d366a-c2bb-448d-be93-402bd2324566" +export const VIEW_ALL_EMPLOYEES = "60611762-7f8a-4fb5-b53f-b1139918796b" + +export const VIEW_TEAM_MEMBERS = "b82d2b7e-0d52-45f3-997b-c008ea460e7f" + + export const MANAGE_PROJECT_INFRA = "cf2825ad-453b-46aa-91d9-27c124d63373" export const VIEW_PROJECT_INFRA = "8d7cc6e3-9147-41f7-aaa7-fa507e450bd4" -- 2.43.0 From 999b8bfb9927d9d4ad6b76437983081b428ae622 Mon Sep 17 00:00:00 2001 From: pramod mahajan Date: Tue, 15 Jul 2025 10:34:35 +0530 Subject: [PATCH 08/14] added permission rights in daily task report --- src/pages/Activities/DailyTask.jsx | 8 +++++++- src/utils/constants.jsx | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pages/Activities/DailyTask.jsx b/src/pages/Activities/DailyTask.jsx index dba18d18..fb121a89 100644 --- a/src/pages/Activities/DailyTask.jsx +++ b/src/pages/Activities/DailyTask.jsx @@ -14,6 +14,8 @@ import GlobalModel from "../../components/common/GlobalModel"; import AssignTask from "../../components/Project/AssignTask"; import SubTask from "../../components/Activities/SubTask"; import {formatNumber} from "../../utils/dateUtils"; +import { useHasUserPermission } from "../../hooks/useHasUserPermission"; +import { APPROVE_TASK, ASSIGN_REPORT_TASK } from "../../utils/constants"; const DailyTask = () => { const [searchParams] = useSearchParams(); @@ -32,6 +34,8 @@ const DailyTask = () => { const [dateRange, setDateRange] = useState({ startDate: "", endDate: "" }); + const ApprovedTaskRights = useHasUserPermission(APPROVE_TASK) + const ReportTaskRights = useHasUserPermission(ASSIGN_REPORT_TASK) const { TaskList, @@ -386,6 +390,7 @@ const DailyTask = () => {
+ { ReportTaskRights && - {task.reportedDate && ( + } + {(ApprovedTaskRights && task.reportedDate ) && (
- - {/* Right: Checkbox and Project Name */} -
- {ShowAllProject == true && ( -
- setShowAllEmployees(e.target.checked)} - /> - -
- )} - {!showAllEmployees && selectedProjectName && ( -

- {selectedProjectName} -

- )} -
{/* Row 2: Time Range Buttons */} diff --git a/src/components/Layout/Header.jsx b/src/components/Layout/Header.jsx index 9c1b4b17..e4bf4e83 100644 --- a/src/components/Layout/Header.jsx +++ b/src/components/Layout/Header.jsx @@ -20,7 +20,7 @@ import { useHasUserPermission } from "../../hooks/useHasUserPermission"; import { MANAGE_PROJECT } from "../../utils/constants"; const Header = () => { - const {profile} = useProfile(); + const { profile } = useProfile(); const location = useLocation(); const dispatch = useDispatch(); const { data, loading } = useMaster(); @@ -32,6 +32,7 @@ const Header = () => { let role = roles.find((role) => role.id === joRoleId); return role ? role.name : "User"; }; + const handleLogout = (e) => { e.preventDefault(); // Prevent default anchor behavior (e.g., page reload) logout(); @@ -39,7 +40,6 @@ const Header = () => { const logout = async () => { try { - // Notify server about the logout (optional) let data = { refreshToken: localStorage.getItem("refreshToken"), }; @@ -54,6 +54,7 @@ const Header = () => { window.location.href = "/auth/login"; }) .catch((error) => { + // Even if logout API fails, clear local storage and redirect localStorage.removeItem("jwtToken"); localStorage.removeItem("refreshToken"); localStorage.removeItem("user"); @@ -71,39 +72,43 @@ const Header = () => { const handleProfilePage = () => { navigate(`/employee/${profile?.employeeInfo?.id}?for=attendance`); }; - // const { projects, loading: projectLoading } = useProjects(); + const { projectNames, loading: projectLoading, fetchData } = useProjectName(); const selectedProject = useSelector( (store) => store.localVariables.projectId ); - const selectedProjectName = projectNames?.find( - (p) => p?.id === selectedProject - )?.name; - + // Determine the display text for the project dropdown let displayText = ""; - if (selectedProjectName) { - displayText = selectedProjectName; - } else if (projectLoading && selectedProject) { - displayText = selectedProject; + if (selectedProject === null) { + displayText = "All Projects"; + } else if (selectedProject) { + const selectedProjectObj = projectNames?.find( + (p) => p?.id === selectedProject + ); + // Fallback to selectedProject ID if name not found during loading or mismatch + displayText = selectedProjectObj ? selectedProjectObj.name : selectedProject; } else if (projectLoading) { displayText = "Loading..."; } const { openChangePassword } = useChangePassword(); + useEffect(() => { if ( projectNames && - selectedProject !== " " && + projectNames.length > 0 && + selectedProject === undefined && !getCachedData("hasReceived") ) { - dispatch(setProjectId(projectNames[0]?.id)); + dispatch(setProjectId(null)); // Set to null for "All Projects" } - }, [projectNames]); + }, [projectNames, selectedProject, dispatch]); - /** Check if current page id project details page */ - const isProjectPath = /^\/projects\/[a-f0-9-]{36}$/.test(location.pathname) + + /** Check if current page is project details page or directory page */ + const isProjectPath = /^\/projects\/[a-f0-9-]{36}$/.test(location.pathname); const isDirectoryPath = /^\/directory$/.test(location.pathname); const handler = useCallback( @@ -111,58 +116,47 @@ const Header = () => { if (!HasManageProjectPermission) { await fetchData(); const projectExist = data.projectIds.some( - (item) => item == selectedProject + (item) => item === selectedProject ); if (projectExist) { cacheData("hasReceived", false); } } }, - [fetchData,projectNames,selectedProject] + [fetchData, selectedProject, HasManageProjectPermission] ); - // useEffect(() => { - // eventBus.on("assign_project_one", handler); - // return () => eventBus.off("assign_project_one", handler); - // }, [handler]); - const newProjectHandler = useCallback( async (msg) => { - if (HasManageProjectPermission && msg.keyword === "Create_Project") { await fetchData(); - } else if (projectNames.some((item) => item.id == msg.response.id)) { - console.log((projectNames.some((item) => item.id == msg.response.id))) + } else if (projectNames?.some((item) => item.id === msg.response.id)) { await fetchData(); } cacheData("hasReceived", false); }, - [HasManageProjectPermission,projectNames] + [HasManageProjectPermission, projectNames, fetchData] ); - // useEffect(() => { - // eventBus.on("project", newProjectHandler); - // return () => eventBus.off("project", newProjectHandler); - // }, [handler]); - - useDispatch( () => - { - dispatch(changeMaster("Job Role")) -},[]) + // Correct way to dispatch an action on mount useEffect(() => { - eventBus.on("assign_project_one", handler); - eventBus.on("project", newProjectHandler); + dispatch(changeMaster("Job Role")); + }, [dispatch]); - return () => { - eventBus.off("assign_project_one", handler); - eventBus.off("project", newProjectHandler); - }; -}, [handler, newProjectHandler]); + // Event bus listeners for project changes + useEffect(() => { + eventBus.on("assign_project_one", handler); + eventBus.on("project", newProjectHandler); + return () => { + eventBus.off("assign_project_one", handler); + eventBus.off("project", newProjectHandler); + }; + }, [handler, newProjectHandler]); return ( ); }; -export default Header; +export default Header; \ No newline at end of file diff --git a/src/pages/project/ProjectDetails.jsx b/src/pages/project/ProjectDetails.jsx index f34586aa..206ea20f 100644 --- a/src/pages/project/ProjectDetails.jsx +++ b/src/pages/project/ProjectDetails.jsx @@ -88,7 +88,7 @@ const ProjectDetails = () => {
- + ); } case "teams": { -- 2.43.0 From 5f8e5d16f8078e141a667d4422058e8af36bdc56 Mon Sep 17 00:00:00 2001 From: Kartik sharma Date: Mon, 14 Jul 2025 15:35:45 +0530 Subject: [PATCH 10/14] Changes in Project Selection. --- src/components/Layout/Header.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Layout/Header.jsx b/src/components/Layout/Header.jsx index e4bf4e83..9769e26b 100644 --- a/src/components/Layout/Header.jsx +++ b/src/components/Layout/Header.jsx @@ -80,7 +80,7 @@ const Header = () => { ); // Determine the display text for the project dropdown - let displayText = ""; + let displayText = "All Projects"; if (selectedProject === null) { displayText = "All Projects"; } else if (selectedProject) { -- 2.43.0 From 6ca72c7e5c465902e70908201a6340b8014873f9 Mon Sep 17 00:00:00 2001 From: Kartik sharma Date: Tue, 15 Jul 2025 14:52:23 +0530 Subject: [PATCH 11/14] added needed closed tag --- src/pages/project/ProjectDetails.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/project/ProjectDetails.jsx b/src/pages/project/ProjectDetails.jsx index 206ea20f..f34586aa 100644 --- a/src/pages/project/ProjectDetails.jsx +++ b/src/pages/project/ProjectDetails.jsx @@ -88,7 +88,7 @@ const ProjectDetails = () => {
- + ); } case "teams": { -- 2.43.0 From 33684031888169d1a859fb48b63e8381f8b41974 Mon Sep 17 00:00:00 2001 From: Kartik sharma Date: Tue, 15 Jul 2025 15:00:49 +0530 Subject: [PATCH 12/14] Changes in Dashboard dropdown adding All Projects Selection. --- src/components/Layout/Header.jsx | 103 ++++++----- src/components/Project/AboutProject.jsx | 58 ++++--- src/components/Project/ProjectCard.jsx | 24 +-- src/pages/project/ProjectDetails.jsx | 220 ++++++++++-------------- src/pages/project/ProjectListView.jsx | 8 +- src/router/AppRoutes.jsx | 2 +- 6 files changed, 186 insertions(+), 229 deletions(-) diff --git a/src/components/Layout/Header.jsx b/src/components/Layout/Header.jsx index 9769e26b..9023d007 100644 --- a/src/components/Layout/Header.jsx +++ b/src/components/Layout/Header.jsx @@ -1,3 +1,4 @@ + import getGreetingMessage from "../../utils/greetingHandler"; import { cacheData, @@ -26,6 +27,8 @@ const Header = () => { const { data, loading } = useMaster(); const navigate = useNavigate(); const HasManageProjectPermission = useHasUserPermission(MANAGE_PROJECT); + const isDashboard = location.pathname === "/dashboard"; + // const isDirectoryPath = location.pathname === "/directory"; const getRole = (roles, joRoleId) => { if (!Array.isArray(roles)) return "User"; @@ -99,7 +102,7 @@ const Header = () => { if ( projectNames && projectNames.length > 0 && - selectedProject === undefined && + selectedProject === undefined && !getCachedData("hasReceived") ) { dispatch(setProjectId(null)); // Set to null for "All Projects" @@ -108,7 +111,7 @@ const Header = () => { /** Check if current page is project details page or directory page */ - const isProjectPath = /^\/projects\/[a-f0-9-]{36}$/.test(location.pathname); + // const isProjectPath = /^\/projects\/[a-f0-9-]{36}$/.test(location.pathname); const isDirectoryPath = /^\/directory$/.test(location.pathname); const handler = useCallback( @@ -172,69 +175,61 @@ const Header = () => { id="navbar-collapse" > {/* Project Selection Dropdown */} - {projectNames && ( // Ensure projectNames is not null before rendering dropdown + {projectNames && !isDirectoryPath && (
- {(!isProjectPath && !isDirectoryPath) && ( - <> - -
- + +
+ - {/* Render dropdown menu only if there are projects or the "All Projects" option is relevant */} - {projectNames.length > 0 && ( -
    - {/* "All Projects" option */} -
  • + {projectNames.length > 0 && ( +
      + {/* Show "All Projects" only on dashboard */} + {isDashboard && ( +
    • + +
    • + )} + {[...projectNames] + .sort((a, b) => a?.name?.localeCompare(b.name)) + .map((project) => ( +
    • - {[...projectNames] - .sort((a, b) => a?.name?.localeCompare(b.name)) - .map((project) => ( -
    • - -
    • - ))} -
    - )} -
- - )} + ))} + + )} +
)} {/* Display project name on project details or directory pages */} - {isProjectPath && ({displayText})} + {/* { ({displayText})} */} {/* User Profile and Shortcuts */}