-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds infoboxes to students who have dietary restrictions, need to leave overnight, or have requested a laptop add "survey response breakdown" component, displaying statistics on how students filled out the post-registration survey
- Loading branch information
Showing
7 changed files
with
89 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
fragment TicketSurveyBreakdown on ClearTicket { | ||
id | ||
age | ||
surveyResponses | ||
type | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React from 'react'; | ||
import { | ||
Text, List, ListItem, | ||
} from '@codeday/topo/Atom'; | ||
import { | ||
Accordion, AccordionButton, AccordionIcon, AccordionItem, AccordionPanel, | ||
} from '@chakra-ui/react'; | ||
import InfoBox from './InfoBox'; | ||
|
||
export default function TicketSurveyBreakdown({ tickets, children, ...props }) { | ||
const multiAnswerQuestions = ['ethnicity', 'interests', 'workshops']; | ||
// structure: { question: { answer1: 5, answer2: 10 } } | ||
const countByValueByKey = {}; | ||
tickets.forEach((ticket) => { | ||
Object.keys(ticket.surveyResponses || {}).forEach((q) => { | ||
let responses = []; | ||
if (multiAnswerQuestions.includes(q)) { | ||
responses = ticket.surveyResponses[q].split(','); | ||
} else { | ||
responses = [ticket.surveyResponses[q]]; | ||
} | ||
// remove empty-like responses | ||
responses.filter((r) => r) | ||
.forEach((r) => { | ||
if (!countByValueByKey[q]) countByValueByKey[q] = {}; | ||
if (!countByValueByKey[q][r]) countByValueByKey[q][r] = 0; | ||
countByValueByKey[q][r] += 1; | ||
}); | ||
}); | ||
}); | ||
return ( | ||
<InfoBox heading="Survey response breakdown"> | ||
<Accordion allowToggle> | ||
<AccordionItem> | ||
<AccordionButton> | ||
(click to show/hide) | ||
<AccordionIcon /> | ||
</AccordionButton> | ||
<AccordionPanel> | ||
{Object.keys(countByValueByKey).map((question) => ( | ||
<Accordion allowMultiple> | ||
<AccordionItem> | ||
|
||
<AccordionButton> | ||
<Text bold>{question}</Text> | ||
<AccordionIcon /> | ||
</AccordionButton> | ||
<AccordionPanel> | ||
|
||
<List styleType="disc" ml={4}> | ||
{Object.keys(countByValueByKey[question]) | ||
.sort((a, b) => countByValueByKey[question][b] - countByValueByKey[question][a]) | ||
.map((answer) => { | ||
const num = countByValueByKey[question][answer]; | ||
return ( | ||
<ListItem>{answer}: {num} ({(num / tickets.length * 100).toFixed(2)}%)</ListItem> | ||
); | ||
})} | ||
</List> | ||
</AccordionPanel> | ||
</AccordionItem> | ||
</Accordion> | ||
))} | ||
</AccordionPanel> | ||
</AccordionItem> | ||
</Accordion> | ||
</InfoBox> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters