Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Portal frontend 52 #63

Merged
merged 27 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"✅ Do add `devDependencies` below that are `peerDependencies` in the CFL package."
],
"dependencies": {
"codeforlife": "github:ocadotechnology/codeforlife-package-javascript#v2.3.5",
"codeforlife": "github:ocadotechnology/codeforlife-package-javascript#v2.3.6",
"crypto-js": "^4.2.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/api/student.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type TransferStudentsArg = BulkUpdateArg<
"klass",
never,
{
user: Arg<User, never, "first_name">
user?: Arg<User, never, "first_name">
}
>

Expand Down
28 changes: 28 additions & 0 deletions src/components/form/ClassAutocompleteField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ApiAutocompleteField } from "codeforlife/components/form"
import { type FC } from "react"

import { type ListClassesArg, useLazyListClassesQuery } from "../../api/klass"

export interface ClassAutocompleteFieldProps {
required?: boolean
name?: string
_id?: ListClassesArg["_id"]
}

const ClassAutocompleteField: FC<ClassAutocompleteFieldProps> = ({

Check warning on line 12 in src/components/form/ClassAutocompleteField.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/form/ClassAutocompleteField.tsx#L12

Added line #L12 was not covered by tests
required = false,
name = "klass",
_id,
}) => (
<ApiAutocompleteField

Check warning on line 17 in src/components/form/ClassAutocompleteField.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/form/ClassAutocompleteField.tsx#L17

Added line #L17 was not covered by tests
useLazyListQuery={useLazyListClassesQuery}
searchKey="id_or_name"
filterOptions={{ _id }}
getOptionLabel={({ name, id, teacher }) =>
`${name} (${id}), ${teacher.user.first_name} ${teacher.user.last_name}`

Check warning on line 22 in src/components/form/ClassAutocompleteField.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/form/ClassAutocompleteField.tsx#L21-L22

Added lines #L21 - L22 were not covered by tests
}
textFieldProps={{ required, name }}
/>
)

export default ClassAutocompleteField
2 changes: 2 additions & 0 deletions src/components/form/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from "./ClassAutocompleteField"
export { default as ClassAutocompleteField } from "./ClassAutocompleteField"
export * from "./ClassNameField"
export { default as ClassNameField } from "./ClassNameField"
export * from "./LastNameField"
Expand Down
17 changes: 0 additions & 17 deletions src/components/table/Body.tsx

This file was deleted.

48 changes: 0 additions & 48 deletions src/components/table/Cell.tsx

This file was deleted.

20 changes: 0 additions & 20 deletions src/components/table/Row.tsx

This file was deleted.

35 changes: 0 additions & 35 deletions src/components/table/Table.tsx

This file was deleted.

