Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
faucomte97 committed Nov 22, 2024
1 parent 6b5584e commit 53010c7
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 142 deletions.
128 changes: 63 additions & 65 deletions src/pages/studentJoinClass/RequestPending.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Button, CircularProgress, Stack, Typography } from "@mui/material"
import { Button, Stack, Typography } from "@mui/material"
import { type FC } from "react"
import { type IndependentUser } from "codeforlife/api"
import { LinkButton } from "codeforlife/components/router"
import { useNavigate } from "react-router-dom"

import { type RetrieveUserResult, useUpdateUserMutation } from "../../api/user"
import { useRetrieveSchoolQuery } from "../../api/school.ts"
import { handleResultState } from "codeforlife/utils/api"
import { paths } from "../../routes"
import { useRetrieveSchoolQuery } from "../../api/school"

export interface RequestPendingProps {
user: IndependentUser<RetrieveUserResult>
Expand All @@ -13,71 +16,66 @@ export interface RequestPendingProps {
const RequestPending: FC<RequestPendingProps> = ({ user }) => {
const navigate = useNavigate()
const [updateUser] = useUpdateUserMutation()
const result = useRetrieveSchoolQuery(user.requesting_to_join_class!.school)
const school = result.data

if (!school) return <CircularProgress />

return (
<>
<Typography variant="h5">Request pending</Typography>
<Typography>
Your request to join class {user.requesting_to_join_class!.id} in the
school or club {school.name} is still pending.
</Typography>
<Typography>
The teacher for that class must review and approve the request to
complete the process.
</Typography>
<Typography>
If successful, the teacher will then contact you with your new login
details.
</Typography>
<Typography>
<strong>Warning:</strong> once the teacher accepts you to their class,
that teacher and the school or club will manage your account.
</Typography>
<Typography>
You may cancel your request now, before the teacher makes their
decision.
</Typography>

<Stack direction="row" spacing={2}>
<Button
variant="outlined"
onClick={() => {
navigate(-1)
}}
>
Back
</Button>
<Button
onClick={() => {
void updateUser({
id: user.id,
requesting_to_join_class: null,
})
.unwrap()
.then(() => {
navigate(".", {
state: {
notifications: [
{
props: {
children:
"Your request to join a school has been revoked successfully.",
},
},
],
},
return handleResultState(
useRetrieveSchoolQuery(user.requesting_to_join_class!.school),
school => {
return (
<>
<Typography variant="h5">Request pending</Typography>
<Typography>
Your request to join class {user.requesting_to_join_class!.id} in
the school or club {school.name} is still pending.
</Typography>
<Typography>
The teacher for that class must review and approve the request to
complete the process.
</Typography>
<Typography>
If successful, the teacher will then contact you with your new login
details.
</Typography>
<Typography>
<strong>Warning:</strong> once the teacher accepts you to their
class, that teacher and the school or club will manage your account.
</Typography>
<Typography>
You may cancel your request now, before the teacher makes their
decision.
</Typography>
<Stack direction="row" spacing={2}>
<LinkButton variant="outlined" to={paths.indy.dashboard._}>
Back
</LinkButton>
<Button
onClick={() => {
void updateUser({
id: user.id,
requesting_to_join_class: null,
})
})
}}
>
Cancel request
</Button>
</Stack>
</>
.unwrap()
.then(() => {
navigate(".", {
state: {
notifications: [
{
props: {
children:
"Your request to join a school has been revoked successfully.",
},
},
],
},
})
})
}}
>
Cancel request
</Button>
</Stack>
</>
)
},
)
}

Expand Down
61 changes: 61 additions & 0 deletions src/pages/studentJoinClass/RequestToJoinClassForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import * as forms from "codeforlife/components/form"
import { type FC } from "react"
import { LinkButton } from "codeforlife/components/router"
import { Stack } from "@mui/material"
import { type User } from "codeforlife/api"
import { useNavigate } from "codeforlife/hooks"

import { classIdSchema } from "../../app/schemas.ts"
import { paths } from "../../routes"
import { useUpdateUserMutation } from "../../api/user"

export interface RequestToJoinClassFormProps {
indyUser: Pick<User, "id" | "requesting_to_join_class">
}

const RequestToJoinClassForm: FC<RequestToJoinClassFormProps> = ({
indyUser,
}) => {
const navigate = useNavigate()

return (
<forms.Form
initialValues={indyUser}
useMutation={useUpdateUserMutation}
submitOptions={{
then: () => {
navigate(".", {
state: {
notifications: [
{
index: 1,
props: {
children:
"Your request to join a school has been received successfully.",
},
},
],
},
})
},
}}
>
<forms.TextField
placeholder="Class access code"
label="Class access code"
name="requesting_to_join_class"
sx={{ width: { xs: "100%", sm: "50%" } }}
schema={classIdSchema}
required
/>
<Stack direction="row" spacing={2} paddingY={3}>
<LinkButton variant="outlined" to={paths.indy.dashboard._}>
Cancel
</LinkButton>
<forms.SubmitButton>Request</forms.SubmitButton>
</Stack>
</forms.Form>
)
}

export default RequestToJoinClassForm
12 changes: 3 additions & 9 deletions src/pages/studentJoinClass/StudentJoinClass.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { type FC } from "react"
import type { IndependentUser } from "codeforlife/api"
import type { SessionMetadata } from "codeforlife/hooks"
import { Typography } from "@mui/material"
import { handleResultState } from "codeforlife/utils/api.tsx"
import { handleResultState } from "codeforlife/utils/api"

import { type RetrieveUserResult, useRetrieveUserQuery } from "../../api/user"
import RequestPending from "./RequestPending.tsx"
import UpdateRequestingToJoinClassForm from "./UpdateRequestingToJoinClassForm.tsx"
import RequestToJoinClassForm from "./RequestToJoinClassForm.tsx"

const _StudentJoinClass: FC<SessionMetadata> = ({ user_id }) => {
return handleResultState(useRetrieveUserQuery(user_id), authUser => {
Expand Down Expand Up @@ -40,13 +40,7 @@ const _StudentJoinClass: FC<SessionMetadata> = ({ user_id }) => {
If successful, the teacher will contact you with your new login
details.
</Typography>

<UpdateRequestingToJoinClassForm
indyUser={{
id: user_id,
requesting_to_join_class: user.requesting_to_join_class,
}}
/>
<RequestToJoinClassForm indyUser={user} />

Check failure on line 43 in src/pages/studentJoinClass/StudentJoinClass.tsx

View workflow job for this annotation

GitHub Actions / main / test / test-js-code

Type 'IndependentUser<RetrieveUserResult>' is not assignable to type 'Pick<User, "id" | "requesting_to_join_class">'.

Check failure on line 43 in src/pages/studentJoinClass/StudentJoinClass.tsx

View workflow job for this annotation

GitHub Actions / main / test / test-js-code

Type 'IndependentUser<RetrieveUserResult>' is not assignable to type 'Pick<User, "id" | "requesting_to_join_class">'.
</>
)}
</page.Section>
Expand Down
68 changes: 0 additions & 68 deletions src/pages/studentJoinClass/UpdateRequestingToJoinClassForm.tsx

This file was deleted.

0 comments on commit 53010c7

Please sign in to comment.