Created
June 23, 2016 15:15
-
-
Save aaronmcadam/d25c5a11b513541bb8a21f8b77cabc6c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const MultiCode = ({ interview, options, dispatchChange }) => { | |
| const currentOptions = () => ( | |
| getCurrentOptions(interview.selections.value, options) | |
| ); | |
| const addValues = (selectedOptions) => { | |
| dispatchChange(selectedOptions.map(option => ({ optionId: option.id }))); | |
| }; | |
| const updateForm = (optionIsSelected, option) => { | |
| const selectedOptions = mapOptions( | |
| currentOptions(), | |
| option, | |
| !optionIsSelected | |
| ); | |
| addValues(selectedOptions); | |
| }; | |
| const isDisabled = (option) => ( | |
| isOptionDisabled(option, currentOptions()) | |
| ); | |
| const isChecked = (option) => ( | |
| isOptionChecked(option, currentOptions()) | |
| ); | |
| return ( | |
| <div className="coded-questions"> | |
| <QuestionErrorMessage element={interview.selections} /> | |
| {options.map(option => ( | |
| <MultiCodeOption | |
| key={option.id} | |
| option={option} | |
| onOptionChange={updateForm} | |
| isChecked={isChecked(option)} | |
| isDisabled={isDisabled(option)} | |
| /> | |
| ))} | |
| </div> | |
| ); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment