feat(frontend): settings page added
This commit is contained in:
47
frontend/src/components/admin/settings/SettingsPage.tsx
Normal file
47
frontend/src/components/admin/settings/SettingsPage.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
import {LstCard} from "@/components/extendedUI/LstCard";
|
||||
import {useSessionStore} from "@/lib/store/sessionStore";
|
||||
import {useModuleStore} from "@/lib/store/useModuleStore";
|
||||
import {useQuery} from "@tanstack/react-query";
|
||||
import {useRouter} from "@tanstack/react-router";
|
||||
import axios from "axios";
|
||||
|
||||
export default function SettingsPage() {
|
||||
const token = localStorage.getItem("auth_token");
|
||||
const {user} = useSessionStore();
|
||||
const {modules} = useModuleStore();
|
||||
const router = useRouter();
|
||||
|
||||
const fetchSettings = async () => {
|
||||
const {data} = await axios.get("/api/server/settings", {headers: {Authorization: `Bearer ${token}`}});
|
||||
return data.data;
|
||||
};
|
||||
|
||||
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: "/"});
|
||||
}
|
||||
|
||||
const {data, isError, error, isLoading} = useQuery({
|
||||
queryKey: ["settings"],
|
||||
queryFn: fetchSettings,
|
||||
enabled: !!token,
|
||||
refetchOnWindowFocus: true,
|
||||
});
|
||||
|
||||
if (isLoading) {
|
||||
return <div>Loading.....</div>;
|
||||
}
|
||||
if (isError) {
|
||||
return <div>{JSON.stringify(error)}</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
{data.map((i) => {
|
||||
return <LstCard key={i.settings_id}>{i.name}</LstCard>;
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user