Refactor_Expenses #321

Merged
pramod.mahajan merged 249 commits from Refactor_Expenses into hotfix/MasterActivity 2025-08-01 13:14:59 +00:00
Showing only changes of commit ba1864a9ff - Show all commits

View File

@ -1,4 +1,3 @@
import getGreetingMessage from "../../utils/greetingHandler"; import getGreetingMessage from "../../utils/greetingHandler";
import { import {
cacheData, cacheData,
@ -28,9 +27,20 @@ const Header = () => {
const navigate = useNavigate(); const navigate = useNavigate();
const HasManageProjectPermission = useHasUserPermission(MANAGE_PROJECT); const HasManageProjectPermission = useHasUserPermission(MANAGE_PROJECT);
const isDirectoryPath = /^\/directory$/.test(location.pathname); const isDirectoryPath = /^\/directory$/.test(location.pathname);
const isProjectPath = /^\/projects$/.test(location.pathname); const isProjectPath = /^\/projects$/.test(location.pathname);
const isDashboard = /^\/dashboard$/.test(location.pathname) || /^\/$/.test(location.pathname) ; const isDashboard =
/^\/dashboard$/.test(location.pathname) || /^\/$/.test(location.pathname);
// Define the specific project status IDs you want to filter by
// Changed to explicitly include only 'Active', 'On Hold', 'In Progress'
const allowedProjectStatusIds = [
"603e994b-a27f-4e5d-a251-f3d69b0498ba", // On Hold
"cdad86aa-8a56-4ff4-b633-9c629057dfef", // In Progress
"ef1c356e-0fe0-42df-a5d3-8daee355492d", // Inactive - Removed as per requirement
"b74da4c2-d07e-46f2-9919-e75e49b12731", // Active
];
const getRole = (roles, joRoleId) => { const getRole = (roles, joRoleId) => {
if (!Array.isArray(roles)) return "User"; if (!Array.isArray(roles)) return "User";
let role = roles.find((role) => role.id === joRoleId); let role = roles.find((role) => role.id === joRoleId);
@ -38,7 +48,7 @@ const Header = () => {
}; };
const handleLogout = (e) => { const handleLogout = (e) => {
e.preventDefault(); e.preventDefault();
logout(); logout();
}; };
@ -83,11 +93,20 @@ const Header = () => {
(store) => store.localVariables.projectId (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 // Determine the display text for the project dropdown
let displayText = "All Projects"; let displayText = "All Projects";
if (selectedProject === null) { if (selectedProject === null) {
displayText = "All Projects"; displayText = "All Projects";
} else if (selectedProject) { } else if (selectedProject) {
// Find the selected project from the full projectNames list
const selectedProjectObj = projectNames?.find( const selectedProjectObj = projectNames?.find(
(p) => p?.id === selectedProject (p) => p?.id === selectedProject
); );
@ -106,17 +125,15 @@ const Header = () => {
selectedProject === undefined && selectedProject === undefined &&
!getCachedData("hasReceived") !getCachedData("hasReceived")
) { ) {
if(isDashboard){ if (isDashboard) {
dispatch(setProjectId(null)); dispatch(setProjectId(null)); // Always set to null for "All Projects" on Dashboard initial load
}else{ } else {
dispatch(setProjectId(projectNames[0]?.id)); // 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]); }, [projectNames, selectedProject, dispatch, isDashboard]);
/** Check if current page is project details page or directory page */
// const isProjectPath = /^\/projects\/[a-f0-9-]{36}$/.test(location.pathname);
const handler = useCallback( const handler = useCallback(
@ -160,14 +177,18 @@ const Header = () => {
}; };
}, [handler, newProjectHandler]); }, [handler, newProjectHandler]);
const handleProjectChange =(project)=>{ const handleProjectChange = (project) => {
if(isProjectPath){ dispatch(setProjectId(project)); // Always set the projectId
dispatch(setProjectId(project))
navigate("/projects/details") if (isProjectPath && project !== null) {
} else{ navigate("/projects/details"); // Navigate only if on /projects and a specific project is selected
dispatch(setProjectId(project))
} }
} // No navigation if on dashboard or if "All Projects" is selected
};
// Determine if the dropdown should be shown
const shouldShowDropdown =
isDashboard || (projectsForDropdown && projectsForDropdown.length > 1);
return ( return (
<nav <nav
@ -190,39 +211,49 @@ const Header = () => {
<div className="align-items-center"> <div className="align-items-center">
<i className="rounded-circle bx bx-building-house bx-sm-lg bx-md me-2"></i> <i className="rounded-circle bx bx-building-house bx-sm-lg bx-md me-2"></i>
<div className="btn-group"> <div className="btn-group">
<button {/* Conditionally render the button based on shouldShowDropdown */}
className={`btn btn-sm-sm btn-xl ${projectNames.length > 0 ? "dropdown-toggle" : "" {shouldShowDropdown ? (
} px-1`} <button
type="button" className={`btn btn-sm-sm btn-xl ${projectsForDropdown && projectsForDropdown.length > 0 ? "dropdown-toggle" : ""
data-bs-toggle="dropdown" } px-1`}
aria-expanded="false" type="button"
> data-bs-toggle="dropdown"
{displayText} aria-expanded="false"
</button> >
{displayText}
</button>
) : (
// If only one project, just display its name without a dropdown
<span className="btn btn-sm-sm btn-xl px-1">
{projectsForDropdown && projectsForDropdown.length === 1
? projectsForDropdown[0].name
: displayText}
</span>
)}
{projectNames.length > 0 && ( {/* Only render the dropdown menu if shouldShowDropdown is true */}
{shouldShowDropdown && projectsForDropdown && projectsForDropdown.length > 0 && (
<ul <ul
className="dropdown-menu" className="dropdown-menu"
style={{ overflow: "auto", maxHeight: "300px" }} style={{ overflow: "auto", maxHeight: "300px" }}
> >
{isDashboard && ( {isDashboard && (
<li> <li>
<button <button
className="dropdown-item" className="dropdown-item"
onClick={() => dispatch(setProjectId(null))} onClick={() => handleProjectChange(null)} // Set projectId to null for "All Projects"
> >
All Projects All Projects
</button> </button>
</li> </li>
)} )}
{[...projectNames] {[...projectsForDropdown] // Sort the conditionally filtered list
.sort((a, b) => a?.name?.localeCompare(b.name)) .sort((a, b) => a?.name?.localeCompare(b.name))
.map((project) => ( .map((project) => (
<li key={project?.id}> <li key={project?.id}>
<button <button
className="dropdown-item" className="dropdown-item"
onClick={()=>handleProjectChange(project?.id)} onClick={() => handleProjectChange(project?.id)}
> >
{project?.name} {project?.name}
{project?.shortName && ( {project?.shortName && (
@ -239,7 +270,6 @@ const Header = () => {
</div> </div>
)} )}
<ul className="navbar-nav flex-row align-items-center ms-md-auto"> <ul className="navbar-nav flex-row align-items-center ms-md-auto">
<li className="nav-item dropdown-shortcuts navbar-dropdown dropdown me-2 me-xl-0"> <li className="nav-item dropdown-shortcuts navbar-dropdown dropdown me-2 me-xl-0">
<a <a