minor fixes
This commit is contained in:
parent
7520000f5b
commit
f3eed84b42
@ -1,9 +1,19 @@
|
|||||||
|
import { DefiniteQuestionType } from "@model/questionTypes/shared";
|
||||||
|
|
||||||
|
|
||||||
export interface CreateQuestionRequest {
|
export interface CreateQuestionRequest {
|
||||||
|
/** id of quiz for what question is creating */
|
||||||
quiz_id: number;
|
quiz_id: number;
|
||||||
title: string;
|
/** title of question. max length 512 */
|
||||||
description: string;
|
title?: string;
|
||||||
type: string;
|
/** description of question. html/text */
|
||||||
required: boolean;
|
description?: string;
|
||||||
page: number;
|
/** type of question. allow only text, select, file, variant, images, varimg, emoji, date, number, page, rating */
|
||||||
content: string;
|
type?: DefiniteQuestionType;
|
||||||
|
/** set true if user MUST answer this question */
|
||||||
|
required?: boolean;
|
||||||
|
/** page of question */
|
||||||
|
page?: number;
|
||||||
|
/** json serialized of question content settings */
|
||||||
|
content?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +1,28 @@
|
|||||||
|
import { Question } from "./question";
|
||||||
|
|
||||||
|
|
||||||
export interface GetQuestionListRequest {
|
export interface GetQuestionListRequest {
|
||||||
limit: number;
|
/** max items on page */
|
||||||
offset: number;
|
limit?: number;
|
||||||
from: number;
|
/** page number */
|
||||||
to: number;
|
offset?: number;
|
||||||
search: string;
|
/** start time of time period. timestamp in seconds */
|
||||||
type: string;
|
from?: number;
|
||||||
deleted: boolean;
|
/** end time of time period. timestamp in seconds */
|
||||||
required: boolean;
|
to?: number;
|
||||||
quiz_id: number;
|
/** string for fulltext search in titles of questions */
|
||||||
|
search?: string;
|
||||||
|
/** allow only - text, select, file, variant, images, varimg, emoji, date, number, page, rating or empty string */
|
||||||
|
type?: string;
|
||||||
|
/** get deleted quizes */
|
||||||
|
deleted?: boolean;
|
||||||
|
/** get only require questions */
|
||||||
|
required?: boolean;
|
||||||
|
/** relation to quiz */
|
||||||
|
quiz_id?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GetQuestionListResponse {
|
export interface GetQuestionListResponse {
|
||||||
count: number;
|
count: number;
|
||||||
items: unknown[]; // TODO
|
items: Question[];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -56,6 +56,7 @@ export interface Quiz {
|
|||||||
group_id: number;
|
group_id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Type that comes from server */
|
||||||
export interface RawQuiz {
|
export interface RawQuiz {
|
||||||
/** Id of created quiz */
|
/** Id of created quiz */
|
||||||
id: number;
|
id: number;
|
||||||
|
|||||||
@ -36,7 +36,7 @@ export default function MyQuizzesFull({
|
|||||||
onError: error => {
|
onError: error => {
|
||||||
const message = isAxiosError<string>(error) ? (error.response?.data ?? "") : "";
|
const message = isAxiosError<string>(error) ? (error.response?.data ?? "") : "";
|
||||||
|
|
||||||
devlog("Error creating quiz", error);
|
devlog("Error getting quiz list", error);
|
||||||
enqueueSnackbar(`Не удалось получить квизы. ${message}`);
|
enqueueSnackbar(`Не удалось получить квизы. ${message}`);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@ -37,7 +37,7 @@ export default function StartPage() {
|
|||||||
onError: error => {
|
onError: error => {
|
||||||
const message = isAxiosError<string>(error) ? (error.response?.data ?? "") : "";
|
const message = isAxiosError<string>(error) ? (error.response?.data ?? "") : "";
|
||||||
|
|
||||||
devlog("Error creating quiz", error);
|
devlog("Error getting quiz list", error);
|
||||||
enqueueSnackbar(`Не удалось получить квизы. ${message}`);
|
enqueueSnackbar(`Не удалось получить квизы. ${message}`);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import { enqueueSnackbar } from "notistack";
|
|||||||
import { NavigateFunction } from "react-router-dom";
|
import { NavigateFunction } from "react-router-dom";
|
||||||
import { QuizStore, useQuizStore } from "./store";
|
import { QuizStore, useQuizStore } from "./store";
|
||||||
import { isAxiosCanceledError } from "../../utils/isAxiosCanceledError";
|
import { isAxiosCanceledError } from "../../utils/isAxiosCanceledError";
|
||||||
|
import { createQuestion } from "@root/questions/actions";
|
||||||
|
|
||||||
|
|
||||||
export const setEditQuizId = (quizId: number | null) => setProducedState(state => {
|
export const setEditQuizId = (quizId: number | null) => setProducedState(state => {
|
||||||
@ -99,37 +100,6 @@ export const setCurrentStep = (step: number) => setProducedState(state => {
|
|||||||
state.currentStep = Math.max(0, Math.min(maxQuizSetupSteps, step)) as QuizSetupStep;
|
state.currentStep = Math.max(0, Math.min(maxQuizSetupSteps, step)) as QuizSetupStep;
|
||||||
});
|
});
|
||||||
|
|
||||||
export const createQuiz = async (navigate: NavigateFunction) => {
|
|
||||||
try {
|
|
||||||
const quiz = await quizApi.create({
|
|
||||||
name: "Quiz name",
|
|
||||||
description: "Quiz description",
|
|
||||||
});
|
|
||||||
|
|
||||||
setQuiz(rawQuizToQuiz(quiz));
|
|
||||||
setEditQuizId(quiz.id);
|
|
||||||
navigate("/edit");
|
|
||||||
} catch (error) {
|
|
||||||
devlog("Error creating quiz", error);
|
|
||||||
|
|
||||||
const message = getMessageFromFetchError(error) ?? "";
|
|
||||||
enqueueSnackbar(`Не удалось создать квиз. ${message}`);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const deleteQuiz = async (quizId: number) => {
|
|
||||||
try {
|
|
||||||
await quizApi.delete(quizId);
|
|
||||||
|
|
||||||
removeQuiz(quizId);
|
|
||||||
} catch (error) {
|
|
||||||
devlog("Error deleting quiz", error);
|
|
||||||
|
|
||||||
const message = getMessageFromFetchError(error) ?? "";
|
|
||||||
enqueueSnackbar(`Не удалось удалить квиз. ${message}`);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const setQuizType = (
|
export const setQuizType = (
|
||||||
quizId: number,
|
quizId: number,
|
||||||
quizType: QuizConfig["type"],
|
quizType: QuizConfig["type"],
|
||||||
@ -177,7 +147,10 @@ export const updateQuizWithFnOptimistic = async (
|
|||||||
|
|
||||||
setQuiz(currentUpdatedQuiz);
|
setQuiz(currentUpdatedQuiz);
|
||||||
try {
|
try {
|
||||||
const { updated: newId } = await quizApi.edit(quizToEditQuizRequest(currentUpdatedQuiz), controller.signal);
|
const { updated: newId } = await quizApi.edit(
|
||||||
|
quizToEditQuizRequest(currentUpdatedQuiz),
|
||||||
|
controller.signal,
|
||||||
|
);
|
||||||
|
|
||||||
setQuizField(quiz.id, "id", newId);
|
setQuizField(quiz.id, "id", newId);
|
||||||
setEditQuizId(newId);
|
setEditQuizId(newId);
|
||||||
@ -203,6 +176,39 @@ export const updateQuizWithFnOptimistic = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const createQuiz = async (navigate: NavigateFunction) => {
|
||||||
|
try {
|
||||||
|
const quiz = await quizApi.create({
|
||||||
|
name: "Quiz name",
|
||||||
|
description: "Quiz description",
|
||||||
|
});
|
||||||
|
|
||||||
|
setQuiz(rawQuizToQuiz(quiz));
|
||||||
|
setEditQuizId(quiz.id);
|
||||||
|
navigate("/edit");
|
||||||
|
|
||||||
|
await createQuestion(quiz.id);
|
||||||
|
} catch (error) {
|
||||||
|
devlog("Error creating quiz", error);
|
||||||
|
|
||||||
|
const message = getMessageFromFetchError(error) ?? "";
|
||||||
|
enqueueSnackbar(`Не удалось создать квиз. ${message}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deleteQuiz = async (quizId: number) => {
|
||||||
|
try {
|
||||||
|
await quizApi.delete(quizId);
|
||||||
|
|
||||||
|
removeQuiz(quizId);
|
||||||
|
} catch (error) {
|
||||||
|
devlog("Error deleting quiz", error);
|
||||||
|
|
||||||
|
const message = getMessageFromFetchError(error) ?? "";
|
||||||
|
enqueueSnackbar(`Не удалось удалить квиз. ${message}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function setProducedState<A extends string | { type: unknown; }>(
|
function setProducedState<A extends string | { type: unknown; }>(
|
||||||
recipe: (state: QuizStore) => void,
|
recipe: (state: QuizStore) => void,
|
||||||
action?: A,
|
action?: A,
|
||||||
|
|||||||
@ -25,7 +25,7 @@ export default function SwitchStepPages({
|
|||||||
case 1: return <StepOne />;
|
case 1: return <StepOne />;
|
||||||
case 2: return <Steptwo />;
|
case 2: return <Steptwo />;
|
||||||
case 3: return <StartPageSettings />;
|
case 3: return <StartPageSettings />;
|
||||||
case 4: return quizType === "form" ? <QuestionsPage /> : <FormQuestionsPage />;
|
case 4: return quizType === "form" ? <FormQuestionsPage /> : <QuestionsPage />;
|
||||||
case 5: return <Result />;
|
case 5: return <Result />;
|
||||||
case 6: return <Setting />;
|
case 6: return <Setting />;
|
||||||
case 7: return <QuestionsMap />;
|
case 7: return <QuestionsMap />;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user