From ccee8eb5e382328d028c67d5d23fa5621c31d713 Mon Sep 17 00:00:00 2001 From: Tamara Date: Sat, 10 Feb 2024 04:41:13 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20=D0=BE=D1=82?= =?UTF-8?q?=D0=B2=D0=B5=D1=82=D0=BE=D0=B2=20=D0=BD=D0=B0=20=D0=B2=D0=BE?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D1=81=D1=8B=20=D1=81=D1=85=D0=B5=D0=BC=D0=B0?= =?UTF-8?q?=D1=82=D0=B8=D1=87=D0=BD=D0=BE,=20=D1=81=D0=BE=D1=85=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8=20=D1=81=D0=B1?= =?UTF-8?q?=D1=80=D0=BE=D1=81=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/result.ts | 45 ++- src/index.tsx | 2 +- src/pages/QuizAnswersPage/CardAnswer.tsx | 129 ++------ src/pages/QuizAnswersPage/QuizAnswersPage.tsx | 292 +++++++++++++----- src/stores/results/actions.ts | 64 +++- src/ui_kit/Modal/ExportContactsModal.tsx | 34 +- src/ui_kit/Modal/FilterModal/FilterModal.tsx | 10 +- 7 files changed, 359 insertions(+), 217 deletions(-) diff --git a/src/api/result.ts b/src/api/result.ts index 67efaa9e..0c91b51d 100644 --- a/src/api/result.ts +++ b/src/api/result.ts @@ -16,20 +16,30 @@ function deleteResult(resultId: number) { }); } -export const obsolescenceResult = async (idResultArray: string[]) => { - try { - const response = await makeRequest({ - url: process.env.REACT_APP_DOMAIN + `/squiz/result/seen`, - body: { - answers: idResultArray, - }, - method: "PATCH", - }); - return response; - } catch (e) { - console.log("ошибка", e); - } -}; +// export const obsolescenceResult = async (idResultArray: string[]) => { +// try { +// const response = await makeRequest({ +// url: process.env.REACT_APP_DOMAIN + `/squiz/result/seen`, +// body: { +// answers: idResultArray, +// }, +// method: "PATCH", +// }); +// return response; +// } catch (e) { +// console.log("ошибка", e); +// } +// }; + +function obsolescenceResult(idResultArray: string[]) { + return makeRequest({ + url: process.env.REACT_APP_DOMAIN + `/squiz/result/seen`, + body: { + answers: idResultArray, + }, + method: "PATCH", + }); +} function getAnswerResultList(resultId: number) { return makeRequest({ @@ -38,13 +48,13 @@ function getAnswerResultList(resultId: number) { }); } -function AnswerResultListEx(quizId: number) { +function AnswerResultListEx(quizId: number, fromDate: string, toDate: string) { return makeRequest({ url: process.env.REACT_APP_DOMAIN + `/squiz/results/${quizId}/export`, method: "POST", body: { - to: new Date(), - from: new Date("2024-01-24"), + to: new Date(toDate), + from: new Date(fromDate), new: true, }, }); @@ -55,4 +65,5 @@ export const resultApi = { delete: deleteResult, getAnswerList: getAnswerResultList, export: AnswerResultListEx, + obsolescence: obsolescenceResult, }; diff --git a/src/index.tsx b/src/index.tsx index 1c5e19c2..47fac85b 100755 --- a/src/index.tsx +++ b/src/index.tsx @@ -13,7 +13,7 @@ import "./index.css"; import lightTheme from "./utils/themes/light"; import { SWRConfig } from "swr"; import { BrowserRouter } from "react-router-dom"; -import moment from "moment" +import moment from "moment"; dayjs.locale("ru"); moment.locale("ru"); diff --git a/src/pages/QuizAnswersPage/CardAnswer.tsx b/src/pages/QuizAnswersPage/CardAnswer.tsx index 138a8cde..b599253e 100644 --- a/src/pages/QuizAnswersPage/CardAnswer.tsx +++ b/src/pages/QuizAnswersPage/CardAnswer.tsx @@ -17,8 +17,10 @@ import { DeleteIcon } from "@icons/questionsPage/deleteIcon"; import homeImg from "./images/home.png"; import videoFrame from "./images/videoFrame.png"; import { EyeIcon } from "./icons/EyeIcon"; -import { deleteResult } from "@root/results/actions"; +import { deleteResult, obsolescenceResult } from "@root/results/actions"; import { resultApi } from "@api/result"; +import { useQuizStore } from "@root/quizes/store"; +import { useQuestionsStore } from "@root/questions/store"; interface Props { isNew: boolean; @@ -29,7 +31,7 @@ interface Props { name?: string; phone?: string; email?: string; - onLossNew: (id: string) => void; + onLossNew?: (id: string) => void; } export const CardAnswer = ({ @@ -47,11 +49,17 @@ export const CardAnswer = ({ const theme = useTheme(); const isTablet = useMediaQuery(theme.breakpoints.down(1000)); const [resultsAnswer, setResultsAnswer] = useState([]); - + const { editQuizId } = useQuizStore(); + const { questions } = useQuestionsStore(); + console.log(questions); + // console.log(questions[0].backendId) + // console.log(questions[1].backendId) + // console.log(questions[2].backendId) + // console.log(questions[3].backendId) return ( { - if (isNew) onLossNew(idResult); + obsolescenceResult(idResult, editQuizId); }} sx={{ borderRadius: "12px", @@ -121,8 +129,9 @@ export const CardAnswer = ({ let resAnswer = await resultApi.getAnswerList( Number(idResult), ); + resAnswer = resAnswer.filter((res) => res.Result !== true); setResultsAnswer(resAnswer); - console.log("тут хранятся ответы", resultsAnswer); + console.log("тут хранятся ответы", resAnswer); } }} > @@ -319,102 +328,22 @@ export const CardAnswer = ({ mt: "20px", }} > - - - 1. - - - Ответ на 1 вопрос - - - - - 2. - - - - - - 3. - - - ответ.doc - - - - - 4. - - - Ответ на 4 вопрос - - - - - 5. - - - Ответ на 5 вопрос - - - - - 6. - - - Ответ на 6 вопрос - - - + {resultsAnswer.map((answer, id) => { + console.log(answer.QuizId); - - - - 7. - - - Ответ на 7 вопрос - - - - - - 8. - - - Ответ на 8 вопрос - - - - - 9. - - - Ответ на 9 вопрос - - - - - 10. - - - + return ( + + + {id + 1}. + + + {answer.content} + + + ); + })} diff --git a/src/pages/QuizAnswersPage/QuizAnswersPage.tsx b/src/pages/QuizAnswersPage/QuizAnswersPage.tsx index dbbb46a7..14012e2f 100644 --- a/src/pages/QuizAnswersPage/QuizAnswersPage.tsx +++ b/src/pages/QuizAnswersPage/QuizAnswersPage.tsx @@ -3,78 +3,88 @@ import { Button, IconButton, Typography, + Select as MuiSelect, + MenuItem, useTheme, useMediaQuery, Skeleton, + FormControl, + Select, } from "@mui/material"; -import moment from "moment" +import moment from "moment"; import HeaderFull from "@ui_kit/Header/HeaderFull"; import SectionWrapper from "@ui_kit/SectionWrapper"; import { FC, useEffect, useState } from "react"; import { FileExportIcon } from "./icons/FileExporIcon"; import { UpdateIcon } from "./icons/UpdateIcon"; -import { Select } from "../../pages/Questions/Select"; +// import { Select } from "../../pages/Questions/Select"; import { CheckboxSelect } from "../../ui_kit/CheckboxSelect"; import { CardAnswer } from "./CardAnswer"; import { FilterIcon } from "./icons/FilterIcon"; import { FilterModal } from "@ui_kit/Modal/FilterModal/FilterModal"; import { ExportContactsModal } from "@ui_kit/Modal/ExportContactsModal"; -import { - AnswerResultListEx, - getResultsList, - obsolescenceResult, - resultApi, -} from "@api/result"; +import { resultApi } from "@api/result"; import { useObsolescenceIdResult, useResultStore } from "@root/results/store"; -import { setResults } from "@root/results/actions"; +import { answerResultListExport, setResults } from "@root/results/actions"; import { quizApi } from "@api/quiz"; import { setQuizes } from "@root/quizes/actions"; import { useCurrentQuiz, useQuizes } from "@root/quizes/hooks"; import { useQuizStore } from "@root/quizes/store"; +import { questionApi } from "@api/question"; +import { setQuestions } from "@root/questions/actions"; +import ArrowDown from "@icons/ArrowDownIcon"; const options = [ { label: "Муром (1)", value: "option1" }, { label: "Москва (1)", value: "option2" }, ]; -let lossDebouncer: null | ReturnType = null; -let lossId: string[] = [] as string[]; +const itemsTime = [ + "За все время", + "Сегодня", + "Вчера", + "Последние 7 дней", + "Последние 30 дней", + "Этот месяц", +]; -const onLossNew = (id: string) => { - //Если в массиве ещё нет такого id - добавляем - if (!lossId.includes(id)) lossId.push(id); - //Если таймер есть - сбрасываем - if (typeof lossDebouncer === "number") clearTimeout(lossDebouncer); - //Назначем новый таймер - lossDebouncer = setTimeout(async () => { - //стреляем на лишение новизны - await obsolescenceResult(lossId); - //сбрасываем массив - lossId = []; - }, 3000); +// let lossDebouncer: null | ReturnType = null; +// let lossId: string[] = [] as string[]; +// +// const onLossNew = (id: string) => { +// //Если в массиве ещё нет такого id - добавляем +// if (!lossId.includes(id)) lossId.push(id); +// //Если таймер есть - сбрасываем +// if (typeof lossDebouncer === "number") clearTimeout(lossDebouncer); +// //Назначем новый таймер +// lossDebouncer = setTimeout(async () => { +// //стреляем на лишение новизны +// await obsolescenceResult(lossId); +// //сбрасываем массив +// lossId = []; +// }, 3000); +// }; + +const resetTime = (date: number) => { + console.log(date); + let a = Math.round(date / 86400) * 86400 - 97200; + console.log(a); + console.log(moment.unix(a).format("dddd, MMMM Do YYYY, h:mm:ss ")); + return moment.unix(a).format("dddd, MMMM Do YYYY, h:mm:ss "); }; -const resetTime = (date:number) => { - console.log(date) - let a = Math.round(date / 86400) * 86400 - 97200 - console.log(a) - console.log(moment.unix(a).format("dddd, MMMM Do YYYY, h:mm:ss ")) - return(moment.unix(a).format("dddd, MMMM Do YYYY, h:mm:ss ")) -} - - - export const QuizAnswersPage: FC = () => { const theme = useTheme(); const isTablet = useMediaQuery(theme.breakpoints.down(1000)); const isMobile = useMediaQuery(theme.breakpoints.down(600)); const [filterModalOpen, setFilterModalOpen] = useState(false); - const [exportContactsModalOpen, setExportContactsModalOpen] = useState(false); - const [filterNew, setFilterNew] = useState("Все заявки") - const [filterDate, setFilterDate] = useState("За всё время") + const [exportContactsModalOpen, setExportContactsModalOpen] = + useState(false); + const [filterNew, setFilterNew] = useState("Все заявки"); + const [filterDate, setFilterDate] = useState("За все время"); const quizList = useQuizStore(); const quiz = useCurrentQuiz(); @@ -82,13 +92,15 @@ export const QuizAnswersPage: FC = () => { const { results } = useResultStore(); const { total_count } = useResultStore(); // const {idResultArray, addIdResult, clearIdResultArray} = useObsolescenceIdResult() - useEffect(() => { const getData = async () => { if (editQuizId !== null) { const quizes = await quizApi.getList(); setQuizes(quizes); + const questions = await questionApi.getList({ quiz_id: editQuizId }); + setQuestions(questions); + const result = await resultApi.getList(editQuizId); setResults(result); } @@ -166,34 +178,9 @@ export const QuizAnswersPage: FC = () => { > { - //setExportContactsModalOpen(true) - const resAnswer = await AnswerResultListEx(quizList.editQuizId) - console.log("ответы респондентов на экспорт по клику", resAnswer) - const download = function () { - - // Creating a Blob for having a csv file format - // and passing the data with type - const blob = new Blob([resAnswer], { type: 'text/csv' }); - - - // Creating an object for downloading url - const url = window.URL.createObjectURL(blob) - - // Creating an anchor(a) tag of HTML - const a = document.createElement('a') - - // Passing the blob downloading url - a.setAttribute('href', url) - - // Setting the anchor tag attribute for downloading - // and passing the download file name - a.setAttribute('download', 'download.csv'); - - // Performing a download with click - a.click() - } - download() + onClick={() => { + // answerResultListExport(editQuizId) + setExportContactsModalOpen(true); }} sx={{ width: "44px", @@ -246,23 +233,154 @@ export const QuizAnswersPage: FC = () => { justifyContent: "flex-end", }} > - + + + - + > + + {/* { /> */}