diff --git a/src/components/Layout/Header.jsx b/src/components/Layout/Header.jsx index 38966865..7a1a6aaa 100644 --- a/src/components/Layout/Header.jsx +++ b/src/components/Layout/Header.jsx @@ -1,4 +1,3 @@ - import getGreetingMessage from "../../utils/greetingHandler"; import { cacheData, @@ -28,9 +27,19 @@ const Header = () => { const navigate = useNavigate(); const HasManageProjectPermission = useHasUserPermission(MANAGE_PROJECT); - const isDirectoryPath = /^\/directory$/.test(location.pathname); - const isProjectPath = /^\/projects$/.test(location.pathname); - const isDashboard = /^\/dashboard$/.test(location.pathname) || /^\/$/.test(location.pathname) ; + const isDirectoryPath = /^\/directory$/.test(location.pathname); + const isProjectPath = /^\/projects$/.test(location.pathname); + const isDashboard = + /^\/dashboard$/.test(location.pathname) || /^\/$/.test(location.pathname); + + // Define the specific project status IDs you want to filter by + const allowedProjectStatusIds = [ + "603e994b-a27f-4e5d-a251-f3d69b0498ba", // On Hold + "cdad86aa-8a56-4ff4-b633-9c629057dfef", // In Progress + "ef1c356e-0fe0-42df-a5d3-8daee355492d", // Inactive + "b74da4c2-d07e-46f2-9919-e75e49b12731", // Active + ]; + const getRole = (roles, joRoleId) => { if (!Array.isArray(roles)) return "User"; let role = roles.find((role) => role.id === joRoleId); @@ -38,7 +47,7 @@ const Header = () => { }; const handleLogout = (e) => { - e.preventDefault(); + e.preventDefault(); logout(); }; @@ -83,11 +92,20 @@ const Header = () => { (store) => store.localVariables.projectId ); + // Conditional filtering for projectsForDropdown + // If on Dashboard, show all projects. Otherwise, filter by allowedProjectStatusIds. + const projectsForDropdown = isDashboard + ? projectNames // On dashboard, show all projects + : projectNames?.filter(project => + allowedProjectStatusIds.includes(project.projectStatusId) + ); + // Determine the display text for the project dropdown let displayText = "All Projects"; if (selectedProject === null) { displayText = "All Projects"; } else if (selectedProject) { + // Find the selected project from the full projectNames list const selectedProjectObj = projectNames?.find( (p) => p?.id === selectedProject ); @@ -101,22 +119,20 @@ const Header = () => { useEffect(() => { if ( - projectNames && + projectNames && // Use the original projectNames for initial setting to ensure all are considered for initial state if needed projectNames.length > 0 && selectedProject === undefined && !getCachedData("hasReceived") ) { - if(isDashboard){ - dispatch(setProjectId(null)); - }else{ - dispatch(setProjectId(projectNames[0]?.id)); + if (isDashboard) { + dispatch(setProjectId(null)); // Always set to null for "All Projects" on Dashboard initial load + } else { + // If not dashboard, set to the first project that matches the allowed statuses if available + const firstAllowedProject = projectNames.find(project => allowedProjectStatusIds.includes(project.projectStatusId)); + dispatch(setProjectId(firstAllowedProject?.id || null)); // Fallback to null if no allowed projects } } - }, [projectNames, selectedProject, dispatch]); - - - /** Check if current page is project details page or directory page */ - // const isProjectPath = /^\/projects\/[a-f0-9-]{36}$/.test(location.pathname); + }, [projectNames, selectedProject, dispatch, isDashboard]); const handler = useCallback( @@ -160,15 +176,16 @@ const Header = () => { }; }, [handler, newProjectHandler]); - const handleProjectChange =(project)=>{ - if(isProjectPath){ - dispatch(setProjectId(project)) - navigate("/projects/details") - } else{ - dispatch(setProjectId(project)) - } - } + const handleProjectChange = (project) => { + dispatch(setProjectId(project)); // Always set the projectId + if (isProjectPath && project !== null) { + navigate("/projects/details"); // Navigate only if on /projects and a specific project is selected + } + // No navigation if on dashboard or if "All Projects" is selected + }; + + console.log("Kartik sharma", projectNames); return (