diff --git a/src/components/Layout/Header.jsx b/src/components/Layout/Header.jsx
index 29e7daa8..b5b62579 100644
--- a/src/components/Layout/Header.jsx
+++ b/src/components/Layout/Header.jsx
@@ -37,7 +37,7 @@ const Header = () => {
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
+ // "ef1c356e-0fe0-42df-a5d3-8daee355492d", // Inactive - Removed as per requirement
"b74da4c2-d07e-46f2-9919-e75e49b12731", // Active
];
diff --git a/src/hooks/useDashboard_Data.jsx b/src/hooks/useDashboard_Data.jsx
index 831d9092..0322566a 100644
--- a/src/hooks/useDashboard_Data.jsx
+++ b/src/hooks/useDashboard_Data.jsx
@@ -104,17 +104,15 @@ export const useDashboardTeamsCardData = (projectId) => {
useEffect(() => {
const fetchTeamsData = async () => {
- if (!projectId) return; // ✅ Skip if projectId is not provided
-
setLoading(true);
setError("");
try {
const response = await GlobalRepository.getDashboardTeamsCardData(projectId);
- setTeamsData(response.data); // ✅ Handle undefined/null
+ setTeamsData(response.data || {});
} catch (err) {
setError("Failed to fetch teams card data.");
- console.error(err);
+ console.error("Error fetching teams card data:", err);
setTeamsData({});
} finally {
setLoading(false);
diff --git a/src/pages/Activities/AttendancePage.jsx b/src/pages/Activities/AttendancePage.jsx
index 34b5e94c..b3224bde 100644
--- a/src/pages/Activities/AttendancePage.jsx
+++ b/src/pages/Activities/AttendancePage.jsx
@@ -1,57 +1,50 @@
import React, { useState, useEffect, useCallback } from "react";
import {
cacheData,
+ clearCacheKey,
+ getCachedData,
getCachedProfileData,
-} from "../../slices/apiDataManager"; // clearCacheKey and getCachedData are not used
+} from "../../slices/apiDataManager";
import Breadcrumb from "../../components/common/Breadcrumb";
import AttendanceLog from "../../components/Activities/AttendcesLogs";
import Attendance from "../../components/Activities/Attendance";
-// import AttendanceModel from "../../components/Activities/AttendanceModel";
+import AttendanceModel from "../../components/Activities/AttendanceModel";
import showToast from "../../services/toastService";
-// import { useProjects } from "../../hooks/useProjects";
import Regularization from "../../components/Activities/Regularization";
import { useAttendance } from "../../hooks/useAttendance";
import { useDispatch, useSelector } from "react-redux";
import { setProjectId } from "../../slices/localVariablesSlice";
-// import { markCurrentAttendance } from "../../slices/apiSlice/attendanceAllSlice";
-import { hasUserPermission } from "../../utils/authUtils";
+import { markCurrentAttendance } from "../../slices/apiSlice/attendanceAllSlice";
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
import { REGULARIZE_ATTENDANCE } from "../../utils/constants";
import eventBus from "../../services/eventBus";
-// import AttendanceRepository from "../../repositories/AttendanceRepository";
+import AttendanceRepository from "../../repositories/AttendanceRepository";
import { useProjectName } from "../../hooks/useProjects";
-import GlobalModel from "../../components/common/GlobalModel";
-import CheckCheckOutmodel from "../../components/Activities/CheckCheckOutForm";
-import AttendLogs from "../../components/Activities/AttendLogs";
-// import Confirmation from "../../components/Activities/Confirmation";
-import { useQueryClient } from "@tanstack/react-query";
const AttendancePage = () => {
const [activeTab, setActiveTab] = useState("all");
const [showPending, setShowPending] = useState(false);
const [searchQuery, setSearchQuery] = useState("");
- // const loginUser = getCachedProfileData(); // Declared but not used
+ const loginUser = getCachedProfileData();
const selectedProject = useSelector((store) => store.localVariables.projectId);
const dispatch = useDispatch();
-
const {
attendance,
loading: attLoading,
- // recall: attrecall, // Declared but not used in the current logic
+ recall: attrecall,
} = useAttendance(selectedProject);
const [attendances, setAttendances] = useState();
- const [empRoles, setEmpRoles] = useState(null); // This state is declared but never populated or used
+ const [empRoles, setEmpRoles] = useState(null);
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
- const [modelConfig, setModelConfig] = useState(null); // Initialize with null for clarity
+ const [modelConfig, setModelConfig] = useState(null); // Initialize as null
const DoRegularized = useHasUserPermission(REGULARIZE_ATTENDANCE);
- // const { projectNames, loading: projectLoading, fetchData } = useProjectName(); // loading and fetchData are not used directly here
+ const { projectNames, loading: projectLoading, fetchData } = useProjectName();
- // FormData is declared but not used in the provided snippet's logic
- // const [formData, setFormData] = useState({
- // markTime: "",
- // description: "",
- // date: new Date().toLocaleDateString(),
- // });
+ const [formData, setFormData] = useState({
+ markTime: "",
+ description: "",
+ date: new Date().toLocaleDateString(),
+ });
const handler = useCallback(
(msg) => {
@@ -66,7 +59,7 @@ const AttendancePage = () => {
cacheData("Attendance", {
data: updatedAttendance,
- projectId: selectedProject, // Corrected key from selectedProject to projectId for consistency
+ projectId: selectedProject,
});
setAttendances(updatedAttendance);
}
@@ -76,13 +69,11 @@ const AttendancePage = () => {
const employeeHandler = useCallback(
(msg) => {
- // This logic fetches all attendance when an employee event occurs,
- // which might be inefficient if only a single employee's data needs updating.
- // Consider a more granular update if performance is an issue.
+ // This logic seems fine for refetching if an employee ID exists in current attendances
if (attendances?.some((item) => item.employeeId === msg.employeeId)) {
AttendanceRepository.getAttendance(selectedProject)
.then((response) => {
- cacheData("Attendance", { data: response.data, projectId: selectedProject }); // Corrected key
+ cacheData("Attendance", { data: response.data, selectedProject });
setAttendances(response.data);
})
.catch((error) => {
@@ -93,29 +84,27 @@ const AttendancePage = () => {
[selectedProject, attendances]
);
- // The `getRole` function has a duplicate line: `const role = empRoles.find((b) => b.id === roleId);`
- // Also, `empRoles` is declared but never set. If this function is meant to be used,
- // `empRoles` needs to be fetched and set in the state.
- const getRole = useCallback((roleId) => {
- if (!empRoles) return "Unassigned"; // empRoles is always null with current code
+ const getRole = (roleId) => {
+ if (!empRoles) return "Unassigned";
if (!roleId) return "Unassigned";
const role = empRoles.find((b) => b.id === roleId);
return role ? role.role : "Unassigned";
- }, [empRoles]);
-
- const openModel = useCallback(() => {
- setIsCreateModalOpen(true);
- }, []);
+ };
+ // Simplified and moved modal opening logic
const handleModalData = useCallback((employee) => {
setModelConfig(employee);
+ setIsCreateModalOpen(true); // Open the modal directly when data is set
}, []);
const closeModal = useCallback(() => {
setModelConfig(null);
setIsCreateModalOpen(false);
- // Directly manipulating DOM is generally discouraged in React.
- // Consider using React state to control modal visibility.
+ // Directly manipulating the DOM is generally not recommended in React.
+ // React handles modal visibility via state. If you must, ensure it's
+ // for external libraries or for very specific, controlled reasons.
+ // For a typical Bootstrap modal, just setting `isCreateModalOpen` to false
+ // should be enough if the modal component itself handles the Bootstrap classes.
const modalElement = document.getElementById("check-Out-modal");
if (modalElement) {
modalElement.classList.remove("show");
@@ -155,24 +144,17 @@ const AttendancePage = () => {
});
}, [dispatch, attendances, selectedProject]);
- const handleToggle = useCallback((event) => {
- setShowPending(event.target.checked);
- }, []);
- // Use useProjectName hook to get projectNames and set selected project
- const { projectNames } = useProjectName();
+ const handleToggle = (event) => {
+ setShowPending(event.target.checked);
+ };
+
useEffect(() => {
if (selectedProject === null && projectNames.length > 0) {
dispatch(setProjectId(projectNames[0]?.id));
}
}, [selectedProject, projectNames, dispatch]);
- useEffect(() => {
- if (modelConfig !== null) {
- openModel();
- }
- }, [modelConfig, openModel]); // Added openModel to dependency array
-
useEffect(() => {
setAttendances(attendance);
}, [attendance]);
@@ -204,8 +186,6 @@ const AttendancePage = () => {
return currentData;
}, [attendances, showPending, searchQuery]);
-
- // Event bus listeners
useEffect(() => {
eventBus.on("attendance", handler);
return () => eventBus.off("attendance", handler);
@@ -218,11 +198,11 @@ const AttendancePage = () => {
return (
<>
- {/* {isCreateModalOpen && modelConfig && (
+ {isCreateModalOpen && modelConfig && (
@@ -232,29 +212,6 @@ const AttendancePage = () => {
handleSubmitForm={handleSubmit}
/>
- )} */}
- {isCreateModalOpen && modelConfig && (
-
- {(modelConfig?.action === 0 ||
- modelConfig?.action === 1 ||
- modelConfig?.action === 2) && (
-
- )}
- {/* For view logs */}
- {modelConfig?.action === 6 && (
-
- )}
- {modelConfig?.action === 7 && (
-
- )}
-
)}
@@ -265,7 +222,10 @@ const AttendancePage = () => {
]}
>
-
+
-
+
{activeTab === "all" && (
+ <>
+ {!attLoading && (
)}
{!attLoading && filteredAndSearchedTodayAttendance()?.length === 0 && (
{" "}
- {showPending
{showPending
? "No Pending Available"
: "No Employee assigned yet."}{" "}
)}
-
+ >
)}
+
{activeTab === "logs" && (
)}
+
{activeTab === "regularization" && DoRegularized && (
{
/>
)}
+
+ {!attLoading && !attendances &&
Not Found}
@@ -362,4 +328,4 @@ const AttendancePage = () => {
);
};
-export default AttendancePage;
+export default AttendancePage;
\ No newline at end of file