mirror of
https://github.com/lemeow125/Borrowing-TrackerFrontend.git
synced 2025-09-17 04:59:35 +08:00
Added conditional rendering to dashboard page and restrict certain pages select user types
This commit is contained in:
parent
0e4c1b9f31
commit
3d20af24c9
9 changed files with 646 additions and 468 deletions
21
src/Components/RestrictedComponent/RestrictedComponent.tsx
Normal file
21
src/Components/RestrictedComponent/RestrictedComponent.tsx
Normal file
|
@ -0,0 +1,21 @@
|
|||
import React from "react";
|
||||
import { UserAPI } from "../API/API";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
type props = {
|
||||
allow_only: string;
|
||||
children: React.ReactNode;
|
||||
};
|
||||
export default function RestrictedComponent(props: props) {
|
||||
const user = useQuery({ queryKey: ["user"], queryFn: UserAPI });
|
||||
if (props.allow_only === "Teacher") {
|
||||
if (user.data && user.data.is_teacher) {
|
||||
return <>{props.children}</>;
|
||||
}
|
||||
} else if (props.allow_only === "Technician") {
|
||||
if (user.data && user.data.is_technician) {
|
||||
return <>{props.children}</>;
|
||||
}
|
||||
}
|
||||
return <></>;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue