--
This commit is contained in:
parent
1eca4195c5
commit
83610dba8d
@ -11,8 +11,8 @@ import ContactFormPage from "./pages/ContactFormPage/ContactFormPage";
|
|||||||
import InstallQuiz from "./pages/InstallQuiz/InstallQuiz";
|
import InstallQuiz from "./pages/InstallQuiz/InstallQuiz";
|
||||||
import Landing from "./pages/Landing/Landing";
|
import Landing from "./pages/Landing/Landing";
|
||||||
import QuestionsPage from "./pages/Questions/QuestionsPage";
|
import QuestionsPage from "./pages/Questions/QuestionsPage";
|
||||||
import { Result } from "./pages/Result/Result";
|
import { Result } from "./pages/ResultPage/Result";
|
||||||
import { Setting } from "./pages/Result/Setting";
|
import { Setting } from "./pages/ResultPage/Setting";
|
||||||
import MyQuizzesFull from "./pages/createQuize/MyQuizzesFull";
|
import MyQuizzesFull from "./pages/createQuize/MyQuizzesFull";
|
||||||
import Main from "./pages/main";
|
import Main from "./pages/main";
|
||||||
import StartPage from "./pages/startPage/StartPage";
|
import StartPage from "./pages/startPage/StartPage";
|
||||||
|
@ -11,6 +11,7 @@ import { QUIZ_QUESTION_SELECT } from "./select";
|
|||||||
import { QUIZ_QUESTION_TEXT } from "./text";
|
import { QUIZ_QUESTION_TEXT } from "./text";
|
||||||
import { QUIZ_QUESTION_VARIANT } from "./variant";
|
import { QUIZ_QUESTION_VARIANT } from "./variant";
|
||||||
import { QUIZ_QUESTION_VARIMG } from "./varimg";
|
import { QUIZ_QUESTION_VARIMG } from "./varimg";
|
||||||
|
import { QUIZ_QUESTION_RESULT } from "./result";
|
||||||
|
|
||||||
|
|
||||||
export const defaultQuestionByType: Record<QuestionType, Omit<AnyTypedQuizQuestion, "id" | "backendId">> = {
|
export const defaultQuestionByType: Record<QuestionType, Omit<AnyTypedQuizQuestion, "id" | "backendId">> = {
|
||||||
@ -25,4 +26,5 @@ export const defaultQuestionByType: Record<QuestionType, Omit<AnyTypedQuizQuesti
|
|||||||
"text": QUIZ_QUESTION_TEXT,
|
"text": QUIZ_QUESTION_TEXT,
|
||||||
"variant": QUIZ_QUESTION_VARIANT,
|
"variant": QUIZ_QUESTION_VARIANT,
|
||||||
"varimg": QUIZ_QUESTION_VARIMG,
|
"varimg": QUIZ_QUESTION_VARIMG,
|
||||||
|
"result": QUIZ_QUESTION_RESULT,
|
||||||
} as const;
|
} as const;
|
||||||
|
26
src/constants/result.ts
Normal file
26
src/constants/result.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import { QUIZ_QUESTION_BASE } from "./base";
|
||||||
|
|
||||||
|
import type { QuizQuestionResult } from "../model/questionTypes/result";
|
||||||
|
import { nanoid } from "nanoid";
|
||||||
|
|
||||||
|
export const QUIZ_QUESTION_RESULT: Omit<QuizQuestionResult, "id" | "backendId"> = {
|
||||||
|
...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: "",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
@ -14,7 +14,8 @@ export type QuestionType =
|
|||||||
| "number"
|
| "number"
|
||||||
| "file"
|
| "file"
|
||||||
| "page"
|
| "page"
|
||||||
| "rating";
|
| "rating"
|
||||||
|
| "result";
|
||||||
|
|
||||||
/** Type that comes from server */
|
/** Type that comes from server */
|
||||||
export interface RawQuestion {
|
export interface RawQuestion {
|
||||||
|
29
src/model/questionTypes/result.ts
Normal file
29
src/model/questionTypes/result.ts
Normal file
@ -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;
|
||||||
|
};
|
||||||
|
}
|
@ -22,10 +22,10 @@ import { updateOpenBranchingPanel, updateEditSomeQuestion } from "@root/question
|
|||||||
|
|
||||||
export default function QuestionsPage() {
|
export default function QuestionsPage() {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { openedModalSettingsId } = useQuestionsStore();
|
const { openedModalSettingsId, openBranchingPanel } = useQuestionsStore();
|
||||||
const isMobile = useMediaQuery(theme.breakpoints.down(660));
|
const isMobile = useMediaQuery(theme.breakpoints.down(660));
|
||||||
const quiz = useCurrentQuiz();
|
const quiz = useCurrentQuiz();
|
||||||
const {openBranchingPanel} = useQuestionsStore.getState()
|
console.log(quiz)
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
updateOpenBranchingPanel(false)
|
updateOpenBranchingPanel(false)
|
||||||
updateEditSomeQuestion()
|
updateEditSomeQuestion()
|
||||||
|
@ -3,7 +3,7 @@ import { updateQuiz } from "@root/quizes/actions";
|
|||||||
import { useCurrentQuiz } from "@root/quizes/hooks";
|
import { useCurrentQuiz } from "@root/quizes/hooks";
|
||||||
import image from "../../assets/Rectangle 110.png";
|
import image from "../../assets/Rectangle 110.png";
|
||||||
import Info from "../../assets/icons/Info";
|
import Info from "../../assets/icons/Info";
|
||||||
import CreationFullCard from "./CreationFullCard";
|
import CreationFullCard from "./FirstEntry";
|
||||||
|
|
||||||
|
|
||||||
export const Result = () => {
|
export const Result = () => {
|
19
src/pages/ResultPage/ResultPage.tsx
Normal file
19
src/pages/ResultPage/ResultPage.tsx
Normal file
@ -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 (
|
||||||
|
<>
|
||||||
|
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
@ -471,3 +471,61 @@ export const clearDesireToOpenABranchingModal = () => {
|
|||||||
export const updateEditSomeQuestion = (contentId?: string) => {
|
export const updateEditSomeQuestion = (contentId?: string) => {
|
||||||
useQuestionsStore.setState({ editSomeQuestion: contentId === undefined ? null : contentId })
|
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 = () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@ import InstallQuiz from "../pages/InstallQuiz/InstallQuiz";
|
|||||||
import FormQuestionsPage from "../pages/Questions/Form/FormQuestionsPage";
|
import FormQuestionsPage from "../pages/Questions/Form/FormQuestionsPage";
|
||||||
import QuestionsPage from "../pages/Questions/QuestionsPage";
|
import QuestionsPage from "../pages/Questions/QuestionsPage";
|
||||||
import { QuestionsMap } from "../pages/QuestionsMap";
|
import { QuestionsMap } from "../pages/QuestionsMap";
|
||||||
import { Result } from "../pages/Result/Result";
|
import { Result } from "../pages/ResultPage/Result";
|
||||||
import { Setting } from "../pages/Result/Setting";
|
import { Setting } from "../pages/ResultPage/Setting";
|
||||||
import StartPageSettings from "../pages/startPage/StartPageSettings";
|
import StartPageSettings from "../pages/startPage/StartPageSettings";
|
||||||
import StepOne from "../pages/startPage/stepOne";
|
import StepOne from "../pages/startPage/stepOne";
|
||||||
import Steptwo from "../pages/startPage/steptwo";
|
import Steptwo from "../pages/startPage/steptwo";
|
||||||
|
Loading…
Reference in New Issue
Block a user