From efd604f627a85afb15cb32afbb7e34202c50b724 Mon Sep 17 00:00:00 2001 From: Vinicius Frota Date: Sun, 21 Nov 2021 20:01:24 -0300 Subject: [PATCH] wip: submit question answers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Vinicius Frota Co-authored-by: Willian Mori Co-authored-by: João Gabriel Josephik Co-authored-by: Erick Rodrigues --- src/pages/QuestionPage/index.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/pages/QuestionPage/index.js b/src/pages/QuestionPage/index.js index a9e179c..724a3e7 100644 --- a/src/pages/QuestionPage/index.js +++ b/src/pages/QuestionPage/index.js @@ -5,13 +5,24 @@ import Selector from "../../components/Selector"; import Question from "../../components/Question"; function QuestionPage() { + const url = process.env.REACT_APP_BACKEND_URL || "http://localhost:3333"; const [allQuestions, setAllQuestions] = useState([]); const [currentQuestion, setQuestion] = useState(0); const [answersDict, setAnswers] = useState({}); const [status, setStatus] = useState("CARREGANDO..."); + function sendAnswers() { + const headers = new Headers(); + headers.append("Content-Type", "application/json"); + + fetch(url + "/questions/answers", { + method: "POST", + body: JSON.stringify(answersDict), + headers, + }); + } + useEffect(() => { - const url = process.env.REACT_APP_BACKEND_URL || "http://localhost:3333"; fetch(url + "/questions") .then(async (resp) => { setAllQuestions((await resp.json()).allQuestions); @@ -25,15 +36,14 @@ function QuestionPage() { if (allQuestions.length === 0) return

{status}

; const questionObj = allQuestions[currentQuestion]; - const questionNumber = questionObj.number; return (
{ - setAnswers({ ...answersDict, [questionNumber]: answer }); + setAnswers({ ...answersDict, [questionObj.id]: answer }); }} />
@@ -46,7 +56,9 @@ function QuestionPage() { numberPerLine={10} />
- +
);