diff options
author | 2022-03-14 14:33:47 -0400 | |
---|---|---|
committer | 2022-03-14 14:33:47 -0400 | |
commit | 85fbf45e0584b157c15b096af177a2e51a486496 (patch) | |
tree | 10da5d590a3e8d1500df4fd40c75cc3e31f20c80 | |
parent | Add new unittestsFailed public_state field (diff) |
Add processing for POST request response
We now process the POST request response, catching the error. It re-runs
the code validationField() function.
It currently processes it assuming there's only one failed codeblock.
This will be updated later.
-rw-r--r-- | src/pages/FormPage.tsx | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/pages/FormPage.tsx b/src/pages/FormPage.tsx index 082be23..c281729 100644 --- a/src/pages/FormPage.tsx +++ b/src/pages/FormPage.tsx @@ -232,6 +232,9 @@ function FormPage(): JSX.Element { const questionRef = refMap.get(question.id); if (questionRef && questionRef.current) { + if(questionRef.current.props.question.type == QuestionType.Code){ + questionRef.current.props.public_state.set("unittestsFailed", false); + } questionRef.current.validateField(); } // In case when field is invalid, add this to invalid fields list. @@ -263,7 +266,6 @@ function FormPage(): JSX.Element { return; } - setSending(true); const answers: { [key: string]: unknown } = {}; questions.forEach(prop => { @@ -297,9 +299,25 @@ function FormPage(): JSX.Element { } }); - await ApiClient.post(`forms/submit/${id}`, {response: answers}); - setSending(false); - setSent(true); + await ApiClient.post(`forms/submit/${id}`, {response: answers}) + .then(() => { + setSending(true); + setSending(false); + setSent(true); + }) + .catch(err => { + // Validation on a submitted code questions + const questionId = err.response.data.test_results[0].question_id; + + questions.forEach((prop) => { + const question: Question = prop.props.question; + const questionRef = refMap.get(question.id); + if (question.id === questionId){ + prop.props.public_state.set("unittestsFailed", true); + questionRef.current.validateField(); + } + }); + }); } return ( |