Skip to content

Commit 509c9a4

Browse files
committed
Add mentor reflections
1 parent 1ef3b17 commit 509c9a4

File tree

3 files changed

+106
-1
lines changed

3 files changed

+106
-1
lines changed

src/pages/dash/mm/[token]/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ export default function MentorDashboard() {
9696
All Students »
9797
</Button>
9898
<Button as="a" fontSize="sm" href={`/dash/mm/${query.token}/status`} target="_blank" mb={8}>
99-
My Student Status Dashboard &raquo;
99+
Student Reflections &raquo;
100+
</Button>
101+
<Button as="a" fontSize="sm" href={`/dash/mm/${query.token}/mentor-surveys`} target="_blank" mb={8}>
102+
Mentor Reflections &raquo;
100103
</Button>
101104
</Box>
102105
<Box as="table" w="100%">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
fragment SurveyResponseDetails on LabsSurveyResponse {
2+
surveyOccurence {
3+
id
4+
survey { id name personType }
5+
dueAt
6+
}
7+
authorMentor { id name }
8+
authorStudent { id name }
9+
student { id name }
10+
mentor { id name }
11+
project { id }
12+
response
13+
caution
14+
}
15+
16+
query MentorSurveys($username: String!) {
17+
labs {
18+
mentors(where: { assignedToManager: $username }) {
19+
name
20+
id
21+
email
22+
surveyResponsesAbout {
23+
...SurveyResponseDetails
24+
}
25+
projects {
26+
surveyResponsesAbout {
27+
...SurveyResponseDetails
28+
}
29+
}
30+
}
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { Content } from "@codeday/topo/Molecule";
2+
import Page from "../../../../components/Page";
3+
import { Accordion, AccordionButton, AccordionIcon, AccordionItem, AccordionPanel } from "@chakra-ui/react";
4+
import { decode } from "jsonwebtoken";
5+
import { apiFetch } from "@codeday/topo/utils";
6+
import { MentorSurveys } from './mentor-surveys.gql';
7+
import { Box, Heading, Link } from "@codeday/topo/Atom";
8+
import { DateTime } from "luxon";
9+
import SurveyFields from "../../../../components/SurveyFields";
10+
11+
12+
function getCautionColors(caution) {
13+
if (caution > 0.9) return { bg: 'red.500', color: 'red.50' };
14+
if (caution > 0.1) return { bg: 'orange.500', color: 'orange.50' };
15+
return {};
16+
}
17+
18+
export default function MentorSurveysPage({ mentors }) {
19+
return (
20+
<Page>
21+
<Content>
22+
{mentors.map((m) => (
23+
<Box mb={4}>
24+
<Link href={`mailto:${m.email}`}>
25+
<Heading as="h4" fontSize="2xl">{m.name}</Heading>
26+
</Link>
27+
<Accordion>
28+
{m.surveyResponsesAbout
29+
.sort((a, b) => {
30+
if (DateTime.fromISO(a.surveyOccurence.dueAt) > DateTime.fromISO(b.surveyOccurence.dueAt)) return -1;
31+
if (DateTime.fromISO(a.surveyOccurence.dueAt) < DateTime.fromISO(b.surveyOccurence.dueAt)) return 1;
32+
if (a.surveyOccurence.survey.personType === 'STUDENT' && b.surveyOccurence.survey.personType === 'MENTOR') return 1;
33+
if (a.surveyOccurence.survey.personType === 'MENTOR' && b.surveyOccurence.survey.personType === 'STUDENT') return -1;
34+
})
35+
.map((sr) => (
36+
<AccordionItem>
37+
<AccordionButton {...getCautionColors(sr.caution)}>
38+
{DateTime.fromISO(sr.surveyOccurence.dueAt).toLocaleString()}{' - '}
39+
{(sr.authorMentor || sr.authorStudent).id === m.id
40+
? 'Self-Reflection'
41+
: `${(sr.authorMentor || sr.authorStudent).name} (${sr.surveyOccurence.survey.personType === 'STUDENT' ? 'student' : 'peer'})`
42+
}
43+
<AccordionIcon />
44+
</AccordionButton>
45+
<AccordionPanel pb={4}>
46+
<SurveyFields content={sr.response} />
47+
</AccordionPanel>
48+
</AccordionItem>
49+
))}
50+
</Accordion>
51+
</Box>
52+
))}
53+
</Content>
54+
</Page>
55+
)
56+
}
57+
58+
59+
export async function getServerSideProps({ params: { token } }) {
60+
const { sid: username } = decode(token) || {};
61+
const result = await apiFetch(MentorSurveys, { username }, {
62+
'X-Labs-Authorization': `Bearer ${token}`,
63+
});
64+
65+
return {
66+
props: {
67+
mentors: result?.labs?.mentors,
68+
},
69+
};
70+
}

0 commit comments

Comments
 (0)