diff --git a/.env.template b/.env.template index 8273d819..db56ff0c 100644 --- a/.env.template +++ b/.env.template @@ -1,2 +1,3 @@ VITE_BACKEND_URL=http://localhost:8080 -VITE_GH_OAUTH_CLIENT_ID= \ No newline at end of file +VITE_GH_OAUTH_CLIENT_ID= +VITE_REGISTRATIONS_OPEN=true \ No newline at end of file diff --git a/src/App.tsx b/src/App.tsx index 07a8b9e9..09d684a6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,7 +6,7 @@ import Projects from "./pages/Projects"; import OAuth from "./pages/OAuth"; import Navbar from "./components/Navbar"; import { AuthProvider } from "./util/auth"; -import { ROUTER_PATHS } from "./util/constants"; +import { REGISTRATIONS_OPEN, ROUTER_PATHS } from "./util/constants"; import MentorDashboard from "./pages/MentorDashboard"; import ProjectForm from "./pages/ProjectForm"; import ScrollToTop from "./util/scrollToTop"; @@ -37,10 +37,10 @@ function App() { element={} /> } /> - } - /> + />} } diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index e5453de9..30845a37 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -4,7 +4,7 @@ import { CiMenuBurger } from "react-icons/ci"; import { RiCloseLine } from "react-icons/ri"; import { IconContext } from "react-icons"; import kwoc_logo from "../assets/kwoc_logo.png"; -import { ROUTER_PATHS, GH_OAUTH_URL } from "../util/constants"; +import { ROUTER_PATHS, GH_OAUTH_URL, REGISTRATIONS_OPEN } from "../util/constants"; import { useAuthContext } from "../util/auth"; import { UserType } from "../util/types"; @@ -75,6 +75,7 @@ function LoginButton({ isMobile }: { isMobile: boolean }) { /> ) : ( + REGISTRATIONS_OPEN ? ["mentor", "student"].map((userType, i) => ( - )) + )) : + + LOGIN + )} ); diff --git a/src/pages/MentorDashboard.tsx b/src/pages/MentorDashboard.tsx index bef83226..e9a8b8d9 100644 --- a/src/pages/MentorDashboard.tsx +++ b/src/pages/MentorDashboard.tsx @@ -5,7 +5,7 @@ import { IEndpointTypes } from "../util/types"; import { HiOutlineViewGridAdd } from "react-icons/hi"; import { Link, useNavigate } from "react-router-dom"; import { useAuthContext } from "../util/auth"; -import { ROUTER_PATHS } from "../util/constants"; +import { REGISTRATIONS_OPEN, ROUTER_PATHS } from "../util/constants"; import { makeRequest } from "../util/backend"; import SpinnerLoader from "../components/SpinnerLoader"; import { Profile, Resources } from "../components/DashboardElements"; @@ -67,13 +67,13 @@ function MentorDashboard() { {dashboard.projects.map((project, i) => ( ))} -
Add Project
- + } ) : (

{error}

diff --git a/src/pages/ProjectForm.tsx b/src/pages/ProjectForm.tsx index ee9b431c..e876e0d1 100644 --- a/src/pages/ProjectForm.tsx +++ b/src/pages/ProjectForm.tsx @@ -1,7 +1,7 @@ import { useEffect, useState } from "react"; import Form from "../components/Form"; import { useAuthContext } from "../util/auth"; -import { DISCORD_INVITE, ROUTER_PATHS } from "../util/constants"; +import { DISCORD_INVITE, REGISTRATIONS_OPEN, ROUTER_PATHS } from "../util/constants"; import { useNavigate, useParams } from "react-router-dom"; import { makeRequest } from "../util/backend"; import { IProject } from "../util/types"; @@ -20,6 +20,11 @@ function ProjectForm(props: { isEditing?: boolean }) { const [loading, setLoading] = useState(false); useEffect(() => { + if (!isEditing && !REGISTRATIONS_OPEN) { + // Redirect if registrations are closed and not editing. + navigate(ROUTER_PATHS.HOME); + } + if (!authContext.isAuthenticated) { navigate(ROUTER_PATHS.HOME); } else if (!authContext.isRegistered) { diff --git a/src/pages/RegistrationForm.tsx b/src/pages/RegistrationForm.tsx index a8ad98e7..8d1d9bcc 100644 --- a/src/pages/RegistrationForm.tsx +++ b/src/pages/RegistrationForm.tsx @@ -1,7 +1,7 @@ import { useEffect, useState } from "react"; import Form from "../components/Form"; import { useAuthContext } from "../util/auth"; -import { ROUTER_PATHS } from "../util/constants"; +import { REGISTRATIONS_OPEN, ROUTER_PATHS } from "../util/constants"; import { useNavigate } from "react-router-dom"; import { makeRequest } from "../util/backend"; @@ -19,6 +19,11 @@ function RegistrationForm({ isStudent }: { isStudent: boolean }) { useEffect(() => { setIsRegistering(!authContext.isRegistered); + if (isRegistering && !REGISTRATIONS_OPEN) { + // Redirect if registrations are closed and is registering + navigate(ROUTER_PATHS.HOME); + } + if (!authContext.isAuthenticated) { navigate(ROUTER_PATHS.HOME); } diff --git a/src/util/constants.ts b/src/util/constants.ts index 1a47e8d2..da603b72 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -1,4 +1,5 @@ export const BACKEND_URL = import.meta.env.VITE_BACKEND_URL; +export const REGISTRATIONS_OPEN = import.meta.env.VITE_REGISTRATIONS_OPEN == 'true'; export enum ROUTER_PATHS { HOME = "/",