This repository has been archived by the owner on Sep 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd7ab60
commit b6614d4
Showing
7 changed files
with
116 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
26 changes: 24 additions & 2 deletions
26
frontend/src/views/users/mission_feedback/FeedbackPage.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 |
---|---|---|
@@ -1,11 +1,33 @@ | ||
import { inject } from 'mobx-react'; | ||
import * as React from 'react'; | ||
import { UserFeedbackQuestionStore } from '../../../stores/userFeedbackQuestionStore'; | ||
import { UserFeedbackQuestion } from '../../../types'; | ||
import FeedbackQuestion from './questions/FeedbackQuestion'; | ||
|
||
interface FeedbackPageProps { | ||
page: number; | ||
userFeedbackQuestionStore?: UserFeedbackQuestionStore; | ||
} | ||
|
||
export class FeedbackPage extends React.Component<FeedbackPageProps> { | ||
interface FeedbackPageState { | ||
currentQuestions: UserFeedbackQuestion[]; | ||
} | ||
|
||
@inject('userFeedbackQuestionStore') | ||
export class FeedbackPage extends React.Component<FeedbackPageProps, FeedbackPageState> { | ||
constructor(props: FeedbackPageProps) { | ||
super(props); | ||
|
||
this.state = { | ||
currentQuestions: props.userFeedbackQuestionStore!.pages[props.page - 1], | ||
}; | ||
} | ||
|
||
render() { | ||
return <div>Page {this.props.page}</div>; | ||
return ( | ||
<div> | ||
{this.state.currentQuestions.map(question => <FeedbackQuestion question={question} key={question.id} />)} | ||
</div> | ||
); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
frontend/src/views/users/mission_feedback/questions/FeedbackQuestion.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,19 @@ | ||
import * as React from 'react'; | ||
import { UserFeedbackQuestionType } from '../../../../types'; | ||
import { FeedbackQuestionProps } from './FeedbackQuestionProps'; | ||
import LikertScale from './types/LikertScale'; | ||
import MultipleChoice from './types/MultipleChoice'; | ||
import SectionTitle from './types/SectionTitle'; | ||
|
||
export default (props: FeedbackQuestionProps) => { | ||
switch (props.question.type) { | ||
case UserFeedbackQuestionType.SectionTitle: | ||
return <SectionTitle {...props}/>; | ||
case UserFeedbackQuestionType.LikertScale: | ||
return <LikertScale {...props}/>; | ||
case UserFeedbackQuestionType.MultipleChoice: | ||
return <MultipleChoice {...props}/>; | ||
default: | ||
return <></>; | ||
} | ||
}; |
5 changes: 5 additions & 0 deletions
5
frontend/src/views/users/mission_feedback/questions/FeedbackQuestionProps.ts
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,5 @@ | ||
import { UserFeedbackQuestion } from '../../../../types'; | ||
|
||
export interface FeedbackQuestionProps { | ||
question: UserFeedbackQuestion; | ||
} |
33 changes: 33 additions & 0 deletions
33
frontend/src/views/users/mission_feedback/questions/types/LikertScale.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,33 @@ | ||
import { useState } from 'react'; | ||
import * as React from 'react'; | ||
import { Button, ButtonGroup } from 'reactstrap'; | ||
import { FeedbackQuestionProps } from '../FeedbackQuestionProps'; | ||
|
||
function renderButton(index: number, activeIndex: number, setActiveIndex: React.Dispatch<React.SetStateAction<number>>) { | ||
return ( | ||
<Button | ||
color="primary" | ||
key={index} | ||
active={activeIndex === index} | ||
onClick={() => setActiveIndex(index)} | ||
> | ||
{index + 1} | ||
</Button> | ||
); | ||
} | ||
|
||
export default ({ question }: FeedbackQuestionProps) => { | ||
const [activeIndex, setActiveIndex] = useState(0); | ||
|
||
return ( | ||
<div> | ||
<p>{question.question}</p> | ||
<ButtonGroup> | ||
{ | ||
[...(Array(4).keys() as any)] | ||
.map(index => renderButton(index, activeIndex, setActiveIndex)) | ||
} | ||
</ButtonGroup> | ||
</div> | ||
); | ||
}; |
29 changes: 29 additions & 0 deletions
29
frontend/src/views/users/mission_feedback/questions/types/MultipleChoice.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,29 @@ | ||
import * as React from 'react'; | ||
import { Form, FormGroup, Label } from 'reactstrap'; | ||
import { FeedbackQuestionProps } from '../FeedbackQuestionProps'; | ||
|
||
function renderOption(option: any) { | ||
const optionId = `opt-${option.value}`; | ||
|
||
return ( | ||
<div key={option.value}> | ||
<input type={'radio'} id={optionId}/> | ||
<Label for={optionId}>{option.text}</Label> | ||
</div> | ||
); | ||
} | ||
|
||
export default ({ question }: FeedbackQuestionProps) => { | ||
const options = JSON.parse(question.custom_info).choices; | ||
|
||
return ( | ||
<div> | ||
<p>{question.question}</p> | ||
<Form> | ||
<FormGroup> | ||
{options.map((option: any) => renderOption(option))} | ||
</FormGroup> | ||
</Form> | ||
</div> | ||
); | ||
}; |
4 changes: 4 additions & 0 deletions
4
frontend/src/views/users/mission_feedback/questions/types/SectionTitle.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,4 @@ | ||
import * as React from 'react'; | ||
import { FeedbackQuestionProps } from '../FeedbackQuestionProps'; | ||
|
||
export default ({ question }: FeedbackQuestionProps) => <h4>{question.question}</h4>; |