15 changes: 0 additions & 15 deletions src/components/table/index.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/pages/home/TargetAudience.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"Helping teachers and families to inspire the next generation of computer scientists.",
"Anyone can learn how to code. We will help you learn how. It's fun, free and easy.",
]
const linkButtons: LinkButtonProps[] = [
const linkButtons: LinkButtonProps<"to">[] = [

Check warning on line 41 in src/pages/home/TargetAudience.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/home/TargetAudience.tsx#L41

Added line #L41 was not covered by tests
{
children: "Learn more",
to: paths.teacher._,
Expand Down
23 changes: 15 additions & 8 deletions src/pages/teacherDashboard/classes/ClassTable.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as tables from "codeforlife/components/table"
import { CopyIconButton, TablePagination } from "codeforlife/components"
import { Create as CreateIcon } from "@mui/icons-material"
import { type FC } from "react"
Expand All @@ -6,7 +7,6 @@
import { Typography } from "@mui/material"
import { generatePath } from "react-router"

import * as tables from "../../../components/table"
import { type RetrieveUserResult } from "../../../api/user"
import { paths } from "../../../routes"
import { useLazyListClassesQuery } from "../../../api/klass"
Expand All @@ -27,31 +27,38 @@
</Typography>
<TablePagination
useLazyListQuery={useLazyListClassesQuery}
filters={
authUser.teacher.is_admin ? undefined : { teacher: authUser.teacher.id }
}
preferCacheValue
>
{classes => (
<tables.Table
titles={
headers={
authUser.teacher.is_admin
? ["Class name", "Access code", "Teacher", "Action"]
: ["Class name", "Access code", "Action"]
}
>
{classes.map(klass => (
<tables.Body key={`klass-${klass.id}`}>
<tables.BodyRow key={`klass-${klass.id}`}>

Check warning on line 44 in src/pages/teacherDashboard/classes/ClassTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/teacherDashboard/classes/ClassTable.tsx#L44

Added line #L44 was not covered by tests
<tables.Cell>{klass.name}</tables.Cell>
<tables.Cell justifyContent="space-between" alignItems="center">
<tables.CellStack
direction="row"
justifyContent="space-between"
alignItems="center"
>
{klass.id}
<CopyIconButton content={klass.id} />
</tables.Cell>
</tables.CellStack>
{authUser.teacher.is_admin && (
<tables.Cell>
{klass.teacher.id === authUser.teacher.id
? "You"
: `${klass.teacher.user.first_name} ${klass.teacher.user.last_name}`}
</tables.Cell>
)}
<tables.Cell justifyContent="center">
<tables.CellStack alignItems="center">
<LinkButton
to={generatePath(
paths.teacher.dashboard.tab.classes.class._,
Expand All @@ -63,8 +70,8 @@
>
Edit details
</LinkButton>
</tables.Cell>
</tables.Body>
</tables.CellStack>
</tables.BodyRow>
))}
</tables.Table>
)}
Expand Down
9 changes: 6 additions & 3 deletions src/pages/teacherDashboard/classes/Classes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { type SchoolTeacherUser } from "codeforlife/api"
import Class from "./class/Class"
import ClassTable from "./ClassTable"
import CreateClassForm from "./CreateClassForm"
import JoinClassRequest from "./JoinClassRequest"
import JoinClassRequest from "./joinClassRequest/JoinClassRequest"
import JoinClassRequestTable from "./JoinClassRequestTable"
import ResetStudentsPassword from "./class/ResetStudentsPassword"
import ResetStudentsPassword from "./resetStudentsPassword/ResetStudentsPassword"
import { type RetrieveUserResult } from "../../../api/user"
import UpdateStudentUser from "./class/UpdateStudentUser"
import TransferStudents from "./transferStudents/TransferStudents"
import UpdateStudentUser from "./updateStudentUser/UpdateStudentUser"

export interface ClassesProps {
authUser: SchoolTeacherUser<RetrieveUserResult>
Expand All @@ -18,6 +19,7 @@ export interface ClassesProps {
| "join-class-request"
| "reset-students-password"
| "update-student-user"
| "transfer-students"
}

const Classes: FC<ClassesProps> = ({ authUser, view }) => {
Expand All @@ -27,6 +29,7 @@ const Classes: FC<ClassesProps> = ({ authUser, view }) => {
"join-class-request": <JoinClassRequest />,
"reset-students-password": <ResetStudentsPassword />,
"update-student-user": <UpdateStudentUser />,
"transfer-students": <TransferStudents />,
}[view]
}

Expand Down
12 changes: 6 additions & 6 deletions src/pages/teacherDashboard/classes/JoinClassRequestTable.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as tables from "codeforlife/components/table"
import {
Add as AddIcon,
DoNotDisturb as DoNotDisturbIcon,
Expand All @@ -10,7 +11,6 @@
import { generatePath } from "react-router"
import { useNavigate } from "codeforlife/hooks"

import * as tables from "../../../components/table"
import {
useHandleJoinClassRequestMutation,
useLazyListUsersQuery,
Expand Down Expand Up @@ -47,10 +47,10 @@
users.length ? (
<tables.Table
className="body"
titles={["Name", "Email address", "Class", "Actions"]}
headers={["Name", "Email address", "Class", "Actions"]}
>
{users.map(user => (
<tables.Body key={`user-${user.id}`}>
<tables.BodyRow key={`user-${user.id}`}>

Check warning on line 53 in src/pages/teacherDashboard/classes/JoinClassRequestTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/teacherDashboard/classes/JoinClassRequestTable.tsx#L53

Added line #L53 was not covered by tests
<tables.Cell>
<Typography>
{user.first_name} {user.last_name}
Expand All @@ -66,7 +66,7 @@
? ""
: ` (${user.requesting_to_join_class!.teacher.user.first_name} ${user.requesting_to_join_class!.teacher.user.last_name})`}
</tables.Cell>
<tables.Cell justifyContent="center">
<tables.CellStack alignItems="center">
<LinkButton
to={generatePath(
paths.teacher.dashboard.tab.classes.class.joinRequest._,
Expand Down Expand Up @@ -106,8 +106,8 @@
>
Reject
</Button>
</tables.Cell>
</tables.Body>
</tables.CellStack>
</tables.BodyRow>
))}
</tables.Table>
) : (
Expand Down
Loading