diff --git a/src/app/private/[uid]/admin/layout.tsx b/src/app/private/[uid]/admin/layout.tsx deleted file mode 100644 index 42524e0c..00000000 --- a/src/app/private/[uid]/admin/layout.tsx +++ /dev/null @@ -1,52 +0,0 @@ -"use client"; - -import { CollapsibleSidebarContainer } from "@components/container"; -import { - faEnvelope, - faHome, - faHouseLock, - faUser, -} from "@fortawesome/free-solid-svg-icons"; -import React, { useContext } from "react"; -import { UserContext } from "src/context/UserProvider"; - -interface IAdminLayout { - children: React.ReactNode; -} - -const AdminLayout = ({ children }: IAdminLayout) => { - const { user } = useContext(UserContext); - const buttons = React.useMemo( - () => [ - { - name: "Home", - link: `/private/${user.id}/admin/home`, - icon: faHome, - }, - { - name: "Pending", - link: `/private/${user.id}/admin/pending-chapters`, - icon: faHouseLock, - }, - { - name: "E-list", - link: `/private/${user.id}/admin/elist`, - icon: faEnvelope, - }, - { - name: "Profile", - link: `/private/${user.id}/admin/edit-profile`, - icon: faUser, - }, - ], - [user.id] - ); - - return ( - - {children} - - ); -}; - -export default AdminLayout; diff --git a/src/app/private/[uid]/chapter-leader/layout.tsx b/src/app/private/[uid]/chapter-leader/layout.tsx deleted file mode 100644 index a1eb7045..00000000 --- a/src/app/private/[uid]/chapter-leader/layout.tsx +++ /dev/null @@ -1,54 +0,0 @@ -"use client"; - -import Sidebar, { ISideBar } from "@components/Sidebar"; -import { CollapsibleSidebarContainer } from "@components/container"; -import { - faHome, - faUser, - faUserGroup, - faUserPlus, -} from "@fortawesome/free-solid-svg-icons"; -import React, { useContext } from "react"; -import { UserContext } from "src/context/UserProvider"; - -interface IUserLayout { - children: React.ReactNode; -} - -const UserLayout = ({ children }: IUserLayout) => { - const { user } = useContext(UserContext); - const buttons: ISideBar["buttons"] = React.useMemo( - () => [ - { - name: "Home", - link: `/private/${user.id}/chapter-leader/home`, - icon: faHome, - }, - { - name: "Members", - link: `/private/${user.id}/chapter-leader/users`, - icon: faUserGroup, - }, - // @TODO(nickbar01234) - Fix icon - { - name: "Seniors", - link: `/private/${user.id}/chapter-leader/seniors`, - icon: faUserGroup, - }, - { - name: "Profile", - link: `/private/${user.id}/chapter-leader/edit-profile`, - icon: faUser, - }, - ], - [user.id] - ); - - return ( - - {children} - - ); -}; - -export default UserLayout; diff --git a/src/app/private/[uid]/layout.tsx b/src/app/private/[uid]/layout.tsx deleted file mode 100644 index 7910e696..00000000 --- a/src/app/private/[uid]/layout.tsx +++ /dev/null @@ -1,37 +0,0 @@ -import { authOptions } from "@api/auth/[...nextauth]/route"; -import { RootNavigation } from "@components/navigation"; -import UserProvider from "@context/UserProvider"; -import { prisma } from "@server/db/client"; -import { getServerSession } from "next-auth"; -import { redirect } from "next/navigation"; - -interface LayoutProps { - children: React.ReactNode; -} - -const Layout = async ({ children }: LayoutProps) => { - const session = await getServerSession(authOptions); - - try { - if (session == null) { - throw new Error(); - } - - const user = await prisma.user.findFirstOrThrow({ - where: { id: session.user?.id }, - include: { - Chapter: true, - }, - }); - - return ( - - {children} - - ); - } catch { - redirect("/public"); - } -}; - -export default Layout; diff --git a/src/app/private/[uid]/user/layout.tsx b/src/app/private/[uid]/user/layout.tsx deleted file mode 100644 index 30a987cb..00000000 --- a/src/app/private/[uid]/user/layout.tsx +++ /dev/null @@ -1,42 +0,0 @@ -"use client"; - -import { CollapsibleSidebarContainer } from "@components/container"; -import { faHome, faUsers, faUser } from "@fortawesome/free-solid-svg-icons"; -import React, { useContext } from "react"; -import { UserContext } from "src/context/UserProvider"; - -interface IUserLayout { - children: React.ReactNode; -} - -const UserLayout = ({ children }: IUserLayout) => { - const { user } = useContext(UserContext); - const buttons = React.useMemo( - () => [ - { - name: "Home", - link: `/private/${user.id}/user/home`, - icon: faHome, - }, - { - name: "Seniors", - link: `/private/${user.id}/user/seniors`, - icon: faUsers, - }, - { - name: "Profile", - link: `/private/${user.id}/user/edit-profile`, - icon: faUser, - }, - ], - [user.id] - ); - - return ( - - {children} - - ); -}; - -export default UserLayout; diff --git a/src/app/private/[uid]/admin/edit-profile/layout.tsx b/src/app/private/admin/edit-profile/layout.tsx similarity index 100% rename from src/app/private/[uid]/admin/edit-profile/layout.tsx rename to src/app/private/admin/edit-profile/layout.tsx diff --git a/src/app/private/[uid]/admin/edit-profile/page.tsx b/src/app/private/admin/edit-profile/page.tsx similarity index 100% rename from src/app/private/[uid]/admin/edit-profile/page.tsx rename to src/app/private/admin/edit-profile/page.tsx diff --git a/src/app/private/[uid]/admin/elist/page.tsx b/src/app/private/admin/elist/page.tsx similarity index 100% rename from src/app/private/[uid]/admin/elist/page.tsx rename to src/app/private/admin/elist/page.tsx diff --git a/src/app/private/[uid]/admin/home/chapters/[chapterId]/page.tsx b/src/app/private/admin/home/chapters/[chapterId]/page.tsx similarity index 98% rename from src/app/private/[uid]/admin/home/chapters/[chapterId]/page.tsx rename to src/app/private/admin/home/chapters/[chapterId]/page.tsx index 5f459324..3a952220 100644 --- a/src/app/private/[uid]/admin/home/chapters/[chapterId]/page.tsx +++ b/src/app/private/admin/home/chapters/[chapterId]/page.tsx @@ -3,7 +3,6 @@ import DisplayChapterInfo from "@components/DisplayChapterInfo"; interface ChapterPageParams { params: { - uid: string; chapterId: string; }; } diff --git a/src/app/private/[uid]/admin/home/chapters/[chapterId]/users/[userId]/page.tsx b/src/app/private/admin/home/chapters/[chapterId]/users/[userId]/page.tsx similarity index 87% rename from src/app/private/[uid]/admin/home/chapters/[chapterId]/users/[userId]/page.tsx rename to src/app/private/admin/home/chapters/[chapterId]/users/[userId]/page.tsx index 62fc23dc..af7b9da9 100644 --- a/src/app/private/[uid]/admin/home/chapters/[chapterId]/users/[userId]/page.tsx +++ b/src/app/private/admin/home/chapters/[chapterId]/users/[userId]/page.tsx @@ -5,14 +5,13 @@ import { CardGrid } from "@components/container"; interface Params { params: { - uid: string; userId: string; chapterId: string; }; } const UserPage = async ({ params }: Params) => { - const { userId, chapterId, uid } = params; + const { userId, chapterId } = params; const user = await prisma.user.findUniqueOrThrow({ where: { id: userId, ChapterID: chapterId }, @@ -42,7 +41,7 @@ const UserPage = async ({ params }: Params) => { ))} /> diff --git a/src/app/private/[uid]/admin/home/chapters/[chapterId]/users/[userId]/seniors/[seniorId]/page.tsx b/src/app/private/admin/home/chapters/[chapterId]/users/[userId]/seniors/[seniorId]/page.tsx similarity index 96% rename from src/app/private/[uid]/admin/home/chapters/[chapterId]/users/[userId]/seniors/[seniorId]/page.tsx rename to src/app/private/admin/home/chapters/[chapterId]/users/[userId]/seniors/[seniorId]/page.tsx index ea81c976..25d812d4 100644 --- a/src/app/private/[uid]/admin/home/chapters/[chapterId]/users/[userId]/seniors/[seniorId]/page.tsx +++ b/src/app/private/admin/home/chapters/[chapterId]/users/[userId]/seniors/[seniorId]/page.tsx @@ -14,7 +14,6 @@ interface Params { const SeniorPage = async ({ params }: Params) => { const { userId, chapterId, seniorId } = params; - // TODO(nickbar01234) - Associate each senior to a chapter const senior = await prisma.senior.findUniqueOrThrow({ where: { id: seniorId, @@ -44,7 +43,6 @@ const SeniorPage = async ({ params }: Params) => { { display: `${senior.firstname} ${senior.lastname}`, url: seniorId }, ]} /> - diff --git a/src/app/private/[uid]/admin/home/chapters/page.tsx b/src/app/private/admin/home/chapters/page.tsx similarity index 100% rename from src/app/private/[uid]/admin/home/chapters/page.tsx rename to src/app/private/admin/home/chapters/page.tsx diff --git a/src/app/private/[uid]/admin/home/layout.tsx b/src/app/private/admin/home/layout.tsx similarity index 100% rename from src/app/private/[uid]/admin/home/layout.tsx rename to src/app/private/admin/home/layout.tsx diff --git a/src/app/private/[uid]/admin/home/page.tsx b/src/app/private/admin/home/page.tsx similarity index 100% rename from src/app/private/[uid]/admin/home/page.tsx rename to src/app/private/admin/home/page.tsx diff --git a/src/app/private/[uid]/admin/home/resources/page.tsx b/src/app/private/admin/home/resources/page.tsx similarity index 100% rename from src/app/private/[uid]/admin/home/resources/page.tsx rename to src/app/private/admin/home/resources/page.tsx diff --git a/src/app/private/admin/layout.tsx b/src/app/private/admin/layout.tsx new file mode 100644 index 00000000..f4f3c588 --- /dev/null +++ b/src/app/private/admin/layout.tsx @@ -0,0 +1,45 @@ +import { ISideBar } from "@components/Sidebar"; +import { CollapsibleSidebarContainer } from "@components/container"; +import { + faEnvelope, + faHome, + faHouseLock, + faUser, +} from "@fortawesome/free-solid-svg-icons"; + +interface IAdminLayout { + children: React.ReactNode; +} + +const AdminLayout = ({ children }: IAdminLayout) => { + const buttons: ISideBar["buttons"] = [ + { + name: "Home", + link: `/private/admin/home`, + icon: faHome, + }, + { + name: "Pending", + link: `/private/admin/pending-chapters`, + icon: faHouseLock, + }, + { + name: "E-list", + link: `/private/admin/elist`, + icon: faEnvelope, + }, + { + name: "Profile", + link: `/private/admin/edit-profile`, + icon: faUser, + }, + ]; + + return ( + + {children} + + ); +}; + +export default AdminLayout; diff --git a/src/app/private/[uid]/admin/pending-chapters/layout.tsx b/src/app/private/admin/pending-chapters/layout.tsx similarity index 100% rename from src/app/private/[uid]/admin/pending-chapters/layout.tsx rename to src/app/private/admin/pending-chapters/layout.tsx diff --git a/src/app/private/[uid]/admin/pending-chapters/page.tsx b/src/app/private/admin/pending-chapters/page.tsx similarity index 100% rename from src/app/private/[uid]/admin/pending-chapters/page.tsx rename to src/app/private/admin/pending-chapters/page.tsx diff --git a/src/app/private/[uid]/chapter-leader/edit-profile/layout.tsx b/src/app/private/chapter-leader/edit-profile/layout.tsx similarity index 100% rename from src/app/private/[uid]/chapter-leader/edit-profile/layout.tsx rename to src/app/private/chapter-leader/edit-profile/layout.tsx diff --git a/src/app/private/[uid]/chapter-leader/edit-profile/page.tsx b/src/app/private/chapter-leader/edit-profile/page.tsx similarity index 100% rename from src/app/private/[uid]/chapter-leader/edit-profile/page.tsx rename to src/app/private/chapter-leader/edit-profile/page.tsx diff --git a/src/app/private/[uid]/chapter-leader/home/layout.tsx b/src/app/private/chapter-leader/home/layout.tsx similarity index 100% rename from src/app/private/[uid]/chapter-leader/home/layout.tsx rename to src/app/private/chapter-leader/home/layout.tsx diff --git a/src/app/private/[uid]/chapter-leader/home/page.tsx b/src/app/private/chapter-leader/home/page.tsx similarity index 86% rename from src/app/private/[uid]/chapter-leader/home/page.tsx rename to src/app/private/chapter-leader/home/page.tsx index d71ce464..a5808990 100644 --- a/src/app/private/[uid]/chapter-leader/home/page.tsx +++ b/src/app/private/chapter-leader/home/page.tsx @@ -1,5 +1,6 @@ import DisplayChapterInfo from "@components/DisplayChapterInfo"; import { prisma } from "@server/db/client"; +import { getServerSessionOrRedirect } from "@server/utils"; interface UserHomePageParams { params: { @@ -8,14 +9,10 @@ interface UserHomePageParams { } const UserHomePage = async ({ params }: UserHomePageParams) => { - const user = await prisma.user.findFirstOrThrow({ - where: { - id: params.uid, - }, - }); + const session = await getServerSessionOrRedirect(); const chapter = await prisma.chapter.findFirstOrThrow({ where: { - id: user.ChapterID ?? "", + id: session.user?.ChapterID ?? "", }, include: { students: { diff --git a/src/app/private/chapter-leader/layout.tsx b/src/app/private/chapter-leader/layout.tsx new file mode 100644 index 00000000..8d473732 --- /dev/null +++ b/src/app/private/chapter-leader/layout.tsx @@ -0,0 +1,41 @@ +import { ISideBar } from "@components/Sidebar"; +import { CollapsibleSidebarContainer } from "@components/container"; +import { faHome, faUser, faUserGroup } from "@fortawesome/free-solid-svg-icons"; + +interface IUserLayout { + children: React.ReactNode; +} + +const UserLayout = ({ children }: IUserLayout) => { + const buttons: ISideBar["buttons"] = [ + { + name: "Home", + link: `/private/chapter-leader/home`, + icon: faHome, + }, + { + name: "Members", + link: `/private/chapter-leader/users`, + icon: faUserGroup, + }, + // @TODO(nickbar01234) - Fix icon + { + name: "Seniors", + link: `/private/chapter-leader/seniors`, + icon: faUserGroup, + }, + { + name: "Profile", + link: `/private/chapter-leader/edit-profile`, + icon: faUser, + }, + ]; + + return ( + + {children} + + ); +}; + +export default UserLayout; diff --git a/src/app/private/[uid]/chapter-leader/seniors/[seniorId]/page.tsx b/src/app/private/chapter-leader/seniors/[seniorId]/page.tsx similarity index 100% rename from src/app/private/[uid]/chapter-leader/seniors/[seniorId]/page.tsx rename to src/app/private/chapter-leader/seniors/[seniorId]/page.tsx diff --git a/src/app/private/[uid]/chapter-leader/seniors/layout.tsx b/src/app/private/chapter-leader/seniors/layout.tsx similarity index 100% rename from src/app/private/[uid]/chapter-leader/seniors/layout.tsx rename to src/app/private/chapter-leader/seniors/layout.tsx diff --git a/src/app/private/[uid]/chapter-leader/seniors/page.tsx b/src/app/private/chapter-leader/seniors/page.tsx similarity index 68% rename from src/app/private/[uid]/chapter-leader/seniors/page.tsx rename to src/app/private/chapter-leader/seniors/page.tsx index 9e4359a1..333eea5a 100644 --- a/src/app/private/[uid]/chapter-leader/seniors/page.tsx +++ b/src/app/private/chapter-leader/seniors/page.tsx @@ -2,22 +2,14 @@ import React from "react"; import { prisma } from "@server/db/client"; import { SeniorView } from "@components/SeniorView"; import { compareSenior } from "@utils"; +import { getServerSessionOrRedirect } from "@server/utils"; -const UserSeniorsPage = async ({ params }: { params: { uid: string } }) => { - const userUid = params.uid; - const user = await prisma.user.findUnique({ - where: { - id: userUid, - }, - }); - if (!user) { - return
User not found
; - } - +const UserSeniorsPage = async () => { + const session = await getServerSessionOrRedirect(); // Fetch the seniors too const chapter = await prisma.chapter.findFirst({ where: { - id: user.ChapterID ?? undefined, + id: session.user?.ChapterID ?? undefined, }, include: { seniors: {}, diff --git a/src/app/private/[uid]/chapter-leader/users/MembersHomePage.tsx b/src/app/private/chapter-leader/users/MembersHomePage.tsx similarity index 94% rename from src/app/private/[uid]/chapter-leader/users/MembersHomePage.tsx rename to src/app/private/chapter-leader/users/MembersHomePage.tsx index e7de0f72..0a8256e9 100644 --- a/src/app/private/[uid]/chapter-leader/users/MembersHomePage.tsx +++ b/src/app/private/chapter-leader/users/MembersHomePage.tsx @@ -3,8 +3,7 @@ import { TileEdit, UserTile } from "@components/TileGrid"; import SearchableContainer from "@components/SearchableContainer"; import { User } from "@prisma/client"; -import { useContext, useState } from "react"; -import { UserContext } from "@context/UserProvider"; +import { useState } from "react"; import { editPosition } from "@api/user/[uid]/edit-position/route.client"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faArrowUpFromBracket } from "@fortawesome/free-solid-svg-icons"; @@ -27,7 +26,6 @@ const EBOARD_POSITIONS = [ ].map((position, idx) => ({ id: idx.toString(), position: position })); const MembersHomePage = ({ members }: MembersHomePageProps) => { - const { user } = useContext(UserContext); const [uidToEdit, setUidToEdit] = useState(null); const [selectedPosition, setSelectedPosition] = useState< typeof EBOARD_POSITIONS @@ -43,7 +41,7 @@ const MembersHomePage = ({ members }: MembersHomePageProps) => { { - const { userId } = params; +const Page = async () => { + const session = await getServerSessionOrRedirect(); const user = await prisma.user.findUniqueOrThrow({ where: { - id: userId, + id: session.user?.id, }, include: { Chapter: { diff --git a/src/app/private/[uid]/chapter-leader/users/layout.tsx b/src/app/private/chapter-leader/users/layout.tsx similarity index 100% rename from src/app/private/[uid]/chapter-leader/users/layout.tsx rename to src/app/private/chapter-leader/users/layout.tsx diff --git a/src/app/private/[uid]/chapter-leader/users/page.tsx b/src/app/private/chapter-leader/users/page.tsx similarity index 64% rename from src/app/private/[uid]/chapter-leader/users/page.tsx rename to src/app/private/chapter-leader/users/page.tsx index 93e30e13..a9a3f1e1 100644 --- a/src/app/private/[uid]/chapter-leader/users/page.tsx +++ b/src/app/private/chapter-leader/users/page.tsx @@ -1,15 +1,13 @@ import React from "react"; import { prisma } from "@server/db/client"; import MembersHomePage from "./MembersHomePage"; +import { getServerSessionOrRedirect } from "@server/utils"; -const MembersPage = async ({ params }: { params: { uid: string } }) => { +const MembersPage = async () => { + const session = await getServerSessionOrRedirect(); const chapter = await prisma.chapter.findFirstOrThrow({ where: { - students: { - some: { - id: params.uid, - }, - }, + id: session.user?.ChapterID ?? "", }, include: { students: true, diff --git a/src/app/private/layout.tsx b/src/app/private/layout.tsx new file mode 100644 index 00000000..b3ee7f47 --- /dev/null +++ b/src/app/private/layout.tsx @@ -0,0 +1,26 @@ +import { RootNavigation } from "@components/navigation"; +import UserProvider from "@context/UserProvider"; +import { prisma } from "@server/db/client"; +import { getServerSessionOrRedirect } from "@server/utils"; + +interface LayoutProps { + children: React.ReactNode; +} + +const Layout = async ({ children }: LayoutProps) => { + const session = await getServerSessionOrRedirect(); + const user = await prisma.user.findFirstOrThrow({ + where: { id: session.user?.id }, + include: { + Chapter: true, + }, + }); + + return ( + + {children} + + ); +}; + +export default Layout; diff --git a/src/app/private/[uid]/user/edit-profile/layout.tsx b/src/app/private/user/edit-profile/layout.tsx similarity index 100% rename from src/app/private/[uid]/user/edit-profile/layout.tsx rename to src/app/private/user/edit-profile/layout.tsx diff --git a/src/app/private/[uid]/user/edit-profile/page.tsx b/src/app/private/user/edit-profile/page.tsx similarity index 100% rename from src/app/private/[uid]/user/edit-profile/page.tsx rename to src/app/private/user/edit-profile/page.tsx diff --git a/src/app/private/[uid]/user/home/layout.tsx b/src/app/private/user/home/layout.tsx similarity index 71% rename from src/app/private/[uid]/user/home/layout.tsx rename to src/app/private/user/home/layout.tsx index 90038e3d..1413b778 100644 --- a/src/app/private/[uid]/user/home/layout.tsx +++ b/src/app/private/user/home/layout.tsx @@ -2,21 +2,27 @@ import { prisma } from "@server/db/client"; import { HeaderContainer } from "@components/container/index"; import { faHouse } from "@fortawesome/free-solid-svg-icons"; import { UserJoinRequest } from "@components/user"; +import { getServerSessionOrRedirect } from "@server/utils"; interface LayoutProps { children: React.ReactNode; - params: { - uid: string; - }; } -const Layout = async ({ children, params }: LayoutProps) => { - const user = await prisma.user.findFirstOrThrow({ - where: { - id: params.uid, - }, - }); - if (user.ChapterID != null) { +const Layout = async ({ children }: LayoutProps) => { + const session = await getServerSessionOrRedirect(); + const maybeChapterId = session.user?.ChapterID ?? undefined; + + if (maybeChapterId == undefined) { + const chapters = await prisma.chapter.findMany({ + include: { students: true }, + }); + const joinRequest = await prisma.userRequest.findFirst({ + where: { + uid: session.user?.id, + }, + }); + return ; + } else { return ( { {children} ); - } else { - const chapters = await prisma.chapter.findMany({ - include: { students: true }, - }); - const joinRequest = await prisma.userRequest.findFirst({ - where: { - uid: params.uid, - }, - }); - return ; } }; diff --git a/src/app/private/[uid]/user/home/page.tsx b/src/app/private/user/home/page.tsx similarity index 68% rename from src/app/private/[uid]/user/home/page.tsx rename to src/app/private/user/home/page.tsx index 506cb40b..f6eceab0 100644 --- a/src/app/private/[uid]/user/home/page.tsx +++ b/src/app/private/user/home/page.tsx @@ -1,26 +1,12 @@ import DisplayChapterInfo from "@components/DisplayChapterInfo"; import { prisma } from "@server/db/client"; +import { getServerSessionOrRedirect } from "@server/utils"; -interface UserHomePageParams { - params: { - uid: string; - }; -} - -const UserHomePage = async ({ params }: UserHomePageParams) => { - const user = await prisma.user.findFirstOrThrow({ - where: { - id: params.uid, - }, - }); - - if (user.ChapterID == null) { - return null; - } - +const UserHomePage = async () => { + const session = await getServerSessionOrRedirect(); const chapter = await prisma.chapter.findFirstOrThrow({ where: { - id: user.ChapterID ?? "", + id: session.user?.ChapterID ?? "", }, include: { students: { diff --git a/src/app/private/user/layout.tsx b/src/app/private/user/layout.tsx new file mode 100644 index 00000000..2fcaa795 --- /dev/null +++ b/src/app/private/user/layout.tsx @@ -0,0 +1,36 @@ +import { ISideBar } from "@components/Sidebar"; +import { CollapsibleSidebarContainer } from "@components/container"; +import { faHome, faUsers, faUser } from "@fortawesome/free-solid-svg-icons"; +import { UserContext } from "src/context/UserProvider"; + +interface IUserLayout { + children: React.ReactNode; +} + +const UserLayout = ({ children }: IUserLayout) => { + const buttons: ISideBar["buttons"] = [ + { + name: "Home", + link: `/private/user/home`, + icon: faHome, + }, + { + name: "Seniors", + link: `/private/user/seniors`, + icon: faUsers, + }, + { + name: "Profile", + link: `/private/user/edit-profile`, + icon: faUser, + }, + ]; + + return ( + + {children} + + ); +}; + +export default UserLayout; diff --git a/src/app/private/[uid]/user/seniors/SeniorsHomePage.tsx b/src/app/private/user/seniors/SeniorsHomePage.tsx similarity index 90% rename from src/app/private/[uid]/user/seniors/SeniorsHomePage.tsx rename to src/app/private/user/seniors/SeniorsHomePage.tsx index 05e9afdc..f8651b37 100644 --- a/src/app/private/[uid]/user/seniors/SeniorsHomePage.tsx +++ b/src/app/private/user/seniors/SeniorsHomePage.tsx @@ -1,7 +1,7 @@ "use client"; import { UserTile } from "@components/TileGrid"; -import { Prisma, Senior, User } from "@prisma/client"; +import { Prisma, Senior } from "@prisma/client"; import SearchableContainer from "@components/SearchableContainer"; import { seniorFullName } from "@utils"; @@ -16,7 +16,7 @@ const SeniorsHomePage = ({ user }: SeniorsHomePageProps) => { ); diff --git a/src/app/private/[uid]/user/seniors/[seniorId]/page.tsx b/src/app/private/user/seniors/[seniorId]/page.tsx similarity index 76% rename from src/app/private/[uid]/user/seniors/[seniorId]/page.tsx rename to src/app/private/user/seniors/[seniorId]/page.tsx index a8c549ac..7029c5ad 100644 --- a/src/app/private/[uid]/user/seniors/[seniorId]/page.tsx +++ b/src/app/private/user/seniors/[seniorId]/page.tsx @@ -1,20 +1,21 @@ import PathNav from "@components/PathNav"; import { DisplaySenior } from "@components/senior"; import { prisma } from "@server/db/client"; +import { getServerSessionOrRedirect } from "@server/utils"; interface PageProps { params: { - uid: string; seniorId: string; }; } const Page = async ({ params }: PageProps) => { + const session = await getServerSessionOrRedirect(); const senior = await prisma.senior.findUniqueOrThrow({ where: { id: params.seniorId, StudentIDs: { - has: params.uid, + has: session.user?.id, }, }, include: { @@ -31,10 +32,10 @@ const Page = async ({ params }: PageProps) => {
diff --git a/src/app/private/[uid]/user/seniors/layout.tsx b/src/app/private/user/seniors/layout.tsx similarity index 100% rename from src/app/private/[uid]/user/seniors/layout.tsx rename to src/app/private/user/seniors/layout.tsx diff --git a/src/app/private/[uid]/user/seniors/page.tsx b/src/app/private/user/seniors/page.tsx similarity index 64% rename from src/app/private/[uid]/user/seniors/page.tsx rename to src/app/private/user/seniors/page.tsx index e4c86a0c..a5d4f788 100644 --- a/src/app/private/[uid]/user/seniors/page.tsx +++ b/src/app/private/user/seniors/page.tsx @@ -1,11 +1,13 @@ import React from "react"; import { prisma } from "@server/db/client"; import SeniorsHomePage from "./SeniorsHomePage"; +import { getServerSessionOrRedirect } from "@server/utils"; -const UserSeniorsPage = async ({ params }: { params: { uid: string } }) => { +const UserSeniorsPage = async () => { + const session = await getServerSessionOrRedirect(); const user = await prisma.user.findFirstOrThrow({ where: { - id: params.uid, + id: session.user?.id, }, include: { Seniors: true, diff --git a/src/components/AdminHomePage.tsx b/src/components/AdminHomePage.tsx index b3b58f22..a82d14df 100644 --- a/src/components/AdminHomePage.tsx +++ b/src/components/AdminHomePage.tsx @@ -46,7 +46,7 @@ const AdminHomePage = ({ chapters }: AdminHomePageProps) => { )} ( - - ))} + tiles={sortedStudents(students).map((student) => { + let link = `/private/${RoleToUrlSegment[user.role]}`; + if (user.role === "ADMIN") { + link += `/home/chapters/${student.ChapterID}`; + } + link += `/users/${student.id}`; + return ( + + ); + })} />
diff --git a/src/components/SeniorView.tsx b/src/components/SeniorView.tsx index cd2f8036..0ea28220 100644 --- a/src/components/SeniorView.tsx +++ b/src/components/SeniorView.tsx @@ -4,8 +4,7 @@ import { Senior, User } from "@prisma/client"; import SearchableContainer from "./SearchableContainer"; import { UserTile, TileEdit } from "./TileGrid"; import AddSenior from "./AddSenior"; -import { useContext, useState } from "react"; -import { UserContext } from "@context/UserProvider"; +import { useState } from "react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faPencil, faTrashCan } from "@fortawesome/free-solid-svg-icons"; @@ -15,7 +14,6 @@ type SeniorViewProps = { }; export const SeniorView = ({ seniors, students }: SeniorViewProps) => { - const context = useContext(UserContext); const [seniorsState, setSeniorsState] = useState(seniors); const [showAddSeniorPopUp, setShowAddSeniorPopUp] = useState(false); const [seniorPatch, setSeniorPatch] = useState(""); @@ -68,7 +66,7 @@ export const SeniorView = ({ seniors, students }: SeniorViewProps) => { // TODO(nickbar01234) - Fix link } /> diff --git a/src/components/user/DisplayUserSeniors.tsx b/src/components/user/DisplayUserSeniors.tsx index 538b827e..3e3f5c8b 100644 --- a/src/components/user/DisplayUserSeniors.tsx +++ b/src/components/user/DisplayUserSeniors.tsx @@ -30,7 +30,6 @@ const DisplayUserSenior = (props: DisplayProps) => { seniors?.filter((senior) => currentUser.SeniorIDs.includes(senior.id)); const [assigned, setAssigned] = React.useState(() => getAssignments()); - console.log(assigned); const onSave = async () => { await editSeniorIDs( @@ -63,7 +62,7 @@ const DisplayUserSenior = (props: DisplayProps) => { diff --git a/src/hooks/useUserRedirect.tsx b/src/hooks/useUserRedirect.tsx index b50908fc..4b6b1106 100644 --- a/src/hooks/useUserRedirect.tsx +++ b/src/hooks/useUserRedirect.tsx @@ -23,7 +23,7 @@ const useUserRedirect = (props: UseRoleProps) => { return; } - const protectedSegment = `/private/${uid}/${RoleToUrlSegment[role]}`; + const protectedSegment = `/private/${RoleToUrlSegment[role]}`; if (!path.startsWith(protectedSegment)) { router.replace(`${protectedSegment}/home`); } diff --git a/src/server/utils/index.ts b/src/server/utils/index.ts new file mode 100644 index 00000000..cd5b7d92 --- /dev/null +++ b/src/server/utils/index.ts @@ -0,0 +1,11 @@ +import { authOptions } from "@api/auth/[...nextauth]/route"; +import { getServerSession } from "next-auth"; +import { redirect } from "next/navigation"; + +export const getServerSessionOrRedirect = async () => { + const session = await getServerSession(authOptions); + if (session == null) { + redirect("/public"); + } + return session; +}; diff --git a/src/utils/index.tsx b/src/utils/index.tsx index 2c034aee..6dfe7871 100644 --- a/src/utils/index.tsx +++ b/src/utils/index.tsx @@ -8,7 +8,7 @@ type PositionOrder = { }; export const formatUserHomeRoute = (user: NonNullable) => { - return `/private/${user.id}/${RoleToUrlSegment[user.role]}/home`; + return `/private/${RoleToUrlSegment[user.role]}/home`; }; /**