fix(submodules): correction to accessing when changes made to roles

This commit is contained in:
2025-07-23 10:10:18 -05:00
parent e1113c49b3
commit 3e680a5a50

View File

@@ -15,6 +15,7 @@ import { ChangeSubModule } from "./SubModuleForm";
import { Skeleton } from "@/components/ui/skeleton";
import { getSubModules } from "@/utils/querys/admin/subModules";
import { useEffect } from "react";
export type Settings = {
settings_id?: string;
@@ -28,14 +29,34 @@ export default function SubModulePage() {
const { modules } = useModuleStore();
const router = useRouter();
const adminModule = modules.filter((n) => n.name === "admin");
const userLevel =
user?.roles.filter((r) => r.module_id === adminModule[0].module_id) ||
[];
// const adminModule = modules.filter((n) => n.name === "admin");
// const userLevel =
// user?.roles.filter((r) => r.module_id === adminModule[0].module_id) ||
// [];
if (!adminModule[0].roles.includes(userLevel[0]?.role)) {
router.navigate({ to: "/" });
}
// if (!adminModule[0]?.roles.includes(userLevel[0]?.role)) {
// //router.navigate({ to: "/" });
// }
useEffect(() => {
if (!user || modules.length === 0) return;
const adminModule = modules.find((n) => n.name === "admin");
if (!adminModule) {
console.log("no module loaded");
//router.navigate({ to: "/" });
return;
}
const userLevel =
user?.roles?.filter((r) => r.module_id === adminModule.module_id) ||
[];
if (!adminModule.roles?.includes(userLevel[0]?.role)) {
console.log("Something failed");
//router.navigate({ to: "/" });
}
}, [modules, user, router]);
const { data, isError, error, isLoading } = useQuery(
getSubModules(token ?? "")