diff --git a/src/components/AnswerKeyForm/index.js b/src/components/AnswerKeyForm/index.js index 00ee2a4..a3c9e82 100644 --- a/src/components/AnswerKeyForm/index.js +++ b/src/components/AnswerKeyForm/index.js @@ -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 { {testRows} - + );