diff --git a/src/app/layout.js b/src/app/layout.js index 0d3254a58..d49a8a894 100644 --- a/src/app/layout.js +++ b/src/app/layout.js @@ -5,6 +5,9 @@ import "bootstrap/dist/css/bootstrap.min.css"; import { Poppins } from "next/font/google"; import { SessionProvider } from "next-auth/react"; import { Toaster } from "react-hot-toast"; +import ProtectedPage from "@/components/dynamic/ProtectedPage"; +import Navigation from "@/components/dynamic/Navigation"; +import { usePathname } from "next/navigation"; const poppins = Poppins({ subsets: ["latin"], @@ -14,20 +17,27 @@ const poppins = Poppins({ }); export default function RootLayout({ children, session }) { + const pathName = usePathname(); + + const navigation = RegExp(/user\/|admin\//).test(pathName); + return ( - - + - - {children} - - +
+ {navigation && } + + + {children} + +
+
+ ); } diff --git a/src/components/dynamic/ProtectedPage.jsx b/src/components/dynamic/ProtectedPage.jsx index fcf93639b..d2490e4bc 100644 --- a/src/components/dynamic/ProtectedPage.jsx +++ b/src/components/dynamic/ProtectedPage.jsx @@ -3,17 +3,19 @@ import { useEffect, useState } from "react"; import { signIn, useSession } from "next-auth/react"; import Loading from "@/components/dynamic/Loading"; import Error from "./Error"; -import Navigation from "./Navigation"; import { usePathname } from "next/navigation"; import RELEASES from "@/data/Releases"; +import { ROUTES } from "@/data/ProtectedRoutes"; -const ProtectedPage = ({ title, children, restrictions }) => { +const ProtectedPage = ({ children }) => { const { data: session, status } = useSession(); const [error, setError] = useState(null); const [confirmed, setConfirmed] = useState(false); const pathName = usePathname(); - const navigation = RegExp(/user\/|admin\//).test(pathName); + const restrictions = ROUTES[pathName].restrictions; + const title = ROUTES[pathName].title; + const bypass = ROUTES[pathName].bypass; useEffect(() => { if (RELEASES.DYNAMIC[pathName] > new Date()) { @@ -63,14 +65,11 @@ const ProtectedPage = ({ title, children, restrictions }) => { {error && ( )} - {status === "authenticated" && confirmed && ( + {(confirmed || bypass) && ( <> - {navigation && } {title} -
-
- {children} -
+
+
{children}
)} diff --git a/src/data/ProtectedRoutes.js b/src/data/ProtectedRoutes.js new file mode 100644 index 000000000..36e7786d4 --- /dev/null +++ b/src/data/ProtectedRoutes.js @@ -0,0 +1,180 @@ +export const ROUTES = { + "/": { + bypass: true, + title: "Hackathon", + }, + "/_not-found": { + bypass: true, + title: "Hackathon | Not Found", + }, + "/_error": { + bypass: true, + title: "Hackathon | Error", + }, + "/admin/participants": { + restrictions: { + admins: 1, + }, + title: "Admin | Participants", + }, + "/admin/feedback": { + restrictions: { + admins: 1, + }, + title: "Admin | Feedback", + }, + "/admin/teams": { + restrictions: { + admins: 1, + }, + title: "Admin | Teams", + }, + "/admin/judges": { + restrictions: { + admins: 1, + }, + title: "Admin | Judges", + }, + "/admin/volunteers": { + restrictions: { + admins: 1, + committees: 1, + committees: 1, + }, + title: "Admin | Volunteers", + }, + "/admin/mentors": { + restrictions: { + admins: 1, + committees: 1, + }, + title: "Admin | Mentors", + }, + "/admin/admins": { + restrictions: { + admins: 1, + }, + title: "Admin | Admins", + }, + "/admin/committees": { + restrictions: { + admins: 1, + }, + title: "Admin | Committees", + }, + "/admin/participants": { + restrictions: { + admins: 1, + }, + title: "Admin | Participants", + }, + "/admin/calendar": { + restrictions: { + admins: 1, + }, + title: "Admin | Calendar", + }, + "/admin/messenger": { + restrictions: { + admins: 1, + committees: 1, + }, + title: "Admin | Messenger", + }, + "/admin/checkin": { + restrictions: { + admins: 1, + committees: 1, + }, + title: "Admin | Checkin", + }, + "/admin/judging": { + restrictions: { + admins: 1, + }, + title: "Admin | Judging", + }, + "/admin/prizes": { + restrictions: { + admins: 1, + committees: 1, + }, + title: "Admin | Prizes", + }, + "/admin/statistics": { + restrictions: { + admins: 1, + committees: 1, + }, + title: "Admin | Statistics", + }, + "/admin/interests": { + restrictions: { + admins: 1, + committees: 1, + }, + title: "Admin | Interests", + }, + + "/form/admin": { + restrictions: { + admins: 1, + }, + title: "Form | Admin", + }, + "/form/committee": { + restrictions: { + admins: 1, + }, + title: "Form | Committee", + }, + "/form/feedback": { + restrictions: { + admins: 1, + }, + title: "Form | Feedback", + }, + "/form/judge": { + restrictions: { + admins: 1, + }, + title: "Form | Judge", + }, + "/form/volunteer": { + restrictions: { + admins: 1, + }, + title: "Form | Volunteer", + }, + "/form/participant": { + restrictions: { + admins: 1, + }, + title: "Form | Participant", + }, + "/form/mentor": { + restrictions: { + admins: 1, + }, + title: "Form | Mentor", + }, + "/form/interest": { + restrictions: { + admins: 1, + }, + title: "Form | Interest", + }, + + "/user/dashboard": { + restrictions: { + participants: [-1, 0, 1], + }, + title: "Form | Dashboard", + }, + "/user/checkin": { + restrictions: { + participants: [-1, 0, 1], + }, + title: "Form | CheckIn", + }, +};