diff --git a/src/App.tsx b/src/App.tsx index 20a522ae..825ef5c9 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -11,8 +11,8 @@ import ContactFormPage from "./pages/ContactFormPage/ContactFormPage"; import InstallQuiz from "./pages/InstallQuiz/InstallQuiz"; import Landing from "./pages/Landing/Landing"; import QuestionsPage from "./pages/Questions/QuestionsPage"; -import { Result } from "./pages/Result/Result"; -import { Setting } from "./pages/Result/Setting"; +import { Result } from "./pages/ResultPage/Result"; +import { Setting } from "./pages/ResultPage/Setting"; import MyQuizzesFull from "./pages/createQuize/MyQuizzesFull"; import Main from "./pages/main"; import StartPage from "./pages/startPage/StartPage"; diff --git a/src/constants/default.ts b/src/constants/default.ts index 648b0b08..f3bcd489 100644 --- a/src/constants/default.ts +++ b/src/constants/default.ts @@ -11,6 +11,7 @@ import { QUIZ_QUESTION_SELECT } from "./select"; import { QUIZ_QUESTION_TEXT } from "./text"; import { QUIZ_QUESTION_VARIANT } from "./variant"; import { QUIZ_QUESTION_VARIMG } from "./varimg"; +import { QUIZ_QUESTION_RESULT } from "./result"; export const defaultQuestionByType: Record> = { @@ -25,4 +26,5 @@ export const defaultQuestionByType: Record = { + ...QUIZ_QUESTION_BASE, + type: "result", + content: { + ...QUIZ_QUESTION_BASE.content, + multi: false, + own: false, + innerNameCheck: false, + innerName: "", + required: false, + variants: [ + { + id: nanoid(), + answer: "", + extendedText: "", + hints: "", + originalImageUrl: "", + }, + ], + }, +}; diff --git a/src/model/question/question.ts b/src/model/question/question.ts index 6601cba3..0a619426 100644 --- a/src/model/question/question.ts +++ b/src/model/question/question.ts @@ -14,7 +14,8 @@ export type QuestionType = | "number" | "file" | "page" - | "rating"; + | "rating" + | "result"; /** Type that comes from server */ export interface RawQuestion { diff --git a/src/model/questionTypes/result.ts b/src/model/questionTypes/result.ts new file mode 100644 index 00000000..6c1f4536 --- /dev/null +++ b/src/model/questionTypes/result.ts @@ -0,0 +1,29 @@ +import type { + QuizQuestionBase, + QuestionVariant, + QuestionHint, + PreviewRule, +} from "./shared"; + +export interface QuizQuestionResult extends QuizQuestionBase { + type: "result"; + content: { + id: string; + /** Чекбокс "Можно несколько" */ + multi: boolean; + /** Чекбокс "Вариант "свой ответ"" */ + own: boolean; + /** Чекбокс "Внутреннее название вопроса" */ + innerNameCheck: boolean; + /** Поле "Внутреннее название вопроса" */ + innerName: string; + /** Чекбокс "Необязательный вопрос" */ + required: boolean; + variants: QuestionVariant[]; + hint: QuestionHint; + rule: PreviewRule; + back: string; + originalBack: string; + autofill: boolean; + }; +} diff --git a/src/pages/Questions/QuestionsPage.tsx b/src/pages/Questions/QuestionsPage.tsx index 54235391..84476a06 100755 --- a/src/pages/Questions/QuestionsPage.tsx +++ b/src/pages/Questions/QuestionsPage.tsx @@ -22,10 +22,10 @@ import { updateOpenBranchingPanel, updateEditSomeQuestion } from "@root/question export default function QuestionsPage() { const theme = useTheme(); - const { openedModalSettingsId } = useQuestionsStore(); + const { openedModalSettingsId, openBranchingPanel } = useQuestionsStore(); const isMobile = useMediaQuery(theme.breakpoints.down(660)); const quiz = useCurrentQuiz(); - const {openBranchingPanel} = useQuestionsStore.getState() + console.log(quiz) useLayoutEffect(() => { updateOpenBranchingPanel(false) updateEditSomeQuestion() diff --git a/src/pages/Result/DescriptionForm/ButtinsOptionsForm.tsx b/src/pages/ResultPage/DescriptionForm/ButtinsOptionsForm.tsx similarity index 100% rename from src/pages/Result/DescriptionForm/ButtinsOptionsForm.tsx rename to src/pages/ResultPage/DescriptionForm/ButtinsOptionsForm.tsx diff --git a/src/pages/Result/DescriptionForm/DescriptionForm.tsx b/src/pages/ResultPage/DescriptionForm/DescriptionForm.tsx similarity index 100% rename from src/pages/Result/DescriptionForm/DescriptionForm.tsx rename to src/pages/ResultPage/DescriptionForm/DescriptionForm.tsx diff --git a/src/pages/Result/DescriptionForm/DiscountButtons.tsx b/src/pages/ResultPage/DescriptionForm/DiscountButtons.tsx similarity index 100% rename from src/pages/Result/DescriptionForm/DiscountButtons.tsx rename to src/pages/ResultPage/DescriptionForm/DiscountButtons.tsx diff --git a/src/pages/Result/DescriptionForm/ImageAndVideoButtons.tsx b/src/pages/ResultPage/DescriptionForm/ImageAndVideoButtons.tsx similarity index 100% rename from src/pages/Result/DescriptionForm/ImageAndVideoButtons.tsx rename to src/pages/ResultPage/DescriptionForm/ImageAndVideoButtons.tsx diff --git a/src/pages/Result/DescriptionForm/PointsQuestions.tsx b/src/pages/ResultPage/DescriptionForm/PointsQuestions.tsx similarity index 100% rename from src/pages/Result/DescriptionForm/PointsQuestions.tsx rename to src/pages/ResultPage/DescriptionForm/PointsQuestions.tsx diff --git a/src/pages/Result/DescriptionForm/PriceButton.tsx b/src/pages/ResultPage/DescriptionForm/PriceButton.tsx similarity index 100% rename from src/pages/Result/DescriptionForm/PriceButton.tsx rename to src/pages/ResultPage/DescriptionForm/PriceButton.tsx diff --git a/src/pages/Result/DescriptionForm/StarIconsPoints.tsx b/src/pages/ResultPage/DescriptionForm/StarIconsPoints.tsx similarity index 100% rename from src/pages/Result/DescriptionForm/StarIconsPoints.tsx rename to src/pages/ResultPage/DescriptionForm/StarIconsPoints.tsx diff --git a/src/pages/Result/DescriptionForm/SwitchResult.tsx b/src/pages/ResultPage/DescriptionForm/SwitchResult.tsx similarity index 100% rename from src/pages/Result/DescriptionForm/SwitchResult.tsx rename to src/pages/ResultPage/DescriptionForm/SwitchResult.tsx diff --git a/src/pages/Result/CreationFullCard.tsx b/src/pages/ResultPage/FirstEntry.tsx similarity index 100% rename from src/pages/Result/CreationFullCard.tsx rename to src/pages/ResultPage/FirstEntry.tsx diff --git a/src/pages/Result/Result.tsx b/src/pages/ResultPage/Result.tsx similarity index 97% rename from src/pages/Result/Result.tsx rename to src/pages/ResultPage/Result.tsx index 5fc0b076..a414e15d 100644 --- a/src/pages/Result/Result.tsx +++ b/src/pages/ResultPage/Result.tsx @@ -3,7 +3,7 @@ import { updateQuiz } from "@root/quizes/actions"; import { useCurrentQuiz } from "@root/quizes/hooks"; import image from "../../assets/Rectangle 110.png"; import Info from "../../assets/icons/Info"; -import CreationFullCard from "./CreationFullCard"; +import CreationFullCard from "./FirstEntry"; export const Result = () => { diff --git a/src/pages/Result/ResultListForm.tsx b/src/pages/ResultPage/ResultListForm.tsx similarity index 100% rename from src/pages/Result/ResultListForm.tsx rename to src/pages/ResultPage/ResultListForm.tsx diff --git a/src/pages/ResultPage/ResultPage.tsx b/src/pages/ResultPage/ResultPage.tsx new file mode 100644 index 00000000..61e7f595 --- /dev/null +++ b/src/pages/ResultPage/ResultPage.tsx @@ -0,0 +1,19 @@ +import { useQuestionsStore } from "@root/questions/store"; +import FirstEntry from "./FirstEntry" + + +export default function ResultPage() { + const { questions } = useQuestionsStore(); + //ищём хотя бы один result + const haveResult = questions.some((question) => { + question.type === "result" + }) + + + + return ( + <> + + + ); +} \ No newline at end of file diff --git a/src/pages/Result/Setting.tsx b/src/pages/ResultPage/Setting.tsx similarity index 100% rename from src/pages/Result/Setting.tsx rename to src/pages/ResultPage/Setting.tsx diff --git a/src/pages/Result/SettingForm.tsx b/src/pages/ResultPage/SettingForm.tsx similarity index 100% rename from src/pages/Result/SettingForm.tsx rename to src/pages/ResultPage/SettingForm.tsx diff --git a/src/pages/Result/SwichResult.tsx b/src/pages/ResultPage/SwichResult.tsx similarity index 100% rename from src/pages/Result/SwichResult.tsx rename to src/pages/ResultPage/SwichResult.tsx diff --git a/src/stores/questions/actions.ts b/src/stores/questions/actions.ts index 58774ba9..dc29751d 100644 --- a/src/stores/questions/actions.ts +++ b/src/stores/questions/actions.ts @@ -471,3 +471,61 @@ export const clearDesireToOpenABranchingModal = () => { export const updateEditSomeQuestion = (contentId?: string) => { useQuestionsStore.setState({ editSomeQuestion: contentId === undefined ? null : contentId }) } + +export const createFrontResult = (quizId: number) => setProducedState(state => { + state.questions.push({ + id: nanoid(), + quizId, + type: "result", + title: "", + description: "", + deleted: false, + expanded: true, + }); +}, { + type: "createFrontResult", + quizId, +}); + + +export const createBackResult = async ( + questionId: string, + type: QuestionType, +) => requestQueue.enqueue(async () => { + const question = useQuestionsStore.getState().questions.find(q => q.id === questionId); + if (!question) return; + if (question.type !== null) throw new Error("Cannot upgrade already typed question"); + + try { + const createdQuestion = await questionApi.create({ + quiz_id: question.quizId, + type, + title: question.title, + description: question.description, + page: 0, + required: true, + content: JSON.stringify(defaultQuestionByType[type].content), + }); + + setProducedState(state => { + const questionIndex = state.questions.findIndex(q => q.id === questionId); + if (questionIndex !== -1) state.questions.splice( + questionIndex, + 1, + rawQuestionToQuestion(createdQuestion) + ); + }, { + type: "createTypedQuestion", + question, + }); + } catch (error) { + devlog("Error creating question", error); + enqueueSnackbar("Не удалось создать вопрос"); + } +}); + +export const updateResult = () => { + +} + + diff --git a/src/ui_kit/switchStepPages.tsx b/src/ui_kit/switchStepPages.tsx index 87662b25..99d5aa80 100755 --- a/src/ui_kit/switchStepPages.tsx +++ b/src/ui_kit/switchStepPages.tsx @@ -4,8 +4,8 @@ import InstallQuiz from "../pages/InstallQuiz/InstallQuiz"; import FormQuestionsPage from "../pages/Questions/Form/FormQuestionsPage"; import QuestionsPage from "../pages/Questions/QuestionsPage"; import { QuestionsMap } from "../pages/QuestionsMap"; -import { Result } from "../pages/Result/Result"; -import { Setting } from "../pages/Result/Setting"; +import { Result } from "../pages/ResultPage/Result"; +import { Setting } from "../pages/ResultPage/Setting"; import StartPageSettings from "../pages/startPage/StartPageSettings"; import StepOne from "../pages/startPage/stepOne"; import Steptwo from "../pages/startPage/steptwo";