Merge branch 'server-empty-strings' into dev
This commit is contained in:
commit
336427349b
@ -5,6 +5,7 @@ import { GetQuestionListRequest, GetQuestionListResponse } from "@model/question
|
|||||||
import { EditQuestionRequest, EditQuestionResponse } from "@model/question/edit";
|
import { EditQuestionRequest, EditQuestionResponse } from "@model/question/edit";
|
||||||
import { DeleteQuestionRequest, DeleteQuestionResponse } from "@model/question/delete";
|
import { DeleteQuestionRequest, DeleteQuestionResponse } from "@model/question/delete";
|
||||||
import { CopyQuestionRequest, CopyQuestionResponse } from "@model/question/copy";
|
import { CopyQuestionRequest, CopyQuestionResponse } from "@model/question/copy";
|
||||||
|
import { replaceSpacesToEmptyLines } from "../utils/replaceSpacesToEmptyLines";
|
||||||
|
|
||||||
|
|
||||||
const baseUrl = process.env.NODE_ENV === "production" ? "/squiz" : "https://squiz.pena.digital/squiz";
|
const baseUrl = process.env.NODE_ENV === "production" ? "/squiz" : "https://squiz.pena.digital/squiz";
|
||||||
@ -26,7 +27,7 @@ async function getQuestionList(body?: Partial<GetQuestionListRequest>) {
|
|||||||
method: "POST",
|
method: "POST",
|
||||||
});
|
});
|
||||||
|
|
||||||
return response.items;
|
return replaceSpacesToEmptyLines(response.items);
|
||||||
}
|
}
|
||||||
|
|
||||||
function editQuestion(body: EditQuestionRequest, signal?: AbortSignal) {
|
function editQuestion(body: EditQuestionRequest, signal?: AbortSignal) {
|
||||||
|
|||||||
@ -5,9 +5,9 @@ import { useCurrentQuiz } from "@root/quizes/hooks";
|
|||||||
import { useQuestionsStore } from "@root/questions/store";
|
import { useQuestionsStore } from "@root/questions/store";
|
||||||
|
|
||||||
import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared";
|
import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared";
|
||||||
import YoutubeEmbedIframe from "../../ui_kit/StartPagePreview/YoutubeEmbedIframe.tsx"
|
import YoutubeEmbedIframe from "../../ui_kit/StartPagePreview/YoutubeEmbedIframe.tsx";
|
||||||
import { NameplateLogo } from "@icons/NameplateLogo";
|
import { NameplateLogo } from "@icons/NameplateLogo";
|
||||||
import {modes} from "../../utils/themes/Publication/themePublication";
|
import { modes } from "../../utils/themes/Publication/themePublication";
|
||||||
|
|
||||||
type ResultFormProps = {
|
type ResultFormProps = {
|
||||||
currentQuestion: AnyTypedQuizQuestion;
|
currentQuestion: AnyTypedQuizQuestion;
|
||||||
@ -21,25 +21,25 @@ export const ResultForm = ({
|
|||||||
showContactForm,
|
showContactForm,
|
||||||
setShowContactForm,
|
setShowContactForm,
|
||||||
setShowResultForm,
|
setShowResultForm,
|
||||||
|
|
||||||
}: ResultFormProps) => {
|
}: ResultFormProps) => {
|
||||||
const quiz = useCurrentQuiz();
|
const quiz = useCurrentQuiz();
|
||||||
const mode = modes;
|
const mode = modes;
|
||||||
const { questions } = useQuestionsStore();
|
const { questions } = useQuestionsStore();
|
||||||
const resultQuestion = questions.find(
|
const resultQuestion = (questions.find(
|
||||||
(question) =>
|
(question) =>
|
||||||
question.type === "result" &&
|
question.type === "result" &&
|
||||||
(question.content.rule.parentId === "line" || currentQuestion.content.id)
|
question.content.rule.parentId === currentQuestion.content.id
|
||||||
);
|
) ||
|
||||||
|
questions.find(
|
||||||
|
(question) =>
|
||||||
|
question.type === "result" && question.content.rule.parentId === "line"
|
||||||
|
)) as AnyTypedQuizQuestion;
|
||||||
|
|
||||||
const followNextForm = () => {
|
const followNextForm = () => {
|
||||||
setShowResultForm(false);
|
setShowResultForm(false);
|
||||||
setShowContactForm(true);
|
setShowContactForm(true);
|
||||||
};
|
};
|
||||||
if (resultQuestion === undefined) return <></>
|
if (resultQuestion === undefined) return <></>;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
@ -50,10 +50,9 @@ export const ResultForm = ({
|
|||||||
justifyContent: "space-between",
|
justifyContent: "space-between",
|
||||||
height: "100vh",
|
height: "100vh",
|
||||||
width: "100vw",
|
width: "100vw",
|
||||||
pt: "28px"
|
pt: "28px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
@ -62,53 +61,57 @@ export const ResultForm = ({
|
|||||||
width: "490px",
|
width: "490px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{
|
{!resultQuestion?.content.useImage && resultQuestion.content.video && (
|
||||||
!resultQuestion?.content.useImage &&
|
|
||||||
resultQuestion.content.video &&
|
|
||||||
<YoutubeEmbedIframe
|
<YoutubeEmbedIframe
|
||||||
videoUrl={resultQuestion.content.video}
|
videoUrl={resultQuestion.content.video}
|
||||||
containerSX={{
|
containerSX={{
|
||||||
width: "490px",
|
width: "490px",
|
||||||
height: "280px"
|
height: "280px",
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
}
|
)}
|
||||||
{
|
{resultQuestion?.content.useImage && resultQuestion.content.back && (
|
||||||
resultQuestion?.content.useImage &&
|
|
||||||
resultQuestion.content.back &&
|
|
||||||
<Box
|
<Box
|
||||||
component='img'
|
component="img"
|
||||||
src={resultQuestion.content.back}
|
src={resultQuestion.content.back}
|
||||||
sx={{
|
sx={{
|
||||||
width: "490px",
|
width: "490px",
|
||||||
height: "280px"
|
height: "280px",
|
||||||
}}
|
}}
|
||||||
>
|
></Box>
|
||||||
</Box>
|
)}
|
||||||
}
|
{resultQuestion.description !== "" &&
|
||||||
{resultQuestion.description !== "" && resultQuestion.description !== " " && <Typography
|
resultQuestion.description !== " " && (
|
||||||
sx={{
|
<Typography
|
||||||
fontSize: "23px",
|
sx={{
|
||||||
fontWeight: 700,
|
fontSize: "23px",
|
||||||
m: "20px 0"
|
fontWeight: 700,
|
||||||
}}
|
m: "20px 0",
|
||||||
>{resultQuestion.description}</Typography>}
|
}}
|
||||||
|
>
|
||||||
|
{resultQuestion.description}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
|
||||||
<Typography
|
<Typography
|
||||||
sx={{
|
sx={{
|
||||||
m: "20px 0"
|
m: "20px 0",
|
||||||
}}
|
}}
|
||||||
>{resultQuestion.title || "Форма результатов"}
|
>
|
||||||
|
{resultQuestion.title || "Форма результатов"}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
{resultQuestion.content.text !== "" && resultQuestion.content.text !== " " && <Typography
|
{resultQuestion.content.text !== "" &&
|
||||||
sx={{
|
resultQuestion.content.text !== " " && (
|
||||||
fontSize: "18px",
|
<Typography
|
||||||
m: "20px 0"
|
sx={{
|
||||||
}}
|
fontSize: "18px",
|
||||||
>{resultQuestion.content.text}</Typography>}
|
m: "20px 0",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{resultQuestion.content.text}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<Box width="100%">
|
<Box width="100%">
|
||||||
@ -117,24 +120,30 @@ export const ResultForm = ({
|
|||||||
display: "flex",
|
display: "flex",
|
||||||
width: "100%",
|
width: "100%",
|
||||||
justifyContent: "end",
|
justifyContent: "end",
|
||||||
px: "20px"
|
px: "20px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
mt: "15px"
|
mt: "15px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<NameplateLogo style={{ fontSize: "34px" }} />
|
<NameplateLogo style={{ fontSize: "34px" }} />
|
||||||
<Typography sx={{ fontSize: "20px", color: mode[quiz.config.theme] ? "#4D4D4D" : "#F5F7FF", whiteSpace: "nowrap" }}>Сделано на PenaQuiz</Typography>
|
<Typography
|
||||||
|
sx={{
|
||||||
|
fontSize: "20px",
|
||||||
|
color: mode[quiz.config.theme] ? "#4D4D4D" : "#F5F7FF",
|
||||||
|
whiteSpace: "nowrap",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Сделано на PenaQuiz
|
||||||
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
{
|
{quiz?.config.resultInfo.when === "before" && (
|
||||||
quiz?.config.resultInfo.when === "before" &&
|
|
||||||
<>
|
<>
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
@ -144,7 +153,7 @@ export const ResultForm = ({
|
|||||||
display: "flex",
|
display: "flex",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
p: "20px"
|
p: "20px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
@ -153,17 +162,15 @@ export const ResultForm = ({
|
|||||||
sx={{
|
sx={{
|
||||||
p: "10px 20px",
|
p: "10px 20px",
|
||||||
width: "210px",
|
width: "210px",
|
||||||
height: "50px"
|
height: "50px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{resultQuestion.content.hint.text || "Узнать подробнее"}
|
{resultQuestion.content.hint.text || "Узнать подробнее"}
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
</>
|
</>
|
||||||
}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
|
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import { QuestionsStore, useQuestionsStore } from "./store";
|
|||||||
import { useUiTools } from "../uiTools/store";
|
import { useUiTools } from "../uiTools/store";
|
||||||
import { withErrorBoundary } from "react-error-boundary";
|
import { withErrorBoundary } from "react-error-boundary";
|
||||||
import { QuizQuestionResult } from "@model/questionTypes/result";
|
import { QuizQuestionResult } from "@model/questionTypes/result";
|
||||||
|
import { replaceEmptyLinesToSpace } from "../../utils/replaceEmptyLinesToSpace";
|
||||||
|
|
||||||
|
|
||||||
export const setQuestions = (questions: RawQuestion[] | null) => setProducedState(state => {
|
export const setQuestions = (questions: RawQuestion[] | null) => setProducedState(state => {
|
||||||
@ -202,7 +203,7 @@ export const updateQuestion = async <T = AnyTypedQuizQuestion>(
|
|||||||
if (q.type === null) throw new Error("Cannot send update request for untyped question");
|
if (q.type === null) throw new Error("Cannot send update request for untyped question");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await questionApi.edit(questionToEditQuestionRequest(q));
|
const response = await questionApi.edit(questionToEditQuestionRequest(replaceEmptyLinesToSpace(q)));
|
||||||
|
|
||||||
//Если мы делаем листочек веточкой - удаляем созданный к нему результ
|
//Если мы делаем листочек веточкой - удаляем созданный к нему результ
|
||||||
const questionResult = useQuestionsStore.getState().questions.find(questionResult => questionResult.type === "result" && questionResult.content.rule.parentId === q.content.id);
|
const questionResult = useQuestionsStore.getState().questions.find(questionResult => questionResult.type === "result" && questionResult.content.rule.parentId === q.content.id);
|
||||||
|
|||||||
33
src/utils/replaceEmptyLinesToSpace.ts
Normal file
33
src/utils/replaceEmptyLinesToSpace.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
export const replaceEmptyLinesToSpace = <T = unknown>(object: T): T => {
|
||||||
|
if (Array.isArray(object)) {
|
||||||
|
return object.map(replaceEmptyLinesToSpace) as T;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!object || typeof object !== "object") {
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
const result: Record<string, unknown> = {};
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(object)) {
|
||||||
|
if (typeof value === "string") {
|
||||||
|
if (value === "") {
|
||||||
|
result[key] = " ";
|
||||||
|
} else {
|
||||||
|
result[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof value === "object") {
|
||||||
|
result[key] = replaceEmptyLinesToSpace(value);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
result[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result as T;
|
||||||
|
};
|
||||||
29
src/utils/replaceSpacesToEmptyLines.ts
Normal file
29
src/utils/replaceSpacesToEmptyLines.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
export const replaceSpacesToEmptyLines = <T = unknown>(object: T): T => {
|
||||||
|
if (Array.isArray(object)) {
|
||||||
|
return object.map(replaceSpacesToEmptyLines) as T;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!object || typeof object !== "object") {
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
const result: Record<string, unknown> = {};
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(object)) {
|
||||||
|
if (typeof value === "string") {
|
||||||
|
result[key] = value.replace(/ /g, "");
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof value === "object") {
|
||||||
|
result[key] = replaceSpacesToEmptyLines(value);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
result[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result as T;
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue
Block a user