mirror of
https://github.com/lemeow125/Borrowing-TrackerFrontend.git
synced 2025-09-17 04:59:35 +08:00
Further simplified the dashboard page and moved functionality to separate components
This commit is contained in:
parent
d220078e69
commit
fce4725ff9
4 changed files with 34 additions and 74 deletions
|
@ -1,6 +1,8 @@
|
|||
import React from "react";
|
||||
import { UserAPI } from "../API/API";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { CircularProgress } from "@mui/material";
|
||||
import styles from "../../styles";
|
||||
|
||||
type props = {
|
||||
allow_only: string;
|
||||
|
@ -8,6 +10,21 @@ type props = {
|
|||
};
|
||||
export default function RestrictedComponent(props: props) {
|
||||
const user = useQuery({ queryKey: ["user"], queryFn: UserAPI });
|
||||
if (user.isLoading) {
|
||||
return (
|
||||
<>
|
||||
<CircularProgress style={{ height: "128px", width: "128px" }} />
|
||||
<p
|
||||
style={{
|
||||
...styles.text_dark,
|
||||
...styles.text_L,
|
||||
}}
|
||||
>
|
||||
Loading
|
||||
</p>
|
||||
</>
|
||||
);
|
||||
}
|
||||
if (props.allow_only === "Teacher") {
|
||||
if (user.data && user.data.is_teacher) {
|
||||
return <>{props.children}</>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue