Skip to content

Commit

Permalink
fix teacher dash
Browse files Browse the repository at this point in the history
  • Loading branch information
vincetiu8 committed Dec 12, 2023
1 parent 067a873 commit 1103b1e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 28 deletions.
13 changes: 3 additions & 10 deletions client/src/Admin/StudentCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,13 @@ import { useData } from '../util/api';

type StudentCardProps = {
studentID: string;
name: string;
lesson: string;
};

function StudentCardFromID({ studentID, lesson }: StudentCardProps) {
function StudentCardFromID({ studentID, name, lesson }: StudentCardProps) {
const navigate = useNavigate();

const user = useData(`user/${studentID}`);
let label = 'Name';
if (user) {
const info = user.data;
const name = `${info?.firstName} ${info?.lastName}`;
label = name;
}

function handleClick() {
const s = `/resources/${studentID}`;
navigate(s);
Expand All @@ -29,7 +22,7 @@ function StudentCardFromID({ studentID, lesson }: StudentCardProps) {
<Card sx={{ p: 2, bgcolor: '#EDEDED', mb: 2, borderRadius: '8px' }}>
<CardActionArea onClick={handleClick}>
<CardContent>
<Typography variant="h5">{label}</Typography>
<Typography variant="h5">{name}</Typography>
<Typography
sx={{
color: '#0175C0',
Expand Down
25 changes: 7 additions & 18 deletions client/src/Teacher/TeacherDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ const ScrollableBox = styled(Box)({
function createData(data: any) {
return data.map((student: any) => (
<StudentCardFromID
studentID={student._id}
lesson={getLessonStringFromLessonLevel(student.lesson)}
studentID={student.userId}
name={`${student.firstName} ${student.lastName}`}
lesson={getLessonStringFromLessonLevel(student.lessonNumber)}
/>
));
}
Expand Down Expand Up @@ -86,23 +87,11 @@ function SplitGrid() {

useEffect(() => {
const fetchData = async () => {
const res = await axios.get(
`http://localhost:4000/api/student/students-by-teacher/${self.email}`,
const { data } = await axios.get(
`http://localhost:4000/api/student/students-lessons-by-teacher/${self.email}`,
);
const { data } = res;
const newData = await Promise.all(
data.map(async (student: any) => {
const res2 = await axios.get(
`http://localhost:4000/api/lesson/${student.lesson_level}`,
);
return {
...student,
lesson: res2.data.number,
};
}),
);
console.log(newData);
setStudentData(newData);

setStudentData(data);
};
fetchData();
}, [self.email]);
Expand Down

0 comments on commit 1103b1e

Please sign in to comment.