From 13a4725a3f413f773e0691b1a689f7d6abcbfdff Mon Sep 17 00:00:00 2001 From: Gaurika Mahajan Date: Wed, 21 Aug 2024 21:47:33 -0400 Subject: [PATCH] added protection to make sure that only registered frosh can access frosh olympiks page --- client/src/pages/FroshOlympiks/FroshOlympiks.jsx | 13 ++++++++++++- client/src/pages/Profile/PageProfileFrosh.jsx | 2 +- client/src/util/pages.jsx | 6 +++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/client/src/pages/FroshOlympiks/FroshOlympiks.jsx b/client/src/pages/FroshOlympiks/FroshOlympiks.jsx index 307f5bc7..dfce03f0 100644 --- a/client/src/pages/FroshOlympiks/FroshOlympiks.jsx +++ b/client/src/pages/FroshOlympiks/FroshOlympiks.jsx @@ -1,11 +1,22 @@ import React, { useState, useEffect, useContext } from 'react'; import './FroshOlympiks.scss'; -import { Link } from 'react-router-dom'; +import { Link, useNavigate } from 'react-router-dom'; +import { registeredSelector, userSelector } from '../../state/user/userSlice'; +import { useSelector } from 'react-redux'; import { ScheduleComponent } from '../../components/schedule/ScheduleOlympiks/ScheduleOlympiks'; import useAxios from '../../hooks/useAxios'; const { axios } = useAxios(); export const FroshOlympiks = () => { + const navigate = useNavigate(); + const isRegistered = useSelector(registeredSelector); + + useEffect(() => { + if (!isRegistered) { + navigate('/profile'); + } + }, [isRegistered]); + return ( <> diff --git a/client/src/pages/Profile/PageProfileFrosh.jsx b/client/src/pages/Profile/PageProfileFrosh.jsx index 04cac246..b21e20a9 100644 --- a/client/src/pages/Profile/PageProfileFrosh.jsx +++ b/client/src/pages/Profile/PageProfileFrosh.jsx @@ -56,7 +56,7 @@ const PageProfileFrosh = () => {
{user?.attendingScunt === true ? : null} - + {isRegistered ? : null} {/* */} diff --git a/client/src/util/pages.jsx b/client/src/util/pages.jsx index 73ed2486..b4437892 100644 --- a/client/src/util/pages.jsx +++ b/client/src/util/pages.jsx @@ -202,7 +202,11 @@ export const pages = { }, { label: 'frosh-olympiks', - component: , + component: ( + + + + ), path: '/frosh-olympiks', includeFooter: true, },