11import { SchedulerWrapper } from "@/components/scheduler/generator/SchedulerWrapper" ;
2- import { getTerms } from "@/lib/dal/terms " ;
2+ import { auth } from "@/lib/auth/auth " ;
33import { getCampuses } from "@/lib/dal/campuses" ;
44import { getNupaths } from "@/lib/dal/nupaths" ;
5-
6- import { db , nupathsT , savedPlansT } from "@/lib/db" ;
7- import { auth } from "@/lib/auth/auth" ;
5+ import { getTerms } from "@/lib/dal/terms" ;
6+ import { db , nupathsT } from "@/lib/db" ;
87import { headers } from "next/headers" ;
9- import { notFound , redirect } from "next/navigation" ;
10- import { eq , and } from "drizzle-orm" ;
11-
12- export default async function Page ( {
13- searchParams,
14- } : {
15- searchParams : Promise < {
16- planId : string ;
17- } > ;
18- } ) {
19- const session = await auth . api . getSession ( {
20- headers : await headers ( ) ,
21- } ) ;
22-
23- if ( ! session ) {
24- redirect ( "/" ) ;
25- }
26-
27- const params = await searchParams ;
28- const planId = params . planId ? parseInt ( params . planId ) : null ;
29-
30- if ( ! planId || isNaN ( planId ) ) {
31- return < div > Invalid or missing plan ID</ div > ;
32- }
33-
34- let plan ;
35-
36- try {
37- plan = await db . query . savedPlansT . findFirst ( {
38- where : and (
39- eq ( savedPlansT . id , planId ) ,
40- eq ( savedPlansT . userId , session . user . id ) ,
41- ) ,
42- } ) ;
43- } catch ( error ) {
44- console . error ( "Error loading plan:" , error ) ;
45- return notFound ( ) ;
46- }
47-
48- if ( ! plan ) {
49- return notFound ( ) ;
50- }
51-
52- // Fetch available NUPath options
53- const nupathOptions = await db
54- . selectDistinct ( { short : nupathsT . short , name : nupathsT . name } )
55- . from ( nupathsT )
56- . then ( ( c ) => c . map ( ( e ) => ( { label : e . name , value : e . short } ) ) ) ;
57-
58- // Fetch terms from the db
59- const terms = await getTerms ( ) ;
60-
61- // Fetch campuses for the mapping
62- const campuses = await getCampuses ( ) ;
638
64- // Fetch nupaths for the mapping
65- const nupaths = await getNupaths ( ) ;
9+ export default async function Page ( ) {
10+ const [ session , nupathOptions , terms , campuses , nupaths ] = await Promise . all ( [
11+ auth . api . getSession ( { headers : await headers ( ) } ) ,
12+ db
13+ . selectDistinct ( { short : nupathsT . short , name : nupathsT . name } )
14+ . from ( nupathsT )
15+ . then ( ( c ) => c . map ( ( e ) => ( { label : e . name , value : e . short } ) ) ) ,
16+ getTerms ( ) ,
17+ getCampuses ( ) ,
18+ getNupaths ( ) ,
19+ ] ) ;
6620
6721 return (
6822 < div className = "bg-secondary h-full w-full px-4 pt-4 xl:px-6" >
@@ -71,6 +25,7 @@ export default async function Page({
7125 terms = { terms }
7226 campuses = { campuses }
7327 nupaths = { nupaths }
28+ isLoggedIn = { ! ! session ?. user ?. id }
7429 />
7530 </ div >
7631 ) ;
0 commit comments