-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
143 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/pages/teacherDashboard/classes/joinClassRequest/AddedStudent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import * as page from "codeforlife/components/page" | ||
import { type FC } from "react" | ||
import { Link } from "codeforlife/components/router" | ||
import { type StudentUser } from "codeforlife/api" | ||
import { Typography } from "@mui/material" | ||
import { generatePath } from "react-router" | ||
|
||
import { type RetrieveClassResult } from "../../../../api/klass" | ||
import { type RetrieveUserResult } from "../../../../api/user" | ||
import { paths } from "../../../../routes" | ||
|
||
export interface AddedStudentProps { | ||
klass: RetrieveClassResult | ||
user: StudentUser<RetrieveUserResult> | ||
} | ||
|
||
const AddedStudent: FC<AddedStudentProps> = ({ klass, user }) => ( | ||
<> | ||
<page.Section> | ||
<Typography variant="h4" align="center" mb={0}> | ||
External student added to class {klass.name} ({klass.id}) | ||
</Typography> | ||
</page.Section> | ||
<page.Section> | ||
<Typography> | ||
The student has been successfully added to the class {klass.name}. | ||
</Typography> | ||
<Typography> | ||
Please provide the student with their new login details: | ||
</Typography> | ||
</page.Section> | ||
<page.Section boxProps={{ bgcolor: "info.main" }}> | ||
<Typography> | ||
<strong>Class Access Code:</strong> {klass.id} | ||
</Typography> | ||
<Typography> | ||
<strong>Name:</strong> {user.first_name} | ||
</Typography> | ||
</page.Section> | ||
<page.Section> | ||
<Typography> | ||
{user.first_name} should now login as a student with these details. | ||
</Typography> | ||
<Typography mb={7}> | ||
{user.first_name}'s password is unchanged. You may manage this | ||
student, including changing their name and password, as with other | ||
students. | ||
</Typography> | ||
<Link | ||
className="back-to" | ||
to={generatePath(paths.teacher.dashboard.tab.classes.class._, { | ||
classId: klass.id, | ||
})} | ||
> | ||
Class | ||
</Link> | ||
</page.Section> | ||
</> | ||
) | ||
|
||
export default AddedStudent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/pages/teacherDashboard/classes/joinClassRequest/JoinClassRequest.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import * as yup from "yup" | ||
import { type FC, useEffect, useState } from "react" | ||
import { type IndependentUser, type StudentUser } from "codeforlife/api" | ||
import { useNavigate, useParams } from "codeforlife/hooks" | ||
import { CircularProgress } from "@mui/material" | ||
|
||
import { | ||
type RetrieveUserResult, | ||
useLazyRetrieveUserQuery, | ||
} from "../../../../api/user" | ||
import AddedStudent from "./AddedStudent" | ||
import HandleRequest from "./HandleRequest" | ||
import { classIdSchema } from "../../../../app/schemas" | ||
import { paths } from "../../../../routes" | ||
import { useLazyRetrieveClassQuery } from "../../../../api/klass" | ||
|
||
export interface JoinClassRequestProps {} | ||
|
||
const JoinClassRequest: FC<JoinClassRequestProps> = () => { | ||
const navigate = useNavigate() | ||
const [wasAccepted, setWasAccepted] = useState(false) | ||
const params = useParams({ | ||
classId: classIdSchema.required(), | ||
userId: yup.number().required(), | ||
}) | ||
|
||
const [ | ||
retrieveUser, | ||
{ data: user, isLoading: userIsLoading, isError: userIsError }, | ||
] = useLazyRetrieveUserQuery() | ||
const [ | ||
retrieveClass, | ||
{ data: klass, isLoading: classIsLoading, isError: classIsError }, | ||
] = useLazyRetrieveClassQuery() | ||
|
||
useEffect(() => { | ||
if (params) { | ||
void retrieveUser(params.userId) | ||
void retrieveClass(params.classId) | ||
} else navigate(paths.error.type.pageNotFound._) | ||
}, [params, navigate, retrieveUser, retrieveClass]) | ||
|
||
if (!params) return <></> | ||
|
||
if (!user || userIsLoading || !klass || classIsLoading) | ||
return <CircularProgress /> | ||
|
||
if (userIsError || classIsError) alert("TODO: handle error") | ||
|
||
return wasAccepted ? ( | ||
<AddedStudent | ||
klass={klass} | ||
user={user as StudentUser<RetrieveUserResult>} | ||
/> | ||
) : ( | ||
<HandleRequest | ||
klass={klass} | ||
user={user as IndependentUser<RetrieveUserResult>} | ||
onAcceptRequest={() => { | ||
setWasAccepted(true) | ||
}} | ||
/> | ||
) | ||
} | ||
|
||
export default JoinClassRequest |