fix(settings page): error with the store not starting as fast as the page
This commit is contained in:
@@ -14,6 +14,7 @@ import { useRouter } from "@tanstack/react-router";
|
||||
import { ChangeSetting } from "./SettingForm";
|
||||
import { getSettings } from "@/utils/querys/settings";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { useEffect } from "react";
|
||||
|
||||
export type Settings = {
|
||||
settings_id?: string;
|
||||
@@ -27,14 +28,25 @@ export default function SettingsPage() {
|
||||
const { modules } = useModuleStore();
|
||||
const router = useRouter();
|
||||
|
||||
const adminModule = modules.filter((n) => n.name === "admin");
|
||||
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[0].module_id) ||
|
||||
user?.roles?.filter((r) => r.module_id === adminModule.module_id) ||
|
||||
[];
|
||||
|
||||
if (!adminModule[0].roles.includes(userLevel[0]?.role)) {
|
||||
router.navigate({ to: "/" });
|
||||
if (!adminModule.roles?.includes(userLevel[0]?.role)) {
|
||||
console.log("Something failed");
|
||||
//router.navigate({ to: "/" });
|
||||
}
|
||||
}, [modules, user, router]);
|
||||
|
||||
const { data, isError, error, isLoading } = useQuery(
|
||||
getSettings(token ?? "")
|
||||
|
||||
Reference in New Issue
Block a user