fix wrong types

This commit is contained in:
nflnkr 2023-10-13 15:09:05 +03:00
parent 4b6ae87e05
commit d8fca6a339
5 changed files with 15 additions and 9 deletions

@ -1,8 +1,8 @@
import type { QuizQuestionBase } from "../model/questionTypes/shared";
import type { QuizQuestionInitial } from "../model/questionTypes/shared";
export const QUIZ_QUESTION_BASE: Omit<QuizQuestionBase, "id"> = {
export const QUIZ_QUESTION_BASE: Omit<QuizQuestionInitial, "id"> = {
title: "",
type: "",
type: "nonselected",
expanded: false,
required: false,
deleted: false,

@ -54,6 +54,10 @@ export interface QuizQuestionBase {
};
}
export interface QuizQuestionInitial extends QuizQuestionBase {
type: "nonselected";
}
export type AnyQuizQuestion =
| QuizQuestionVariant
| QuizQuestionImages
@ -66,6 +70,8 @@ export type AnyQuizQuestion =
| QuizQuestionFile
| QuizQuestionPage
| QuizQuestionRating
| QuizQuestionBase;
| QuizQuestionInitial;
export type QuizQuestionType = AnyQuizQuestion["type"];
export type DefiniteQuestionType = Exclude<QuizQuestionType, "nonselected">;

@ -415,7 +415,7 @@ export default function QuestionsPageCard({
}}
>
<Box
onClick={() => createQuestion(quizId, "", totalIndex + 1)}
onClick={() => createQuestion(quizId, "nonselected", totalIndex + 1)}
sx={{
display: plusVisible && !isDragging ? "flex" : "none",
width: "100%",

@ -117,7 +117,7 @@ export const updateVariants = (
export const createQuestion = (
quizId: number,
questionType: QuizQuestionType = "",
questionType: QuizQuestionType = "nonselected",
placeIndex = -1
) => {
const id = getRandom(1000000, 10000000);

@ -1,7 +1,7 @@
import { Box, Button, LinearProgress, Paper, Typography } from "@mui/material";
import { questionStore } from "@root/questions";
import { decrementCurrentQuestionIndex, incrementCurrentQuestionIndex, useQuizPreviewStore } from "@root/quizPreview";
import { AnyQuizQuestion, QuizQuestionType } from "model/questionTypes/shared";
import { AnyQuizQuestion, DefiniteQuestionType } from "model/questionTypes/shared";
import { FC, useEffect } from "react";
import { useParams } from "react-router-dom";
import ArrowLeft from "../../assets/icons/questionsPage/arrowLeft";
@ -18,7 +18,7 @@ import Variant from "./QuizPreviewQuestionTypes/Variant";
import Varimg from "./QuizPreviewQuestionTypes/Varimg";
const QuestionPreviewComponentByType: Record<QuizQuestionType, FC<any>> = {
const QuestionPreviewComponentByType: Record<DefiniteQuestionType, FC<any>> = {
variant: Variant,
images: Images,
varimg: Varimg,
@ -44,7 +44,7 @@ export default function QuizPreviewLayout() {
const currentQuestion = nonDeletedQuizQuestions[currentQuizStep];
const QuestionComponent = currentQuestion
? QuestionPreviewComponentByType[currentQuestion.type as QuizQuestionType]
? QuestionPreviewComponentByType[currentQuestion.type as DefiniteQuestionType]
: null;
const questionElement = QuestionComponent