diff --git a/components/ClassInviteTable.js b/components/ClassInviteTable.js index 5501a308a..f0ea0367c 100644 --- a/components/ClassInviteTable.js +++ b/components/ClassInviteTable.js @@ -30,12 +30,11 @@ export default function ClassInviteTable({ ); const ref = useRef(); - const userCurrentDomain = process.env.NEXTAUTH_URL; const copy = async () => { //Add the full URL to send to student await navigator.clipboard.writeText( - `${userCurrentDomain}/join/` + currentClass.classroomId + `${window.location.origin}/join/` + currentClass.classroomId ); toast('Class code successfully copied', { diff --git a/pages/join/[...joinCode].js b/pages/join/[...joinCode].js index cf2065ab2..0fc8390af 100644 --- a/pages/join/[...joinCode].js +++ b/pages/join/[...joinCode].js @@ -1,4 +1,5 @@ import Head from 'next/head'; +import Link from 'next/link'; import Navbar from '../../components/navbar'; import { useState } from 'react'; import { useRouter } from 'next/router'; @@ -7,16 +8,35 @@ import AuthButton from '../../components/authButton'; import DisplayNotification from '../../components/displayNotification'; import { ToastContainer } from 'react-toastify'; import 'react-toastify/dist/ReactToastify.css'; +import prisma from '../../prisma/prisma'; export async function getServerSideProps(ctx) { const userSession = await getSession(ctx); + + const params = ctx.params || {}; + const joinParam = params.joinCode || null; + const classroomId = Array.isArray(joinParam) ? joinParam[0] : joinParam; + + let classroom = null; + if (classroomId) { + try { + classroom = await prisma.classroom.findUnique({ + where: { classroomId }, + select: { classroomName: true, description: true, classroomId: true } + }); + } catch (err) { + classroom = null; + } + } + return { props: { - userSession: userSession + userSession: userSession, + classroom } }; } -export default function JoinWithCode({ userSession }) { +export default function JoinWithCode({ userSession, classroom }) { const [formData] = useState({}); const router = useRouter(); const { joinCode } = router.query; @@ -61,57 +81,84 @@ export default function JoinWithCode({ userSession }) { - {userSession ? ( + {!userSession ? ( <> -
-
+
+
-

- Register for Classroom +

+ Sign In with FreeCodeCamp

-
-
- -
-
+
+ +
+ ) : classroom === null ? ( +
+
+

+ Classroom Not Found +

+

+ We could not find a classroom for this invite link. Please check + the link or ask your teacher to resend the invite. +

+
+ + Back to Home + +
+
+
) : ( <> -
-
+
+
-

- Sign In with FreeCodeCamp +

+ Join Classroom

+ {classroom && ( +

+ Joining:{' '} + + {classroom.classroomName || classroom.classroomId} + +

+ )}
-
- +
+
+ +
+
+
+

+ If you have not enabled Classroom access on freeCodeCamp, + please open your settings and enable it before connecting. +

+ +

+ Note: If you change the email on your freeCodeCamp account + later, you may need to reconnect to this classroom. +

diff --git a/pages/join/index.js b/pages/join/index.js index 82e401616..428f4e537 100644 --- a/pages/join/index.js +++ b/pages/join/index.js @@ -1,21 +1,59 @@ import Layout from '../../components/layout'; import Head from 'next/head'; import Navbar from '../../components/navbar'; +import Link from 'next/link'; +import AuthButton from '../../components/authButton'; +import { getSession } from 'next-auth/react'; -export default function Join() { +export default function Join({ userSession }) { return ( - Create Next App - + Join a Classroom + - -
  • -

    Welcome

    -
  • -
    - No code given + + +
    +
    + {!userSession ? ( +
    +
    +

    + Sign In with FreeCodeCamp +

    +
    + +
    +
    +
    + ) : ( +
    +

    No join code provided

    +

    + To join a Classroom, you must open the unique join link provided + by your instructor. The link should look like{' '} + /join/<classroomId>. +

    + + + Return to Home + + +
    + )} +
    +
    ); } + +export async function getServerSideProps(ctx) { + const session = await getSession(ctx); + return { + props: { + userSession: session || null + } + }; +}