Working answer key submission
This commit is contained in:
@@ -17,6 +17,7 @@ class AnswerKeyForm extends React.Component {
|
||||
|
||||
this.handleInputChange = this.handleInputChange.bind(this);
|
||||
this.handleAnswerChange = this.handleAnswerChange.bind(this);
|
||||
this.submit = this.submit.bind(this);
|
||||
console.log(this.state.answers);
|
||||
}
|
||||
|
||||
@@ -71,6 +72,30 @@ class AnswerKeyForm extends React.Component {
|
||||
});
|
||||
}
|
||||
|
||||
submit(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const payload = {
|
||||
name: this.state.courseName,
|
||||
num_tests: this.state.numTests,
|
||||
num_questions_per_test: this.state.numQuestionsPerTest,
|
||||
answers: this.state.answers.slice(),
|
||||
};
|
||||
|
||||
const result = fetch(
|
||||
'https://bzwy0j344j.execute-api.us-east-2.amazonaws.com/dev/courses',
|
||||
{
|
||||
method: 'POST',
|
||||
mode: 'cors',
|
||||
cache: 'no-cache',
|
||||
headers: {'Content-Type': 'application/json; charset=utf-8'},
|
||||
body: JSON.stringify(payload),
|
||||
}
|
||||
).then(res => res.json());
|
||||
|
||||
console.log(result);
|
||||
}
|
||||
|
||||
render() {
|
||||
const testRows = [...Array(this.state.numTests).keys()].map(
|
||||
(test, index) => (
|
||||
@@ -131,7 +156,12 @@ class AnswerKeyForm extends React.Component {
|
||||
</thead>
|
||||
<tbody>{testRows}</tbody>
|
||||
</table>
|
||||
<input className="button-primary" type="submit" value="Save" />
|
||||
<input
|
||||
className="button-primary"
|
||||
type="submit"
|
||||
value="Save"
|
||||
onClick={this.submit}
|
||||
/>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user