fix ticket 6, 10, 15
All checks were successful
publish-main / release-image (push) Successful in 6m56s
All checks were successful
publish-main / release-image (push) Successful in 6m56s
This commit is contained in:
parent
cdd43807f8
commit
e4dba30177
13
src/assets/styles/components/loading.module.scss
Normal file
13
src/assets/styles/components/loading.module.scss
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
.loading__wrapper {
|
||||||
|
width: 100%;
|
||||||
|
height: 80%;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
&__body {
|
||||||
|
// margin-top: 100px;
|
||||||
|
span {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -172,4 +172,3 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,8 @@ const AnswerModal = ({
|
|||||||
setQuestion,
|
setQuestion,
|
||||||
setComment,
|
setComment,
|
||||||
setCurrentTypeAnswer,
|
setCurrentTypeAnswer,
|
||||||
setFile
|
setFile,
|
||||||
|
removeOptionAnswer
|
||||||
}) => {
|
}) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -67,7 +68,7 @@ const AnswerModal = ({
|
|||||||
{optionAnswer.map((item, i) =>
|
{optionAnswer.map((item, i) =>
|
||||||
<span key={i} className={classes.myModal__dialog__content__body__answerOptions__list__answer}>
|
<span key={i} className={classes.myModal__dialog__content__body__answerOptions__list__answer}>
|
||||||
{item.id}) {item.text}
|
{item.id}) {item.text}
|
||||||
<i class="fa-solid fa-xmark" onClick={() => setOptionAnswer([...optionAnswer].filter(answer => answer.id !== item.id))}></i>
|
<i class="fa-solid fa-xmark" onClick={() => removeOptionAnswer(item.id)}></i>
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
15
src/components/Loading.jsx
Normal file
15
src/components/Loading.jsx
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import React from "react";
|
||||||
|
import classes from "../assets/styles/components/loading.module.scss";
|
||||||
|
|
||||||
|
const Loading = () => {
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={classes.loading__wrapper}>
|
||||||
|
<div class="spinner-border text-dark" className={classes.loading__wrapper__body} role="status">
|
||||||
|
<span class="visually-hidden">Загрузка...</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Loading;
|
@ -2,7 +2,7 @@ import React, { useState } from "react";
|
|||||||
import classes from "../../assets/styles/components/typeAnswer/dropDownList.module.scss"
|
import classes from "../../assets/styles/components/typeAnswer/dropDownList.module.scss"
|
||||||
|
|
||||||
const DropDownList = ({postfix, optionAnswer, answers, updateAnswersForm}) => {
|
const DropDownList = ({postfix, optionAnswer, answers, updateAnswersForm}) => {
|
||||||
console.log(optionAnswer)
|
// console.log(optionAnswer)
|
||||||
return (
|
return (
|
||||||
<div className={classes.main}>
|
<div className={classes.main}>
|
||||||
<select
|
<select
|
||||||
|
@ -153,4 +153,22 @@ async function getAnswersApi(token, formToken) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export { addFormBlockApi, listFormBlockApi, saveFormApi, updateBlockApi, updateOrderBlockApi, listFormBlockByTokenApi, saveAnswersApi, getAnswersApi, removeBlockApi }
|
async function getBlockApi(token, formId, order) {
|
||||||
|
try {
|
||||||
|
const response = await axios.post(`https://api.minerva.krbl.ru/formBuilder/edit/${formId}/get`,
|
||||||
|
{
|
||||||
|
"order": order
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
"Authorization": `Token ${token}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export { addFormBlockApi, listFormBlockApi, saveFormApi, updateBlockApi, updateOrderBlockApi, listFormBlockByTokenApi, saveAnswersApi, getAnswersApi, removeBlockApi, getBlockApi }
|
@ -16,8 +16,8 @@ function responseDataToListBlock(data) {
|
|||||||
|
|
||||||
if (Array.isArray(param.Value) && param.Value.length) {
|
if (Array.isArray(param.Value) && param.Value.length) {
|
||||||
newParam[param.Key] = param.Value.map(item => ({
|
newParam[param.Key] = param.Value.map(item => ({
|
||||||
id: item[0].Value,
|
id: item.find(obj => obj.Key === "id").Value,
|
||||||
text: item[1].Value
|
text: item.find(obj => obj.Key === "text").Value
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -47,6 +47,11 @@ function dateTimeParse(date) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return newDate
|
return newDate
|
||||||
|
};
|
||||||
|
|
||||||
|
function numberingBlocks(list, key, increase = 0) {
|
||||||
|
list.forEach((value, i) => list[i][key] = i + increase)
|
||||||
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
export { responseDataToListBlock, dateTimeParse }
|
export { responseDataToListBlock, dateTimeParse, numberingBlocks }
|
@ -6,6 +6,7 @@ import classes from "../assets/styles/answersForm.module.scss";
|
|||||||
import { responseDataToListBlock, dateTimeParse } from "../hooks/sundry/parseListBlock";
|
import { responseDataToListBlock, dateTimeParse } from "../hooks/sundry/parseListBlock";
|
||||||
import { listFormBlockApi, getAnswersApi } from "../hooks/api/formApi";
|
import { listFormBlockApi, getAnswersApi } from "../hooks/api/formApi";
|
||||||
import { listUsersApi } from "../hooks/api/adminApi";
|
import { listUsersApi } from "../hooks/api/adminApi";
|
||||||
|
import Loading from "../components/Loading.jsx";
|
||||||
|
|
||||||
const AnswersForm = () => {
|
const AnswersForm = () => {
|
||||||
const { formId } = useParams();
|
const { formId } = useParams();
|
||||||
@ -19,8 +20,6 @@ const AnswersForm = () => {
|
|||||||
const responseBlocks = await listFormBlockApi(cookies.token, formId);
|
const responseBlocks = await listFormBlockApi(cookies.token, formId);
|
||||||
const responseAnswers = await getAnswersApi(cookies.token, formId);
|
const responseAnswers = await getAnswersApi(cookies.token, formId);
|
||||||
const listUsers = await listUsersApi(cookies.token);
|
const listUsers = await listUsersApi(cookies.token);
|
||||||
console.log("responseBlocks", responseBlocks)
|
|
||||||
console.log("responseAnswers", responseAnswers)
|
|
||||||
|
|
||||||
if (responseBlocks.status === 200 && responseBlocks.data) {
|
if (responseBlocks.status === 200 && responseBlocks.data) {
|
||||||
const listBlocks = responseDataToListBlock(responseBlocks.data);
|
const listBlocks = responseDataToListBlock(responseBlocks.data);
|
||||||
@ -35,7 +34,10 @@ const AnswersForm = () => {
|
|||||||
|
|
||||||
if (item.data) {
|
if (item.data) {
|
||||||
for (let i = 0; i < item.data.length; i++) {
|
for (let i = 0; i < item.data.length; i++) {
|
||||||
blocks.block.push({answers: {id: item.data[i][0].Value, answer: item.data[i][1].Value}, question: listBlocks[i]})
|
blocks.block.push({
|
||||||
|
answers: {id: item.data[i].find(obj => obj.Key === "id").Value, answer: item.data[i].find(obj => obj.Key === "answer").Value},
|
||||||
|
question: listBlocks[i]
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -46,7 +48,6 @@ const AnswersForm = () => {
|
|||||||
|
|
||||||
result.push(blocks)
|
result.push(blocks)
|
||||||
}
|
}
|
||||||
console.log("result", result)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setData(result)
|
setData(result)
|
||||||
@ -111,11 +112,7 @@ const AnswersForm = () => {
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
<div className={classes.loading__wrapper}>
|
<Loading/>}
|
||||||
<div class="spinner-border text-dark" className={classes.loading__wrapper__body} role="status">
|
|
||||||
<span class="visually-hidden">Загрузка...</span>
|
|
||||||
</div>
|
|
||||||
</div>}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -34,7 +34,7 @@ const Forms = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
listForms();
|
listForms();
|
||||||
}, [])
|
}, []);
|
||||||
|
|
||||||
async function createForm() {
|
async function createForm() {
|
||||||
setStateLoading(true);
|
setStateLoading(true);
|
||||||
@ -43,7 +43,6 @@ const Forms = () => {
|
|||||||
|
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
const token = await newFormTokenApi(cookies.token, response.data.id)
|
const token = await newFormTokenApi(cookies.token, response.data.id)
|
||||||
|
|
||||||
navigate(`/forms/${response.data.id}/edit`)
|
navigate(`/forms/${response.data.id}/edit`)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -64,8 +63,6 @@ const Forms = () => {
|
|||||||
else {
|
else {
|
||||||
console.log(response);
|
console.log(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
setRemoveIdForm(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
async function openFormView(formId) {
|
async function openFormView(formId) {
|
||||||
@ -90,7 +87,7 @@ const Forms = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const filterFormsBySearch = () => [...forms].filter(item => item.title.toLowerCase().includes(searchForm))
|
const filterFormsBySearch = () => [...forms].filter(item => item.title.toLowerCase().includes(searchForm));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classes.main}>
|
<div className={classes.main}>
|
||||||
|
@ -4,11 +4,12 @@ import { useCookies } from "react-cookie";
|
|||||||
import classes from "../assets/styles/newForm.module.scss";
|
import classes from "../assets/styles/newForm.module.scss";
|
||||||
import MyButton from "../components/MyButton.jsx";
|
import MyButton from "../components/MyButton.jsx";
|
||||||
import AnswerModal from "../components/AnswerModal.jsx";
|
import AnswerModal from "../components/AnswerModal.jsx";
|
||||||
import PreviewModal from "../components/PreviewModal.jsx"
|
import PreviewModal from "../components/PreviewModal.jsx";
|
||||||
|
import Loading from "../components/Loading.jsx";
|
||||||
import { FormsData, TypeAnswerData } from "../context";
|
import { FormsData, TypeAnswerData } from "../context";
|
||||||
import { listFormsApi, updateTitleFormApi } from "../hooks/api/listFormsApi.js";
|
import { listFormsApi, updateTitleFormApi } from "../hooks/api/listFormsApi.js";
|
||||||
import { saveFormApi, addFormBlockApi, listFormBlockApi, updateBlockApi, updateOrderBlockApi, removeBlockApi } from "../hooks/api/formApi.js";
|
import { saveFormApi, addFormBlockApi, listFormBlockApi, updateBlockApi, updateOrderBlockApi, removeBlockApi, getBlockApi } from "../hooks/api/formApi.js";
|
||||||
import { responseDataToListBlock } from "../hooks/sundry/parseListBlock.js";
|
import { responseDataToListBlock, numberingBlocks } from "../hooks/sundry/parseListBlock.js";
|
||||||
import MyInput from "../components/MyInput.jsx";
|
import MyInput from "../components/MyInput.jsx";
|
||||||
|
|
||||||
const NewForm = () => {
|
const NewForm = () => {
|
||||||
@ -17,6 +18,7 @@ const NewForm = () => {
|
|||||||
const { formId } = useParams();
|
const { formId } = useParams();
|
||||||
const [dragElem, setDragElem] = useState(null);
|
const [dragElem, setDragElem] = useState(null);
|
||||||
const [dropElem, setDropElem] = useState(null);
|
const [dropElem, setDropElem] = useState(null);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
const [cookies, _, __] = useCookies(["user"]);
|
const [cookies, _, __] = useCookies(["user"]);
|
||||||
|
|
||||||
@ -43,10 +45,6 @@ const NewForm = () => {
|
|||||||
|
|
||||||
const [stateModal, setStateModal] = useState(false);
|
const [stateModal, setStateModal] = useState(false);
|
||||||
|
|
||||||
function removeAnswerByForm(id) {
|
|
||||||
setListBlock([...listBlock.filter(item => item.id !== id)]);
|
|
||||||
};
|
|
||||||
|
|
||||||
function cleanStates() {
|
function cleanStates() {
|
||||||
setStateModal(false)
|
setStateModal(false)
|
||||||
setQuestion("");
|
setQuestion("");
|
||||||
@ -65,7 +63,6 @@ const NewForm = () => {
|
|||||||
const responseBlock = await listFormBlockApi(cookies.token, formId);
|
const responseBlock = await listFormBlockApi(cookies.token, formId);
|
||||||
|
|
||||||
if (responseBlock.status === 200 && responseBlock.data && responseForms.status === 200) {
|
if (responseBlock.status === 200 && responseBlock.data && responseForms.status === 200) {
|
||||||
console.log(responseDataToListBlock(responseBlock.data))
|
|
||||||
setListBlock(responseDataToListBlock(responseBlock.data));
|
setListBlock(responseDataToListBlock(responseBlock.data));
|
||||||
const title = responseForms.data.find(item => item.id === formId).title
|
const title = responseForms.data.find(item => item.id === formId).title
|
||||||
setNewTitleForm(title);
|
setNewTitleForm(title);
|
||||||
@ -76,20 +73,33 @@ const NewForm = () => {
|
|||||||
setNewTitleForm("Новыя форма");
|
setNewTitleForm("Новыя форма");
|
||||||
setOldTitleForm("Новыя форма");
|
setOldTitleForm("Новыя форма");
|
||||||
}
|
}
|
||||||
|
setLoading(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
totalData();
|
totalData();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
function addOptionAnswer(text) {
|
function addOptionAnswer() {
|
||||||
setOptionAnswer([...optionAnswer, {
|
setOptionAnswer(numberingBlocks(
|
||||||
id: nextID(optionAnswer, "id"),
|
[...optionAnswer, {
|
||||||
text: currentOptionAnswer
|
id: nextID(optionAnswer, "id"),
|
||||||
}]);
|
text: currentOptionAnswer
|
||||||
|
}],
|
||||||
|
"id",
|
||||||
|
1
|
||||||
|
));
|
||||||
setCurrentOptionAnswer("");
|
setCurrentOptionAnswer("");
|
||||||
};
|
};
|
||||||
|
|
||||||
function editAnswerByForm(id, order) {
|
function removeOptionAnswer(id) {
|
||||||
|
setOptionAnswer(numberingBlocks(
|
||||||
|
[...optionAnswer].filter(answer => answer.id !== id),
|
||||||
|
"id",
|
||||||
|
1
|
||||||
|
));
|
||||||
|
};
|
||||||
|
|
||||||
|
function editAnswerByForm(id) {
|
||||||
const obj = listBlock.find(item => item.id === id);
|
const obj = listBlock.find(item => item.id === id);
|
||||||
setQuestion(obj.question);
|
setQuestion(obj.question);
|
||||||
setComment(obj.comment);
|
setComment(obj.comment);
|
||||||
@ -102,6 +112,8 @@ const NewForm = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
async function updateBlock() {
|
async function updateBlock() {
|
||||||
|
console.log(optionAnswer)
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
question: question,
|
question: question,
|
||||||
comment: comment,
|
comment: comment,
|
||||||
@ -118,15 +130,16 @@ const NewForm = () => {
|
|||||||
data,
|
data,
|
||||||
listBlock.find(item => item.id === stateModal).order
|
listBlock.find(item => item.id === stateModal).order
|
||||||
);
|
);
|
||||||
console.log(response)
|
|
||||||
|
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
setListBlock(listBlock.map(item => {
|
const responseBlock = await listFormBlockApi(cookies.token, formId);
|
||||||
if (item.id === stateModal) {
|
|
||||||
item = data
|
if (responseBlock.status === 200) {
|
||||||
}
|
setListBlock(responseDataToListBlock(responseBlock.data));
|
||||||
return item
|
}
|
||||||
}))
|
else {
|
||||||
|
setListBlock([])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.log(response)
|
console.log(response)
|
||||||
@ -144,9 +157,11 @@ const NewForm = () => {
|
|||||||
else {
|
else {
|
||||||
console.log(response)
|
console.log(response)
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
async function addFormBlock() {
|
async function addFormBlock() {
|
||||||
|
console.log(optionAnswer)
|
||||||
|
|
||||||
const newBlock = {
|
const newBlock = {
|
||||||
question: question,
|
question: question,
|
||||||
typeAnswer: currentTypeAnswer,
|
typeAnswer: currentTypeAnswer,
|
||||||
@ -160,7 +175,14 @@ const NewForm = () => {
|
|||||||
const response = await addFormBlockApi(cookies.token, formId, newBlock)
|
const response = await addFormBlockApi(cookies.token, formId, newBlock)
|
||||||
|
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
setListBlock([...listBlock, {...newBlock, order: nextID(listBlock, "order")}]);
|
const responseBlock = await listFormBlockApi(cookies.token, formId);
|
||||||
|
|
||||||
|
if (responseBlock.status === 200) {
|
||||||
|
setListBlock(responseDataToListBlock(responseBlock.data));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setListBlock([])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.log(response)
|
console.log(response)
|
||||||
@ -198,26 +220,10 @@ const NewForm = () => {
|
|||||||
tListBlock.splice(dragElem, 1);
|
tListBlock.splice(dragElem, 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
tListBlock.forEach((value, i) => tListBlock[i].order = i)
|
||||||
|
|
||||||
setListBlock(tListBlock);
|
setListBlock(tListBlock);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function updateFormByForms() {
|
|
||||||
updateFormByFormsApi(location.state.id, "Новая форма", listBlock)
|
|
||||||
.then((resolve, _) => {
|
|
||||||
console.log(resolve);
|
|
||||||
setForms(
|
|
||||||
forms.map(item => {
|
|
||||||
if (item.id === location.state.id) {
|
|
||||||
item.title = "Новая форма",
|
|
||||||
item.questions = listBlock
|
|
||||||
}
|
|
||||||
return item
|
|
||||||
})
|
|
||||||
);
|
|
||||||
cleanStates();
|
|
||||||
navigate("/forms");
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
|
||||||
async function saveForm() {
|
async function saveForm() {
|
||||||
@ -284,6 +290,7 @@ const NewForm = () => {
|
|||||||
addOptionAnswer={addOptionAnswer}
|
addOptionAnswer={addOptionAnswer}
|
||||||
updateBlock={updateBlock}
|
updateBlock={updateBlock}
|
||||||
setCurrentTypeAnswer={setCurrentTypeAnswer}
|
setCurrentTypeAnswer={setCurrentTypeAnswer}
|
||||||
|
removeOptionAnswer={removeOptionAnswer}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className={classes.content__newForm}>
|
<div className={classes.content__newForm}>
|
||||||
@ -291,7 +298,7 @@ const NewForm = () => {
|
|||||||
<h3>Новая форма</h3>
|
<h3>Новая форма</h3>
|
||||||
</div>
|
</div>
|
||||||
<div className={classes.content__newForm__list}>
|
<div className={classes.content__newForm__list}>
|
||||||
{listBlock.map((item, i) =>
|
{loading ? listBlock.map((item, i) =>
|
||||||
<div
|
<div
|
||||||
className={classes.content__newForm__list__item}
|
className={classes.content__newForm__list__item}
|
||||||
key={i}
|
key={i}
|
||||||
@ -323,7 +330,8 @@ const NewForm = () => {
|
|||||||
<i class="fa-solid fa-trash" onClick={() => removeBlock(item.order)}></i>
|
<i class="fa-solid fa-trash" onClick={() => removeBlock(item.order)}></i>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
) :
|
||||||
|
<Loading/>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -41,7 +41,6 @@ const ViewForm = () => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
function updateAnswersForm(value, id) {
|
function updateAnswersForm(value, id) {
|
||||||
console.log(value)
|
|
||||||
setAnswers(
|
setAnswers(
|
||||||
answers.map((item, i) => {
|
answers.map((item, i) => {
|
||||||
if (id === i) {
|
if (id === i) {
|
||||||
|
Loading…
Reference in New Issue
Block a user