-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create components for each survey element
- Loading branch information
1 parent
662fc2c
commit 6c46a81
Showing
5 changed files
with
120 additions
and
21 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
70 changes: 70 additions & 0 deletions
70
src/features/surveys/components/surveyForm/OptionsQuestion.tsx
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,70 @@ | ||
import { FC } from 'react'; | ||
import { | ||
Checkbox, | ||
FormControl, | ||
FormControlLabel, | ||
FormGroup, | ||
FormLabel, | ||
MenuItem, | ||
Radio, | ||
RadioGroup, | ||
Select, | ||
} from '@mui/material'; | ||
import { | ||
ZetkinSurveyOption, | ||
ZetkinSurveyOptionsQuestionElement, | ||
} from 'utils/types/zetkin'; | ||
|
||
const OptionsQuestion: FC<{ element: ZetkinSurveyOptionsQuestionElement }> = ({ | ||
element, | ||
}) => { | ||
return ( | ||
<FormControl> | ||
<FormLabel id="demo-radio-buttons-group-label"> | ||
{element.question.question} | ||
</FormLabel> | ||
{element.question.response_config.widget_type === 'checkbox' && ( | ||
<FormGroup aria-labelledby="demo-radio-buttons-group-label"> | ||
{element.question.options!.map((option: ZetkinSurveyOption) => ( | ||
<FormControlLabel | ||
key={option.id} | ||
control={<Checkbox />} | ||
label={option.text} | ||
name={`${element.id}.options`} | ||
value={option.id} | ||
/> | ||
))} | ||
</FormGroup> | ||
)} | ||
{element.question.response_config.widget_type === 'radio' && ( | ||
<RadioGroup | ||
aria-labelledby="demo-radio-buttons-group-label" | ||
name={`${element.id}.options`} | ||
> | ||
{element.question.options!.map((option: ZetkinSurveyOption) => ( | ||
<FormControlLabel | ||
key={option.id} | ||
control={<Radio />} | ||
label={option.text} | ||
value={option.id} | ||
/> | ||
))} | ||
</RadioGroup> | ||
)} | ||
{element.question.response_config.widget_type === 'select' && ( | ||
<Select | ||
aria-labelledby="demo-radio-buttons-group-label" | ||
name={`${element.id}.options`} | ||
> | ||
{element.question.options!.map((option: ZetkinSurveyOption) => ( | ||
<MenuItem key={option.id} value={option.id}> | ||
{option.text} | ||
</MenuItem> | ||
))} | ||
</Select> | ||
)} | ||
</FormControl> | ||
); | ||
}; | ||
|
||
export default OptionsQuestion; |
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,8 @@ | ||
import { FC } from 'react'; | ||
import { ZetkinSurveyTextElement } from 'utils/types/zetkin'; | ||
|
||
const TextBlock: FC<{ element: ZetkinSurveyTextElement }> = ({ element }) => { | ||
return <p>{element.text_block.content}</p>; | ||
}; | ||
|
||
export default TextBlock; |
22 changes: 22 additions & 0 deletions
22
src/features/surveys/components/surveyForm/TextQuestion.tsx
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,22 @@ | ||
import { FC } from 'react'; | ||
import { ZetkinSurveyTextQuestionElement } from 'utils/types/zetkin'; | ||
import { FormControl, FormLabel, TextField } from '@mui/material'; | ||
|
||
const OptionsQuestion: FC<{ element: ZetkinSurveyTextQuestionElement }> = ({ | ||
element, | ||
}) => { | ||
return ( | ||
<FormControl> | ||
<FormLabel id="demo-radio-buttons-group-label"> | ||
{element.question.question} | ||
</FormLabel> | ||
<TextField | ||
id={`input-${element.id}`} | ||
name={`${element.id}.text`} | ||
type="text" | ||
/> | ||
</FormControl> | ||
); | ||
}; | ||
|
||
export default OptionsQuestion; |
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