minor fixes
This commit is contained in:
parent
7520000f5b
commit
f3eed84b42
@ -1,9 +1,19 @@
|
||||
import { DefiniteQuestionType } from "@model/questionTypes/shared";
|
||||
|
||||
|
||||
export interface CreateQuestionRequest {
|
||||
/** id of quiz for what question is creating */
|
||||
quiz_id: number;
|
||||
title: string;
|
||||
description: string;
|
||||
type: string;
|
||||
required: boolean;
|
||||
page: number;
|
||||
content: string;
|
||||
/** title of question. max length 512 */
|
||||
title?: string;
|
||||
/** description of question. html/text */
|
||||
description?: string;
|
||||
/** type of question. allow only text, select, file, variant, images, varimg, emoji, date, number, page, rating */
|
||||
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 {
|
||||
limit: number;
|
||||
offset: number;
|
||||
from: number;
|
||||
to: number;
|
||||
search: string;
|
||||
type: string;
|
||||
deleted: boolean;
|
||||
required: boolean;
|
||||
quiz_id: number;
|
||||
/** max items on page */
|
||||
limit?: number;
|
||||
/** page number */
|
||||
offset?: number;
|
||||
/** start time of time period. timestamp in seconds */
|
||||
from?: number;
|
||||
/** end time of time period. timestamp in seconds */
|
||||
to?: 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 {
|
||||
count: number;
|
||||
items: unknown[]; // TODO
|
||||
items: Question[];
|
||||
}
|
||||
|
||||
@ -56,6 +56,7 @@ export interface Quiz {
|
||||
group_id: number;
|
||||
}
|
||||
|
||||
/** Type that comes from server */
|
||||
export interface RawQuiz {
|
||||
/** Id of created quiz */
|
||||
id: number;
|
||||
|
||||
@ -36,7 +36,7 @@ export default function MyQuizzesFull({
|
||||
onError: error => {
|
||||
const message = isAxiosError<string>(error) ? (error.response?.data ?? "") : "";
|
||||
|
||||
devlog("Error creating quiz", error);
|
||||
devlog("Error getting quiz list", error);
|
||||
enqueueSnackbar(`Не удалось получить квизы. ${message}`);
|
||||
},
|
||||
});
|
||||
|
||||
@ -37,7 +37,7 @@ export default function StartPage() {
|
||||
onError: error => {
|
||||
const message = isAxiosError<string>(error) ? (error.response?.data ?? "") : "";
|
||||
|
||||
devlog("Error creating quiz", error);
|
||||
devlog("Error getting quiz list", error);
|
||||
enqueueSnackbar(`Не удалось получить квизы. ${message}`);
|
||||
},
|
||||
});
|
||||
|
||||
@ -8,6 +8,7 @@ import { enqueueSnackbar } from "notistack";
|
||||
import { NavigateFunction } from "react-router-dom";
|
||||
import { QuizStore, useQuizStore } from "./store";
|
||||
import { isAxiosCanceledError } from "../../utils/isAxiosCanceledError";
|
||||
import { createQuestion } from "@root/questions/actions";
|
||||
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
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 = (
|
||||
quizId: number,
|
||||
quizType: QuizConfig["type"],
|
||||
@ -177,7 +147,10 @@ export const updateQuizWithFnOptimistic = async (
|
||||
|
||||
setQuiz(currentUpdatedQuiz);
|
||||
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);
|
||||
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; }>(
|
||||
recipe: (state: QuizStore) => void,
|
||||
action?: A,
|
||||
|
||||
@ -25,7 +25,7 @@ export default function SwitchStepPages({
|
||||
case 1: return <StepOne />;
|
||||
case 2: return <Steptwo />;
|
||||
case 3: return <StartPageSettings />;
|
||||
case 4: return quizType === "form" ? <QuestionsPage /> : <FormQuestionsPage />;
|
||||
case 4: return quizType === "form" ? <FormQuestionsPage /> : <QuestionsPage />;
|
||||
case 5: return <Result />;
|
||||
case 6: return <Setting />;
|
||||
case 7: return <QuestionsMap />;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user