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