Working answer key submission

This commit is contained in:
Ben Ramey
2018-09-19 06:58:37 -05:00
parent e52b0b2a34
commit be9d1f6c41

View File

@@ -17,6 +17,7 @@ class AnswerKeyForm extends React.Component {
this.handleInputChange = this.handleInputChange.bind(this); this.handleInputChange = this.handleInputChange.bind(this);
this.handleAnswerChange = this.handleAnswerChange.bind(this); this.handleAnswerChange = this.handleAnswerChange.bind(this);
this.submit = this.submit.bind(this);
console.log(this.state.answers); 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() { render() {
const testRows = [...Array(this.state.numTests).keys()].map( const testRows = [...Array(this.state.numTests).keys()].map(
(test, index) => ( (test, index) => (
@@ -131,7 +156,12 @@ class AnswerKeyForm extends React.Component {
</thead> </thead>
<tbody>{testRows}</tbody> <tbody>{testRows}</tbody>
</table> </table>
<input className="button-primary" type="submit" value="Save" /> <input
className="button-primary"
type="submit"
value="Save"
onClick={this.submit}
/>
</form> </form>
</div> </div>
); );