Merge branch 'Kartik_Task#832' of https://git.marcoaiot.com/admin/marco.pms.web into Kartik_Task#832
This commit is contained in:
commit
71ee3e65d9
@ -4,6 +4,7 @@ import {
|
||||
clearAllCache,
|
||||
getCachedData,
|
||||
useSelectedproject,
|
||||
useSelectedproject,
|
||||
} from "../../slices/apiDataManager";
|
||||
import AuthRepository from "../../repositories/AuthRepository";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
@ -14,17 +15,20 @@ import { useLocation, useNavigate, useParams } from "react-router-dom";
|
||||
import Avatar from "../../components/common/Avatar";
|
||||
import { useChangePassword } from "../Context/ChangePasswordContext";
|
||||
import { useProjects, useProjectName } from "../../hooks/useProjects"; // Make sure useProjects is imported if needed elsewhere
|
||||
import { useProjects, useProjectName } from "../../hooks/useProjects"; // Make sure useProjects is imported if needed elsewhere
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import eventBus from "../../services/eventBus";
|
||||
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
||||
import { MANAGE_PROJECT } from "../../utils/constants";
|
||||
import { useMemo } from "react";
|
||||
import { useMemo } from "react";
|
||||
|
||||
const Header = () => {
|
||||
const { profile } = useProfile();
|
||||
const location = useLocation();
|
||||
const dispatch = useDispatch();
|
||||
const { data, loading: masterLoading } = useMaster(); // Renamed loading to masterLoading for clarity
|
||||
const { data, loading: masterLoading } = useMaster(); // Renamed loading to masterLoading for clarity
|
||||
const navigate = useNavigate();
|
||||
const HasManageProjectPermission = useHasUserPermission(MANAGE_PROJECT);
|
||||
|
||||
@ -85,6 +89,7 @@ const Header = () => {
|
||||
navigate(`/employee/${profile?.employeeInfo?.id}?for=attendance`);
|
||||
};
|
||||
|
||||
const { projectNames, loading: projectLoading, fetchData } = useProjectName(); // Renamed loading to projectLoading
|
||||
const { projectNames, loading: projectLoading, fetchData } = useProjectName(); // Renamed loading to projectLoading
|
||||
|
||||
const selectedProject = useSelectedproject();
|
||||
@ -120,6 +125,17 @@ const Header = () => {
|
||||
}
|
||||
// Determine the display text for the project dropdown
|
||||
let displayText = "Loading..."; // Default to loading
|
||||
if (!projectLoading && projectNames) { // Only update if not loading and projectNames is available
|
||||
if (selectedProject === null) {
|
||||
displayText = "All Projects";
|
||||
} else {
|
||||
// Find the selected project from the full projectNames list
|
||||
const selectedProjectObj = projectNames.find( // Use projectNames directly here
|
||||
(p) => p?.id === selectedProject
|
||||
);
|
||||
displayText = selectedProjectObj ? selectedProjectObj.name : "All Projects"; // Fallback to "All Projects" if selected project is not found
|
||||
}
|
||||
let displayText = "Loading..."; // Default to loading
|
||||
if (!projectLoading && projectNames) { // Only update if not loading and projectNames is available
|
||||
if (selectedProject === null) {
|
||||
displayText = "All Projects";
|
||||
@ -133,6 +149,7 @@ const Header = () => {
|
||||
}
|
||||
|
||||
|
||||
|
||||
const { openChangePassword } = useChangePassword();
|
||||
|
||||
// Effect to set initial projectId based on scenarios
|
||||
@ -161,6 +178,7 @@ const Header = () => {
|
||||
}
|
||||
}
|
||||
}, [projectNames, selectedProject, dispatch, isDashboard, allowedProjectStatusIds]);
|
||||
}, [projectNames, selectedProject, dispatch, isDashboard, allowedProjectStatusIds]);
|
||||
|
||||
|
||||
const handler = useCallback(
|
||||
@ -182,6 +200,7 @@ const Header = () => {
|
||||
async (msg) => {
|
||||
if (HasManageProjectPermission && msg.keyword === "Create_Project") {
|
||||
await fetchData();
|
||||
await fetchData();
|
||||
} else if (projectNames?.some((item) => item.id === msg.response.id)) {
|
||||
await fetchData();
|
||||
}
|
||||
@ -205,6 +224,17 @@ const Header = () => {
|
||||
}, [handler, newProjectHandler]);
|
||||
|
||||
|
||||
const handleProjectChange = (projectId) => {
|
||||
dispatch(setProjectId(projectId));
|
||||
if (isProjectPath && projectId !== null) {
|
||||
navigate(`/projects/details?resetDates=true`);
|
||||
} else if (isProjectPath && projectId === null) {
|
||||
navigate("/projects");
|
||||
} else if (isDashboard) {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const handleProjectChange = (projectId) => {
|
||||
dispatch(setProjectId(projectId));
|
||||
if (isProjectPath && projectId !== null) {
|
||||
@ -259,6 +289,8 @@ const Header = () => {
|
||||
? projectsForDropdown[0].name
|
||||
: (isDashboard ? "All Projects" : "No Projects")) // Handle "No Projects" for non-dashboard views
|
||||
}
|
||||
: (isDashboard ? "All Projects" : "No Projects")) // Handle "No Projects" for non-dashboard views
|
||||
}
|
||||
</span>
|
||||
)}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user