Skip to content

Commit

Permalink
fix tables
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Sep 24, 2024
1 parent 39a0abb commit e2e2f18
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 213 deletions.
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.

42 changes: 0 additions & 42 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.

20 changes: 12 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 { type SchoolTeacherUser } from "codeforlife/api"
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 @@ -31,27 +31,31 @@ const ClassTable: FC<ClassTableProps> = ({ authUser }) => (
>
{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}`}>
<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 +67,8 @@ const ClassTable: FC<ClassTableProps> = ({ authUser }) => (
>
Edit details
</LinkButton>
</tables.Cell>
</tables.Body>
</tables.CellStack>
</tables.BodyRow>
))}
</tables.Table>
)}
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 { TablePagination } from "codeforlife/components"
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 @@ const JoinClassRequestTable: FC<JoinClassRequestTableProps> = ({
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}`}>
<tables.Cell>
<Typography>
{user.first_name} {user.last_name}
Expand All @@ -66,7 +66,7 @@ const JoinClassRequestTable: FC<JoinClassRequestTableProps> = ({
? ""
: ` (${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 @@ const JoinClassRequestTable: FC<JoinClassRequestTableProps> = ({
>
Reject
</Button>
</tables.Cell>
</tables.Body>
</tables.CellStack>
</tables.BodyRow>
))}
</tables.Table>
) : (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as tables from "codeforlife/components/table"
import { type FC } from "react"
import { TablePagination } from "codeforlife/components"
import { Typography } from "@mui/material"

import * as tables from "../../../../components/table"
import { type RetrieveClassResult } from "../../../../api/klass"
import { useLazyListUsersQuery } from "../../../../api/user"

Expand All @@ -27,7 +27,7 @@ const StudentTable: FC<StudentTableProps> = ({ klass, newClass }) => (
>
{users => (
<tables.Table
titles={["Student name"]}
headers={["Student name"]}
containerProps={{
sx: {
margin: "auto",
Expand All @@ -37,14 +37,14 @@ const StudentTable: FC<StudentTableProps> = ({ klass, newClass }) => (
>
{users.length ? (
users.map(user => (
<tables.Body key={`user-${user.id}`}>
<tables.BodyRow key={`user-${user.id}`}>
<tables.Cell>{user.first_name}</tables.Cell>
</tables.Body>
</tables.BodyRow>
))
) : (
<tables.Body>
<tables.BodyRow>
<tables.Cell>(no students)</tables.Cell>
</tables.Body>
</tables.BodyRow>
)}
</tables.Table>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as forms from "codeforlife/components/form"
import * as tables from "codeforlife/components/table"
import { Stack, Typography } from "@mui/material"
import { type FC } from "react"
import { LinkButton } from "codeforlife/components/router"
import { type StudentUser } from "codeforlife/api"
import { submitForm } from "codeforlife/utils/form"
import { useNavigate } from "codeforlife/hooks"

import * as tables from "../../../../components/table"
import {
type TransferStudentsArg,
useTransferStudentsMutation,
Expand Down Expand Up @@ -81,9 +81,9 @@ const TransferStudentsForm: FC<TransferStudentsFormProps> = ({
},
})}
>
<tables.Table titles={["Existing name", "New student name"]}>
<tables.Table headers={["Existing name", "New student name"]}>
{studentUsers.map(studentUser => (
<tables.Body key={`user-${studentUser.id}`}>
<tables.BodyRow key={`user-${studentUser.id}`}>
<tables.Cell>{studentUser.first_name}</tables.Cell>
<tables.Cell>
<forms.FirstNameField
Expand All @@ -93,7 +93,7 @@ const TransferStudentsForm: FC<TransferStudentsFormProps> = ({
placeholder={`Enter a name for ${studentUser.first_name}`}
/>
</tables.Cell>
</tables.Body>
</tables.BodyRow>
))}
</tables.Table>
<Stack className="form-buttons" justifyContent="end">
Expand Down
20 changes: 10 additions & 10 deletions src/pages/teacherDashboard/school/Leave.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as form from "codeforlife/components/form"
import * as page from "codeforlife/components/page"
import * as tables from "codeforlife/components/table"
import * as yup from "yup"
import { CircularProgress, Stack, Typography } from "@mui/material"
import { type FC, useEffect } from "react"
Expand All @@ -9,7 +10,6 @@ import { TablePagination } from "codeforlife/components"
import { type User } from "codeforlife/api"
import { submitForm } from "codeforlife/utils/form"

import * as table from "../../../components/table"
import {
useLazyListClassesQuery,
useUpdateClassesMutation,
Expand Down Expand Up @@ -125,27 +125,27 @@ const Leave: FC<LeaveProps> = ({ authUserId }) => {
)}
onSubmit={submitForm(updateClasses)}
>
<table.Table
<tables.Table
className="body"
titles={["Class name", "New teacher"]}
headers={["Class name", "New teacher"]}
>
{classes.map(klass => (
<table.Body key={klass.id}>
<table.Cell>
<tables.BodyRow key={klass.id}>
<tables.Cell>
<Typography variant="subtitle1">
{klass.name}
</Typography>
</table.Cell>
<table.Cell direction="column" alignItems="flex-start">
</tables.Cell>
<tables.CellStack alignItems="flex-start">
<TeacherAutocompleteField
required
name={`${klass.id}.teacher`}
_id={user.id}
/>
</table.Cell>
</table.Body>
</tables.CellStack>
</tables.BodyRow>
))}
</table.Table>
</tables.Table>
<Stack direction="row" spacing={2}>
<LinkButton
variant="outlined"
Expand Down
Loading

0 comments on commit e2e2f18

Please sign in to comment.