From fbe6a41113a1a01afa00297c7d4ba33e9fbd3516 Mon Sep 17 00:00:00 2001 From: nathan-j-edwards Date: Thu, 14 Mar 2024 22:37:49 -0400 Subject: [PATCH] fixed id --- src/pages/senior/[id].tsx | 323 +++++++++++++++++++------------------- 1 file changed, 162 insertions(+), 161 deletions(-) diff --git a/src/pages/senior/[id].tsx b/src/pages/senior/[id].tsx index 53646516..ceb13fa6 100644 --- a/src/pages/senior/[id].tsx +++ b/src/pages/senior/[id].tsx @@ -3,7 +3,7 @@ import type { GetServerSidePropsContext } from "next"; import { useState } from "react"; import FileTile from "@components/TileGrid/FileTile"; import SearchBar from "@components/SearchBar"; -import AddFile from "@components/user/AddFile"; +import AddFile from "@components/AddFile"; import TileGrid from "@components/TileGrid"; import SortDropdown, { SortMethod } from "@components/SortDropdown"; @@ -12,20 +12,20 @@ import { z } from "zod"; import { Approval } from "@prisma/client"; import { prisma } from "@server/db/client"; -type ISeniorProfileProps = Awaited< - ReturnType ->["props"] & { - redirect: undefined; -}; +// type ISeniorProfileProps = Awaited< +// ReturnType +// >["props"] & { +// redirect: undefined; +// }; -type SerialzedFile = ISeniorProfileProps["senior"]["Files"][number]; +// type SerialzedFile = ISeniorProfileProps["senior"]["Files"][number]; const SeniorProfile = ({ senior }: any) => { - const [files, _] = useState(senior.Files); - const [sortMethod, setSortMethod] = useState("By Name"); - const [filter, setFilter] = useState(""); - const [showAddFilePopUp, setShowAddFilePopUp] = useState(false); - + // const [files, _] = useState(senior.Files); + // const [sortMethod, setSortMethod] = useState("By Name"); + // const [filter, setFilter] = useState(""); + // const [showAddFilePopUp, setShowAddFilePopUp] = useState(false); + /* const sortFunction = sortMethod === "By Name" ? ({ name: nameA }: SerialzedFile, { name: nameB }: SerialzedFile) => @@ -46,156 +46,157 @@ const SeniorProfile = ({ senior }: any) => { const handlePopUp = () => { setShowAddFilePopUp(!showAddFilePopUp); }; - - return ( -
- {showAddFilePopUp ? ( - - ) : null} -
-

- {senior.name} -

{senior.location}

- -
-

- {senior.description} -

-
-
- -
- -
-
- - - - {filteredFiles.map((file, key) => ( -
- -
- ))} -
-
-
- ); + */ + + return null; + + // return ( + //
+ // {showAddFilePopUp ? ( + // + // ) : null} + //
+ //

+ // {senior.name} + //

{senior.location}

+ // + //
+ //

+ // {senior.description} + //

+ //
+ //
+ // + //
+ // + //
+ //
+ + // + // + // {filteredFiles.map((file, key) => ( + //
+ // + //
+ // ))} + //
+ //
+ //
+ // ); }; export default SeniorProfile; -export const getServerSideProps = async ( - context: GetServerSidePropsContext -) => { - const session = await getServerAuthSession(context); - const seniorId = z.string().parse(context.query.id); - - if (!session || !session.user) { - return { - redirect: { - destination: "/login", - permanent: false, - }, - }; - } - - if (!prisma) { - return { - redirect: { - destination: "/", - permanent: false, - }, - }; - } - - const user = await prisma.user.findUnique({ - where: { - id: session.user.id, - }, - }); - - if (!user) { - return { - redirect: { - destination: "/", - permanent: false, - }, - }; - } - - if (user.approved === Approval.PENDING) { - return { - redirect: { - destination: "/pending", - permanent: false, - }, - }; - } - - // await fetch ("/api/senior/" + seniorId, { method: "GET" }); - // TODO: not using our beautiful API routes?? - const senior = await prisma.senior.findUnique({ - where: { - id: seniorId, //get all information for given senior - }, - include: { - Files: true, - }, - }); - - if ( - !senior || - (!user.admin && !senior.StudentIDs.includes(session.user.id)) - ) { - return { - redirect: { - destination: "/", - permanent: false, - }, - }; - } - - return { - props: { - senior: { - ...senior, - Files: senior.Files.map((file) => ({ - ...file, - lastModified: file.lastModified.getTime(), - })), - }, - }, - }; -}; +// export const getServerSideProps = async ( +// context: GetServerSidePropsContext +// ) => { +// const session = await getServerAuthSession(context); +// const seniorId = z.string().parse(context.query.id); + +// if (!session || !session.user) { +// return { +// redirect: { +// destination: "/login", +// permanent: false, +// }, +// }; +// } + +// if (!prisma) { +// return { +// redirect: { +// destination: "/", +// permanent: false, +// }, +// }; +// } + +// const user = await prisma.user.findUnique({ +// where: { +// id: session.user.id, +// }, +// }); + +// if (!user) { +// return { +// redirect: { +// destination: "/", +// permanent: false, +// }, +// }; +// } + +// if (user.approved === Approval.PENDING) { +// return { +// redirect: { +// destination: "/pending", +// permanent: false, +// }, +// }; +// } + +// // await fetch ("/api/senior/" + seniorId, { method: "GET" }); +// // TODO: not using our beautiful API routes?? +// const senior = await prisma.senior.findUnique({ +// where: { +// id: seniorId, //get all information for given senior +// }, +// include: { +// Files: true, +// }, +// }); + +// if ( +// !senior || +// (!user.admin && !senior.StudentIDs.includes(session.user.id)) +// ) { +// return { +// redirect: { +// destination: "/", +// permanent: false, +// }, +// }; +// } + +// return { +// // props: { +// // senior: { +// // ...senior, +// // Files: senior.Files.map((file) => ({ +// // ...file, +// // lastModified: file.lastModified.getTime(), +// // })), +// // }, +// // }, +// }; +// };