From be6e1ba229d5ab71d64626e470d43ab9169f1758 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Thu, 14 Dec 2023 18:08:27 +0800 Subject: [PATCH] Added student type to component and page restrictions --- .../RestrictedComponent/RestrictedComponent.tsx | 4 ++++ src/Components/RestrictedPage/RestrictedPage.tsx | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/Components/RestrictedComponent/RestrictedComponent.tsx b/src/Components/RestrictedComponent/RestrictedComponent.tsx index 8539599..8517d54 100644 --- a/src/Components/RestrictedComponent/RestrictedComponent.tsx +++ b/src/Components/RestrictedComponent/RestrictedComponent.tsx @@ -33,6 +33,10 @@ export default function RestrictedComponent(props: props) { if (user.data && user.data.is_technician) { return <>{props.children}; } + } else if (props.allow_only === "Student") { + if (user.data && !user.data.is_technician && !user.data.is_teacher) { + return <>{props.children}; + } } return <>; } diff --git a/src/Components/RestrictedPage/RestrictedPage.tsx b/src/Components/RestrictedPage/RestrictedPage.tsx index f8cf63f..8e9f6a0 100644 --- a/src/Components/RestrictedPage/RestrictedPage.tsx +++ b/src/Components/RestrictedPage/RestrictedPage.tsx @@ -39,6 +39,20 @@ export default function RestrictedPage(props: props) { theme: "light", }); } + } else if (props.allow_only == "Student") { + if (user.data && (user.data.is_technician || user.data.is_teacher)) { + navigate("/"); + toast("You are not a student!", { + position: "bottom-center", + autoClose: 2000, + hideProgressBar: false, + closeOnClick: true, + pauseOnHover: true, + draggable: true, + progress: undefined, + theme: "light", + }); + } } }, [navigate, props.allow_only, user.data]);