Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed made #874

Merged
merged 4 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions src/app/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -14,20 +17,27 @@ const poppins = Poppins({
});

export default function RootLayout({ children, session }) {
const pathName = usePathname();

const navigation = RegExp(/user\/|admin\//).test(pathName);

return (
<html lang="en" className="h-full">
<SessionProvider
session={session}
refetchInterval={5 * 60}
className="h-full"
>
<body
className={`${poppins.variable} flex flex-col lg:flex-row h-full`}
<body className={`${poppins.variable} flex flex-col lg:flex-row h-full`}>
<SessionProvider
session={session}
refetchInterval={5 * 60}
className="h-full"
>
<Toaster />
{children}
</body>
</SessionProvider>
<div className="flex w-full">
{navigation && <Navigation />}
<ProtectedPage>
<Toaster />
{children}
</ProtectedPage>
</div>
</SessionProvider>
</body>
</html>
);
}
17 changes: 8 additions & 9 deletions src/components/dynamic/ProtectedPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -63,14 +65,11 @@ const ProtectedPage = ({ title, children, restrictions }) => {
{error && (
<Error code={error.code} error={error.error} message={error.message} />
)}
{status === "authenticated" && confirmed && (
{(confirmed || bypass) && (
<>
{navigation && <Navigation />}
<title>{title}</title>
<div className="flex justify-center items-start w-full bg-hackathon-page z-0 h-screen pt-12 lg:pt-0">
<div className={`${navigation ? "w-11/12" : "w-full"} h-full`}>
{children}
</div>
<div className="flex justify-center items-start w-full bg-hackathon-page h-screen pt-12 lg:pt-0 z-0">
<div className={`w-[96%] h-full`}>{children}</div>
</div>
</>
)}
Expand Down
180 changes: 180 additions & 0 deletions src/data/ProtectedRoutes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
export const ROUTES = {
"/": {
bypass: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need a title here

title: "Hackathon",
},
"/_not-found": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need title

bypass: true,
title: "Hackathon | Not Found",
},
"/_error": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

title

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",
},
};