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
b6614d4
commit e6ce7fb
Showing
6 changed files
with
96 additions
and
42 deletions.
There are no files selected for viewing
32 changes: 17 additions & 15 deletions
32
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,33 +1,35 @@ | ||
import { inject } from 'mobx-react'; | ||
import * as React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
import { Button, ButtonGroup, Container } from 'reactstrap'; | ||
import { UserFeedbackQuestionStore } from '../../../stores/userFeedbackQuestionStore'; | ||
import { UserFeedbackQuestion } from '../../../types'; | ||
import FeedbackQuestion from './questions/FeedbackQuestion'; | ||
|
||
interface FeedbackPageProps { | ||
page: number; | ||
missionId: number; | ||
userFeedbackQuestionStore?: UserFeedbackQuestionStore; | ||
} | ||
|
||
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], | ||
}; | ||
export class FeedbackPage extends React.Component<FeedbackPageProps> { | ||
get currentQuestions() { | ||
return this.props.userFeedbackQuestionStore!.pages[this.props.page - 1] | ||
} | ||
|
||
render() { | ||
return ( | ||
<div> | ||
{this.state.currentQuestions.map(question => <FeedbackQuestion question={question} key={question.id} />)} | ||
</div> | ||
<Container fluid> | ||
{this.currentQuestions.map(question => <FeedbackQuestion question={question} key={question.id}/>)} | ||
<ButtonGroup className="mt-3"> | ||
<Link to={`/mission/${this.props.missionId}/feedback/${this.props.page - 1}`}> | ||
<Button color="primary">Zurück</Button> | ||
</Link> | ||
<Link to={`/mission/${this.props.missionId}/feedback/${this.props.page + 1}`}> | ||
<Button color="primary">Vorwärts</Button> | ||
</Link> | ||
</ButtonGroup> | ||
</Container> | ||
); | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
frontend/src/views/users/mission_feedback/questions/FeedbackQuestionContainer.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,10 @@ | ||
import * as React from 'react'; | ||
import Row from 'reactstrap/lib/Row'; | ||
|
||
export default ({ children }: { children: React.ReactNode }) => { | ||
return ( | ||
<Row className="mt-3"> | ||
{children} | ||
</Row> | ||
); | ||
}; |
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
44 changes: 32 additions & 12 deletions
44
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 |
---|---|---|
@@ -1,29 +1,49 @@ | ||
import * as React from 'react'; | ||
import { Form, FormGroup, Label } from 'reactstrap'; | ||
import Col from 'reactstrap/lib/Col'; | ||
import { UserFeedbackQuestion } from '../../../../../types'; | ||
import FeedbackQuestionContainer from '../FeedbackQuestionContainer'; | ||
import { FeedbackQuestionProps } from '../FeedbackQuestionProps'; | ||
|
||
function renderOption(option: any) { | ||
interface Choice { | ||
value: string; | ||
text: string; | ||
} | ||
|
||
interface JSONResponse { | ||
choices: Choice[]; | ||
} | ||
|
||
function renderOption(option: Choice, name: string) { | ||
const optionId = `opt-${option.value}`; | ||
|
||
return ( | ||
<div key={option.value}> | ||
<input type={'radio'} id={optionId}/> | ||
<Label for={optionId}>{option.text}</Label> | ||
<input type={'radio'} id={optionId} name={`multiple-choice-${name}`}/> | ||
<Label for={optionId} className="ml-2">{option.text}</Label> | ||
</div> | ||
); | ||
} | ||
|
||
function parseCustomInfo(question: UserFeedbackQuestion) { | ||
return JSON.parse(question.custom_info) as JSONResponse; | ||
} | ||
|
||
export default ({ question }: FeedbackQuestionProps) => { | ||
const options = JSON.parse(question.custom_info).choices; | ||
const options = parseCustomInfo(question).choices; | ||
|
||
return ( | ||
<div> | ||
<p>{question.question}</p> | ||
<Form> | ||
<FormGroup> | ||
{options.map((option: any) => renderOption(option))} | ||
</FormGroup> | ||
</Form> | ||
</div> | ||
<FeedbackQuestionContainer> | ||
<Col> | ||
<h6>{question.question}</h6> | ||
</Col> | ||
<Col> | ||
<Form> | ||
<FormGroup> | ||
{options.map(choice => renderOption(choice, question.id.toString()))} | ||
</FormGroup> | ||
</Form> | ||
</Col> | ||
</FeedbackQuestionContainer> | ||
); | ||
}; |
13 changes: 12 additions & 1 deletion
13
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 |
---|---|---|
@@ -1,4 +1,15 @@ | ||
import * as React from 'react'; | ||
import Col from 'reactstrap/lib/Col'; | ||
import FeedbackQuestionContainer from '../FeedbackQuestionContainer'; | ||
import { FeedbackQuestionProps } from '../FeedbackQuestionProps'; | ||
|
||
export default ({ question }: FeedbackQuestionProps) => <h4>{question.question}</h4>; | ||
export default ({ question }: FeedbackQuestionProps) => ( | ||
<FeedbackQuestionContainer> | ||
<Col> | ||
<h4>{question.question}</h4> | ||
</Col> | ||
<Col> | ||
<p>{question.options[0]} - {question.options[1]}</p> | ||
</Col> | ||
</FeedbackQuestionContainer> | ||
); |