This commit is contained in:
Mikola 2023-12-12 15:18:12 +03:00
parent 7e5503e576
commit dcf0bbbe68
2 changed files with 30 additions and 29 deletions

View File

@ -1,7 +1,7 @@
import moment from "moment"; import moment from "moment";
import React, { useState } from "react"; import React, { useState } from "react";
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
import { useParams, useNavigate } from "react-router-dom"; import { useNavigate, useParams } from "react-router-dom";
import { questionsSelector } from "@redux/quizSlice"; import { questionsSelector } from "@redux/quizSlice";
@ -40,7 +40,6 @@ export const TaskQuiz = ({ timer }) => {
return; return;
} }
// setLoadingSendAnswers(true); // setLoadingSendAnswers(true);
// .finally(() => setLoadingSendAnswers(false)); // .finally(() => setLoadingSendAnswers(false));
@ -51,39 +50,38 @@ export const TaskQuiz = ({ timer }) => {
data: { data: {
user_id: userId, user_id: userId,
user_questionnaire_uuid: uuid, user_questionnaire_uuid: uuid,
userResponses: JSON.stringify(userResponses) userResponses: JSON.stringify(userResponses),
}, },
}) }).then(() => {
.then(() => { showNotification({
showNotification({ show: true,
show: true, text: "Тест успешно пройден",
text: "Тест успешно пройден", type: "success",
type: "success", });
}); navigate("/quiz");
navigate("/quiz"); // if (String(res?.status)[0] !== "2") {
// if (String(res?.status)[0] !== "2") {
// showNotification({
// show: true,
// text: res?.message || "",
// type: "error",
// });
// return;
// }
})
// .catch((e) => {
// showNotification({ // showNotification({
// show: true, // show: true,
// text: e?.message || "", // text: res?.message || "",
// type: "error", // type: "error",
// }); // });
// }) // return;
// }
});
// .catch((e) => {
// showNotification({
// show: true,
// text: e?.message || "",
// type: "error",
// });
// })
} }
//установка таймера на вопрос если он существует //установка таймера на вопрос если он существует
if (questions[index + 1]?.time_limit !== "00:00:00") setValueTimer(); if (questions[index + 1]?.time_limit !== "00:00:00") setValueTimer();
// переход на следующий вопрос // переход на следующий вопрос
setIndex((prev) => questions[prev + 1] ? prev + 1 : prev); setIndex((prev) => (questions[prev + 1] ? prev + 1 : prev));
}; };
const complete = (e) => { const complete = (e) => {

View File

@ -3,13 +3,16 @@ import { useState } from "react";
export const useHandlerFieldTest = ({ questions, indexQuestion }) => { export const useHandlerFieldTest = ({ questions, indexQuestion }) => {
const [userResponses, setUserResponses] = useState([]); const [userResponses, setUserResponses] = useState([]);
const handleChangeCheckbox = (e) => { const handleChangeCheckbox = (e) => {
setUserResponses((prev) => setUserResponses((prev) => [
[...prev.filter((item) => item.question_id !== questions[indexQuestion].id), ...prev.filter(
(item) => item.question_id !== questions[indexQuestion].id
),
{ {
question_id: questions[indexQuestion].id, question_id: questions[indexQuestion].id,
response_body: e.target.value, response_body: e.target.value,
answer_id: e.target.id ? e.target.id : questions[indexQuestion].id answer_id: e.target.id ? e.target.id : questions[indexQuestion].id,
}]) },
]);
}; };
// const handleFieldsForm = (e) => { // const handleFieldsForm = (e) => {
@ -25,5 +28,5 @@ export const useHandlerFieldTest = ({ questions, indexQuestion }) => {
const handleChange = (e) => { const handleChange = (e) => {
handleChangeCheckbox(e); handleChangeCheckbox(e);
}; };
return { handleChange, userResponses}; return { handleChange, userResponses };
}; };