diff --git a/src/components/Employee/EmpAttendance.jsx b/src/components/Employee/EmpAttendance.jsx
index d3cbe817..b8ff8b83 100644
--- a/src/components/Employee/EmpAttendance.jsx
+++ b/src/components/Employee/EmpAttendance.jsx
@@ -22,6 +22,7 @@ const EmpAttendance = ({ employee }) => {
data = [],
isLoading: loading,
isFetching,
+ isError,
error,
refetch,
} = useAttendanceByEmployee(employee, dateRange.startDate, dateRange.endDate);
@@ -145,7 +146,7 @@ const EmpAttendance = ({ employee }) => {
{!loading && data.length === 0 &&
No employee logs}
- {error &&
{error}
}
+ {isError &&
{error.message}
}
{loading && !data &&
Loading...
}
{data && data.length > 0 && (
diff --git a/src/components/Layout/MenuItemSkeleton.jsx b/src/components/Layout/MenuItemSkeleton.jsx
new file mode 100644
index 00000000..304c33c3
--- /dev/null
+++ b/src/components/Layout/MenuItemSkeleton.jsx
@@ -0,0 +1,36 @@
+
+const SkeletonLine = ({ height = 50, width = "100%", className = "" }) => (
+
+);
+export const MenuItemSkeleton = ({ hasSubmenu = false, submenuCount = 3 }) => {
+ return (
+
+
+ {/* icon placeholder */}
+
+ {/* text placeholder */}
+
+
+
+ {/* Submenu skeletons */}
+ {hasSubmenu && (
+
+ {[...Array(submenuCount)].map((_, idx) => (
+ -
+
+
+
+
+
+ ))}
+
+ )}
+
+ );
+};
diff --git a/src/components/Layout/Sidebar.jsx b/src/components/Layout/Sidebar.jsx
index de754542..c6f16e61 100644
--- a/src/components/Layout/Sidebar.jsx
+++ b/src/components/Layout/Sidebar.jsx
@@ -2,10 +2,13 @@ import React from "react";
import { Link, NavLink, useLocation, useNavigate } from "react-router-dom";
import menuData from "../../data/menuData.json";
import { getCachedProfileData } from "../../slices/apiDataManager";
+import { useSidBarMenu } from "../../hooks/useProfile";
+import { MenuItemSkeleton } from "./MenuItemSkeleton";
const Sidebar = () => {
const navigate = useNavigate();
-
+ const { data, isError, isLoading, isFetched,error } = useSidBarMenu();
+ console.log(data)
return (
);
};
const MenuItem = (item) => {
- item.id = Math.random();
const location = useLocation();
const isActive = location.pathname === item.link;
- const hasSubmenu = item.submenu && item.submenu.length > 0;
+ const hasSubmenu = Array.isArray(item.submenu) && item.submenu.length > 0;
const isSubmenuActive =
- hasSubmenu &&
- item.submenu.some((subitem) => location.pathname === subitem.link);
+ hasSubmenu && item.submenu.some((sub) => location.pathname === sub.link);
return (
{
- {item.text}
{" "}
+ {item.text}
{item.available === false && (
Pro
)}
- {item.submenu && (
-
- {item.submenu.map(MenuItem)}
+
+ {/* Only render submenu if exists */}
+ {hasSubmenu && (
+
+ {item.submenu.map((sub) => (
+
+ ))}
)}
diff --git a/src/hooks/useProfile.js b/src/hooks/useProfile.js
index d9efefd1..d1619ed6 100644
--- a/src/hooks/useProfile.js
+++ b/src/hooks/useProfile.js
@@ -99,3 +99,13 @@ export const useProfile = () => {
refetch,
};
};
+
+
+export const useSidBarMenu = ()=>{
+ const userLogged = useSelector((store)=>store.globalVariables.loginUser);
+ return useQuery({
+ queryKey:["AppMenu"],
+ queryFn:async()=> await AuthRepository.appmenu(),
+ enabled: !!userLogged
+ })
+}
\ No newline at end of file
diff --git a/src/repositories/AuthRepository.jsx b/src/repositories/AuthRepository.jsx
index 4df8c89d..55ef3e3e 100644
--- a/src/repositories/AuthRepository.jsx
+++ b/src/repositories/AuthRepository.jsx
@@ -15,6 +15,8 @@ const AuthRepository = {
logout: (data) => api.post("/api/auth/logout", data),
profile: () => api.get("/api/user/profile"),
changepassword: (data) => api.post("/api/auth/change-password", data),
+ appmenu:()=>api.get('/api/AppMenu/sidebar/menu-section')
+
};
export default AuthRepository;